Documentation
¶
Index ¶
- func ParseAndValidateParams[Params any](r *http.Request) (Params, error)
- type Application
- type AuthenticatedJsonHandlerFunc
- func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetAccepts() string
- func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetAuthHandler() any
- func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetAuthModel() any
- func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetHandler() any
- func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetParams() any
- func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetProduces() string
- func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetRequestBody() any
- func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetResponseBody() any
- func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type AuthenticatedMultipartHandlerFunc
- func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetAccepts() string
- func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthHandler() any
- func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthModel() any
- func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetHandler() any
- func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetParams() any
- func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetProduces() string
- func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetRequestBody() any
- func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetResponseBody() any
- func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type AuthenticatedRawBodyHandlerFunc
- func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetAccepts() string
- func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthHandler() any
- func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthModel() any
- func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetHandler() any
- func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetParams() any
- func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetProduces() string
- func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetRequestBody() any
- func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetResponseBody() any
- func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Handler
- func AuthJsonHandler[RequestBody, Params, AuthModel, ResponseBody any](...) Handler
- func AuthMultipartHandler[Params, AuthModel, ResponseBody any](...) Handler
- func AuthRawBodyHandler[Params, AuthModel, ResponseBody any](...) Handler
- func HTTPHandler(handler http.Handler) Handler
- func JsonHandler[RequestBody, Params, ResponseBody any](h JsonHandlerFunc[RequestBody, Params, ResponseBody]) Handler
- func MultipartHandler[Params any, ResponseBody any](h MultipartHandlerFunc[Params, ResponseBody]) Handler
- func RawBodyHandler[Params, ResponseBody any](h RawBodyHandlerFunc[Params, ResponseBody]) Handler
- type JsonHandlerFunc
- func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetAccepts() string
- func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetAuthHandler() any
- func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetAuthModel() any
- func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetHandler() any
- func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetParams() any
- func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetProduces() string
- func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetRequestBody() any
- func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetResponseBody() any
- func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type MultipartHandlerFunc
- func (h MultipartHandlerFunc[Params, ResponseBody]) GetAccepts() string
- func (h MultipartHandlerFunc[Params, ResponseBody]) GetAuthHandler() any
- func (h MultipartHandlerFunc[Params, ResponseBody]) GetAuthModel() any
- func (h MultipartHandlerFunc[Params, ResponseBody]) GetHandler() any
- func (h MultipartHandlerFunc[Params, ResponseBody]) GetParams() any
- func (h MultipartHandlerFunc[Params, ResponseBody]) GetProduces() string
- func (h MultipartHandlerFunc[Params, ResponseBody]) GetRequestBody() any
- func (h MultipartHandlerFunc[Params, ResponseBody]) GetResponseBody() any
- func (h MultipartHandlerFunc[Params, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type NoOpTelemetryProvider
- type RawBodyHandlerFunc
- func (h RawBodyHandlerFunc[Params, ResponseBody]) GetAccepts() string
- func (h RawBodyHandlerFunc[Params, ResponseBody]) GetAuthHandler() any
- func (h RawBodyHandlerFunc[Params, ResponseBody]) GetAuthModel() any
- func (h RawBodyHandlerFunc[Params, ResponseBody]) GetHandler() any
- func (h RawBodyHandlerFunc[Params, ResponseBody]) GetParams() any
- func (h RawBodyHandlerFunc[Params, ResponseBody]) GetProduces() string
- func (h RawBodyHandlerFunc[Params, ResponseBody]) GetRequestBody() any
- func (h RawBodyHandlerFunc[Params, ResponseBody]) GetResponseBody() any
- func (h RawBodyHandlerFunc[Params, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type Router
- func (r *Router) DELETE(path string, handler Handler)
- func (r *Router) DELETEWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
- func (r *Router) Extend(middleware []func(http.Handler) http.Handler)
- func (r *Router) GET(path string, handler Handler)
- func (r *Router) GETWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
- func (r *Router) GenerateOpenAPIDocumentation(ctx context.Context, title, version string) error
- func (r *Router) HEAD(path string, handler Handler)
- func (r *Router) HEADWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
- func (r *Router) Handle(method, path string, handler Handler)
- func (r *Router) HandleHTTP(method, path string, handler http.Handler)
- func (r *Router) OPTIONS(path string, handler Handler)
- func (r *Router) OPTIONSWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
- func (r *Router) PATCH(path string, handler Handler)
- func (r *Router) PATCHWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
- func (r *Router) POST(path string, handler Handler)
- func (r *Router) POSTWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
- func (r *Router) PUT(path string, handler Handler)
- func (r *Router) PUTWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Use(middleware func(http.Handler) http.Handler)
- func (r *Router) WithMiddleware(method, path string, handler Handler, ...)
- type TelemetryProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Application ¶
type Application struct {
// ApplicationName is the name of the application
ApplicationName string `yaml:"application-name" env:"APPLICATION_NAME" default:"Simba Application"`
// ApplicationVersion is the version of the application
ApplicationVersion string `yaml:"application-version" env:"APPLICATION_VERSION" default:"0.1.0"`
// Server is the HTTP server for the application
Server *http.Server
// Router is the main Mux for the application
Router *Router
// Settings is the application Settings
Settings *settings.Simba
// contains filtered or unexported fields
}
Application is the main application struct that holds the Mux and other application Settings
func Default ¶
func Default(opts ...settings.Option) *Application
Default returns a new Application application with default Simba
func (*Application) RegisterShutdownHook ¶
func (a *Application) RegisterShutdownHook(hook any)
RegisterShutdownHook adds a callback invoked during Stop. Hooks are executed in registration order.
Supported hook forms include, but are not limited to:
- func()
- func() error
- func(context.Context)
- func(context.Context) error
For other function signatures, non-context parameters are passed as zero values. If a returned value implements error and is non-nil, it is propagated.
func (*Application) SetTelemetryProvider ¶
func (a *Application) SetTelemetryProvider(tp TelemetryProvider)
SetTelemetryProvider allows injection or replacement of the TelemetryProvider after application creation.
func (*Application) Start ¶ added in v0.4.0
func (a *Application) Start()
func (*Application) Stop ¶ added in v0.4.0
func (a *Application) Stop() error
type AuthenticatedJsonHandlerFunc ¶ added in v0.6.0
type AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody any] struct { // contains filtered or unexported fields }
AuthenticatedJsonHandlerFunc is a function type for handling authenticated routes with Request body and params
func (AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetAccepts ¶
func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetAccepts() string
func (AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetAuthHandler ¶
func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetAuthHandler() any
func (AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetAuthModel ¶
func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetAuthModel() any
func (AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetHandler ¶
func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetHandler() any
func (AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetParams ¶
func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetParams() any
func (AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetProduces ¶
func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetProduces() string
func (AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetRequestBody ¶
func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetRequestBody() any
func (AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetResponseBody ¶
func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) GetResponseBody() any
func (AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) ServeHTTP ¶ added in v0.6.0
func (h AuthenticatedJsonHandlerFunc[RequestBody, Params, AuthModel, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface for AuthenticatedJsonHandlerFunc
type AuthenticatedMultipartHandlerFunc ¶ added in v0.7.0
type AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody any] struct { // contains filtered or unexported fields }
AuthenticatedMultipartHandlerFunc is a function type for handling a MultipartRequest with params and an authenticated model
func (AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetAccepts ¶
func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetAccepts() string
func (AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthHandler ¶
func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthHandler() any
func (AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthModel ¶
func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthModel() any
func (AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetHandler ¶
func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetHandler() any
func (AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetParams ¶
func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetParams() any
func (AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetProduces ¶
func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetProduces() string
func (AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetRequestBody ¶
func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetRequestBody() any
func (AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetResponseBody ¶
func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) GetResponseBody() any
func (AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) ServeHTTP ¶ added in v0.7.0
func (h AuthenticatedMultipartHandlerFunc[Params, AuthModel, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
type AuthenticatedRawBodyHandlerFunc ¶ added in v0.27.0
type AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody any] struct { // contains filtered or unexported fields }
AuthenticatedRawBodyHandlerFunc is a function type for handling authenticated routes with Request body and params
func (AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetAccepts ¶
func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetAccepts() string
func (AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthHandler ¶
func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthHandler() any
func (AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthModel ¶
func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetAuthModel() any
func (AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetHandler ¶
func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetHandler() any
func (AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetParams ¶
func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetParams() any
func (AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetProduces ¶
func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetProduces() string
func (AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetRequestBody ¶
func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetRequestBody() any
func (AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetResponseBody ¶
func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) GetResponseBody() any
func (AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) ServeHTTP ¶ added in v0.27.0
func (h AuthenticatedRawBodyHandlerFunc[Params, AuthModel, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface for AuthenticatedRawBodyHandlerFunc
type Handler ¶
type Handler interface {
ServeHTTP(w http.ResponseWriter, r *http.Request)
GetRequestBody() any
GetParams() any
GetResponseBody() any
GetAccepts() string
GetProduces() string
GetHandler() any
GetAuthModel() any
GetAuthHandler() any
}
Handler specifies the interface for a handler that can be registered with the Router.
func AuthJsonHandler ¶ added in v0.6.0
func AuthJsonHandler[RequestBody, Params, AuthModel, ResponseBody any]( handler func(ctx context.Context, req *models.Request[RequestBody, Params], authModel AuthModel) (*models.Response[ResponseBody], error), authHandler auth.Handler[AuthModel], ) Handler
AuthJsonHandler handles a Request with the Request body and params.
Example usage:
Define a Request body struct:
type RequestBody struct {
Test string `json:"test" validate:"required"`
}
Define a Request params struct:
type Params struct {
Name string `header:"name" validate:"required"`
ID int `path:"id" validate:"required"`
Active bool `query:"active" validate:"required"`
Page int64 `query:"page" validate:"min=0"`
Size int64 `query:"size" validate:"min=0"`
}
Define a user struct:
type AuthModel struct {
ID int
Name string
Role string
}
Define a handler function:
func(ctx context.Context, req *simba.Request[RequestBody, Params], authModel AuthModel) (*simba.Response[map[string]string], error) {
// Access the Request body and params fields
req.Body.Test
req.Params.Name
req.Params.ID
req.Params.Page
req.Params.Size
// Access the user fields
user.ID
user.Name
user.Role
// Return a response
return &simba.Response[map[string]string]{
Headers: map[string][]string{"My-Header": {"header-value"}},
Cookies: []*http.Cookie{{Name: "My-Cookie", Value: "cookie-value"}},
Body: map[string]string{"message": "success"},
Status: http.StatusOK,
}, nil
}
Register the handler:
Mux.POST("/test/{id}", simba.AuthJsonHandler(handler))
func AuthMultipartHandler ¶ added in v0.7.0
func AuthMultipartHandler[Params, AuthModel, ResponseBody any]( handler func(ctx context.Context, req *models.MultipartRequest[Params], authModel AuthModel) (*models.Response[ResponseBody], error), authHandler auth.Handler[AuthModel], ) Handler
AuthMultipartHandler handles a MultipartRequest with params and an authenticated model. The MultipartRequest holds a MultipartReader and the parsed params. The reason to provide the reader is to allow the logic for processing the parts to be handled by the handler function.
Example usage:
Define a Request params struct:
type Params struct {
Name string `header:"name" validate:"required"`
ID int `path:"id" validate:"required"`
Active bool `query:"active" validate:"required"`
Page int64 `query:"page" validate:"min=0"`
Size int64 `query:"size" validate:"min=0"`
}
Define a user struct:
type AuthModel struct {
ID int
Name string
Role string
}
Define a handler function:
func(ctx context.Context, req *simba.MultipartRequest[Params], authModel AuthModel) (*simba.Response[map[string]string], error) {
// Access the Multipart reader and params fields
req.Params.Name
req.Params.ID
req.Params.Page
req.Params.Size
req.Reader // Multipart reader
// Access the user fields
user.ID
user.Name
user.Role
// Return a response
return &simba.Response[map[string]string]{
Headers: map[string][]string{"My-Header": {"header-value"}},
Cookies: []*http.Cookie{{Name: "My-Cookie", Value: "cookie-value"}},
Body: map[string]string{"message": "success"},
Status: http.StatusOK,
}, nil
}
Register the handler:
Mux.POST("/test/{id}", simba.AuthMultipartHandler(handler))
func AuthRawBodyHandler ¶ added in v0.27.0
func AuthRawBodyHandler[Params, AuthModel, ResponseBody any]( handler func(ctx context.Context, req *models.Request[io.ReadCloser, Params], authModel AuthModel) (*models.Response[ResponseBody], error), authHandler auth.Handler[AuthModel], ) Handler
AuthRawBodyHandler handles a Request with the Request body and params.
Register the handler:
Mux.POST("/test/{id}", simba.AuthRawBodyHandler(handler))
func HTTPHandler ¶
HTTPHandler adapts a plain http.Handler into a Simba handler. This is useful when mounting protocol-specific handlers, such as WebSocket upgrades, behind the Simba router.
func JsonHandler ¶ added in v0.6.0
func JsonHandler[RequestBody, Params, ResponseBody any](h JsonHandlerFunc[RequestBody, Params, ResponseBody]) Handler
JsonHandler handles a Request with the Request body and params.
Example usage:
Define a Request body struct:
type RequestBody struct {
Test string `json:"test" validate:"required"`
}
Define a Request params struct:
type Params struct {
Name string `header:"name" validate:"required"`
ID int `path:"id" validate:"required"`
Active bool `query:"active" validate:"required"`
Page int64 `query:"page" validate:"min=0"`
Size int64 `query:"size" validate:"min=0"`
}
Define a handler function:
func(ctx context.Context, req *simba.Request[RequestBody, Params]) (*simba.Response[map[string]string], error) {
// Access the Request body and params fields
req.Body.Test
req.Params.Name
req.Params.ID
req.Params.Page
req.Params.Size
// Return a response
return &simba.Response[map[string]string]{
Headers: map[string][]string{"My-Header": {"header-value"}},
Cookies: []*http.Cookie{{Name: "My-Cookie", Value: "cookie-value"}},
Body: map[string]string{"message": "success"},
Status: http.StatusOK,
}, nil
}
Register the handler:
Mux.POST("/test/{id}", simba.JsonHandler(handler))
func MultipartHandler ¶ added in v0.7.0
func MultipartHandler[Params any, ResponseBody any](h MultipartHandlerFunc[Params, ResponseBody]) Handler
MultipartHandler handles a MultipartRequest with params. // The MultipartRequest holds a MultipartReader and the parsed params. // The reason to provide the reader is to allow the logic for processing the parts to be handled by the handler function.
Example usage:
Define a Request params struct:
type Params struct {
Name string `header:"name" validate:"required"`
ID int `path:"id" validate:"required"`
Active bool `query:"active" validate:"required"`
Page int64 `query:"page" validate:"min=0"`
Size int64 `query:"size" validate:"min=0"`
}
Define a handler function:
func(ctx context.Context, req *simba.Request[RequestBody, Params]) (*simba.Response[map[string]string], error) {
// Access the Multipart reader and params fields
req.Params.Name
req.Params.ID
req.Params.Page
req.Params.Size
req.Reader // Multipart reader
// Return a response
return &simba.Response[map[string]string]{
Headers: map[string][]string{"My-Header": {"header-value"}},
Cookies: []*http.Cookie{{Name: "My-Cookie", Value: "cookie-value"}},
Body: map[string]string{"message": "success"},
Status: http.StatusOK,
}, nil
}
Register the handler:
Mux.POST("/test/{id}", simba.MultipartHandler(handler))
func RawBodyHandler ¶ added in v0.27.0
func RawBodyHandler[Params, ResponseBody any](h RawBodyHandlerFunc[Params, ResponseBody]) Handler
RawBodyHandler handles a Request with the Request body and params.
Register the handler:
Mux.POST("/test/{id}", simba.RawBodyHandler(handler))
type JsonHandlerFunc ¶ added in v0.6.0
type JsonHandlerFunc[RequestBody, Params, ResponseBody any] func(ctx context.Context, req *models.Request[RequestBody, Params]) (*models.Response[ResponseBody], error)
JsonHandlerFunc is a function type for handling routes with Request body and params
func (JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetAccepts ¶
func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetAccepts() string
func (JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetAuthHandler ¶
func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetAuthHandler() any
func (JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetAuthModel ¶
func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetAuthModel() any
func (JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetHandler ¶
func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetHandler() any
func (JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetParams ¶
func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetParams() any
func (JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetProduces ¶
func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetProduces() string
func (JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetRequestBody ¶
func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetRequestBody() any
func (JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetResponseBody ¶
func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) GetResponseBody() any
func (JsonHandlerFunc[RequestBody, Params, ResponseBody]) ServeHTTP ¶ added in v0.6.0
func (h JsonHandlerFunc[RequestBody, Params, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface for JsonHandlerFunc
type MultipartHandlerFunc ¶ added in v0.7.0
type MultipartHandlerFunc[Params any, ResponseBody any] func(ctx context.Context, req *models.MultipartRequest[Params]) (*models.Response[ResponseBody], error)
MultipartHandlerFunc is a function type for handling routes with Request body and params
func (MultipartHandlerFunc[Params, ResponseBody]) GetAccepts ¶
func (h MultipartHandlerFunc[Params, ResponseBody]) GetAccepts() string
func (MultipartHandlerFunc[Params, ResponseBody]) GetAuthHandler ¶
func (h MultipartHandlerFunc[Params, ResponseBody]) GetAuthHandler() any
func (MultipartHandlerFunc[Params, ResponseBody]) GetAuthModel ¶
func (h MultipartHandlerFunc[Params, ResponseBody]) GetAuthModel() any
func (MultipartHandlerFunc[Params, ResponseBody]) GetHandler ¶
func (h MultipartHandlerFunc[Params, ResponseBody]) GetHandler() any
func (MultipartHandlerFunc[Params, ResponseBody]) GetParams ¶
func (h MultipartHandlerFunc[Params, ResponseBody]) GetParams() any
func (MultipartHandlerFunc[Params, ResponseBody]) GetProduces ¶
func (h MultipartHandlerFunc[Params, ResponseBody]) GetProduces() string
func (MultipartHandlerFunc[Params, ResponseBody]) GetRequestBody ¶
func (h MultipartHandlerFunc[Params, ResponseBody]) GetRequestBody() any
func (MultipartHandlerFunc[Params, ResponseBody]) GetResponseBody ¶
func (h MultipartHandlerFunc[Params, ResponseBody]) GetResponseBody() any
func (MultipartHandlerFunc[Params, ResponseBody]) ServeHTTP ¶ added in v0.7.0
func (h MultipartHandlerFunc[Params, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface for JsonHandlerFunc
type NoOpTelemetryProvider ¶
type NoOpTelemetryProvider struct{}
NoOpTelemetryProvider implements the TelemetryProvider interface with no-op handlers, for use when no telemetry is desired.
func (NoOpTelemetryProvider) MetricsMiddleware ¶
func (NoOpTelemetryProvider) MetricsMiddleware() func(http.Handler) http.Handler
func (NoOpTelemetryProvider) Shutdown ¶
func (NoOpTelemetryProvider) Shutdown(ctx context.Context) error
func (NoOpTelemetryProvider) TracingMiddleware ¶
func (NoOpTelemetryProvider) TracingMiddleware() func(http.Handler) http.Handler
type RawBodyHandlerFunc ¶ added in v0.27.0
type RawBodyHandlerFunc[Params, ResponseBody any] func(ctx context.Context, req *models.Request[io.ReadCloser, Params]) (*models.Response[ResponseBody], error)
RawBodyHandlerFunc is a function type for handling routes with Request body and params
func (RawBodyHandlerFunc[Params, ResponseBody]) GetAccepts ¶
func (h RawBodyHandlerFunc[Params, ResponseBody]) GetAccepts() string
func (RawBodyHandlerFunc[Params, ResponseBody]) GetAuthHandler ¶
func (h RawBodyHandlerFunc[Params, ResponseBody]) GetAuthHandler() any
func (RawBodyHandlerFunc[Params, ResponseBody]) GetAuthModel ¶
func (h RawBodyHandlerFunc[Params, ResponseBody]) GetAuthModel() any
func (RawBodyHandlerFunc[Params, ResponseBody]) GetHandler ¶
func (h RawBodyHandlerFunc[Params, ResponseBody]) GetHandler() any
func (RawBodyHandlerFunc[Params, ResponseBody]) GetParams ¶
func (h RawBodyHandlerFunc[Params, ResponseBody]) GetParams() any
func (RawBodyHandlerFunc[Params, ResponseBody]) GetProduces ¶
func (h RawBodyHandlerFunc[Params, ResponseBody]) GetProduces() string
func (RawBodyHandlerFunc[Params, ResponseBody]) GetRequestBody ¶
func (h RawBodyHandlerFunc[Params, ResponseBody]) GetRequestBody() any
func (RawBodyHandlerFunc[Params, ResponseBody]) GetResponseBody ¶
func (h RawBodyHandlerFunc[Params, ResponseBody]) GetResponseBody() any
func (RawBodyHandlerFunc[Params, ResponseBody]) ServeHTTP ¶ added in v0.27.0
func (h RawBodyHandlerFunc[Params, ResponseBody]) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface for RawBodyHandlerFunc
type Router ¶ added in v0.2.0
Router is a simple Mux that wraps http.ServeMux and allows for middleware chaining and type information storage for routes.
func (*Router) DELETE ¶ added in v0.2.0
DELETE registers a handler for DELETE requests to the given pattern
func (*Router) DELETEWithMiddleware ¶ added in v0.26.0
func (r *Router) DELETEWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
DELETEWithMiddleware registers a handler for DELETE requests to the given pattern wrapped with a middleware function
func (*Router) GETWithMiddleware ¶ added in v0.26.0
func (r *Router) GETWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
GETWithMiddleware registers a handler for GET requests to the given pattern wrapped with a middleware function
func (*Router) GenerateOpenAPIDocumentation ¶ added in v0.15.0
GenerateOpenAPIDocumentation generates the OpenAPI documentation for the routes mounted in the router if enabled in settings.Docs
func (*Router) HEAD ¶ added in v0.2.0
HEAD registers a handler for HEAD requests to the given pattern
func (*Router) HEADWithMiddleware ¶ added in v0.26.0
func (r *Router) HEADWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
HEADWithMiddleware registers a handler for HEAD requests to the given pattern wrapped with a middleware function
func (*Router) HandleHTTP ¶
HandleHTTP registers a plain http.Handler for the given method and path. This is useful for protocol upgrades such as WebSockets where OpenAPI metadata does not apply.
func (*Router) OPTIONS ¶ added in v0.2.0
OPTIONS registers a handler for OPTIONS requests to the given pattern
func (*Router) OPTIONSWithMiddleware ¶ added in v0.26.0
func (r *Router) OPTIONSWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
OPTIONSWithMiddleware registers a handler for OPTIONS requests to the given pattern wrapped with a middleware function
func (*Router) PATCH ¶ added in v0.2.0
PATCH registers a handler for PATCH requests to the given pattern
func (*Router) PATCHWithMiddleware ¶ added in v0.26.0
func (r *Router) PATCHWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
PATCHWithMiddleware registers a handler for PATCH requests to the given pattern wrapped with a middleware function
func (*Router) POST ¶ added in v0.2.0
POST registers a handler for POST requests to the given pattern
func (*Router) POSTWithMiddleware ¶ added in v0.26.0
func (r *Router) POSTWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
POSTWithMiddleware registers a handler for POST requests to the given pattern wrapped with a middleware function
func (*Router) PUTWithMiddleware ¶ added in v0.26.0
func (r *Router) PUTWithMiddleware(path string, handler Handler, middleware ...func(http.Handler) http.Handler)
PUTWithMiddleware registers a handler for PUT requests to the given pattern wrapped with a middleware function
func (*Router) ServeHTTP ¶ added in v0.2.0
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface for the Router type
type TelemetryProvider ¶
type TelemetryProvider interface {
// TracingMiddleware returns an http.Handler middleware for request tracing.
TracingMiddleware() func(http.Handler) http.Handler
// MetricsMiddleware returns an http.Handler middleware for request metrics.
MetricsMiddleware() func(http.Handler) http.Handler
// Shutdown cleanly shuts down the telemetry provider (noop for NoOpTelemetryProvider)
Shutdown(ctx context.Context) error
}
TelemetryProvider defines the pluggable interface for telemetry (tracing/metrics) in Simba. It is intentionally provider-agnostic: concrete implementations (e.g., OpenTelemetry) live in a subpackage or plugin.