func main() { mux := http.NewServeMux() logger := mw.NewLogger(os.Stdout, "[Example]", 2) c := claw.New(logger) stk := claw.NewStack(Middle1, Middle2) mux.HandleFunc("/home", Home) http.ListenAndServe(":8080", c.Merge(mux).Stack(stk)) }
func main() { muxx := bone.New() clw := claw.New(mw.Logger) // API ROUTE muxx.Get("/api/:user", clw.Use(func(rw http.ResponseWriter, req *http.Request) { })) muxx.Post("/api/:user", clw.Use(func(rw http.ResponseWriter, req *http.Request) { m := &Mail{} err := json.NewDecoder(req.Body).Decode(m) if err != nil { json.NewEncoder(rw).Encode(err) return } fmt.Printf("Sending mail to %s ...\n", m.To) go m.Send() })) http.ListenAndServe(":8000", muxx) }
func main() { port := flag.String("port", "80", "-port [your port]") flag.Parse() mux := bone.New() clw := claw.New(mw.Logger) // GET Handler mux.Get("/", clw.Use(handle.Handler)) mux.Get("/profil", clw.Use(handle.ProfilHandler)) mux.Get("/home", clw.Use(handle.HomeHandler)) mux.Get("/find", clw.Use(handle.FindHandler)) // POST Handler mux.Post("/signin", clw.Use(handle.SignIn)) mux.Post("/logout", clw.Use(handle.LogOut)) mux.Post("/add", clw.Use(handle.AddUser)) mux.Post("/fish", clw.Use(handle.AddFish)) mux.Post("/delete", clw.Use(handle.DeleteFish)) // Ressources mux.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("public")))) // Start to serve http.ListenAndServe(":"+*port, mux) }
package main import ( "net/http" "local/spoon/api" "github.com/go-zoo/bone" "github.com/go-zoo/claw" mw "github.com/go-zoo/claw/middleware" ) var ( muxx = bone.New() apiMux = bone.New() clw = claw.New(mw.Logger) ) func main() { muxx.SubRoute("/api", apiMux) muxx.GetFunc("/", api.IndexHandler) apiMux.GetFunc("/movie/:id", api.GetMovie) apiMux.GetFunc("/movie/title/:title", api.GetMovieByTitle) apiMux.PostFunc("/movie/new", api.PostMovie) http.ListenAndServe(":8080", clw.Merge(muxx)) }