/example/main.go
Go | 39 lines | 32 code | 7 blank | 0 comment | 4 complexity | 61a2e92a62e142cb0d2ec54553a7f05a MD5 | raw file
- package main
- import (
- "fmt"
- "http"
- "flow-go.googlecode.com/hg/flow"
- )
- const flowPath = "/flow"
- var flowMux = flow.NewMux(flowPath)
- func main() {
- http.Handle(flowPath, flowMux)
- http.HandleFunc("/", handler)
- http.ListenAndServe("localhost:8080", nil)
- }
- func handler(w http.ResponseWriter, r *http.Request) {
- if r.URL.Path != "/" {
- http.Error(w, "not found", http.StatusNotFound)
- return
- }
- flowMux.Become(myFlow, w, r)
- }
- func myFlow(c flow.Context) {
- for n := 0; ; n++ {
- rw, _ := c.Next()
- fmt.Fprintf(rw, "n = %d<br>", n)
- if n > 5 {
- fmt.Fprint(rw, "Shutting down")
- break
- }
- fmt.Fprintf(rw, `<a href="%s">Continue</a>`, c.URL())
- }
- c.Close()
- }