cleanups
This commit is contained in:
@@ -18,20 +18,19 @@ type Access struct {
|
||||
}
|
||||
|
||||
type Calendar struct {
|
||||
ID string `yaml:"id"`
|
||||
Owner string `yaml:"owner"`
|
||||
Color string `yaml:"color,omitempty"`
|
||||
Access []Access `yaml:"access,omitempty"`
|
||||
ID string `yaml:"id"`
|
||||
Owner string `yaml:"owner"`
|
||||
Color string `yaml:"color,omitempty"`
|
||||
Access []Access `yaml:"access,omitempty"`
|
||||
}
|
||||
|
||||
type AddressBook struct {
|
||||
ID string `yaml:"id"`
|
||||
Owner string `yaml:"owner"`
|
||||
Access []Access `yaml:"access,omitempty"`
|
||||
ID string `yaml:"id"`
|
||||
Owner string `yaml:"owner"`
|
||||
Access []Access `yaml:"access,omitempty"`
|
||||
}
|
||||
|
||||
type Aggregate struct {
|
||||
|
||||
ID string `yaml:"id"`
|
||||
Owner string `yaml:"owner"`
|
||||
Color string `yaml:"color,omitempty"`
|
||||
@@ -54,18 +53,16 @@ type ServerConfig struct {
|
||||
BindAddress string `yaml:"bind_address"`
|
||||
PublicURL string `yaml:"public_url"`
|
||||
EmailDomain string `yaml:"email_domain"`
|
||||
Redaction string `yaml:"redaction_text"`
|
||||
DefaultClass string `yaml:"default_class"`
|
||||
Redaction string `yaml:"redaction_text"` // "[-]"
|
||||
DefaultClass string `yaml:"default_class"` // CONFIDENTIAL/PRIVATE/PUBLIC
|
||||
}
|
||||
|
||||
func (s ServerConfig) BasePath() string {
|
||||
u, err := url.Parse(s.PublicURL)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if err != nil { return "" }
|
||||
return strings.TrimSuffix(u.Path, "/")
|
||||
}
|
||||
|
||||
|
||||
type SMTPConfig struct {
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
@@ -74,14 +71,29 @@ type SMTPConfig struct {
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Server ServerConfig `yaml:"server"`
|
||||
Database DatabaseConfig `yaml:"database"`
|
||||
SMTP SMTPConfig `yaml:"smtp"`
|
||||
Users []User `yaml:"users"`
|
||||
Calendars []Calendar `yaml:"calendars"`
|
||||
AddressBooks []AddressBook `yaml:"address_books"`
|
||||
Aggregates []Aggregate `yaml:"aggregates"`
|
||||
Server ServerConfig `yaml:"server"`
|
||||
Database DatabaseConfig `yaml:"database"`
|
||||
SMTP SMTPConfig `yaml:"smtp"`
|
||||
Users []User `yaml:"users"`
|
||||
Calendars []Calendar `yaml:"calendars"`
|
||||
AddressBooks []AddressBook `yaml:"address_books"`
|
||||
Aggregates []Aggregate `yaml:"aggregates"`
|
||||
}
|
||||
func (c *Config) setDefaults() {
|
||||
if c.Server.BindAddress == "" { c.Server.BindAddress = ":8080" }
|
||||
if c.Server.Redaction == "" { c.Server.Redaction = "Busy" }
|
||||
if c.Server.DefaultClass == "" { c.Server.DefaultClass = "CONFIDENTIAL" }
|
||||
if c.Server.EmailDomain == "" { c.Server.EmailDomain = "nx2.site" }
|
||||
if c.Database.URL == "" { c.Database.URL = "postgres://nxcaldav@localhost:5432/nxcaldav?sslmode=disable" }
|
||||
if c.SMTP.Host == "" { c.SMTP.Host = "localhost" }
|
||||
if c.SMTP.Port == 0 { c.SMTP.Port = 25 }
|
||||
}
|
||||
func (c *Config) checkConfig() {
|
||||
if !(slices.Contains([]string{"PUBLIC", "PRIVATE", "CONFIDENTIAL"}, c.Server.DefaultClass)) {
|
||||
panic("Invaldi Config, default_class")
|
||||
}
|
||||
}
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
@@ -100,32 +112,3 @@ func Load(path string) (*Config, error) {
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func (c *Config) checkConfig() {
|
||||
if !(slices.Contains([]string{"PUBLIC", "PRIVATE", "CONFIDENTIAL"}, c.Server.DefaultClass)) {
|
||||
panic("Invaldi Config, default_class")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) setDefaults() {
|
||||
if c.Server.BindAddress == "" {
|
||||
c.Server.BindAddress = ":8080"
|
||||
}
|
||||
if c.Server.Redaction == "" {
|
||||
c.Server.Redaction = "Busy"
|
||||
}
|
||||
if c.Server.DefaultClass == "" {
|
||||
c.Server.DefaultClass = "CONFIDENTIAL"
|
||||
}
|
||||
if c.Server.EmailDomain == "" {
|
||||
c.Server.EmailDomain = "nx2.site"
|
||||
}
|
||||
if c.Database.URL == "" {
|
||||
c.Database.URL = "postgres://nxcaldav@localhost:5432/nxcaldav?sslmode=disable"
|
||||
}
|
||||
if c.SMTP.Host == "" {
|
||||
c.SMTP.Host = "localhost"
|
||||
}
|
||||
if c.SMTP.Port == 0 {
|
||||
c.SMTP.Port = 25
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user