6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-28 09:41:02 +00:00
prologic-saltyim/internal/options.go
James Mills 801d6b93bb Add support for client and server (broker) registration (#43)
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Reviewed-on: https://git.mills.io/prologic/saltyim/pulls/43
2022-03-22 22:59:09 +00:00

71 lines
1.6 KiB
Go

package internal
import "net/url"
const (
// InvalidConfigValue is the constant value for invalid config values
// which must be changed for production configurations before successful
// startup
InvalidConfigValue = "INVALID CONFIG VALUE - PLEASE CHANGE THIS VALUE"
// DefaultDebug is the default debug mode
DefaultDebug = false
// DefaultData is the default data directory for storage
DefaultData = "./data"
// DefaultStore is the default data store used for accounts, sessions, etc
DefaultStore = "bitcask://saltyim.db"
// DefaultBaseURL is the default Base URL for the server
DefaultBaseURL = "http://0.0.0.0:8000"
)
func NewConfig() *Config {
return &Config{
Debug: DefaultDebug,
Store: DefaultStore,
BaseURL: DefaultBaseURL,
}
}
// Option is a function that takes a config struct and modifies it
type Option func(*Config) error
// WithDebug sets the debug mode lfag
func WithDebug(debug bool) Option {
return func(cfg *Config) error {
cfg.Debug = debug
return nil
}
}
// WithData sets the data directory to use for storage
func WithData(data string) Option {
return func(cfg *Config) error {
cfg.Data = data
return nil
}
}
// WithStore sets the store to use for accounts, sessions, etc.
func WithStore(store string) Option {
return func(cfg *Config) error {
cfg.Store = store
return nil
}
}
// WithBaseURL sets the Base URL used for constructing feed URLs
func WithBaseURL(baseURL string) Option {
return func(cfg *Config) error {
u, err := url.Parse(baseURL)
if err != nil {
return err
}
cfg.BaseURL = baseURL
cfg.baseURL = u
return nil
}
}