Documentation
¶
Index ¶
- Constants
- Variables
- func BadRequest(w http.ResponseWriter, err error) error
- func BoolParam(r *http.Request, name string) (bool, error)
- func DecodeJSON(r *http.Request, v any) error
- func Error(w http.ResponseWriter, statusCode int, err error) error
- func Float64Param(r *http.Request, name string) (float64, error)
- func Int64Param(r *http.Request, name string) (int64, error)
- func IntParam(r *http.Request, name string) (int, error)
- func InternalServerError(w http.ResponseWriter, err error) error
- func JSON(w http.ResponseWriter, statusCode int, v any) error
- func MessageError(message string) error
- func Param(r *http.Request, name string) string
- type Components
- type DocIn
- type DocOut
- type Docs
- type Info
- type MediaType
- type Middleware
- type OpenAPI
- type Operation
- type Parameter
- type PathItem
- type RequestBody
- type Response
- type RouteError
- type RouteInfo
- type RouteRegistration
- type Router
- func (r *Router) AddServerEndpoint(url string, description string)
- func (r *Router) Delete(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
- func (r *Router) FuncMap() map[string]any
- func (r *Router) Get(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
- func (r *Router) Group(basePath string, fn func(*Router))
- func (r *Router) Handle(pattern string, handler http.Handler)
- func (r *Router) HandleFunc(pattern string, handler http.HandlerFunc)
- func (r *Router) HandleStatus(httpStatus int, handler http.HandlerFunc)
- func (r *Router) Head(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
- func (r *Router) Host(hostPattern string, fn func(*Router))
- func (r *Router) Mount(pattern string, handler http.Handler)
- func (r *Router) OpenAPI() *OpenAPI
- func (r *Router) OperationID(s string) string
- func (r *Router) Options(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
- func (r *Router) Patch(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
- func (r *Router) Post(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
- func (r *Router) Put(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
- func (r *Router) RedirectTrailingSlash(redirect bool)
- func (r *Router) RouteHost(name string) string
- func (r *Router) RoutePath(name string) string
- func (r *Router) RoutePathWithParams(name string, params map[string]any) string
- func (r *Router) RouteTable() string
- func (r *Router) RouteURL(name string, params map[string]any, scheme string) string
- func (r *Router) Routes() map[string]RouteInfo
- func (r *Router) ServeFile(pattern string, filepath string)
- func (r *Router) ServeFiles(pattern string, fs http.FileSystem)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Subdomain(subdomain string, domain string, fn func(*Router))
- func (r *Router) TryDelete(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
- func (r *Router) TryGet(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
- func (r *Router) TryHandle(pattern string, handler http.Handler) (err error)
- func (r *Router) TryHandleFunc(pattern string, handler http.HandlerFunc) error
- func (r *Router) TryHead(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
- func (r *Router) TryMount(pattern string, handler http.Handler) (err error)
- func (r *Router) TryOptions(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
- func (r *Router) TryPatch(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
- func (r *Router) TryPost(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
- func (r *Router) TryPut(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
- func (r *Router) Use(middleware Middleware)
- func (r *Router) UseDocs(doc Docs)
- func (r *Router) UseOpenapiDocs(use bool)
- func (r *Router) Walk(fn WalkFunc) error
- func (r *Router) WildcardSubdomain(domain string, fn func(*Router))
- func (r *Router) With(fn func(*Router))
- func (r *Router) WriteRouteTable(w io.Writer) error
- type Schema
- type SecurityScheme
- type Server
- type Tag
- type WalkFunc
Constants ¶
View Source
const HeaderFlagDoNotIntercept = "do_not_intercept"
Variables ¶
View Source
var ( DefaultRedirectTrailingSlash = false DefaultRedirectStatusCode = http.StatusTemporaryRedirect // or http.StatusMovedPermanently DefaultUseOpenapiDocs = false OpenApiVersion = "3.0.1" )
Functions ¶
func BadRequest ¶ added in v0.9.0
func BadRequest(w http.ResponseWriter, err error) error
func Float64Param ¶ added in v0.9.0
func InternalServerError ¶ added in v0.9.0
func InternalServerError(w http.ResponseWriter, err error) error
func MessageError ¶ added in v0.9.0
Types ¶
type Components ¶
type Components struct {
Schemas map[string]Schema `json:"schemas,omitempty"` // Reusable schemas
SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty"` // Security schemes
}
Components holds reusable components such as schemas and security schemes.
type Docs ¶
type Docs struct {
Tags []string // Tags for the operation
Summary string // Short summary of the operation
Description string // Operation description
Parameters []Parameter // Parameters for the operation
RequestBody *RequestBody // Request body for the operation
Responses map[string]Response // Expected responses
Security []map[string][]string // Security requirements
In map[string]DocIn
Out map[string]DocOut
}
type Info ¶
type Info struct {
Title string `json:"title" validate:"required"` // API title
Description string `json:"description,omitempty"` // API description
Version string `json:"version" validate:"required"` // API version
}
Info represents the API metadata.
type MediaType ¶
type MediaType struct {
Schema *Schema `json:"schema,omitempty"` // Schema describing the type
}
MediaType represents the media type of a request or response body.
type OpenAPI ¶
type OpenAPI struct {
Openapi string `json:"openapi" validate:"required"` // OpenAPI version (e.g., "3.0.1")
Info Info `json:"info" validate:"required"` // API information
Servers []Server `json:"servers,omitempty"` // Server details
Paths map[string]PathItem `json:"paths" validate:"required"` // Paths and operations
Components Components `json:"components,omitempty"` // Components such as schemas and security schemes
Security []map[string][]string `json:"security,omitempty"` // Global security settings
Tags []Tag `json:"tags,omitempty"` // Tags for API organization
}
OpenAPI represents the root OpenAPI document.
type Operation ¶
type Operation struct {
Tags []string `json:"tags,omitempty"` // Tags for the operation
Summary string `json:"summary,omitempty"` // Short summary of the operation
Description string `json:"description,omitempty"` // Operation description
OperationID string `json:"operationId,omitempty"` // Unique operation ID
Parameters []Parameter `json:"parameters,omitempty"` // Parameters for the operation
RequestBody *RequestBody `json:"requestBody,omitempty"` // Request body for the operation
Responses map[string]Response `json:"responses" validate:"required"` // Expected responses
Security []map[string][]string `json:"security,omitempty"` // Security requirements
}
Operation describes a single API operation on a path.
type Parameter ¶
type Parameter struct {
Name string `json:"name" validate:"required"` // Parameter name
In string `json:"in" validate:"required"` // Location (e.g., "query", "header", "path")
Description string `json:"description,omitempty"` // Parameter description
Required bool `json:"required,omitempty"` // Is parameter required?
Schema *Schema `json:"schema,omitempty"` // Schema defining the type
}
Parameter represents a single parameter for an operation.
type PathItem ¶
type PathItem struct {
Get *Operation `json:"get,omitempty"` // GET operation
Head *Operation `json:"head,omitempty"` // HEAD operation
Post *Operation `json:"post,omitempty"` // POST operation
Put *Operation `json:"put,omitempty"` // PUT operation
Delete *Operation `json:"delete,omitempty"` // DELETE operation
Patch *Operation `json:"patch,omitempty"` // PATCH operation
Options *Operation `json:"options,omitempty"` // OPTIONS operation
}
PathItem describes the operations available on a single path.
type RequestBody ¶
type RequestBody struct {
Description string `json:"description,omitempty"` // Request body description
Content map[string]MediaType `json:"content"` // Media types supported by the request
Required bool `json:"required,omitempty"` // Is request body required?
}
RequestBody represents a request body for an operation.
type Response ¶
type Response struct {
Description string `json:"description" validate:"required"` // Response description
Content map[string]MediaType `json:"content,omitempty"` // Media types produced by the response
}
Response describes a single response from an API operation.
type RouteError ¶ added in v0.9.0
type RouteError struct {
Err any
}
func (RouteError) Error ¶ added in v0.9.0
func (e RouteError) Error() string
type RouteRegistration ¶ added in v0.9.0
type RouteRegistration struct {
// contains filtered or unexported fields
}
func (*RouteRegistration) As ¶ added in v0.9.0
func (rr *RouteRegistration) As(name string)
func (*RouteRegistration) TryAs ¶ added in v0.9.0
func (rr *RouteRegistration) TryAs(name string) (err error)
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) AddServerEndpoint ¶
func (*Router) Delete ¶
func (r *Router) Delete(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
func (*Router) Get ¶
func (r *Router) Get(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
func (*Router) HandleFunc ¶ added in v0.9.0
func (r *Router) HandleFunc(pattern string, handler http.HandlerFunc)
func (*Router) HandleStatus ¶ added in v0.2.0
func (r *Router) HandleStatus(httpStatus int, handler http.HandlerFunc)
func (*Router) Head ¶
func (r *Router) Head(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
func (*Router) OperationID ¶
func (*Router) Options ¶ added in v0.9.0
func (r *Router) Options(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
func (*Router) Patch ¶
func (r *Router) Patch(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
func (*Router) Post ¶
func (r *Router) Post(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
func (*Router) Put ¶
func (r *Router) Put(pattern string, handler http.HandlerFunc, doc ...Docs) *RouteRegistration
func (*Router) RedirectTrailingSlash ¶
func (*Router) RoutePathWithParams ¶ added in v0.9.0
func (*Router) RouteTable ¶ added in v0.9.0
func (*Router) ServeFiles ¶
func (r *Router) ServeFiles(pattern string, fs http.FileSystem)
func (*Router) TryDelete ¶ added in v0.9.0
func (r *Router) TryDelete(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
func (*Router) TryGet ¶ added in v0.9.0
func (r *Router) TryGet(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
func (*Router) TryHandleFunc ¶ added in v0.9.0
func (r *Router) TryHandleFunc(pattern string, handler http.HandlerFunc) error
func (*Router) TryHead ¶ added in v0.9.0
func (r *Router) TryHead(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
func (*Router) TryOptions ¶ added in v0.9.0
func (r *Router) TryOptions(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
func (*Router) TryPatch ¶ added in v0.9.0
func (r *Router) TryPatch(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
func (*Router) TryPost ¶ added in v0.9.0
func (r *Router) TryPost(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
func (*Router) TryPut ¶ added in v0.9.0
func (r *Router) TryPut(pattern string, handler http.HandlerFunc, doc ...Docs) (*RouteRegistration, error)
func (*Router) Use ¶
func (r *Router) Use(middleware Middleware)
func (*Router) UseOpenapiDocs ¶
func (*Router) WildcardSubdomain ¶ added in v0.9.0
type Schema ¶
type Schema struct {
Ref string `json:"$ref,omitempty"` // Reference to a schema
Type string `json:"type,omitempty"` // Data type (e.g., "string", "object")
Format string `json:"format,omitempty"` // Data format (e.g., "uuid", "email")
Properties map[string]Schema `json:"properties,omitempty"` // Properties of the object
Items *Schema `json:"items,omitempty"` // Schema for array items
AdditionalProperties *Schema `json:"additionalProperties,omitempty"` // Schema for map values
Required []string `json:"required,omitempty"` // Required properties
Enum []any `json:"enum,omitempty"` // Allowed values
Nullable bool `json:"nullable,omitempty"` // Whether the value can be null
}
Schema represents the structure of a request or response body.
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type" validate:"required"` // Security scheme type (e.g., "http", "apiKey")
Scheme string `json:"scheme,omitempty"` // HTTP Authorization scheme (e.g., "bearer")
BearerFormat string `json:"bearerFormat,omitempty"` // Bearer token format
}
SecurityScheme defines a security scheme for the API.
type Server ¶
type Server struct {
URL string `json:"url" validate:"required"` // Server URL
Description string `json:"description,omitempty"` // Server description
Variables map[string]string `json:"variables,omitempty"` // Variables for URL template
}
Server represents an API server.
Click to show internal directories.
Click to hide internal directories.