Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Module = fx.Module( "appconfig", fx.Provide( func(log *zap.Logger) Config { if err := config.LoadConfig(&defaultConfig); err != nil { log.Error("Error loading config", zap.Error(err)) } return defaultConfig }, fx.Private, ), fx.Provide(func(cfg Config) http.Config { return http.Config{ Listen: cfg.HTTP.Listen, Proxies: cfg.HTTP.Proxies, WriteTimeout: 30 * time.Minute, } }), fx.Provide(func(cfg Config) db.Config { return db.Config{ Dialect: db.Dialect(cfg.Database.Dialect), Host: cfg.Database.Host, Port: cfg.Database.Port, User: cfg.Database.User, Password: cfg.Database.Password, Database: cfg.Database.Database, Timezone: cfg.Database.Timezone, Debug: cfg.Database.Debug, MaxOpenConns: cfg.Database.MaxOpenConns, MaxIdleConns: cfg.Database.MaxIdleConns, } }), fx.Provide(func(cfg Config) push.Config { mode := push.ModeFCM if cfg.Gateway.Mode == GatewayModePrivate { mode = push.ModeUpstream } return push.Config{ Mode: mode, ClientOptions: map[string]string{ "credentials": cfg.FCM.CredentialsJSON, }, Debounce: time.Duration(cfg.FCM.DebounceSeconds) * time.Second, Timeout: time.Duration(cfg.FCM.TimeoutSeconds) * time.Second, } }), fx.Provide(func(cfg Config) messages.HashingTaskConfig { return messages.HashingTaskConfig{ Interval: time.Duration(cfg.Tasks.Hashing.IntervalSeconds) * time.Second, } }), fx.Provide(func(cfg Config) auth.Config { return auth.Config{ Mode: auth.Mode(cfg.Gateway.Mode), PrivateToken: cfg.Gateway.PrivateToken, } }), fx.Provide(func(cfg Config) handlers.Config { if cfg.HTTP.API.Host == "" { cfg.HTTP.API.Path = "/api" } if !strings.HasPrefix(cfg.HTTP.API.Path, "/") { cfg.HTTP.API.Path = "/" + cfg.HTTP.API.Path } if cfg.HTTP.API.Path != "/" && strings.HasSuffix(cfg.HTTP.API.Path, "/") { cfg.HTTP.API.Path = strings.TrimRight(cfg.HTTP.API.Path, "/") } cfg.HTTP.API.Host = strings.TrimPrefix(strings.TrimPrefix(cfg.HTTP.API.Host, "https://"), "http://") return handlers.Config{ PublicHost: cfg.HTTP.API.Host, PublicPath: cfg.HTTP.API.Path, UpstreamEnabled: cfg.Gateway.Mode == GatewayModePublic, OpenAPIEnabled: cfg.HTTP.OpenAPI.Enabled, } }), fx.Provide(func(cfg Config) messages.Config { return messages.Config{ ProcessedLifetime: time.Duration(cfg.Messages.ProcessedLifetimeHours) * time.Hour, CacheTTL: time.Duration(cfg.Messages.CacheTTLSeconds) * time.Second, } }), fx.Provide(func(cfg Config) devices.Config { return devices.Config{ UnusedLifetime: 365 * 24 * time.Hour, } }), fx.Provide(func(cfg Config) sse.Config { return sse.NewConfig( sse.WithKeepAlivePeriod(time.Duration(cfg.SSE.KeepAlivePeriodSeconds) * time.Second), ) }), fx.Provide(func(cfg Config) cache.Config { return cache.Config{ URL: cfg.Cache.URL, } }), fx.Provide(func(cfg Config) pubsub.Config { return pubsub.Config{ URL: cfg.PubSub.URL, BufferSize: 128, } }), )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Gateway Gateway `yaml:"gateway"` // gateway config
HTTP HTTP `yaml:"http"` // http server config
Database Database `yaml:"database"` // database config
FCM FCMConfig `yaml:"fcm"` // firebase cloud messaging config
Tasks Tasks `yaml:"tasks"` // tasks config
SSE SSE `yaml:"sse"` // server-sent events config
Messages Messages `yaml:"messages"` // messages config
Cache Cache `yaml:"cache"` // cache (memory or redis) config
PubSub PubSub `yaml:"pubsub"` // pubsub (memory or redis) config
}
type Database ¶
type Database struct {
Dialect string `yaml:"dialect" envconfig:"DATABASE__DIALECT"` // database dialect
Host string `yaml:"host" envconfig:"DATABASE__HOST"` // database host
Port int `yaml:"port" envconfig:"DATABASE__PORT"` // database port
User string `yaml:"user" envconfig:"DATABASE__USER"` // database user
Password string `yaml:"password" envconfig:"DATABASE__PASSWORD"` // database password
Database string `yaml:"database" envconfig:"DATABASE__DATABASE"` // database name
Timezone string `yaml:"timezone" envconfig:"DATABASE__TIMEZONE"` // database timezone
Debug bool `yaml:"debug" envconfig:"DATABASE__DEBUG"` // debug mode
MaxOpenConns int `yaml:"max_open_conns" envconfig:"DATABASE__MAX_OPEN_CONNS"` // max open connections
MaxIdleConns int `yaml:"max_idle_conns" envconfig:"DATABASE__MAX_IDLE_CONNS"` // max idle connections
}
type FCMConfig ¶
type FCMConfig struct {
CredentialsJSON string `yaml:"credentials_json" envconfig:"FCM__CREDENTIALS_JSON"` // firebase credentials json (public mode only)
DebounceSeconds uint16 `yaml:"debounce_seconds" envconfig:"FCM__DEBOUNCE_SECONDS"` // push notification debounce (>= 5s)
TimeoutSeconds uint16 `yaml:"timeout_seconds" envconfig:"FCM__TIMEOUT_SECONDS"` // push notification send timeout
}
type Gateway ¶
type Gateway struct {
Mode GatewayMode `yaml:"mode" envconfig:"GATEWAY__MODE"` // gateway mode: public or private
PrivateToken string `yaml:"private_token" envconfig:"GATEWAY__PRIVATE_TOKEN"` // device registration token in private mode
}
type GatewayMode ¶
type GatewayMode string
const ( GatewayModePublic GatewayMode = "public" GatewayModePrivate GatewayMode = "private" )
type HashingTask ¶
type HashingTask struct {
IntervalSeconds uint16 `yaml:"interval_seconds" envconfig:"TASKS__HASHING__INTERVAL_SECONDS"` // hashing interval in seconds
}
type OpenAPI ¶ added in v1.29.0
type OpenAPI struct {
Enabled bool `yaml:"enabled" envconfig:"HTTP__OPENAPI__ENABLED"` // openapi enabled
}
type PubSub ¶ added in v1.32.0
type PubSub struct {
URL string `yaml:"url" envconfig:"PUBSUB__URL"`
}
type SSE ¶ added in v1.26.0
type SSE struct {
KeepAlivePeriodSeconds uint16 `yaml:"keep_alive_period_seconds" envconfig:"SSE__KEEP_ALIVE_PERIOD_SECONDS"` // keep alive period in seconds, 0 for no keep alive
}
type Tasks ¶
type Tasks struct {
Hashing HashingTask `yaml:"hashing"`
}
Click to show internal directories.
Click to hide internal directories.