cfg

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: AGPL-3.0 Imports: 13 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// nolint:gochecknoglobals
	// DefaultConfig is the default config for the application.
	// It is used as a fallback if loading the proper config fails.
	// Loading it should always be accompanied by a warning.
	DefaultConfig = Config{
		DBConfig: DBConfig{
			Engine:   "postgres",
			Host:     "localhost",
			Port:     uint16(5432),
			Database: "librate",
			User:     "postgres",
			Password: "postgres",
			SSL:      "unknown",
			PGConfig: "/usr/bin/pg_config",
			StartCmd: "sudo service postgresql start",
		},
		Fiber: FiberConfig{
			Host:    "localhost",
			Port:    3000,
			Prefork: false,
		},
		Secret:     uuid.Must(uuid.NewV7()).String(),
		LibrateEnv: "production",
	}
	// nolint:gochecknoglobals
	// TestConfig is a convenience config for testing, so that the test functions are terser, avoiding unnecessary repetition.
	TestConfig = Config{
		DBConfig: DBConfig{
			Engine:             "postgres",
			Host:               "localhost",
			Port:               uint16(5432),
			Database:           "librate_test",
			User:               "postgres",
			Password:           "postgres",
			SSL:                "disable",
			PGConfig:           "/usr/bin/pg_config",
			StartCmd:           "skip",
			AutoMigrate:        true,
			ExitAfterMigration: false,
		},
		Fiber: FiberConfig{
			Host:    "0.0.0.0",
			Port:    3000,
			Prefork: false,
		},
		Secret:     "secret",
		LibrateEnv: "test",
	}
)

Functions

func FileExists added in v0.6.6

func FileExists(path string) bool

FileExists checks whether the config file exists. It is useful for the fallback mechanism of using default config

func LoadConfig

func LoadConfig() mo.Result[*Config]

LoadConfig loads the config from the config file, or falls back to defaults. It is used only when no --config flag is passed.

func LoadLoggerConfig

func LoadLoggerConfig() mo.Result[logging.Config]

TODO: refactor so that parser parses each section of the config separately

Types

type Config

type Config struct {
	DBConfig `json:"database,omitempty" yaml:"database" mapstructure:"database"`
	Fiber    FiberConfig `json:"fiber,omitempty" yaml:"fiber" mapstructure:"fiber"`
	Secret   string      `json:"secret,omitempty" yaml:"secret" mapstructure:"secret"`
	// default to production for security reasons
	LibrateEnv string      `json:"librateEnv,omitempty" yaml:"librateEnv" default:"production" mapstructure:"librateEnv"`
	Redis      RedisConfig `json:"redis,omitempty" yaml:"redis" mapstructure:"redis"`
}

func LoadFromFile added in v0.6.2

func LoadFromFile(path string) (conf *Config, err error)

LoadFromFile loads the config from the config file, or tries to call LoadConfig.

type DBConfig

type DBConfig struct {
	Engine             string `yaml:"engine" default:"postgres"`
	Host               string `yaml:"host" default:"localhost"`
	Port               uint16 `yaml:"port" default:"5432"`
	Database           string `yaml:"database" default:"librate"`
	User               string `yaml:"user" default:"postgres"`
	Password           string `yaml:"password,omitempty" default:"postgres"`
	SSL                string `yaml:"SSL" default:"unknown"`
	PGConfig           string `yaml:"pgConfig,omitempty" default:"/usr/bin/pg_config"`
	StartCmd           string `yaml:"startCmd,omitempty" default:"sudo service postgresql start"`
	AutoMigrate        bool   `yaml:"autoMigrate,omitempty" default:"true"`
	ExitAfterMigration bool   `yaml:"exitAfterMigration,omitempty" default:"false"`
}

type FiberConfig

type FiberConfig struct {
	Host           string `yaml:"host" default:"localhost"`
	Port           int    `yaml:"port" default:"3000"`
	Prefork        bool   `yaml:"prefork" default:"false"`
	ReduceMemUsage bool   `yaml:"reduceMemUsage" default:"false"`
	StaticDir      string `yaml:"staticDir" default:"./static"`
	PowInterval    int    `yaml:"powInterval" default:"300"`
	PowDifficulty  int    `yaml:"powDifficulty" default:"30000"`
}

refer to https://docs.gofiber.io/api/fiber#config

type RedisConfig

type RedisConfig struct {
	Host     string `yaml:"host,omitempty" default:"localhost"`
	Port     int    `yaml:"port,omitempty" default:"6379"`
	Username string `yaml:"username,omitempty" default:""`
	Password string `yaml:"password,omitempty" default:""`
	Database int    `yaml:"database,omitempty" default:"0"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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