goup is a simple web framework, Born from gin
and 7days-golang, it provides usage similar to (request, response) => { }
engine := goup.New()
engine.GET("/", func (req Request, res Response) {
/* ... */
})
engine.Run(":9527")
engine := goup.New()
engine.Use(func (req Request, res Response) {
/* ... */
})
engine.Use(Recovery(), Logger(), Cors())
engine := goup.New()
api := engine.Group("/api")
api.GET("/xxx", func (req Request, res Response) {
/* ... */
})
engine := goup.New()
engine.File("/favicon.ico", "./public/favicon.ico")
engine.File("/public", "./public") //engine.Static("/public","./public")
Request
get urlreq.URL()
get host
req.Host()
get remote address
req.Addr()
get path, params
req.UseRouter()
get the key from params
req.Param(key)
get URLSearchParams
req.Query()
get key from URLSearchParams
req.GetQuery()
get the key from form
req.GetFormValue()
get the key file from form
req.GetFormFile()
get all headers
req.Header()
get the key from headers
req.GetHeader(key)
get all cookies
req.Cookies()
get the key from cookies
req.GetCookie(key)
get body as string
req.StringBody()
get body as bytes
req.BytesBody()
set value
req.Set(key, value)
req.SetValue(key, value)
get value
req.Get(key)
req.GetValue(key)
Response
writeheader(status)res.Status(200)
res.WriteHeader(200)
write
res.Write([]byte("hello"))
res.Bytes([]byte("hello"))
res.String("hello")
header
res.SetHeader("Content-Type", "text/html")
content type
res.ContentType("text/html")
set cookie
res.SetCookie(&cookie{})
html
res.HTML("index.html", map[string]any{
"title": "goup",
})
json
res.JSON(map[string]any{
"title": "goup",
})
status and error html page
res.Error(404, "Not Found.")