mux

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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 OnPort

func OnPort(port string) routerOpt

func WithLogLevel

func WithLogLevel(level slog.Level) routerOpt

func WithLogger

func WithLogger(logger *slog.Logger) routerOpt

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) routerOpt

func WithServer

func WithServer(server *http.Server) routerOpt

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) routerOpt

Types

type Context

type Context struct {
	Request  *http.Request
	Response Response
	// contains filtered or unexported fields
}

func (*Context) Cookie

func (c *Context) Cookie(name string) (*http.Cookie, error)

Cookie retrieves a cookie from the request by name.

func (*Context) Error

func (c *Context) Error(status int)

Error responds to a request with the provided error status.

func (*Context) Get

func (c *Context) Get(key ContextKey) any

Get retrieves a value from the context.

func (*Context) HTML

func (c *Context) HTML(status int, body string) error

HTML sends an HTML response with a status.

func (*Context) JSON

func (c *Context) JSON(status int, body any) error

JSON sends a JSON response with a status.

func (*Context) Logger

func (c *Context) Logger() *slog.Logger

Logger returns the logger for the context.

func (*Context) Redirect

func (c *Context) Redirect(status int, path string)

Redirect redirects to a url with a status.

func (*Context) Set

func (c *Context) Set(key ContextKey, value any)

Set saves a value to the context.

func (*Context) SetCookie

func (c *Context) SetCookie(cookie *http.Cookie)

SetCookie sets a cookie on the response.

func (*Context) Stream

func (c *Context) Stream(status int, contentType string, body io.Reader) error

Stream sends a streaming response with a status and content type.

func (*Context) WithContentType

func (c *Context) WithContentType(contentType string)

WithContentType sets the http response header with the content type.

func (*Context) WithStatus

func (c *Context) WithStatus(statusCode int)

WithStatus sets the http response header with the status code.

type ContextKey

type ContextKey string

type HandlerFunc

type HandlerFunc func(*Context) error

type Middleware

type Middleware func(HandlerFunc) HandlerFunc

type Response

type Response struct {
	Writer     http.ResponseWriter
	StatusCode int
	Written    bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL