go-healthchecks/check.go

60 lines
942 B
Go
Raw Normal View History

2024-10-02 13:26:14 +00:00
package gohealthchecks
import (
"path"
"github.com/google/uuid"
)
type Check interface {
path() string
params() map[string]string
}
type uuidCheck uuid.UUID
func (c uuidCheck) path() string {
return uuid.UUID(c).String()
}
func (c uuidCheck) params() map[string]string {
return nil
}
func NewUUIDCheck(rawUUID string) (Check, error) {
val, err := uuid.Parse(rawUUID)
if err != nil {
return nil, err
}
return uuidCheck(val), nil
}
type slugCheck struct {
pingKey string
slug string
autoCreate bool
}
func (c slugCheck) path() string {
return path.Join(c.pingKey, c.slug)
}
func (c slugCheck) params() map[string]string {
res := map[string]string{}
createVal := "0"
if c.autoCreate {
createVal = "1"
}
res["create"] = createVal
return res
}
func NewSlugCheck(pingKey, slug string, autoCreate bool) Check {
return slugCheck{
pingKey: pingKey,
slug: slug,
autoCreate: autoCreate,
}
}