config

package
v1.7.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

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.Provide(func(cfg Config) http.Config {
		return http.Config{
			Listen:  cfg.HTTP.Listen,
			Proxies: cfg.HTTP.Proxies,
		}
	}),
	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,
		}
	}),
	fx.Provide(func(cfg Config) push.Config {
		mode := push.ModeFCM
		if cfg.Gateway.Mode == "private" {
			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 {
		return handlers.Config{
			GatewayMode: handlers.GatewayMode(cfg.Gateway.Mode),
		}
	}),
)

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
}

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
}

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 added in v1.7.0

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 added in v1.7.0

type GatewayMode string
const (
	GatewayModePublic  GatewayMode = "public"
	GatewayModePrivate GatewayMode = "private"
)

type HTTP

type HTTP struct {
	Listen  string   `yaml:"listen" envconfig:"HTTP__LISTEN"`   // listen address
	Proxies []string `yaml:"proxies" envconfig:"HTTP__PROXIES"` // proxies
}

type HashingTask added in v1.4.0

type HashingTask struct {
	IntervalSeconds uint16 `yaml:"interval_seconds" envconfig:"TASKS__HASHING__INTERVAL_SECONDS"` // hashing interval in seconds
}

type Tasks added in v1.4.0

type Tasks struct {
	Hashing HashingTask `yaml:"hashing"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL