2020-08-10 13:18:04 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
type SyncAPI struct {
|
|
|
|
Matrix *Global `yaml:"-"`
|
|
|
|
|
2022-09-01 13:15:41 +00:00
|
|
|
InternalAPI InternalAPIOptions `yaml:"internal_api,omitempty"`
|
|
|
|
ExternalAPI ExternalAPIOptions `yaml:"external_api,omitempty"`
|
2020-08-10 13:18:04 +00:00
|
|
|
|
2022-09-01 13:15:41 +00:00
|
|
|
Database DatabaseOptions `yaml:"database,omitempty"`
|
2020-11-20 11:29:02 +00:00
|
|
|
|
|
|
|
RealIPHeader string `yaml:"real_ip_header"`
|
2022-09-07 16:15:54 +00:00
|
|
|
|
|
|
|
Fulltext Fulltext `yaml:"fulltext"`
|
2020-08-10 13:18:04 +00:00
|
|
|
}
|
|
|
|
|
2022-09-01 13:15:41 +00:00
|
|
|
func (c *SyncAPI) Defaults(opts DefaultOpts) {
|
|
|
|
if !opts.Monolithic {
|
|
|
|
c.InternalAPI.Listen = "http://localhost:7773"
|
|
|
|
c.InternalAPI.Connect = "http://localhost:7773"
|
|
|
|
c.ExternalAPI.Listen = "http://localhost:8073"
|
|
|
|
c.Database.Defaults(20)
|
|
|
|
}
|
2022-09-07 16:15:54 +00:00
|
|
|
c.Fulltext.Defaults(opts)
|
2022-09-01 13:15:41 +00:00
|
|
|
if opts.Generate {
|
|
|
|
if !opts.Monolithic {
|
|
|
|
c.Database.ConnectionString = "file:syncapi.db"
|
|
|
|
}
|
2021-11-24 11:57:39 +00:00
|
|
|
}
|
2020-08-10 13:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *SyncAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
2022-09-07 16:15:54 +00:00
|
|
|
c.Fulltext.Verify(configErrs, isMonolith)
|
2022-05-13 07:33:55 +00:00
|
|
|
if isMonolith { // polylith required configs below
|
|
|
|
return
|
|
|
|
}
|
2022-09-01 13:15:41 +00:00
|
|
|
if c.Matrix.DatabaseOptions.ConnectionString == "" {
|
|
|
|
checkNotEmpty(configErrs, "sync_api.database", string(c.Database.ConnectionString))
|
|
|
|
}
|
2022-05-13 07:33:55 +00:00
|
|
|
checkURL(configErrs, "sync_api.internal_api.listen", string(c.InternalAPI.Listen))
|
|
|
|
checkURL(configErrs, "sync_api.internal_api.connect", string(c.InternalAPI.Connect))
|
|
|
|
checkURL(configErrs, "sync_api.external_api.listen", string(c.ExternalAPI.Listen))
|
2020-08-10 13:18:04 +00:00
|
|
|
}
|
2022-09-07 16:15:54 +00:00
|
|
|
|
|
|
|
type Fulltext struct {
|
|
|
|
Enabled bool `yaml:"enabled"`
|
|
|
|
IndexPath Path `yaml:"index_path"`
|
|
|
|
InMemory bool `yaml:"in_memory"` // only useful in tests
|
|
|
|
Language string `yaml:"language"` // the language to use when analysing content
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fulltext) Defaults(opts DefaultOpts) {
|
|
|
|
f.Enabled = false
|
|
|
|
f.IndexPath = "./fulltextindex"
|
|
|
|
f.Language = "en"
|
|
|
|
if opts.Generate {
|
|
|
|
f.Enabled = true
|
|
|
|
f.InMemory = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *Fulltext) Verify(configErrs *ConfigErrors, isMonolith bool) {
|
|
|
|
checkNotEmpty(configErrs, "syncapi.fulltext.index_path", string(f.IndexPath))
|
|
|
|
checkNotEmpty(configErrs, "syncapi.fulltext.language", f.Language)
|
|
|
|
}
|