Documentation
¶
Index ¶
- Variables
- type App
- func (a *App) DELETE(path string, h ...Handler)
- func (a *App) GET(path string, h ...Handler)
- func (a *App) Group(basePath string, m ...Handler) Router
- func (a *App) Listen() error
- func (a *App) ListenHTTPS(certPath, keyPath string) error
- func (a *App) PATCH(path string, h ...Handler)
- func (a *App) POST(path string, h ...Handler)
- func (a *App) PUT(path string, h ...Handler)
- func (a *App) ServeFiles(endpoint, dirPath string) error
- func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (a *App) Shutdown(ctx context.Context) error
- func (a *App) Use(h Handler)
- type AppConfig
- type Context
- func (c *Context) Abort()
- func (c *Context) Body() []byte
- func (c *Context) BodyParser(v any) error
- func (c *Context) FormFile(key string) (*multipart.FileHeader, error)
- func (c *Context) Header(key string) string
- func (c *Context) HeaderAppend(key, value string)
- func (c *Context) HeaderSet(key, value string)
- func (c *Context) Headers() map[string][]string
- func (c *Context) IP() string
- func (c *Context) IPs() []string
- func (c *Context) JSON(data any) error
- func (c *Context) Logger() Logger
- func (c *Context) Method() string
- func (c *Context) Next() error
- func (c *Context) Now() time.Time
- func (c *Context) Param(key string) string
- func (c *Context) Params(name string, defaultValue ...string) string
- func (c *Context) ParamsParser(v any) error
- func (c *Context) Path(defaultValue ...string) string
- func (c *Context) Query(name string, defaultValue ...string) string
- func (c *Context) QueryParser(v any) error
- func (c *Context) ReqHeaderParser(v any) error
- func (c *Context) Send(data []byte) error
- func (c *Context) SendFile(filePath string)
- func (c *Context) SendFileFromReader(r io.ReadCloser)
- func (c *Context) SendStatus(status int) error
- func (c *Context) Status(statusCode int) *Context
- type Handler
- type KV
- type Logger
- type MaxBodySize
- type Router
Constants ¶
This section is empty.
Variables ¶
var ( ErrDstMustBeAPointer = errors.New("dst must be pointer") ErrUnsupportedFieldType = errors.New("unsupported field type") )
var ( ErrInvalidSize = errors.New("invalid maxBodySize") ErrUnknownUnit = errors.New("unknown unit") ErrInvalidMaxBodySizeFormat = errors.New("invalid format") )
var ErrAborted = errors.New("aborted")
var ErrEmptyBody = errors.New("empty body")
var ErrFormFileNotFound = errors.New("form file not found")
var ErrInvalidCertKeyPaths = errors.New("certPath and keyPath must be provided")
ErrInvalidCertKeyPaths is returned when either the certificate or key path is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) Group ¶ added in v1.1.1
Group creates a new route group with a common base path and middleware.
All routes registered within this group will be prefixed with basePath, and the provided middlewares will be executed before the route handlers.
Groups can be nested, and child groups inherit both the path prefix and middleware stack from their parent.
func (*App) ListenHTTPS ¶ added in v1.2.4
ListenHTTPS starts an HTTPS server using the provided certificate and key files.
func (*App) ServeFiles ¶ added in v1.3.2
ServeFiles serves static files from the specified directory at the given endpoint. For example:
ServeFiles("/static/", "./public")
will serve files from the "./public" directory at the "/static/" endpoint.
func (*App) ServeHTTP ¶ added in v1.2.8
func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP makes the app implement Go's http.Handler interface. This allows the app to be used in http.ListenAndServe.
type AppConfig ¶
type AppConfig struct {
Port string
AppName string
MaxBodySize MaxBodySize
Logger Logger
Startup startFn
// MaxConns caps the number of connections served concurrently.
// A non-positive value falls back to defaultMaxConns.
MaxConns int
}
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) Body ¶
Body returns a copy of the request body.
A copy is returned (rather than the internal buffer) so a handler may safely retain the result — or hand it to a spawned goroutine — without risking mutation by request parsing. Header/Params/Query lookups already return string copies and are likewise safe to retain.
func (*Context) BodyParser ¶
func (*Context) HeaderAppend ¶ added in v1.3.3
func (*Context) Logger ¶ added in v1.3.5
Logger returns the app-configured logger, falling back to a default one when the Context was built without an App. Never nil, so middlewares outside this package can report diagnostics through the same sink as the framework.
func (*Context) ParamsParser ¶
func (*Context) QueryParser ¶
func (*Context) ReqHeaderParser ¶
func (*Context) SendFileFromReader ¶ added in v1.1.3
func (c *Context) SendFileFromReader(r io.ReadCloser)
SendFileFromReader streams a file from a reader, writing HTTP headers first and using Transfer-Encoding: chunked to avoid buffering the entire payload.
func (*Context) SendStatus ¶
type Handler ¶
type Handler func(c *Context)
Handler defines the signature for request handler functions that process a Context.
type Logger ¶ added in v1.2.1
type Logger func(msg ...string)
func NewDefaultLogger ¶ added in v1.2.1
type MaxBodySize ¶
type MaxBodySize string
func (MaxBodySize) String ¶
func (s MaxBodySize) String() string
type Router ¶ added in v1.1.1
type Router interface {
Get(path string, h ...Handler)
Post(path string, h ...Handler)
Put(path string, h ...Handler)
Delete(path string, h ...Handler)
Patch(path string, h ...Handler)
// Group creates a new Router with the given path prefix and optional middleware.
//
// The returned Router inherits the current base path and middleware stack,
// allowing nested groups for better route organization.
Group(path string, m ...Handler) Router
Use(h ...Handler)
}
Router defines a contract for registering HTTP routes and creating route groups.
A Router allows attaching handlers to specific HTTP methods and paths. It also supports grouping routes under a common path prefix with shared middleware.
Implementations should ensure that middlewares defined in groups are executed before route-specific handlers.