Documentation
¶
Index ¶
- Constants
- func NewRouter(opts ...routerOpt) *router
- func OnPort(port string) routerOpt
- func WithLogLevel(level slog.Level) routerOpt
- func WithLogger(logger *slog.Logger) routerOpt
- func WithReadTimeout(timeout time.Duration) routerOpt
- func WithServer(server *http.Server) routerOpt
- func WithWriteTimeout(timeout time.Duration) routerOpt
- type Context
- func (c *Context) Cookie(name string) (*http.Cookie, error)
- func (c *Context) Error(status int)
- func (c *Context) Get(key ContextKey) any
- func (c *Context) HTML(status int, body string) error
- func (c *Context) JSON(status int, body any) error
- func (c *Context) Logger() *slog.Logger
- func (c *Context) Redirect(status int, path string)
- func (c *Context) Set(key ContextKey, value any)
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) Stream(status int, contentType string, body io.Reader) error
- func (c *Context) WithContentType(contentType string)
- func (c *Context) WithStatus(statusCode int)
- type ContextKey
- type HandlerFunc
- type Middleware
- type Response
Constants ¶
View Source
const ( MIMEApplicationJSON = "application/json" MIMETextHTML = "text/html" )
Variables ¶
This section is empty.
Functions ¶
func NewRouter ¶
func NewRouter(opts ...routerOpt) *router
NewRouter create a new router instance with the config loaded from environment variables.
func WithLogLevel ¶
func WithLogger ¶
func WithReadTimeout ¶
func WithServer ¶
func WithWriteTimeout ¶
Types ¶
type Context ¶
type Context struct {
Request *http.Request
Response Response
// contains filtered or unexported fields
}
func (*Context) Get ¶
func (c *Context) Get(key ContextKey) any
Get retrieves a value from the context.
func (*Context) Set ¶
func (c *Context) Set(key ContextKey, value any)
Set saves a value to the context.
func (*Context) WithContentType ¶
WithContentType sets the http response header with the content type.
func (*Context) WithStatus ¶
WithStatus sets the http response header with the status code.
type ContextKey ¶
type ContextKey string
type HandlerFunc ¶
type Middleware ¶
type Middleware func(HandlerFunc) HandlerFunc
Click to show internal directories.
Click to hide internal directories.