configen

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: MIT Imports: 13 Imported by: 3

README

configen

config for apps

Documentation

Index

Constants

View Source
const (
	ErrIni      = "failed to parse ini"
	ErrJson     = "failed to parse json"
	ErrYaml     = "failed to parse yaml"
	ErrGdx      = "failed to parse gdx"
	ErrSaveIni  = "failed to save ini"
	ErrSaveJson = "failed to save json"
	ErrSaveYaml = "failed to save yaml"
	ErrSaveGdx  = "failed to save gdx"
	ErrSuffix   = "file type not support"
	ErrLoad     = "failed to load file"
	ErrSave     = "failed to save file"
	ErrGenTemp  = "failed to generate template"

	ErrNotPointer = "input is not a pointer"
	ErrNotStruct  = "input is not a struct"
	ErrValidate   = "failed to reflect type"
)

errors

View Source
const (
	INI    = "ini"
	JSON   = "json"
	Pig    = "pig"    // pig is an alias of json
	Config = "config" // config is an alias of json
	Yaml   = "yaml"
	Gdx    = "gdx"
)

infos

View Source
const (
	INIType = iota
	JSONType
	YamlType
	GdxType
)

类型枚举

View Source
const (
	TpName = "ConfigenTpl"
	TpRaw  = `# config generate by configen
# copyright github.com/landers1037/configen
{{range $r := . -}}
	{{print $r}}
{{end}}`
)

配置文件模板生成 支持py的gunicorn和nginx

Variables

This section is empty.

Functions

func Default

func Default(filed interface{}, def interface{})

Default 修改默认值 field must be a pointer

func Err

func Err(e string, args ...string) error

func MakeTemplate added in v1.0.1

func MakeTemplate(tpl string, w io.Writer, data interface{}) error

MakeTemplate 生成模板

func MakeTemplateGunicorn added in v1.0.1

func MakeTemplateGunicorn(tpl, file string, data interface{}) error

MakeTemplateGunicorn 生成nginx配置文件 支持端口

func MakeTemplateGunicornString added in v1.0.1

func MakeTemplateGunicornString(tpl, file string, data interface{}) error

func MakeTemplateGunicornTest added in v1.0.1

func MakeTemplateGunicornTest(tpl string, data interface{}) error

func MakeTemplateNginx added in v1.0.1

func MakeTemplateNginx(tpl, file string, data interface{}) error

MakeTemplateNginx 生成nginx配置文件 支持自定义域名 服务名 端口 IP 代理转发

func MakeTemplateNginxString added in v1.0.1

func MakeTemplateNginxString(tpl, file string, data interface{}) error

func MakeTemplateNginxTest added in v1.0.1

func MakeTemplateNginxTest(tpl string, data interface{}) error

func MakeTemplateRaw added in v1.0.1

func MakeTemplateRaw(w io.Writer, data []string) error

MakeTemplateRaw 按照字符串数组生成配置文件 需要传入[]string

func MakeTemplateString added in v1.0.1

func MakeTemplateString(tpl string, w io.Writer, data interface{}) error

MakeTemplateString 使用字符串生成模板

func ParseConfig

func ParseConfig(c interface{}, t, file string) error

ParseConfig 指定配置文件类型解析 c must be a pointer t only support messages INI, Json, Yaml, Gdx

func ParseConfigMap

func ParseConfigMap(t, file string) (*map[string]interface{}, error)

ParseConfigMap 指定配置文件类型解析为字典 t only support messages INI, Json, Yaml, Gdx

func RegToConfig

func RegToConfig(v interface{})

RegToConfig 注册gob

func SaveConfig

func SaveConfig(c interface{}, t, file string) error

SaveConfig 保存数据到文件中 c must be a pointer t is type must be in supports file is the output file

func ValidateTags

func ValidateTags(v interface{}, env string, f HandleEnv) error

ValidateTags 自定义标签的解析 用于配置默认值 eg: `config:"env"` 默认为0值时从环境变量key: env读取 env 需要读取的环境变量 f 处理环境变量的函数,返回最终处理后需要更改的值

Types

type HandleEnv added in v1.0.1

type HandleEnv func(env string) interface{}

Jump to

Keyboard shortcuts

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