Documentation
¶
Index ¶
- Constants
- Variables
- func NewAuthService(users []UserConfig) *authService
- func NewRoot(engine *httpGin.Engine, root string) *routerGroup
- type Config
- type Context
- func (ctx *Context) Abort()
- func (ctx *Context) CanAccessTask(taskUserID string) bool
- func (ctx *Context) ClientIP() string
- func (ctx *Context) DefaultQuery(key, defaultValue string) string
- func (ctx *Context) ErrorStatusMapper() response.HTTPStatusMapper
- func (ctx *Context) Header(key, val string)
- func (ctx *Context) JSON(code int, obj any)
- func (ctx *Context) Next()
- func (ctx *Context) Param(key string) string
- func (ctx *Context) ParseListParams() (ListParams, error)
- func (ctx *Context) ProtoBuf(code int, obj any)
- func (ctx *Context) Query(key string) string
- func (ctx *Context) Request() *http.Request
- func (ctx *Context) ShouldBindBodyWith(obj any, b httpBinding.BindingBody) error
- func (ctx *Context) ShouldBindJSON(obj any) error
- func (ctx *Context) ShouldBindQuery(obj any) error
- func (ctx *Context) Status(code int)
- func (ctx *Context) Writer() http.ResponseWriter
- type ErrHandlerContextFunc
- type HandlerContextFunc
- type ListParams
- type Permission
- type RateLimitConfig
- type Route
- type Server
- func (s *Server) Close() error
- func (s *Server) Done() <-chan struct{}
- func (s *Server) Group() *routerGroup
- func (s *Server) MustRegisterRoutes(subGroup string, routes []Route)
- func (s *Server) RegisterOpenAPIHandlers(specification []byte, register func(router httpGin.IRouter)) error
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Start(addr string) error
- func (s *Server) StrictErrorHandlers() StrictErrorHandlers
- func (s *Server) Wait(ctx context.Context) error
- type StrictErrorHandlers
- type User
- type UserConfig
Constants ¶
const ( // DefaultListLimit is the default page size for list endpoints. DefaultListLimit = 100 // MaxListLimit is the maximum allowed page size. MaxListLimit = 1000 )
const MethodAny = "*"
MethodAny registers a route for all HTTP methods supported by Gin.
Variables ¶
var ErrServerStopping = errors.New("http server is stopping")
ErrServerStopping indicates that the server is already shutting down.
Functions ¶
func NewAuthService ¶
func NewAuthService(users []UserConfig) *authService
NewAuthService creates a compatibility adapter for the HTTP server.
Types ¶
type Config ¶
type Config struct {
EnablePProf bool
RateLimit *RateLimitConfig
EnableRetry bool
AuthTokens []string
AuthUsers []UserConfig
PublicPaths []string
AdminPaths []string
PromReg *prometheus.Registry
VersionInfo *version.Info
ReadHeaderTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
MaxHeaderBytes int
MaxBodyBytes int64
ErrorStatusMapper response.HTTPStatusMapper
}
Config defines the configuration options for the HTTP server.
type Context ¶
Context is a custom request context that wraps gin.Context internally. All gin types are hidden; callers only interact with this type.
func (*Context) Abort ¶
func (ctx *Context) Abort()
Abort prevents pending handlers from being called.
func (*Context) CanAccessTask ¶
CanAccessTask reports whether the current user may access a task owned by taskUserID.
func (*Context) DefaultQuery ¶
Query returns the query string value for the given key, or the defaultValue if not present.
func (*Context) ErrorStatusMapper ¶
func (ctx *Context) ErrorStatusMapper() response.HTTPStatusMapper
ErrorStatusMapper returns the process-specific API error status directory.
func (*Context) Param ¶
Param returns the URL path parameter for the given key (e.g. "id" for "/:id").
func (*Context) ParseListParams ¶
func (ctx *Context) ParseListParams() (ListParams, error)
ParseListParams reads limit/offset/sort from the query string. Defaults apply only to absent parameters; explicit limits must be positive.
func (*Context) ShouldBindBodyWith ¶
func (ctx *Context) ShouldBindBodyWith(obj any, b httpBinding.BindingBody) error
ShouldBindBodyWith decodes the request body using the given binding. Useful for ProtoBuf and other non-JSON encodings.
func (*Context) ShouldBindJSON ¶
ShouldBindJSON decodes the JSON request body into obj.
func (*Context) ShouldBindQuery ¶
ShouldBindQuery binds query string parameters into obj using the form binding.
func (*Context) Writer ¶
func (ctx *Context) Writer() http.ResponseWriter
Writer returns the underlying http.ResponseWriter.
type ErrHandlerContextFunc ¶
ErrHandlerContextFunc is a handler that returns an error for uniform error handling.
type HandlerContextFunc ¶
type HandlerContextFunc func(*Context)
HandlerContextFunc is a middleware/handler that receives a custom Context.
func NewAuthMiddleware ¶
func NewAuthMiddleware(svc *authService, pathSets ...[]string) HandlerContextFunc
NewAuthMiddleware returns a HandlerContextFunc that validates requests using the given authService.
type ListParams ¶
ListParams holds pagination and sorting parameters for list endpoints. Sort uses a leading "-" for descending, e.g. "-created_at".
type Permission ¶
type Permission = authn.Permission
type RateLimitConfig ¶
RateLimitConfig enables per-client rate limiting.
type Route ¶
type Route struct {
Method string
Path string
Handler ErrHandlerContextFunc
}
Route defines an HTTP route.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is an HTTP server instance.
func (*Server) Close ¶
Close forcefully closes active HTTP connections after graceful draining fails.
func (*Server) Done ¶
func (s *Server) Done() <-chan struct{}
Done is closed when the serving goroutine exits.
func (*Server) Group ¶
func (s *Server) Group() *routerGroup
Group return the cgroup for this httpserver
func (*Server) MustRegisterRoutes ¶
func (*Server) RegisterOpenAPIHandlers ¶
func (s *Server) RegisterOpenAPIHandlers( specification []byte, register func(router httpGin.IRouter), ) error
RegisterOpenAPIHandlers validates generated routes against their bundled specification before dispatching to the generated Gin adapter.
func (*Server) StrictErrorHandlers ¶
func (s *Server) StrictErrorHandlers() StrictErrorHandlers
StrictErrorHandlers returns callbacks using the server's error directory.
type StrictErrorHandlers ¶
type StrictErrorHandlers struct {
RequestError func(ctx *httpGin.Context, err error)
HandlerError func(ctx *httpGin.Context, err error)
ResponseError func(ctx *httpGin.Context, err error)
}
StrictErrorHandlers adapts generated Strict Server errors to the shared error response boundary.
func NewStrictErrorHandlers ¶
func NewStrictErrorHandlers(statusMapper response.HTTPStatusMapper) StrictErrorHandlers
NewStrictErrorHandlers returns callbacks for generated Strict Server options.
type UserConfig ¶
type UserConfig = authn.UserConfig
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth provides framework-independent authentication and authorization.
|
Package auth provides framework-independent authentication and authorization. |
|
Package pprof provides a standalone HTTP server for Go runtime profiles.
|
Package pprof provides a standalone HTTP server for Go runtime profiles. |