Documentation
¶
Overview ¶
Package kern provides a lightweight web framework for Go.
kern is built on Go 1.22's enhanced net/http router with zero dependencies. It provides a simple, intuitive API for building web applications while leveraging the standard library's performance and reliability.
Example usage:
app := kern.Default()
app.GET("/", func(c *kern.Context) {
c.JSON(200, map[string]string{"message": "Hello, kern!"})
})
app.Run(":8080")
Features:
- Go 1.22+ native routing with method matching and path parameters
- Standard http.Handler middleware pattern
- Route groups for organization
- Zero dependencies
Index ¶
- Variables
- func IntPathConstraint(value string) bool
- func IsBodyTooLarge(err error) bool
- func LoggerFromContext(ctx context.Context) *slog.Logger
- func RequestIDCtxKey() any
- func RequestIDFromContext(ctx context.Context) string
- func SlugPathConstraint(value string) bool
- func UUIDPathConstraint(value string) bool
- func UintPathConstraint(value string) bool
- type App
- func (app *App) AddConstraints(method, path string, constraints Constraints, handler HandlerFunc)
- func (app *App) AddNamedConstraints(name, method, path string, constraints Constraints, handler HandlerFunc)
- func (app *App) DELETE(path string, handler HandlerFunc)
- func (app *App) DELETENamed(name, path string, handler HandlerFunc)
- func (app *App) GET(path string, handler HandlerFunc)
- func (app *App) GETNamed(name, path string, handler HandlerFunc)
- func (app *App) Group(prefix string, middlewares ...MiddlewareFunc) *Group
- func (app *App) HEAD(path string, handler HandlerFunc)
- func (app *App) HEADNamed(name, path string, handler HandlerFunc)
- func (app *App) OPTIONS(path string, handler HandlerFunc)
- func (app *App) OPTIONSNamed(name, path string, handler HandlerFunc)
- func (app *App) OnError(hook ErrorHook)
- func (app *App) OnListen(hook ListenHook)
- func (app *App) OnRoute(hook RouteHook)
- func (app *App) OnShutdown(hook ShutdownHook)
- func (app *App) PATCH(path string, handler HandlerFunc)
- func (app *App) PATCHNamed(name, path string, handler HandlerFunc)
- func (app *App) POST(path string, handler HandlerFunc)
- func (app *App) POSTNamed(name, path string, handler HandlerFunc)
- func (app *App) PUT(path string, handler HandlerFunc)
- func (app *App) PUTNamed(name, path string, handler HandlerFunc)
- func (app *App) Route(method, path string, handler HandlerFunc)
- func (app *App) RouteByName(name string) (RouteInfo, bool)
- func (app *App) RouteNamed(name, method, path string, handler HandlerFunc)
- func (app *App) Routes() []RouteInfo
- func (app *App) Run(addr string, opts ...RunOption) error
- func (app *App) RunTLS(addr, certFile, keyFile string, opts ...RunOption) error
- func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (app *App) Static(prefix, dir string)
- func (app *App) Use(middlewares ...MiddlewareFunc)
- type BasicAuthConfig
- type BearerAuthConfig
- type CORSConfig
- type Constraints
- type Context
- func (c *Context) Accepted(data interface{}) error
- func (c *Context) Bind(data interface{}) error
- func (c *Context) BindForm(data interface{}) error
- func (c *Context) BindHeader(data interface{}) error
- func (c *Context) BindQuery(data interface{}) error
- func (c *Context) Body() ([]byte, error)
- func (c *Context) CheckPreconditions(etag string, modTime time.Time) bool
- func (c *Context) ClientIP() string
- func (c *Context) Context() context.Context
- func (c *Context) Cookie(name string) (*http.Cookie, error)
- func (c *Context) Created(data interface{}) error
- func (c *Context) Data(status int, contentType string, data []byte) error
- func (c *Context) DecodeJSON(data interface{}) error
- func (c *Context) DecodeXML(data interface{}) error
- func (c *Context) DefaultQuery(name, defaultValue string) string
- func (c *Context) DownloadFile(filepath string, downloadName string) error
- func (c *Context) ETag(tag string) string
- func (c *Context) Error(status int, message string) error
- func (c *Context) File(name string) (*multipart.FileHeader, error)
- func (c *Context) Form(name string) string
- func (c *Context) GetHeader(key string) string
- func (c *Context) HTML(status int, html string) error
- func (c *Context) HeaderBool(key string, defaultValue bool) (bool, error)
- func (c *Context) HeaderInt(key string, defaultValue int) (int, error)
- func (c *Context) IsNotModified(etag string, modTime time.Time) bool
- func (c *Context) JSON(status int, data interface{}) error
- func (c *Context) JSONError(status int, message string, details ...interface{}) error
- func (c *Context) LastModified(modTime time.Time)
- func (c *Context) Logger() *slog.Logger
- func (c *Context) Method() string
- func (c *Context) NoContent(status int)
- func (c *Context) OK(data interface{}) error
- func (c *Context) Param(name string) string
- func (c *Context) Path() string
- func (c *Context) Query(name string) string
- func (c *Context) QueryBool(name string, defaultValue bool) (bool, error)
- func (c *Context) QueryInt(name string, defaultValue int) (int, error)
- func (c *Context) QueryPair(name1, name2 string) (string, string)
- func (c *Context) QueryPairDefault(name1, default1, name2, default2 string) (string, string)
- func (c *Context) QueryPairDefaultRaw(name1, default1, name2, default2 string) (string, string)
- func (c *Context) QueryPairRaw(name1, name2 string) (string, string)
- func (c *Context) Redirect(status int, url string)
- func (c *Context) SaveFile(file *multipart.FileHeader, path string) error
- func (c *Context) ServeStatic(dir string) error
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SetLogger(logger *slog.Logger)
- func (c *Context) Status(status int)
- func (c *Context) StreamFile(filepath string) error
- func (c *Context) Text(status int, format string, values ...interface{}) error
- func (c *Context) TextPair(status int, left, sep, right string) error
- func (c *Context) XML(status int, data interface{}) error
- type Error
- type ErrorHook
- type FieldValidationError
- type Group
- func (g *Group) AddConstraints(method, path string, constraints Constraints, handler HandlerFunc)
- func (g *Group) AddNamedConstraints(name, method, path string, constraints Constraints, handler HandlerFunc)
- func (g *Group) DELETE(path string, handler HandlerFunc)
- func (g *Group) DELETENamed(name, path string, handler HandlerFunc)
- func (g *Group) GET(path string, handler HandlerFunc)
- func (g *Group) GETNamed(name, path string, handler HandlerFunc)
- func (g *Group) Group(prefix string, middlewares ...MiddlewareFunc) *Group
- func (g *Group) HEAD(path string, handler HandlerFunc)
- func (g *Group) HEADNamed(name, path string, handler HandlerFunc)
- func (g *Group) OPTIONS(path string, handler HandlerFunc)
- func (g *Group) OPTIONSNamed(name, path string, handler HandlerFunc)
- func (g *Group) PATCH(path string, handler HandlerFunc)
- func (g *Group) PATCHNamed(name, path string, handler HandlerFunc)
- func (g *Group) POST(path string, handler HandlerFunc)
- func (g *Group) POSTNamed(name, path string, handler HandlerFunc)
- func (g *Group) PUT(path string, handler HandlerFunc)
- func (g *Group) PUTNamed(name, path string, handler HandlerFunc)
- func (g *Group) Use(middlewares ...MiddlewareFunc)
- type HandlerFunc
- type JSONErrorPayload
- type ListenHook
- type ListenInfo
- type LoggerConfig
- type MiddlewareFunc
- func BasicAuth(username, password string) MiddlewareFunc
- func BasicAuthWithConfig(config BasicAuthConfig) MiddlewareFunc
- func BearerAuth(token string) MiddlewareFunc
- func BearerAuthWithConfig(config BearerAuthConfig) MiddlewareFunc
- func CORS(allowOrigins []string) MiddlewareFunc
- func CORSWithConfig(config CORSConfig) MiddlewareFunc
- func Logger(configs ...LoggerConfig) MiddlewareFunc
- func Recovery() MiddlewareFunc
- type Option
- func WithBodyLimit(limit int64) Option
- func WithDebug() Option
- func WithLogger() Option
- func WithRecovery() Option
- func WithSlogLogger(logger *slog.Logger) Option
- func WithStrictProxyHeaders(enabled bool) Option
- func WithStrictRequestParsing(enabled bool) Option
- func WithTrustedProxies(entries ...string) Option
- type PathConstraint
- type PathConstraints
- type RouteHook
- type RouteInfo
- type RunOption
- func WithGracefulShutdown(timeout time.Duration) RunOption
- func WithIdleTimeout(duration time.Duration) RunOption
- func WithKeepAlivesEnabled(enabled bool) RunOption
- func WithMaxHeaderBytes(max int) RunOption
- func WithReadHeaderTimeout(duration time.Duration) RunOption
- func WithReadTimeout(duration time.Duration) RunOption
- func WithWriteTimeout(duration time.Duration) RunOption
- type ShutdownHook
- type TestClient
- func (tc *TestClient) Delete(path string) *httptest.ResponseRecorder
- func (tc *TestClient) Do(req *http.Request) *httptest.ResponseRecorder
- func (tc *TestClient) Get(path string) *httptest.ResponseRecorder
- func (tc *TestClient) Post(path string, body io.Reader) *httptest.ResponseRecorder
- func (tc *TestClient) PostJSON(path string, payload interface{}) *httptest.ResponseRecorder
- func (tc *TestClient) Put(path string, body io.Reader) *httptest.ResponseRecorder
- func (tc *TestClient) Request(method, path string, body io.Reader) *httptest.ResponseRecorder
- func (tc *TestClient) WithHeader(key, value string) *TestClient
- type ValidationErrors
Constants ¶
This section is empty.
Variables ¶
var ( ErrEmptyRequestBody = errors.New("request body is empty") ErrInvalidBindTarget = errors.New("bind target must be a non-nil pointer to struct") )
Functions ¶
func IntPathConstraint ¶
IntPathConstraint validates signed base-10 integers.
func IsBodyTooLarge ¶
IsBodyTooLarge reports whether err is caused by MaxBytesReader limits.
func RequestIDCtxKey ¶ added in v0.2.0
func RequestIDCtxKey() any
func RequestIDFromContext ¶ added in v1.0.1
func SlugPathConstraint ¶
SlugPathConstraint validates URL-safe slugs ([a-zA-Z0-9_-]+).
func UUIDPathConstraint ¶
UUIDPathConstraint validates canonical UUID format.
func UintPathConstraint ¶
UintPathConstraint validates unsigned base-10 integers.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the main application instance
func (*App) AddConstraints ¶
func (app *App) AddConstraints(method, path string, constraints Constraints, handler HandlerFunc)
AddConstraints registers a handler with route-level constraints: typed path parameters and/or body validation middleware.
func (*App) AddNamedConstraints ¶
func (app *App) AddNamedConstraints(name, method, path string, constraints Constraints, handler HandlerFunc)
AddNamedConstraints registers a named handler with route-level constraints.
func (*App) DELETE ¶
func (app *App) DELETE(path string, handler HandlerFunc)
DELETE registers a DELETE route
func (*App) DELETENamed ¶
func (app *App) DELETENamed(name, path string, handler HandlerFunc)
DELETENamed registers a named DELETE route.
func (*App) GETNamed ¶
func (app *App) GETNamed(name, path string, handler HandlerFunc)
GETNamed registers a named GET route.
func (*App) Group ¶
func (app *App) Group(prefix string, middlewares ...MiddlewareFunc) *Group
Group creates a route group with common prefix and middleware
func (*App) HEAD ¶
func (app *App) HEAD(path string, handler HandlerFunc)
HEAD registers a HEAD route
func (*App) HEADNamed ¶
func (app *App) HEADNamed(name, path string, handler HandlerFunc)
HEADNamed registers a named HEAD route.
func (*App) OPTIONS ¶
func (app *App) OPTIONS(path string, handler HandlerFunc)
OPTIONS registers a OPTIONS route
func (*App) OPTIONSNamed ¶
func (app *App) OPTIONSNamed(name, path string, handler HandlerFunc)
OPTIONSNamed registers a named OPTIONS route.
func (*App) OnListen ¶
func (app *App) OnListen(hook ListenHook)
OnListen registers a callback for listen events.
func (*App) OnShutdown ¶
func (app *App) OnShutdown(hook ShutdownHook)
OnShutdown registers a callback for graceful shutdown events.
func (*App) PATCH ¶
func (app *App) PATCH(path string, handler HandlerFunc)
PATCH registers a PATCH route
func (*App) PATCHNamed ¶
func (app *App) PATCHNamed(name, path string, handler HandlerFunc)
PATCHNamed registers a named PATCH route.
func (*App) POST ¶
func (app *App) POST(path string, handler HandlerFunc)
POST registers a POST route
func (*App) POSTNamed ¶
func (app *App) POSTNamed(name, path string, handler HandlerFunc)
POSTNamed registers a named POST route.
func (*App) PUTNamed ¶
func (app *App) PUTNamed(name, path string, handler HandlerFunc)
PUTNamed registers a named PUT route.
func (*App) Route ¶
func (app *App) Route(method, path string, handler HandlerFunc)
Route registers a handler for the given method and path
func (*App) RouteByName ¶
RouteByName retrieves a route by its unique name.
func (*App) RouteNamed ¶
func (app *App) RouteNamed(name, method, path string, handler HandlerFunc)
RouteNamed registers a named handler for the given method and path.
func (*App) ServeHTTP ¶
func (app *App) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the handler for serving each request
func (*App) Use ¶
func (app *App) Use(middlewares ...MiddlewareFunc)
Use adds a global middleware to the application
type BasicAuthConfig ¶
type BasicAuthConfig struct {
// Realm is used in the WWW-Authenticate response header.
Realm string
// Username is compared against incoming basic-auth username when ValidateCredentials is nil.
Username string
// Password is compared against incoming basic-auth password when ValidateCredentials is nil.
Password string
// ValidateCredentials provides custom username/password verification logic.
ValidateCredentials func(username, password string, r *http.Request) bool
}
BasicAuthConfig configures HTTP basic authentication middleware.
type BearerAuthConfig ¶
type BearerAuthConfig struct {
// Realm is used in the WWW-Authenticate response header.
Realm string
// Token is compared against incoming bearer tokens when ValidateToken is nil.
Token string
// ValidateToken provides custom token verification logic.
ValidateToken func(token string, r *http.Request) bool
}
BearerAuthConfig configures bearer token authentication middleware.
type CORSConfig ¶
type Constraints ¶
type Constraints struct {
Path PathConstraints
Validate MiddlewareFunc
}
Constraints bundles all route-level restrictions: path parameter constraints and optional body validation middleware. A zero value means no constraints.
type Context ¶
type Context struct {
Request *http.Request
Response http.ResponseWriter
// contains filtered or unexported fields
}
Context adds helpful methods to the ongoing request
func (*Context) Bind ¶
Bind automatically binds request data based on method and Content-Type, then validates the result using `validate` struct tags.
func (*Context) BindHeader ¶
BindHeader binds request headers into a struct using `header` tags.
func (*Context) CheckPreconditions ¶
CheckPreconditions evaluates HTTP conditional headers and writes 304/412 when applicable. It sets ETag and Last-Modified response headers when values are provided.
func (*Context) ClientIP ¶
ClientIP returns the client IP address. Use this if you trust request headers passed to the server (ie: reverse proxy sits before server) else use c.Request.RemoteAddr()
func (*Context) DecodeJSON ¶
DecodeJSON decodes a request body into a struct
func (*Context) DefaultQuery ¶
DefaultQuery gets query param with default value
func (*Context) DownloadFile ¶
DownloadFile sends a downloadable file response with the specified filename
func (*Context) File ¶
func (c *Context) File(name string) (*multipart.FileHeader, error)
File gets an uploaded file by key name. The file header containing the file is returned
func (*Context) HeaderBool ¶
HeaderBool reads a boolean request header, returning defaultValue when absent.
func (*Context) HeaderInt ¶
HeaderInt reads an integer request header, returning defaultValue when absent.
func (*Context) IsNotModified ¶
IsNotModified checks request cache validators and writes 304 when fresh. It also sets ETag and Last-Modified response headers when provided.
func (*Context) JSONError ¶
JSONError sends a structured JSON error payload. Pass an optional details value to attach machine-readable context.
func (*Context) LastModified ¶
LastModified sets the Last-Modified response header.
func (*Context) Logger ¶
Logger returns the request logger configured for this context.
It returns nil when no slog logger is configured on the app.
func (*Context) Param ¶
Param gets a path parameter by name. For example, this returns the value of id from /users/{id}
func (*Context) QueryBool ¶
QueryBool reads a boolean query parameter, returning defaultValue when absent.
func (*Context) QueryInt ¶
QueryInt reads an integer query parameter, returning defaultValue when absent.
func (*Context) QueryPair ¶
QueryPair returns two named query parameters using a single lookup path. This is useful in hot handlers that consistently read the same pair.
func (*Context) QueryPairDefault ¶
QueryPairDefault returns two query parameters with independent defaults.
func (*Context) QueryPairDefaultRaw ¶
QueryPairDefaultRaw returns two raw query parameters with independent defaults.
func (*Context) QueryPairRaw ¶
QueryPairRaw returns two query parameters without URL decoding. This is a faster path for hot handlers when keys/values are plain ASCII.
func (*Context) SaveFile ¶
func (c *Context) SaveFile(file *multipart.FileHeader, path string) error
SaveFile saves an uploaded file to the specified destination path.
func (*Context) ServeStatic ¶
func (*Context) StreamFile ¶
StreamFile streams the content of a file in chunks to the client
type Error ¶
Error represents a framework-level HTTP error.
type ErrorHook ¶
type ErrorHook func(error)
ErrorHook is triggered when app-level server errors are observed.
type FieldValidationError ¶
FieldValidationError describes a single field validation failure.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group is a route group with common named prefix
func (*Group) AddConstraints ¶
func (g *Group) AddConstraints(method, path string, constraints Constraints, handler HandlerFunc)
AddConstraints registers a route with route-level constraints.
func (*Group) AddNamedConstraints ¶
func (g *Group) AddNamedConstraints(name, method, path string, constraints Constraints, handler HandlerFunc)
AddNamedConstraints registers a named route with route-level constraints.
func (*Group) DELETE ¶
func (g *Group) DELETE(path string, handler HandlerFunc)
DELETE registers a DELETE route for the group
func (*Group) DELETENamed ¶
func (g *Group) DELETENamed(name, path string, handler HandlerFunc)
DELETENamed registers a named DELETE route for the group.
func (*Group) GET ¶
func (g *Group) GET(path string, handler HandlerFunc)
GET registers a GET route for the group
func (*Group) GETNamed ¶
func (g *Group) GETNamed(name, path string, handler HandlerFunc)
GETNamed registers a named GET route for the group.
func (*Group) Group ¶
func (g *Group) Group(prefix string, middlewares ...MiddlewareFunc) *Group
Group creates a sub-group. Global middlewares come first in the chain
func (*Group) HEAD ¶
func (g *Group) HEAD(path string, handler HandlerFunc)
HEAD registers a HEAD route for the group
func (*Group) HEADNamed ¶
func (g *Group) HEADNamed(name, path string, handler HandlerFunc)
HEADNamed registers a named HEAD route for the group.
func (*Group) OPTIONS ¶
func (g *Group) OPTIONS(path string, handler HandlerFunc)
OPTIONS registers a OPTIONS route for the group
func (*Group) OPTIONSNamed ¶
func (g *Group) OPTIONSNamed(name, path string, handler HandlerFunc)
OPTIONSNamed registers a named OPTIONS route for the group.
func (*Group) PATCH ¶
func (g *Group) PATCH(path string, handler HandlerFunc)
PATCH registers a PATCH route for the group
func (*Group) PATCHNamed ¶
func (g *Group) PATCHNamed(name, path string, handler HandlerFunc)
PATCHNamed registers a named PATCH route for the group.
func (*Group) POST ¶
func (g *Group) POST(path string, handler HandlerFunc)
POST registers a POST route for the group
func (*Group) POSTNamed ¶
func (g *Group) POSTNamed(name, path string, handler HandlerFunc)
POSTNamed registers a named POST route for the group.
func (*Group) PUT ¶
func (g *Group) PUT(path string, handler HandlerFunc)
PUT registers a PUT route for the group
func (*Group) PUTNamed ¶
func (g *Group) PUTNamed(name, path string, handler HandlerFunc)
PUTNamed registers a named PUT route for the group.
func (*Group) Use ¶
func (g *Group) Use(middlewares ...MiddlewareFunc)
Use registers middlewares to the group
type JSONErrorPayload ¶
type JSONErrorPayload struct {
Error string `json:"error"`
Details interface{} `json:"details,omitempty"`
}
JSONErrorPayload is the default structured payload for JSONError responses.
type ListenHook ¶
type ListenHook func(ListenInfo)
ListenHook is triggered before a server starts listening.
type ListenInfo ¶
ListenInfo contains listen metadata for lifecycle hooks.
type LoggerConfig ¶
type LoggerConfig struct {
Format string
Logger *log.Logger
SLogger *slog.Logger
Output io.Writer
Fields map[string]interface{}
}
LoggerConfig configures request logging middleware output.
type MiddlewareFunc ¶
MiddlewareFunc is the middleware signature
func BasicAuth ¶
func BasicAuth(username, password string) MiddlewareFunc
BasicAuth validates Authorization: Basic <base64(username:password)>.
func BasicAuthWithConfig ¶
func BasicAuthWithConfig(config BasicAuthConfig) MiddlewareFunc
BasicAuthWithConfig validates basic-auth credentials using either static credentials or ValidateCredentials.
func BearerAuth ¶
func BearerAuth(token string) MiddlewareFunc
BearerAuth validates Authorization: Bearer <token> using a static token.
func BearerAuthWithConfig ¶
func BearerAuthWithConfig(config BearerAuthConfig) MiddlewareFunc
BearerAuthWithConfig validates bearer tokens using either Token or ValidateToken.
func CORS ¶
func CORS(allowOrigins []string) MiddlewareFunc
func CORSWithConfig ¶
func CORSWithConfig(config CORSConfig) MiddlewareFunc
func Logger ¶
func Logger(configs ...LoggerConfig) MiddlewareFunc
func Recovery ¶
func Recovery() MiddlewareFunc
type Option ¶
type Option func(*App)
Option configures the app
func WithBodyLimit ¶
WithBodyLimit sets a max number of bytes readable from request bodies.
func WithSlogLogger ¶
WithSlogLogger configures app lifecycle logging with slog.
func WithStrictProxyHeaders ¶
WithStrictProxyHeaders enables strict validation of forwarding headers. When enabled, malformed X-Forwarded-For or X-Real-IP values are ignored.
func WithStrictRequestParsing ¶
WithStrictRequestParsing enables strict query parsing for binding helpers. When enabled, malformed URL query strings return errors in BindQuery/Bind.
func WithTrustedProxies ¶
WithTrustedProxies configures reverse proxies whose forwarding headers are trusted. Entries may be plain IP addresses (e.g. "10.0.0.1") or CIDR blocks (e.g. "10.0.0.0/24").
type PathConstraint ¶
PathConstraint validates a single path parameter value.
type PathConstraints ¶
type PathConstraints map[string]PathConstraint
PathConstraints maps path parameter names to validators.
type RunOption ¶
type RunOption func(*serverConfig)
RunOption configures the server
func WithGracefulShutdown ¶
WithGracefulShutdown sets the graceful shutdown timeout.
func WithIdleTimeout ¶
WithIdleTimeout sets the server idle timeout.
func WithKeepAlivesEnabled ¶
WithKeepAlivesEnabled enables or disables HTTP keep-alives.
func WithMaxHeaderBytes ¶
WithMaxHeaderBytes sets the server MaxHeaderBytes value.
func WithReadHeaderTimeout ¶
WithReadHeaderTimeout sets the server read header timeout.
func WithReadTimeout ¶
WithReadTimeout sets the server read timeout
func WithWriteTimeout ¶
WithWriteTimeout sets the server write timeout
type ShutdownHook ¶
type ShutdownHook func(error)
ShutdownHook is triggered when graceful shutdown exits.
type TestClient ¶ added in v0.1.3
type TestClient struct {
// contains filtered or unexported fields
}
TestClient provides concise, reusable request helpers for app tests.
func NewTestClient ¶ added in v0.1.3
func NewTestClient(app *App) *TestClient
NewTestClient creates a test client for the given app.
func (*TestClient) Delete ¶ added in v0.1.3
func (tc *TestClient) Delete(path string) *httptest.ResponseRecorder
Delete sends a DELETE request.
func (*TestClient) Do ¶ added in v0.1.3
func (tc *TestClient) Do(req *http.Request) *httptest.ResponseRecorder
Do sends a prepared request and returns the recorded response.
func (*TestClient) Get ¶ added in v0.1.3
func (tc *TestClient) Get(path string) *httptest.ResponseRecorder
Get sends a GET request to the given path.
func (*TestClient) Post ¶ added in v0.1.3
func (tc *TestClient) Post(path string, body io.Reader) *httptest.ResponseRecorder
Post sends a POST request with an optional body.
func (*TestClient) PostJSON ¶ added in v0.1.3
func (tc *TestClient) PostJSON(path string, payload interface{}) *httptest.ResponseRecorder
PostJSON sends a POST request with a JSON-encoded body.
func (*TestClient) Put ¶ added in v0.1.3
func (tc *TestClient) Put(path string, body io.Reader) *httptest.ResponseRecorder
Put sends a PUT request with an optional body.
func (*TestClient) Request ¶ added in v0.1.3
func (tc *TestClient) Request(method, path string, body io.Reader) *httptest.ResponseRecorder
Request creates a request with the given method, path, and body, then sends it.
func (*TestClient) WithHeader ¶ added in v0.1.3
func (tc *TestClient) WithHeader(key, value string) *TestClient
WithHeader sets a default header on all subsequent requests.
type ValidationErrors ¶
type ValidationErrors []FieldValidationError
ValidationErrors contains all field validation errors.
func (ValidationErrors) Error ¶
func (e ValidationErrors) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
|
|
|
file-download
command
|
|
|
file-upload
command
|
|
|
middleware
command
|
|
|
nested-routes
command
|
|
|
observability
command
|
|
|
rest-api
command
|
|
|
extensions
|
|
|
xconfig
module
|
|
|
xlog
module
|
|
|
xotel
module
|
|
|
xvalidator
module
|
|