Documentation
¶
Overview ¶
Package gout is a go web framework
Index ¶
- func BindJSON[T any](c *Context) (T, error)
- func Success[T any](c *Context, data T)
- type Context
- func (c *Context) ClientIP() string
- func (c *Context) Data(code int, data []byte)
- func (c *Context) Fail(code int, err string)
- func (c *Context) File(filepath string)
- func (c *Context) HTML(code int, name string, data any)
- func (c *Context) JSON(code int, obj any)
- func (c *Context) Next()
- func (c *Context) Param(key string) string
- func (c *Context) PostFrom(key string) string
- func (c *Context) Query(key string) string
- func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (c *Context) SetHeader(key string, value string)
- func (c *Context) Status(code int)
- func (c *Context) String(code int, format string, values ...any)
- type DataResp
- type Engine
- type FormatterType
- type H
- type HandlerFunc
- type LoggerConfig
- type RouterGroup
- func (group *RouterGroup) DELETE(pattern string, handler HandlerFunc)
- func (group *RouterGroup) GET(pattern string, handler HandlerFunc)
- func (group *RouterGroup) Group(prefix string) *RouterGroup
- func (group *RouterGroup) HEAD(pattern string, handler HandlerFunc)
- func (group *RouterGroup) OPTIONS(pattern string, handler HandlerFunc)
- func (group *RouterGroup) PATCH(pattern string, handler HandlerFunc)
- func (group *RouterGroup) POST(pattern string, handler HandlerFunc)
- func (group *RouterGroup) PUT(pattern string, handler HandlerFunc)
- func (group *RouterGroup) Static(relativePath string, root string)
- func (group *RouterGroup) Use(middleware ...HandlerFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct {
// origin objects
Writer http.ResponseWriter
Req *http.Request
// request info
Path string
Method string
Params map[string]string
// response info
StatusCode int
// contains filtered or unexported fields
}
Context holds the HTTP request and response objects, as well as URL path, method middleware handlers.
func (*Context) File ¶ added in v0.2.1
File writes the specified file into the body stream in an efficient way.
func (*Context) SetCookie ¶ added in v0.2.1
func (c *Context) SetCookie( name, value string, maxAge int, path, domain string, secure, httpOnly bool, )
SetCookie adds a Set-Cookie header to the ResponseWriter's headers.
type Engine ¶
type Engine struct {
*RouterGroup
// contains filtered or unexported fields
}
Engine implement the interface of ServeHTTP
func (*Engine) LoadHTMLGlob ¶
LoadHTMLGlob loads HTML templates matching the specified pattern.
func (*Engine) RunGracefully ¶ added in v0.2.1
RunGracefully starts the HTTP server and handlers graceful shutdown on interrupt signals.
func (*Engine) ServeHTTP ¶
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP conforms to the http.Handler interface.
func (*Engine) SetFuncMap ¶
SetFuncMap sets a custom template.FuncMap for the Engine.
type FormatterType ¶ added in v0.2.1
type FormatterType int
FormatterType defines the type of log formatting.
const ( TextFormatter FormatterType = iota JSONFormatter )
type HandlerFunc ¶
type HandlerFunc func(c *Context)
HandlerFunc defines the request handler used by gout
func CORS ¶ added in v0.2.1
func CORS() HandlerFunc
CORS returns a middleware handler that enables Cross-Origin Resources Sharing.
func Logger ¶
func Logger(configs ...LoggerConfig) HandlerFunc
Logger returns a middleware handler that logs HTTP requests.
func Recovery ¶
func Recovery() HandlerFunc
Recovery returns a middleware handler that recovers from any panics and writes a 500 error.
type LoggerConfig ¶ added in v0.2.1
type LoggerConfig struct {
Formatter FormatterType
}
LoggerConfig defines the configuration for the Logger middleware.
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup implement the group routes
func (*RouterGroup) DELETE ¶ added in v0.2.1
func (group *RouterGroup) DELETE(pattern string, handler HandlerFunc)
DELETE defines the method to add DELETE request
func (*RouterGroup) GET ¶
func (group *RouterGroup) GET(pattern string, handler HandlerFunc)
GET define the method to add GET request
func (*RouterGroup) Group ¶
func (group *RouterGroup) Group(prefix string) *RouterGroup
Group is defined to create a new RouterGroup remember all groups share the same Engine instance
func (*RouterGroup) HEAD ¶ added in v0.2.1
func (group *RouterGroup) HEAD(pattern string, handler HandlerFunc)
HEAD defines the method to add HEAD request
func (*RouterGroup) OPTIONS ¶ added in v0.2.1
func (group *RouterGroup) OPTIONS(pattern string, handler HandlerFunc)
OPTIONS defines the method to add OPTIONS request
func (*RouterGroup) PATCH ¶ added in v0.2.1
func (group *RouterGroup) PATCH(pattern string, handler HandlerFunc)
PATCH defines the method to add PATCH request
func (*RouterGroup) POST ¶
func (group *RouterGroup) POST(pattern string, handler HandlerFunc)
POST defines the method to add POST request
func (*RouterGroup) PUT ¶ added in v0.2.1
func (group *RouterGroup) PUT(pattern string, handler HandlerFunc)
PUT defines the method to add PUT request
func (*RouterGroup) Static ¶
func (group *RouterGroup) Static(relativePath string, root string)
Static regisiters a route to serve static files from the specified root directory.
func (*RouterGroup) Use ¶
func (group *RouterGroup) Use(middleware ...HandlerFunc)
Use is defined to add middleware to the group