gatus/config/endpoint/key.go

19 lines
528 B
Go
Raw Normal View History

package endpoint
import "strings"
// ConvertGroupAndEndpointNameToKey converts a group and an endpoint to a key
2021-12-14 01:23:35 +01:00
func ConvertGroupAndEndpointNameToKey(groupName, endpointName string) string {
return sanitize(groupName) + "_" + sanitize(endpointName)
}
func sanitize(s string) string {
s = strings.TrimSpace(strings.ToLower(s))
s = strings.ReplaceAll(s, "/", "-")
s = strings.ReplaceAll(s, "_", "-")
s = strings.ReplaceAll(s, ".", "-")
s = strings.ReplaceAll(s, ",", "-")
s = strings.ReplaceAll(s, " ", "-")
return s
}