blasphem/pkg/server/config/config.go

42 lines
779 B
Go
Raw Permalink Normal View History

2022-09-25 11:42:36 -04:00
package config
2022-10-25 19:03:23 -04:00
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
}
2022-09-25 11:42:36 -04:00
type Config struct {
2022-10-25 21:18:50 -04:00
Bind string `yaml:"bind"`
IPSource IPSource `yaml:"ip_source"`
LogRequestErrors bool `yaml:"log_req_errors"`
TrustedProxies []string `yaml:"trusted_proxies"`
2022-09-25 11:42:36 -04:00
}