package config import ( "net/url" "strings" ) type Config struct { Core CoreConfig `toml:"core"` Web WebConfig `toml:"web"` Security SecurityConfig `toml:"security"` } type WebConfig struct { // Domain should be the instance's full domain, including https:// but without the trailing slash. Domain string `toml:"domain"` // WebFingerDomain should be the instance's WebFinger domain, used for usernames. // .well-known/webfinger *must* listen on this domain. // It should only be the bare domain, i.e. `mercury.localhost` WebFingerDomain string `toml:"webfinger_domain"` // Port is the port the server should listen on. Port int `toml:"port"` } // WebFingerDomains returns the domains valid for WebFinger requests. // The first one is always the canonical domain. // This function is guaranteed to return at least one domain. func (c WebConfig) WebFingerDomains() []string { domains := make([]string, 0, 2) if c.WebFingerDomain != "" { domains = append(domains, c.WebFingerDomain) } u, err := url.Parse(c.Domain) if err != nil { return append(domains, strings.TrimPrefix( strings.TrimPrefix(c.Domain, "http://"), "https://")) } return append(domains, u.Host) } type CoreConfig struct { Postgres string `toml:"postgres"` Dev bool `toml:"dev"` SecretKey string `toml:"secret_key"` } type SecurityConfig struct { RestrictAPI bool `toml:"restrict_api"` PublicTimelines bool `toml:"public_timelines"` }