mercury/config/config.go

55 lines
1.4 KiB
Go
Raw Permalink Normal View History

2023-09-03 00:23:48 +02:00
package config
2023-10-16 15:45:43 +02:00
import (
"net/url"
"strings"
)
2023-09-03 00:23:48 +02:00
type Config struct {
Core CoreConfig `toml:"core"`
Web WebConfig `toml:"web"`
Security SecurityConfig `toml:"security"`
2023-09-03 00:23:48 +02:00
}
type WebConfig struct {
// Domain should be the instance's full domain, including https:// but without the trailing slash.
Domain string `toml:"domain"`
2023-10-16 15:45:43 +02:00
// 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"`
2023-09-03 00:23:48 +02:00
// Port is the port the server should listen on.
Port int `toml:"port"`
}
2023-10-16 15:45:43 +02:00
// 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)
}
2023-09-03 00:23:48 +02:00
type CoreConfig struct {
2023-09-04 03:33:13 +02:00
Postgres string `toml:"postgres"`
Dev bool `toml:"dev"`
SecretKey string `toml:"secret_key"`
2023-09-03 00:23:48 +02:00
}
type SecurityConfig struct {
RestrictAPI bool `toml:"restrict_api"`
PublicTimelines bool `toml:"public_timelines"`
}