44 lines
842 B
Go

package handler
import (
"context"
"net/http"
"os"
)
// HandlerFunc describes the signature all metric handler functions must have.
type HandlerFunc func(
ctx context.Context,
metricParams map[string]string,
extraParams ...string,
) (any, error)
// Handler hold client and syscall implementation for request functions.
type Handler struct {
client *http.Client
sysCalls systemCalls
}
type systemCalls interface {
environ() []string
lookupEnv(key string) (string, bool)
}
type osWrapper struct{}
// New creates a new handler with initialized clients for system and tcp calls.
func New() *Handler {
return &Handler{
client: http.DefaultClient,
sysCalls: osWrapper{},
}
}
func (osWrapper) environ() []string {
return os.Environ()
}
func (osWrapper) lookupEnv(key string) (string, bool) {
return os.LookupEnv(key)
}