blasphem/pkg/server/config/config.go
2022-10-25 21:18:50 -04:00

41 lines
779 B
Go

package config
import (
"fmt"
"strings"
"gopkg.in/yaml.v3"
)
type IPSource string
const (
Legacy IPSource = ""
Direct IPSource = "direct"
XForwardedFor IPSource = "x-forwarded-for"
XRealIP IPSource = "x-real-ip"
)
func (ips *IPSource) UnmarshalYAML(val *yaml.Node) error {
var str string
err := val.Decode(&str)
if err != nil {
return err
}
switch v := IPSource(strings.ToLower(str)); v {
case Legacy, Direct, XForwardedFor, XRealIP:
*ips = v
default:
return fmt.Errorf("invalid IP source '%s'", str)
}
return nil
}
type Config struct {
Bind string `yaml:"bind"`
IPSource IPSource `yaml:"ip_source"`
LogRequestErrors bool `yaml:"log_req_errors"`
TrustedProxies []string `yaml:"trusted_proxies"`
}