Documentation ¶
Index ¶
- Variables
- func ClientIP(r *http.Request) string
- type Context
- func (c *Context) Buffer() *bytes.Buffer
- func (c *Context) ClientIP() string
- func (c *Context) File(filepath string)
- func (c *Context) Flush()
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) GetBool(key string) (b bool)
- func (c *Context) GetDuration(key string) (d time.Duration)
- func (c *Context) GetFloat64(key string) (f64 float64)
- func (c *Context) GetInt(key string) (i int)
- func (c *Context) GetInt64(key string) (i64 int64)
- func (c *Context) GetString(key string) (s string)
- func (c *Context) GetStringMap(key string) (sm map[string]any)
- func (c *Context) GetStringMapString(key string) (sms map[string]string)
- func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
- func (c *Context) GetStringSlice(key string) (ss []string)
- func (c *Context) GetTime(key string) (t time.Time)
- func (c *Context) GetUint(key string) (ui uint)
- func (c *Context) GetUint64(key string) (ui64 uint64)
- 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) SSEvent(name string, message any) error
- 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 Event
- 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) StaticFile(relativePath, filepath string)
- func (r Router) StaticFileFS(relativePath, filepath string, fs http.FileSystem)
- func (r Router) Sub() Router
- func (r Router) Use(mds ...Middleware)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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
NewContext returns a new Context instance.
func (*Context) Flush ¶
func (c *Context) Flush()
Flush implements the http.Flusher interface to allow an HTTP handler to flush buffered data to the client.
func (*Context) GetBool ¶ added in v0.0.2
GetBool returns the value associated with the key as a boolean.
func (*Context) GetDuration ¶ added in v0.0.2
GetDuration returns the value associated with the key as a duration.
func (*Context) GetFloat64 ¶ added in v0.0.2
GetFloat64 returns the value associated with the key as a float64.
func (*Context) GetInt ¶ added in v0.0.2
GetInt returns the value associated with the key as an integer.
func (*Context) GetInt64 ¶ added in v0.0.2
GetInt64 returns the value associated with the key as an integer.
func (*Context) GetString ¶ added in v0.0.2
GetString returns the value associated with the key as a string.
func (*Context) GetStringMap ¶ added in v0.0.2
GetStringMap returns the value associated with the key as a map of interfaces.
func (*Context) GetStringMapString ¶ added in v0.0.2
GetStringMapString returns the value associated with the key as a map of strings.
func (*Context) GetStringMapStringSlice ¶ added in v0.0.2
GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
func (*Context) GetStringSlice ¶ added in v0.0.2
GetStringSlice returns the value associated with the key as a slice of strings.
func (*Context) GetTime ¶ added in v0.0.2
GetTime returns the value associated with the key as time.
func (*Context) GetUint ¶ added in v0.0.2
GetUint returns the value associated with the key as an unsigned integer.
func (*Context) GetUint64 ¶ added in v0.0.2
GetUint64 returns the value associated with the key as an unsigned integer.
func (*Context) Hijack ¶
Hijack implements the http.Hijacker interface to allow an HTTP handler to take over the connection.
func (*Context) PathParams ¶
PathParams returns the path parameters associated with the request.
func (*Context) PathRegex ¶
PathRegex returns the path regex used to match the current request, if any.
func (*Context) PathTemplate ¶
PathTemplate returns the path template used to match the current request, if any.
func (*Context) RouteName ¶
RouteName returns the name of the route matched for the current request, if any.
func (*Context) WriteHeader ¶
WriteHeader writes the response header
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 ¶
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (Router) StaticFS ¶
func (r Router) StaticFS(relativePath string, fs http.FileSystem, listFiles bool)
func (Router) StaticFile ¶ added in v0.0.2
func (Router) StaticFileFS ¶ added in v0.0.2
func (r Router) StaticFileFS(relativePath, filepath string, fs http.FileSystem)
func (Router) Use ¶
func (r Router) Use(mds ...Middleware)