~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/bmizerany/pat/example/patexample/hello_appengine.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// hello.go ported for appengine
 
2
//
 
3
// this differs from the standard hello.go example in two ways: appengine
 
4
// already provides an http server for you, obviating the need for the
 
5
// ListenAndServe call (with associated logging), and the package must not be
 
6
// called main (appengine reserves package 'main' for the underlying program).
 
7
 
 
8
package patexample
 
9
 
 
10
import (
 
11
        "io"
 
12
        "net/http"
 
13
 
 
14
        "github.com/bmizerany/pat"
 
15
)
 
16
 
 
17
// hello world, the web server
 
18
func HelloServer(w http.ResponseWriter, req *http.Request) {
 
19
        io.WriteString(w, "hello, "+req.URL.Query().Get(":name")+"!\n")
 
20
}
 
21
 
 
22
func init() {
 
23
        m := pat.New()
 
24
        m.Get("/hello/:name", http.HandlerFunc(HelloServer))
 
25
 
 
26
        // Register this pat with the default serve mux so that other packages
 
27
        // may also be exported. (i.e. /debug/pprof/*)
 
28
        http.Handle("/", m)
 
29
}