安裝

  1. go get github.com/clevergo/clevergo

舉個栗子

  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/clevergo/clevergo"
  6. )
  7. func home(ctx *clevergo.Context) error {
  8. return ctx.String(http.StatusOK, "hello world")
  9. }
  10. func hello(ctx *clevergo.Context) error {
  11. return ctx.String(http.StatusOK, fmt.Sprintf("hello %s", ctx.Params.String("name")))
  12. }
  13. func main() {
  14. router := clevergo.NewRouter()
  15. router.Get("/", home)
  16. router.Get("/hello/:name", hello)
  17. http.ListenAndServe(":8080", router)
  18. }
  1. $ curl http://localhost:8080/
  2. hello world
  3. $ curl http://localhost:8080/hello/foobar
  4. hello foobar