Documentation
¶
Overview ¶
Package service provides service-related facilities.
Index ¶
Constants ¶
const ( // AnyMethod should be passed when a handler wants to support any HTTP method. AnyMethod = "Any" // ReadinessEndpoint is the default URL for a readiness endpoint. ReadinessEndpoint = "/readiness" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { ListenAddress string // Address in the format [host/ip]:port. Mandatory. LogLevel string // INFO,FATAL,ERROR,WARN, DEBUG, TRACE. Cors *CorsConfig // Optional cors config. ReadinessCheck bool // Set to true to add a readiness handler at /readiness. Handlers []Handler // Array of handlers. CertConfig *ServerCertificateConfig // Optional TLS configuration. RateLimit *RateLimitConfig // Optional rate limiting config. MiddlewareHandlers []MiddlewareHandler // Optional middleware handlers which will be run on every request. Metrics bool // Optional. If true add a prometheus endpoint. ErrorHandler *MiddlewareHandler // Optional. If true a handler will be added to the end of the chain. }
Config will hold the configuration of the service.
type CorsConfig ¶
type CorsConfig struct { Groups []string // Optional - which group(s) should the CORS config run on. Empty means the default route. Enabled bool // Whether CORS is enabled or not. OverrideCfg *cors.Config // Optional. Only required if you do not want to use the default CORS configuration. }
CorsConfig specifies the CORS related config.
type Handler ¶
type Handler struct { Method string // HTTP method or service.AnyMethod to support all limits. Path string // The path the endpoint runs on. Group string // Optional - specify a group (used to control which middlewares will run) Handler func(c *gin.Context) // The handler to be used. RateLimitConfig *HandlerRateLimitConfig // Optional rate limiting config specifically for the handler. }
Handler will hold all the callback handlers to be registered. N.B. gin will be used.
type HandlerRateLimitConfig ¶ added in v0.3.0
type HandlerRateLimitConfig struct { Limit int // The number of requests allowed within the timeframe. Within int // The timeframe(seconds) the requests are allowed in. }
HandlerRateLimitConfig holds the rate limiting config fo a sepecific handler.
type MiddlewareHandler ¶
type MiddlewareHandler struct { Groups []string // Optional - what group should this middleware run on. Empty means the default route. Handler func(c *gin.Context) // The handler to be used. }
MiddlewareHandler will hold a middleware handler and the groups on which it should be registered.
type RateLimitConfig ¶
type RateLimitConfig struct { Groups []string // Optional - which group(s) should the rate limiting run on. Empty means the default route. Limit int // The number of requests allowed within the timeframe. Within int // The timeframe(seconds) the requests are allowed in. }
RateLimitConfig specifies the rate limiting config.
type ServerCertificateConfig ¶
type ServerCertificateConfig struct { CertificateFile string // The TLS certificate file. KeyFile string // The TLS private key file. }
ServerCertificateConfig holds detail of the certificate config to be used.
type Service ¶
type Service struct { *http.Server // Anonymous embedded struct to allow access to http server methods. // contains filtered or unexported fields }
Service will be the actual structure returned.
func NewService ¶
NewService will setup a new service based on the config and return this service.