Documentation ¶
Index ¶
- Constants
- Variables
- func Authorization(version string, tokenMaker token.Maker) gin.HandlerFunc
- func CORS() gin.HandlerFunc
- func GetAuthPayload(c *gin.Context) *token.Payload
- func GetTokenMaker(c *gin.Context) token.Maker
- func GetUserID(c *gin.Context) (int64, error)
- func GetUsername(c *gin.Context) (string, error)
- func Jsonifier(version string) gin.HandlerFunc
- func LimitRate(version string, maxRequestsPerSecond int) gin.HandlerFunc
- func Logger(logger *zap.Logger) gin.HandlerFunc
- func ModifyResponse(urls *set.Set, cb func(c *gin.Context, url string, body *bytes.Buffer)) gin.HandlerFunc
- func NewMetric(m *Metric, namespace, subsystem string) prometheus.Collector
- func Recovery(version string, logger *zap.Logger, stack bool) gin.HandlerFunc
- func SetErr(c *gin.Context, statusCode int, err error)
- func SetErrWithTraceBack(c *gin.Context, statusCode int, err error)
- func SetResp(c *gin.Context, value interface{})
- func SetTokenMaker(maker token.Maker) gin.HandlerFunc
- type Error
- type Metric
- type Prometheus
- func (p *Prometheus) HandlerFunc() gin.HandlerFunc
- func (p *Prometheus) SetListenAddress(address string)
- func (p *Prometheus) SetListenAddressWithRouter(listenAddress string, r *gin.Engine)
- func (p *Prometheus) SetMetricsPath(e *gin.Engine)
- func (p *Prometheus) SetMetricsPathWithAuth(e *gin.Engine, accounts gin.Accounts)
- func (p *Prometheus) SetPushGateway(pushGatewayURL, metricsURL string, pushInterval time.Duration)
- func (p *Prometheus) SetPushGatewayJob(j string)
- func (p *Prometheus) Use(e *gin.Engine)
- func (p *Prometheus) UseWithAuth(e *gin.Engine, accounts gin.Accounts)
- type PrometheusPushGateway
- type RequestCounterURLLabelMappingFn
- type Response
- type ResponseBufferWriter
- func (w *ResponseBufferWriter) Flush()
- func (w *ResponseBufferWriter) Size() int
- func (w *ResponseBufferWriter) Status() int
- func (w *ResponseBufferWriter) Write(buf []byte) (int, error)
- func (w *ResponseBufferWriter) WriteHeader(status int)
- func (w *ResponseBufferWriter) WriteString(s string) (int, error)
- func (w *ResponseBufferWriter) Written() bool
Constants ¶
const ( AuthorizationHeaderKey = "authorization" AuthorizationTypeBear = "bearer" )
Variables ¶
var ErrNotfound = errors.New("cannot found")
Functions ¶
func Authorization ¶
func Authorization(version string, tokenMaker token.Maker) gin.HandlerFunc
func CORS ¶
func CORS() gin.HandlerFunc
func Jsonifier ¶
func Jsonifier(version string) gin.HandlerFunc
func ModifyResponse ¶
func ModifyResponse(urls *set.Set, cb func(c *gin.Context, url string, body *bytes.Buffer)) gin.HandlerFunc
ModifyResponse modify response body in cb before returning to client, can filter url through urls parameter, does not filter if urls is nil
func NewMetric ¶
func NewMetric(m *Metric, namespace, subsystem string) prometheus.Collector
NewMetric associates prometheus.Collector based on Metric.Type
func SetTokenMaker ¶
func SetTokenMaker(maker token.Maker) gin.HandlerFunc
Types ¶
type Metric ¶
type Metric struct { MetricCollector prometheus.Collector ID string Name string Description string Type string Args []string }
Metric is a definition for the name, description, type, ID, and prometheus.Collector type (i.e. CounterVec, Summary, etc) of each metric
type Prometheus ¶
type Prometheus struct { Ppg PrometheusPushGateway MetricsList []*Metric MetricsPath string ReqCntURLLabelMappingFn RequestCounterURLLabelMappingFn // gin.Context string to use as a prometheus URL label URLLabelFromContext string // contains filtered or unexported fields }
Prometheus contains the metrics gathered by the instance and its path
func NewPrometheus ¶
func NewPrometheus(namespace, subsystem string, customMetricsList ...[]*Metric) *Prometheus
NewPrometheus generates a new set of metrics with a certain subsystem name
func (*Prometheus) HandlerFunc ¶
func (p *Prometheus) HandlerFunc() gin.HandlerFunc
HandlerFunc defines handler function for middleware
func (*Prometheus) SetListenAddress ¶
func (p *Prometheus) SetListenAddress(address string)
SetListenAddress for exposing metrics on address. If not set, it will be exposed at the same address of the gin engine that is being used
func (*Prometheus) SetListenAddressWithRouter ¶
func (p *Prometheus) SetListenAddressWithRouter(listenAddress string, r *gin.Engine)
SetListenAddressWithRouter for using a separate router to expose metrics. (this keeps things like GET /metrics out of your content's access log).
func (*Prometheus) SetMetricsPath ¶
func (p *Prometheus) SetMetricsPath(e *gin.Engine)
SetMetricsPath set metrics paths
func (*Prometheus) SetMetricsPathWithAuth ¶
func (p *Prometheus) SetMetricsPathWithAuth(e *gin.Engine, accounts gin.Accounts)
SetMetricsPathWithAuth set metrics paths with authentication
func (*Prometheus) SetPushGateway ¶
func (p *Prometheus) SetPushGateway(pushGatewayURL, metricsURL string, pushInterval time.Duration)
SetPushGateway sends metrics to a remote pushgateway exposed on pushGatewayURL every pushInterval. Metrics are fetched from metricsURL
func (*Prometheus) SetPushGatewayJob ¶
func (p *Prometheus) SetPushGatewayJob(j string)
SetPushGatewayJob job name, defaults to "gin"
func (*Prometheus) Use ¶
func (p *Prometheus) Use(e *gin.Engine)
Use adds the middleware to a gin engine.
func (*Prometheus) UseWithAuth ¶
func (p *Prometheus) UseWithAuth(e *gin.Engine, accounts gin.Accounts)
UseWithAuth adds the middleware to a gin engine with BasicAuth.
type PrometheusPushGateway ¶
type PrometheusPushGateway struct { // Push interval in seconds PushInterval time.Duration // Push Gateway URL in format http://domain:port // where JOBNAME can be any string of your choice PushGatewayURL string // Local metrics URL where metrics are fetched from, this could be omitted in the future // if implemented using prometheus common/expfmt instead MetricsURL string // pushgateway job name, defaults to "gin" Job string }
PrometheusPushGateway contains the configuration for pushing to a Prometheus pushgateway (optional)
type RequestCounterURLLabelMappingFn ¶
RequestCounterURLLabelMappingFn is a function which can be supplied to the middleware to control the cardinality of the request counter's "url" label, which might be required in some contexts. For instance, if for a "/customer/:name" route you don't want to generate a time series for every possible customer name, you could use this function:
func(c *gin.Context) string { url := c.Request.URL.Path for _, p := range c.Params { if p.Key == "name" { url = strings.Replace(url, p.Value, ":name", 1) break } } return url }
which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name".
type ResponseBufferWriter ¶
type ResponseBufferWriter struct { gin.ResponseWriter // contains filtered or unexported fields }
func NewResponseBufferWriter ¶
func NewResponseBufferWriter(w gin.ResponseWriter) *ResponseBufferWriter
func (*ResponseBufferWriter) Flush ¶
func (w *ResponseBufferWriter) Flush()
func (*ResponseBufferWriter) Size ¶
func (w *ResponseBufferWriter) Size() int
func (*ResponseBufferWriter) Status ¶
func (w *ResponseBufferWriter) Status() int
func (*ResponseBufferWriter) WriteHeader ¶
func (w *ResponseBufferWriter) WriteHeader(status int)
func (*ResponseBufferWriter) WriteString ¶
func (w *ResponseBufferWriter) WriteString(s string) (int, error)
func (*ResponseBufferWriter) Written ¶
func (w *ResponseBufferWriter) Written() bool