Documentation
¶
Index ¶
- Constants
- func GinHandler(h Handler) gin.HandlerFunc
- func MetricsHandler() http.Handler
- func MetricsMiddleware() gin.HandlerFunc
- func MetricsRegistry() *prometheus.Registry
- func StartAdmin(ctx context.Context, cfg AdminConfig) error
- type AdminConfig
- type AdminSetup
- type Component
- type Config
- type Context
- func (c *Context) BindJSON(v any) error
- func (c *Context) ClientIP() string
- func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
- func (c *Context) FormValue(name string) string
- func (c *Context) Get(key string) (any, bool)
- func (c *Context) GetCookie(name string) (string, error)
- func (c *Context) GetHeader(name string) string
- func (c *Context) Html(layout, view string, data any) error
- func (c *Context) JSON(resp any)
- func (c *Context) Json(resp any)
- func (c *Context) Next()
- func (c *Context) Param(name string) string
- func (c *Context) ParamInt(name string) (int, error)
- func (c *Context) Path() string
- func (c *Context) Query(name string) string
- func (c *Context) QueryInt(name string) (int, error)
- func (c *Context) Redirect(url string, code int)
- func (c *Context) Request() *http.Request
- func (c *Context) ResponseWriter() http.ResponseWriter
- func (c *Context) Set(key string, value any)
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) Status(code int)
- func (c *Context) Write(data []byte) (int, error)
- type Handler
- type Router
- type Server
- func (s *Server) AdvancedConfig(handler func(*gin.Engine)) *Server
- func (s *Server) EnableMetrics() *Server
- func (s *Server) GetEngine() *gin.Engine
- func (s *Server) LoadHTMLGlob(pattern string) *Server
- func (s *Server) RegisterComponent(component Component) *Server
- func (s *Server) RegisterComponents(components ...Component) *Server
- func (s *Server) SetHomePage(indexHTML string) *Server
- func (s *Server) SetNoRoute(handler Handler) *Server
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) StaticFS(relativePath string, fs http.FileSystem) *Server
Constants ¶
const DefaultAdminListen = ":6060"
DefaultAdminListen is the default admin listen address (pprof + metrics + admin API).
const DefaultAdminLogLevelPath = "/cl"
DefaultAdminLogLevelPath is the admin listener path for runtime log level changes.
const DefaultMetricsPath = "/metrics"
const DefaultPprofPath = "/pprof"
DefaultPprofPath is the URL prefix for pprof routes on the admin listener.
Variables ¶
This section is empty.
Functions ¶
func GinHandler ¶ added in v1.23.2
func GinHandler(h Handler) gin.HandlerFunc
GinHandler adapts a server.Handler to gin.HandlerFunc (e.g. admin listener routes).
func MetricsHandler ¶ added in v1.23.2
MetricsHandler serves Prometheus metrics from the shared registry (admin listener).
func MetricsMiddleware ¶ added in v1.23.2
func MetricsMiddleware() gin.HandlerFunc
MetricsMiddleware records HTTP RED metrics into the shared registry (main web server).
func MetricsRegistry ¶ added in v1.23.2
func MetricsRegistry() *prometheus.Registry
MetricsRegistry returns the shared Prometheus registry for custom business metrics.
func StartAdmin ¶ added in v1.23.7
func StartAdmin(ctx context.Context, cfg AdminConfig) error
StartAdmin listens on cfg.Listen and serves pprof, /metrics, and admin routes. Returns immediately with nil when Listen is empty.
Types ¶
type AdminConfig ¶ added in v1.23.7
type AdminConfig struct {
Listen string // e.g. DefaultAdminListen; empty disables the listener
Path string // pprof prefix, default DefaultPprofPath
MetricsPath string // default DefaultMetricsPath
LogLvl string // "debug" enables Gin route listing (same as web LogLvl)
StripTrailingSlash bool // rewrite /demo/ping/ → /demo/ping before routing (no 301)
Setup AdminSetup
}
AdminConfig configures the admin HTTP listener (pprof, metrics, and admin API).
type AdminSetup ¶ added in v1.23.5
type AdminSetup func(Router)
AdminSetup registers custom routes on the admin HTTP listener (:6060). Same signature as Component so business code uses server.Router, not gin.
type Context ¶ added in v1.12.6
type Context struct {
// contains filtered or unexported fields
}
Context is the framework-agnostic HTTP request context passed to handlers and middleware.
func (*Context) FormFile ¶ added in v1.23.2
func (c *Context) FormFile(name string) (*multipart.FileHeader, error)
FormFile returns the first file for the given multipart form key.
func (*Context) FormValue ¶ added in v1.23.2
FormValue returns the first value for the given form key.
func (*Context) Html ¶ added in v1.12.6
Html renders a server-side template named view with data. layout is ignored; templates must be loaded via Server.LoadHTMLGlob.
func (*Context) Next ¶ added in v1.23.2
func (c *Context) Next()
Next invokes the remaining handlers in the middleware chain.
func (*Context) Param ¶ added in v1.23.2
Param returns the path parameter named name (e.g. ":id" in the route).
func (*Context) ParamInt ¶ added in v1.23.2
ParamInt parses the path parameter named name as an int.
func (*Context) QueryInt ¶ added in v1.23.2
QueryInt parses the URL query parameter named name as an int.
func (*Context) Redirect ¶ added in v1.23.2
Redirect sends an HTTP redirect to url with the given status code.
func (*Context) ResponseWriter ¶ added in v1.23.2
func (c *Context) ResponseWriter() http.ResponseWriter
ResponseWriter returns the underlying HTTP response writer.
func (*Context) Set ¶ added in v1.23.2
Set stores a value in the per-request context (visible to later middleware/handlers).
type Handler ¶ added in v1.12.6
type Handler func(ctx Context)
func FileServerNoRoute ¶ added in v1.23.4
func FileServerNoRoute(fs http.FileSystem) Handler
FileServerNoRoute serves files from fs for unmatched GET/HEAD requests. Use as Gin NoRoute handler so root StaticFS does not conflict with /api, /m, etc.
type Router ¶ added in v1.12.6
type Router interface {
Get(path string, handlers ...Handler)
Post(path string, handlers ...Handler)
Put(path string, handlers ...Handler)
Delete(path string, handlers ...Handler)
Patch(path string, handlers ...Handler)
Options(path string, handlers ...Handler)
Any(path string, handlers ...Handler)
Path(prefix string) Router
MountPprof(relativePath string)
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) EnableMetrics ¶ added in v1.23.2
EnableMetrics installs HTTP RED Prometheus middleware on the main web server.