conf

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: MIT Imports: 13 Imported by: 0

README

package conf

统一提供

  • 应用配置
  • 通用约定

Documentation

Index

Constants

View Source
const (
	CONF_TOML_FILE string = "conf.toml"
	PATH_STEP_SEP  byte   = '.'
	CONF_TOML_ENV  string = "CONF_TOML"

	LAYOUT_DATE       string = "2006-01-02"
	LAYOUT_TIME       string = "15:04:05"
	LAYOUT_DATETIME   string = "2006-01-02 15:04:05"
	LAYOUT_DATETIME_T string = "2006-01-02T15:04:05"

	LENGTH_DATETIME = len(LAYOUT_DATETIME)
)

Variables

View Source
var ZERO_TIME = time.Unix(0, 0)

Functions

func Bind

func Bind(keys string, ret interface{}) bool

func BindWith

func BindWith(keys string, f BindFunc) (interface{}, bool)

func Elem

func Elem(val interface{}, key string) (ret interface{}, ok bool)

it will panic if parse key failed

func ElemBool

func ElemBool(val interface{}, key string) (ret bool, ok bool)

func ElemDuration

func ElemDuration(val interface{}, key string) (ret time.Duration, ok bool)

func ElemFloat64

func ElemFloat64(val interface{}, key string) (ret float64, ok bool)

func ElemInt

func ElemInt(val interface{}, key string) (ret int, ok bool)

func ElemInt64

func ElemInt64(val interface{}, key string) (ret int64, ok bool)

func ElemMap

func ElemMap(val interface{}, key string) (ret map[string]interface{}, ok bool)

func ElemSlice

func ElemSlice(val interface{}, key string) (ret []interface{}, ok bool)

func ElemString

func ElemString(val interface{}, key string) (ret string, ok bool)

func ElemStringMap

func ElemStringMap(val interface{}, key string) (ret map[string]string, ok bool)

func ElemStringSlice

func ElemStringSlice(val interface{}, key string) (ret []string, ok bool)

func ElemTime

func ElemTime(val interface{}, key string) (ret time.Time, ok bool)

func Evaluate

func Evaluate(val string) string

替换环境变量: ${NAME-default}, 如果没有指定"-"则保留${NAME}的字样

func FirstPrivIpv4

func FirstPrivIpv4() string

func Get

func Get(keys string) (interface{}, bool)

func GetBool

func GetBool(keys string) (bool, bool)

func GetDuration

func GetDuration(keys string) (time.Duration, bool)

func GetFloat64

func GetFloat64(keys string) (float64, bool)

func GetInt

func GetInt(keys string) (int, bool)

func GetInt64

func GetInt64(keys string) (int64, bool)

func GetMap

func GetMap(keys string) (map[string]interface{}, bool)

func GetSlice

func GetSlice(keys string) ([]interface{}, bool)

func GetString

func GetString(keys string) (string, bool)

func GetStringMap

func GetStringMap(keys string) (map[string]string, bool)

func GetStringSlice

func GetStringSlice(keys string) ([]string, bool)

func GetTime

func GetTime(keys string) (time.Time, bool)

func InitConf

func InitConf(vs map[string]interface{})

func LoadConf

func LoadConf(env string, name string) (bs []byte, path string, err error)

func MarshalToml

func MarshalToml(vl interface{}) (bs []byte, err error)

需要对称marshal为toml才能进行对称解析, 否则tag里面的toml:...会失败

func MustBind

func MustBind(keys string, ret interface{})

func MustBool

func MustBool(keys string) bool

func MustDuration

func MustDuration(keys string) time.Duration

func MustFloat64

func MustFloat64(keys string) float64

func MustInt

func MustInt(keys string) int

func MustInt64

func MustInt64(keys string) int64

func MustMap

func MustMap(keys string) map[string]interface{}

func MustSlice

func MustSlice(keys string) []interface{}

func MustString

func MustString(keys string) string

func MustStringMap

func MustStringMap(keys string) map[string]string

func MustStringSlice

func MustStringSlice(keys string) []string

func MustTime

func MustTime(keys string) time.Time

func OptiBool

func OptiBool(keys string, def bool) bool

func OptiDuration

func OptiDuration(keys string, def time.Duration) time.Duration

func OptiFloat64

func OptiFloat64(keys string, def float64) float64

func OptiInt

func OptiInt(keys string, def int) int

func OptiInt64

func OptiInt64(keys string, def int64) int64

func OptiMap

func OptiMap(keys string, def map[string]interface{}) map[string]interface{}

func OptiSlice

func OptiSlice(keys string, def []interface{}) []interface{}

func OptiString

func OptiString(keys string, def string) string

func OptiStringMap

func OptiStringMap(keys string, def map[string]string) map[string]string

func OptiStringSlice

func OptiStringSlice(keys string, def []string) []string

func OptiTime

func OptiTime(keys string, def time.Time) time.Time

func ToBool

func ToBool(val interface{}) bool

func ToDuration

func ToDuration(val interface{}) time.Duration

func ToFloat64

func ToFloat64(val interface{}) float64

func ToInt

func ToInt(val interface{}) int

func ToInt64

func ToInt64(val interface{}) int64

func ToMap

func ToMap(val interface{}) map[string]interface{}

func ToSlice

func ToSlice(val interface{}) []interface{}

func ToString

func ToString(val interface{}) string

func ToStringMap

func ToStringMap(val interface{}) map[string]string

func ToStringSlice

func ToStringSlice(val interface{}) []string

func ToTime

func ToTime(val interface{}) time.Time

Types

type BindFunc

type BindFunc func(val interface{}) interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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