Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetNextCtxKey ¶
func GetNextCtxKey() int
GetNextCtxKey returns next available integer key for the Ctx
Types ¶
type HandlerFunc ¶
func (HandlerFunc) ServeHTTPWithCtx ¶
func (hf HandlerFunc) ServeHTTPWithCtx(c Ctx, h *Http) Ctx
type Router ¶
Router impliments http handler registration Usage example: http.Handle("/query", router.Router{"GET":getHandler, "POST":postHandler}) In case there is no handler found, http status code 501 is returned Refer to https://golang.org/src/net/http/method.go for supported methods
https://golang.org/pkg/net/http/ for overall http information
Below is a simple HTTP server:
//Get Http request handler function
var getHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("GetTestResponse")) })
//Post http request handler function
var postHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("PostTestResponse")) })
//Put http request handler type PutHandler struct { }
func (ph *PutHandler) ServeHTTP (w http.ResponseWriter, r *http.Request) { //decode request //process request //encode response //write encoded response w.Write([]byte("PutTestResponse")) }
func main() { mux := http.NewServeMux() mux.Handle("/test", Router{"GET":getHandler, "POST":postHandler, "PUT":PutHanlder{}}) log.Println("Listening on port 8080...") log.Println(http.ListenAndServe(":8080", mux)) }
type Router map[string]http.Handler
Click to show internal directories.
Click to hide internal directories.