Documentation ¶
Index ¶
- Variables
- func ClientIP(r *http.Request) string
- type Context
- func (c *Context) ClientIP() string
- func (c *Context) Flush()
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) Header() http.Header
- func (c *Context) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (c *Context) PathParams() map[string]string
- func (c *Context) PathRegex() string
- func (c *Context) PathTemplate() string
- func (c *Context) RouteName() string
- func (c *Context) Set(key string, value any)
- func (c *Context) Size() int
- func (c *Context) Status() int
- func (c *Context) Value(key any) any
- func (c *Context) Write(b []byte) (int, error)
- func (c *Context) WriteHeader(s int)
- func (c *Context) Written() bool
- type CorsConfig
- type Engine
- type Handler
- type Middleware
- type Option
- type ResponseFunc
- type Route
- type Router
- func (r Router) Any(path string, handler Handler) Route
- func (r Router) DELETE(path string, handler Handler) Route
- func (r Router) GET(path string, handler Handler) Route
- func (r Router) Group(pathPrefix string) Router
- func (r Router) HEAD(path string, handler Handler) Route
- func (r Router) OPTIONS(path string, handler Handler) Route
- func (r Router) PATCH(path string, handler Handler) Route
- func (r Router) POST(path string, handler Handler) Route
- func (r Router) PUT(path string, handler Handler) Route
- func (r Router) Static(relativePath, root string, listFiles bool)
- func (r Router) StaticFS(relativePath string, fs http.FileSystem, listFiles bool)
- func (r Router) Sub() Router
- func (r Router) Use(mds ...Middleware)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultCorsConfig = CorsConfig{ AllowAllOrigins: true, AllowMethods: []string{ http.MethodGet, http.MethodPost, http.MethodPut, http.MethodPatch, http.MethodDelete, http.MethodHead, http.MethodOptions, }, AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"}, MaxAge: 12 * time.Hour, }
Functions ¶
Types ¶
type Context ¶
type Context struct { context.Context Request *http.Request // contains filtered or unexported fields }
func NewContext ¶
func NewContext(rsp http.ResponseWriter, req *http.Request) *Context
func (*Context) PathParams ¶
func (*Context) PathTemplate ¶
func (*Context) WriteHeader ¶
type CorsConfig ¶
type Engine ¶
type Engine struct { Router // contains filtered or unexported fields }
func (*Engine) PrintRoutes ¶
func (e *Engine) PrintRoutes()
func (*Engine) ServeHTTP ¶
func (e *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
Example ¶
engine := New() engine.POST("/test1", func(c *Context) (any, error) { return map[string]string{"greeting": "hello"}, nil }) srv := httptest.NewServer(engine) rsp, err := srv.Client().Post(srv.URL+"/test1", "", nil) if err != nil { fmt.Println("err occurred:", err) return } defer rsp.Body.Close() b, _ := io.ReadAll(rsp.Body) fmt.Println(string(b))
Output: {"data":{"greeting":"hello"}}
func (*Engine) UseCors ¶
func (e *Engine) UseCors(c CorsConfig)
type Option ¶
type Option func(*Engine)
func WithLogger ¶
func WithResponseFunc ¶
func WithResponseFunc(rspFunc ResponseFunc) Option
type ResponseFunc ¶
Click to show internal directories.
Click to hide internal directories.