Documentation
¶
Index ¶
- Constants
- func GinHandler(h Handler) gin.HandlerFunc
- func MetricsHandler() http.Handler
- func MetricsMiddleware() gin.HandlerFunc
- func MetricsRegistry() *prometheus.Registry
- func StartPprof(ctx context.Context, cfg PprofConfig) error
- 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 PprofConfig
- 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 DefaultAdminLogLevelPath = "/cl"
DefaultAdminLogLevelPath is the admin listener path for runtime log level changes.
const DefaultMetricsPath = "/metrics"
const DefaultPprofListen = ":6060"
DefaultPprofListen is the default admin listen address (pprof + 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 StartPprof ¶ added in v1.23.2
func StartPprof(ctx context.Context, cfg PprofConfig) error
StartPprof listens on cfg.Listen and serves pprof and /metrics. Returns immediately with nil when Listen is empty.
Types ¶
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 PprofConfig ¶ added in v1.23.2
type PprofConfig struct {
Listen string // e.g. DefaultPprofListen; empty disables the listener
Path string // pprof prefix, default DefaultPprofPath
MetricsPath string // default DefaultMetricsPath
Setup func(*gin.Engine)
}
PprofConfig configures the admin HTTP listener (pprof, metrics, and admin API).
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.