Ctp is a web framework written in Go. Now , the purpose for this project is only to learn how to write a go http framework !
package main
import (
"github.com/cit965/ctp"
"time"
)
func main() {
r := ctp.Default()
r.GET("/foo", ctp.Recovery(), ctp.Log(), FooControllerHandler)
g := r.Group("/boo")
g.Use(ctp.Log())
{
g.GET("/hello", FooControllerHandler)
g.GET("/xx/:id", FooControllerHandler)
}
r.Run(":8000")
}
func FooControllerHandler(c *ctp.Context) {
time.Sleep(time.Second * 3)
c.Json(200, "success")
}
there are two ways to add middleware
- add to group
- add to single router