config

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 10 Imported by: 1

README

Configure Loader

Documentation

Overview

Configuration loader

Index

Constants

View Source
const (
	KeyDefaultProfile = "default"

	KeyRedisBase = "redis"
	KeyRedisHost = "host"
	KeyRedisPort = "port"
	KeyRedisPass = "pass"
	KeyRedisDb   = "db"

	KeyMongoBase        = "mongo"
	KeyMongoAddrs       = "addrs"
	KeyMongoPerformAuth = "with_auth"

	KeyMongoAuthBase      = "auth"
	KeyMongoAuthDatabase  = "db"
	KeyMongoAuthUser      = "user"
	KeyMongoAuthPass      = "pass"
	KeyMongoAuthMechanism = "mechanism"

	KeyMongoTimeoutSec = "timeout_sec"
	KeyMongoDatabase   = "db"

	KeyMailBase = "mail"

	KeyMailSMTPBase                     = "smtp"
	KeyMailSMTPHost                     = "host"
	KeyMailSMTPPort                     = "port"
	KeyMailSMTPSender                   = "sender"
	KeyMailSMTPUser                     = "user"
	KeyMailSMTPPass                     = "pass"
	KeyMailSMTPOption                   = "option"
	KeyMailSMTPOptionInsecureSkipVerify = "insecure_skip_verify"
)

Variables

This section is empty.

Functions

func CheckKeyIsExists

func CheckKeyIsExists(key string) bool

func GetBoolOrDefault

func GetBoolOrDefault(key string, or bool) bool

func GetFloat32OrDefault

func GetFloat32OrDefault(key string, or float32) float32

func GetFloat64OrDefault

func GetFloat64OrDefault(key string, or float64) float64

func GetInt64OrDefault

func GetInt64OrDefault(key string, or int64) int64

func GetIntOrDefault

func GetIntOrDefault(key string, or int) int

func GetStringOrDefault

func GetStringOrDefault(key, or string) string

func GetStringSliceOrDefault

func GetStringSliceOrDefault(key string, or []string) []string

func LoadConfig

func LoadConfig(options ...Option) (err error)

this function will search and load configurations

func SetConfig

func SetConfig(key string, value interface{}) error

Types

type KeyBuilder

type KeyBuilder struct {
	Base    string
	Profile string
	Class   []string
	Src     *viper.Viper
}

func NewKeyBuilder

func NewKeyBuilder(base string, rest ...string) (ckb *KeyBuilder)

func (*KeyBuilder) CheckKeyIsExists

func (ckb *KeyBuilder) CheckKeyIsExists(key string) bool

func (*KeyBuilder) Clone

func (ckb *KeyBuilder) Clone() *KeyBuilder

func (*KeyBuilder) Current

func (ckb *KeyBuilder) Current() string

func (*KeyBuilder) GetBoolOrDefault

func (ckb *KeyBuilder) GetBoolOrDefault(key string, or bool) bool

func (*KeyBuilder) GetFloat32OrDefault

func (ckb *KeyBuilder) GetFloat32OrDefault(key string, or float32) float32

func (*KeyBuilder) GetFloat64OrDefault

func (ckb *KeyBuilder) GetFloat64OrDefault(key string, or float64) float64

func (*KeyBuilder) GetInt64OrDefault

func (ckb *KeyBuilder) GetInt64OrDefault(key string, or int64) int64

func (*KeyBuilder) GetIntOrDefault

func (ckb *KeyBuilder) GetIntOrDefault(key string, or int) int

func (*KeyBuilder) GetKey

func (ckb *KeyBuilder) GetKey(key string) string

func (*KeyBuilder) GetStringOrDefault

func (ckb *KeyBuilder) GetStringOrDefault(key string, or string) string

func (*KeyBuilder) GetStringSliceOrDefault

func (ckb *KeyBuilder) GetStringSliceOrDefault(key string, or []string) []string

func (*KeyBuilder) Join

func (ckb *KeyBuilder) Join(elems ...string) string

func (*KeyBuilder) SubViper

func (ckb *KeyBuilder) SubViper(key string) *viper.Viper

func (*KeyBuilder) WithClass

func (ckb *KeyBuilder) WithClass(c string) *KeyBuilder

func (*KeyBuilder) WithProfile

func (ckb *KeyBuilder) WithProfile(p string) *KeyBuilder

type MongoAuth

type MongoAuth struct {
	Source    string
	Username  string
	Password  string
	Mechanism string
}

*

  • Database is the default database name used when the Session.DB method
  • is called with an empty name, and is also used during the initial
  • authentication if Source is unset. *
  • Username and Password inform the credentials for the initial authentication
  • done on the database defined by the Source field. See Session.Login. *

func GetDBMongoAuth

func GetDBMongoAuth(ckb *KeyBuilder) *MongoAuth

type MongoConfig

type MongoConfig struct {
	Addrs     []string
	Timeout   time.Duration
	DefaultDb string
	Auth      *MongoAuth
}

func LoadMongoConfig

func LoadMongoConfig(profile string) (cfg *MongoConfig)

type Option

type Option struct {
	Project                  string
	Path                     string
	FileMustExists           bool
	DefaultPath              string
	DefaultConfigureName     string
	ConfigSearchPath         string
	ConfigSearchPaths        []string
	ConfigFallbackSearchPath string
}

func (*Option) GetDefaultPath

func (c *Option) GetDefaultPath() string

func (*Option) With

func (c *Option) With(rhs *Option) *Option

type RedisConfig

type RedisConfig = struct {
	Host string
	Port int
	Pass string
	Db   int
}

func LoadRedisConfig

func LoadRedisConfig(profile string) *RedisConfig

Example Config File:

redis:
	default: # profile
		host: 127.0.0.1
		port: 6379
		pass: "" # empty for not encrypted
		db: 0 # db number

type SMTPConfig

type SMTPConfig struct {
	Host   string `mapstructure:"host"`
	Port   int    `mapstructure:"port"`
	Sender string `mapstructure:"sender"`
	User   string `mapstructure:"user"`
	Pass   string `mapstructure:"pass"`
	// SkipTLS
	Option SMTPConfigOption `mapstructure:"option"`
}

func LoadSMTPConfig

func LoadSMTPConfig(profile string) (cfg *SMTPConfig, err error)

Example Config File:

mail: # base-0
	smtp: # base-1
		default: # profile
			host: 127.0.0.1
			port: 25
			sender: Alice Ez
			user: "[email protected]"
			pass: "your-password" # empty for no authorization
			option:
				insecure_skip_verify: true
		nightly: # profile
			host: 127.0.0.1
			port: 25
			sender: Alice Ez
			user: "[email protected]"
			pass: "your-password" # empty for no authorization
			option:
				insecure_skip_verify: true

type SMTPConfigOption

type SMTPConfigOption struct {
	InsecureSkipVerify bool `mapstructure:"insecure_skip_verify"`
}

Jump to

Keyboard shortcuts

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