Documentation
¶
Index ¶
Constants ¶
const ( DefaultReadTimeout = 600 DefaultWriteTimeout = 600 DefaultHost = "localhost" DefaultPort = 2201 DefaultEndpoint = "/metrics" ErrNilConfig = utils.Error("Config is nil") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Host string `json:"host"`
Port int `json:"port"`
Endpoint string `json:"endpoint"`
ReadTimeout int `json:"readTimeout"`
WriteTimeout int `json:"writeTimeout"`
tlsProvider.ServerConfig
}
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewCustomServer ¶
func NewCustomServer(cfg *Config, gatherer prometheus.Gatherer, opts promhttp.HandlerOpts) (*Server, error)
NewCustomServer creates a new custom server based on the provided config, Prometheus gatherer, and handler options. It validates the config using the ParseToken method, then creates a new http.ServeMux and registers the Prometheus handler with it. The server is created with the specified host, port, router, read timeout, write timeout, and TLS config. Finally, it returns a pointer to the created Server instance. Example usage:
cfg := &Config{...}
gatherer := prometheus.DefaultGatherer
opts := promhttp.HandlerOpts{...}
server, err := NewCustomServer(*cfg, gatherer, opts)
if err != nil {
// handle error
}
defer server.Shutdown(context.Background())
err = server.Start()
if err != nil {
// handle error
}
func (*Server) Shutdown ¶
Shutdown gracefully shuts down the server by calling the Shutdown method of the underlying http.Server It takes a context.Context object as a parameter, which can be used to control the shutdown process. The method returns an error if the shutdown process fails.
func (*Server) Start ¶
Start starts the server and listens for incoming connections. It uses the http.ListenAndServe function if the server's TLSConfig is nil, otherwise it uses the http.ListenAndServeTLS function. The method returns an error if the server fails to start. If the server is shut down using the Shutdown method, the returned error is http.ErrServerClosed.