You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// start serverrouter.Run(":80")
// start server with TLS & HTTP2router.RunTLS("0.0.0.0:443", "cert.pem", "private.key", &tls.Config{})
// custom HTTP server and start serverrouter.Serve(&http.Server{})
router.ServeTLS(&http.Server{}, "cert.pem", "private.key")
// close serverrouter.Close()
easierweb.Group
Create
// create a api groupgroup:=router.Group("/group")
// create a api group and set middlewaregroup:=router.Group("/group", middlewares.Logger())
Set APIs Handle
// set handle (setting method is the same as router)group.GET("/hello", hello)
group.EasyGET("/hello", hello)
easierweb.Context
Middleware Related Operations
// go to the next handlectx.Next()
// process terminationctx.Abort()
Bind Request Data
// bind uri query parameters (based on mapstructure)ctx.BindQuery(&request)
// bind uri path parameters (based on mapstructure)ctx.BindPath(&request)
// bind form parameters (based on mapstructure)ctx.BindForm(&request)
// bind header parameters (based on mapstructure)ctx.BindHeader(&request)
// bind body datactx.BindJSON(&request)
ctx.BindYAML(&request)
ctx.BindXML(&request)
// prerequisites for using these function: router.WS("/hello", hello)// receive websocket messagectx.ReceiveJSON(&message)
ctx.ReceiveYAML(&message)
ctx.ReceiveXML(&message)
ctx.ReceiveString()
ctx.Receive()
// send websocket messagectx.SendJSON(Message{Msg: "hello world"})
ctx.SendYAML(Message{Msg: "hello world"})
ctx.SendXML(Message{Msg: "hello world"})
ctx.SendString("hello world")
ctx.Send([]byte("hello world"))
// close websocket connectctx.Close()
Server-Sent Events (SSE)
// prerequisites for using these function: router.SSE("/hello", hello)// server-sent events (SSE) push messagectx.Push("data: hello\n\n")
File
// get all the file keys in the formctx.FileKeys()
// get form file by keyctx.GetFile("hello")
Other Request Parameters
// get all cookiesctx.Cookies()
// get cookie by namectx.GetCookie("hello")
// get other request parametersctx.URI()
ctx.Method()
ctx.URL()
ctx.RemoteAddr()
ctx.Host()
ctx.Proto()
// get all keysctx.Query.Keys()
// get all valuesctx.Query.Values()
// get value (string) by keyctx.Query.Get("hello")
// check whether the key existsctx.Query.Has("hello")
// set key-valuectx.Query.Set("hello", "world")
// delete keyctx.Query.Del("hello")
// bind structctx.Query.Bind(&request)
Value Type Conversion
// when parsing errors, error will be returnedctx.Query.ParseInt("hello")
ctx.Query.ParseInt32("hello")
ctx.Query.ParseInt64("hello")
ctx.Query.ParseFloat32("hello")
ctx.Query.ParseFloat64("hello")
// when parsing errors, default value will be returnedctx.Query.GetInt("hello")
ctx.Query.GetInt32("hello")
ctx.Query.GetInt64("hello")
ctx.Query.GetFloat32("hello")
ctx.Query.GetFloat64("hello")
// when parsing errors, panic errorctx.Query.Int("hello")
ctx.Query.Int32("hello")
ctx.Query.Int64("hello")
ctx.Query.Float32("hello")
ctx.Query.Float64("hello")