config

package
v0.0.0-...-25c9f67 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagEnv  = "env"
	TagFlag = "flag"
	TagDesc = "desc"

	StrFlagNotDefined = "flag provided but not defined"
)

Variables

View Source
var (
	BuildVersion = "TO BE SET AT BUILD TIME"
	Commit       = "TO BE SET AT BUILD TIME"
)
View Source
var (
	ErrEnvLoad          = errors.New("error during loading .env file")
	ErrEnvParse         = errors.New("cannot parse env variable")
	ErrFlagParse        = errors.New("cannot parse flag")
	ErrConfigInvalid    = errors.New("invalid config struct")
	ErrConfigValidation = errors.New("config validation error")
)

Functions

func LoadConfig

func LoadConfig(cfg ConfigInterface, osArgs *[]string, validator Validator) error

func NewValidator

func NewValidator() (*validator.Validate, error)

func RegisterDuration

func RegisterDuration(v *validator.Validate) error

func RegisterEthAddr

func RegisterEthAddr(v *validator.Validate) error

func RegisterHex32

func RegisterHex32(v *validator.Validate) error

func RegisterHexadecimal

func RegisterHexadecimal(v *validator.Validate) error

Types

type Config

type Config struct {
	AIEngine struct {
		OpenAIBaseURL string `env:"OPENAI_BASE_URL"     flag:"open-ai-base-url"   validate:"required,url"`
		OpenAIKey     string `env:"OPENAI_API_KEY"      flag:"open-ai-api-key"`
	}
	Blockchain struct {
		EthNodeAddress string `env:"ETH_NODE_ADDRESS"   flag:"eth-node-address"   validate:"required,url"`
		EthLegacyTx    bool   `env:"ETH_NODE_LEGACY_TX" flag:"eth-node-legacy-tx" desc:"use it to disable EIP-1559 transactions"`
		ExplorerApiUrl string `env:"EXPLORER_API_URL"   flag:"explorer-api-url"   validate:"required,url"`
	}
	Environment string `env:"ENVIRONMENT" flag:"environment"`
	Marketplace struct {
		DiamondContractAddress *common.Address `env:"DIAMOND_CONTRACT_ADDRESS" flag:"diamond-address"   validate:"omitempty,eth_addr"`
		MorTokenAddress        *common.Address `env:"MOR_TOKEN_ADDRESS"        flag:"mor-token-address" validate:"omitempty,eth_addr"`
		WalletPrivateKey       *lib.HexString  `` /* 179-byte string literal not displayed */
	}
	Log struct {
		Color           bool   `env:"LOG_COLOR"            flag:"log-color"`
		FolderPath      string `` /* 139-byte string literal not displayed */
		IsProd          bool   `` /* 130-byte string literal not displayed */
		JSON            bool   `env:"LOG_JSON"             flag:"log-json"`
		LevelApp        string `env:"LOG_LEVEL_APP"        flag:"log-level-app"        validate:"omitempty,oneof=debug info warn error dpanic panic fatal"`
		LevelConnection string `env:"LOG_LEVEL_CONNECTION" flag:"log-level-connection" validate:"omitempty,oneof=debug info warn error dpanic panic fatal"`
		LevelProxy      string `env:"LOG_LEVEL_PROXY"      flag:"log-level-proxy"      validate:"omitempty,oneof=debug info warn error dpanic panic fatal"`
		LevelScheduler  string `env:"LOG_LEVEL_SCHEDULER"  flag:"log-level-scheduler"  validate:"omitempty,oneof=debug info warn error dpanic panic fatal"`
		LevelContract   string `env:"LOG_LEVEL_CONTRACT"   flag:"log-level-contract"   validate:"omitempty,oneof=debug info warn error dpanic panic fatal"`
	}
	Proxy struct {
		Address        string `env:"PROXY_ADDRESS" flag:"proxy-address" validate:"required,hostname_port"`
		MaxCachedDests int    `` /* 140-byte string literal not displayed */
		StoragePath    string `` /* 138-byte string literal not displayed */
	}
	System struct {
		Enable           bool   `env:"SYS_ENABLE"              flag:"sys-enable" desc:"enable system level configuration adjustments"`
		LocalPortRange   string `env:"SYS_LOCAL_PORT_RANGE"    flag:"sys-local-port-range"    desc:""`
		NetdevMaxBacklog string `env:"SYS_NET_DEV_MAX_BACKLOG" flag:"sys-netdev-max-backlog"  desc:""`
		RlimitHard       uint64 `env:"SYS_RLIMIT_HARD"         flag:"sys-rlimit-hard"         desc:""`
		RlimitSoft       uint64 `env:"SYS_RLIMIT_SOFT"         flag:"sys-rlimit-soft"         desc:""`
		Somaxconn        string `env:"SYS_SOMAXCONN"           flag:"sys-somaxconn"           desc:""`
		TcpMaxSynBacklog string `env:"SYS_TCP_MAX_SYN_BACKLOG" flag:"sys-tcp-max-syn-backlog" desc:""`
	}
	Web struct {
		Address   string `env:"WEB_ADDRESS"    flag:"web-address"    validate:"required,hostname_port" desc:"http server address host:port"`
		PublicUrl string `` /* 150-byte string literal not displayed */
	}
}

Validation tags described here: https://pkg.go.dev/github.com/go-playground/validator/v10

func (*Config) GetSanitized

func (cfg *Config) GetSanitized() interface{}

GetSanitized returns a copy of the config with sensitive data removed explicitly adding each field here to avoid accidentally leaking sensitive data

func (*Config) SetDefaults

func (cfg *Config) SetDefaults()

type ConfigInterface

type ConfigInterface interface {
	SetDefaults()
}

type DerivedConfig

type DerivedConfig struct {
	WalletAddress common.Address
}

type Validator

type Validator interface {
	Struct(s interface{}) error
}

Jump to

Keyboard shortcuts

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