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) PATCH(path string, h ...Handler)
- func (a *App) POST(path string, h ...Handler)
- func (a *App) PUT(path string, h ...Handler)
- 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) 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) 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 ( ErrInvalidSize = errors.New("invalid maxBodySize") ErrUnknowUnit = errors.New("unknown unit") ErrInvalidMaxBodySizeFormat = errors.New("invalid format") )
var ErrAborted = errors.New("aborted")
var ErrDstMustBeAPointer = errors.New("dst must be pointer")
var ErrEmptyBody = errors.New("empty body")
var ErrFormFileNotFound = errors.New("form file not found")
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App represents a netio HTTP application.
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) Shutdown ¶ added in v1.1.1
Shutdown gracefully stops the application listener when the context is done.
It blocks until the context is canceled or reaches its deadline, then closes the underlying network listener, causing any blocking Accept calls to return.
If the listener is not initialized, Shutdown returns nil.
type AppConfig ¶
type AppConfig struct {
Port string
AppName string
MaxBodySize MaxBodySize
Logger Logger
}
AppConfig represents configuration options for a new App.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents a single HTTP request/response cycle.
func (*Context) Abort ¶
func (c *Context) Abort()
Abort stops the execution of the remaining handlers.
func (*Context) BodyParser ¶
BodyParser parses the request body JSON into the given destination.
func (*Context) FormFile ¶
func (c *Context) FormFile(key string) (*multipart.FileHeader, error)
FormFile retrieves an uploaded file from a multipart/form request.
func (*Context) ParamsParser ¶
ParamsParser parses path parameters into a struct using `param` tags.
func (*Context) QueryParser ¶
QueryParser parses query parameters into a struct using `query` tags.
func (*Context) ReqHeaderParser ¶
ReqHeaderParser parses headers into a struct using `header` tags.
func (*Context) SendFile ¶ added in v1.1.3
SendFile reads a file from the given path and sends its content as the response.
If the file cannot be read, it sends the current status code without a body.
func (*Context) SendFileFromReader ¶ added in v1.1.3
func (c *Context) SendFileFromReader(r io.ReadCloser)
SendFileFromReader streams data directly to the underlying connection.
It uses io.Copy with net.Conn, which is efficient and avoids buffering the entire content in memory. Suitable for large payloads.
The reader is closed after the operation.
func (*Context) SendStatus ¶
SendStatus sends an HTTP response with the given status code.
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
MaxBodySize is a string type for configuration of max body size.
func (MaxBodySize) String ¶
func (s MaxBodySize) String() string
String returns the max body size as a string, with default "15 MB".
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.