config

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GRPCServerType = ServerType("grpc")
	RESTServerType = ServerType("rest")
)
View Source
var (
	DevelopmentEnvType = EnvType("development")
	ProductionEnvType  = EnvType("production")
)

ServerTypes is a list of server types

Functions

func IsFlakeConfiguredProperly

func IsFlakeConfiguredProperly(c Config) bool

IsFlakeConfiguredProperly returns true if the flake configuration is properly configured, sum of bits length must be 63

func IsValidEnvType

func IsValidEnvType(envType EnvType) bool

IsValidEnvType returns true if the environment type is valid

func IsValidServerType

func IsValidServerType(serverType ServerType) bool

IsValidServerType returns true if the server type is valid

func IsValidTLSConfig added in v1.0.2

func IsValidTLSConfig(c Config) bool

IsValidTLSConfig returns true if the tls configuration is valid

Types

type Config

type Config struct {
	Env          EnvType `json:"env"`
	LogLevel     string  `mapstructure:"log_level" json:"log_level"`
	DatacenterID uint8   `mapstructure:"datacenter_id" json:"datacenter_id"`
	MachineID    uint8   `mapstructure:"machine_id" json:"machine_id"`
	Server       struct {
		Type ServerType `mapstructure:"type" json:"type"`
		Host string     `mapstructure:"host" json:"host"`
		Port int        `mapstructure:"port" json:"port"`
		TLS  struct {
			CertPath string `mapstructure:"cert_path" json:"cert_path"`
			KeyPath  string `mapstructure:"key_path" json:"key_path"`
		} `mapstructure:"tls" json:"tls"`
	} `mapstructure:"server" json:"server"`
	Flake struct {
		Epoch   uint64 `mapstructure:"epoch" json:"epoch"`
		TickMs  uint64 `mapstructure:"tick_ms" json:"tick_ms"`
		BitsLen struct {
			DatacenterID uint8 `mapstructure:"datacenter_id" json:"datacenter_id"`
			MachineID    uint8 `mapstructure:"machine_id" json:"machine_id"`
			Time         uint8 `mapstructure:"time" json:"time"`
			Sequence     uint8 `mapstructure:"sequence" json:"sequence"`
		} `mapstructure:"bits_len" json:"bits_len"`
	} `mapstructure:"flake" json:"flake"`
}

Config is the configuration for the application

func GetConfig

func GetConfig() Config

GetConfig returns the configuration

func MustConfig

func MustConfig() *Config

MustConfig configures the application and panics on error

func (Config) ToString

func (c Config) ToString() string

ToString returns the configuration as a string

type EnvType

type EnvType string

EnvType is the type of environment (development, production, etc)

type ErrInvalidConfig

type ErrInvalidConfig struct {
	Err string
}

ErrInvalidConfig is returned when the configuration is invalid

func (ErrInvalidConfig) Error

func (e ErrInvalidConfig) Error() string

Error returns the error message

type ServerType

type ServerType string

ServerType is the type of server (grpc, rest, etc)

Jump to

Keyboard shortcuts

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