config

package
v0.0.0-...-5e9c659 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CONFIG_FILE_NAME = "config.json"
	DEFAULT_PREFIX   = "volts"

	MODE_NORMAL ModeType = iota
	MODE_DEBUG
)

Variables

View Source
var (
	// App settings.
	AppVer       string
	AppName      string
	AppUrl       string
	AppSubUrl    string
	AppPath      = utils.AppPath()
	AppFilePath  = utils.AppFilePath()
	AppDir       = utils.AppDir()
	AppModuleDir = "module"
)

Functions

func Init

func Init(opts ...Option)

func Load

func Load(fileName ...string) error

func Register

func Register(cfg IConfig)

func Unregister

func Unregister(cfg IConfig)

Types

type Config

type Config struct {
	//name string
	//fmt        *format
	//models     sync.Map
	AutoCreateFile bool `field:"-"`
	//Mode       ModeType
	//FileName   string
	Debug bool
	// contains filtered or unexported fields
}

func Default

func Default() *Config

func New

func New(name string, opts ...Option) *Config

func (*Config) Core

func (self *Config) Core() *core

func (*Config) GetBool

func (self *Config) GetBool(field string, defaultValue bool) bool

func (*Config) GetDuration

func (self *Config) GetDuration(field string, defaultValue time.Duration) time.Duration

func (*Config) GetFloat64

func (self *Config) GetFloat64(field string, defaultValue float64) float64

func (*Config) GetInt

func (self *Config) GetInt(field string, defaultValue int) int

GetIntValue from default namespace

func (*Config) GetInt32

func (self *Config) GetInt32(field string, defaultValue int32) int32

func (*Config) GetInt64

func (self *Config) GetInt64(field string, defaultValue int64) int64

func (*Config) GetIntSlice

func (self *Config) GetIntSlice(field string, defaultValue []int) []int

func (*Config) GetString

func (self *Config) GetString(field, defaultValue string) string

GetStringValue from default namespace

func (*Config) GetTime

func (self *Config) GetTime(field string, defaultValue time.Time) time.Time

func (*Config) InConfig

func (self *Config) InConfig(path string) bool

检测配置路径是否在Config里出现了

func (*Config) Init

func (self *Config) Init(opts ...Option)

config: the config struct with binding the options

func (*Config) LoadFromFile

func (self *Config) LoadFromFile(fileName ...string) error

func (*Config) LoadToModel

func (self *Config) LoadToModel(model IConfig) error

func (*Config) Register

func (self *Config) Register(cfg IConfig)

注册添加其他配置

func (*Config) Reload

func (self *Config) Reload()

func (*Config) SaveFromModel

func (self *Config) SaveFromModel(model IConfig, immed ...bool) error

从数据类型加载数据 只支持map[string]any 和struct

func (*Config) SaveToFile

func (self *Config) SaveToFile(opts ...Option) error

func (*Config) SetValue

func (self *Config) SetValue(field string, value interface{})

func (*Config) Unregister

func (self *Config) Unregister(cfg IConfig)

type IConfig

type IConfig interface {
	String() string // the Prefix name
	Load() error
	Save(immed ...bool) error // immed mean save to file immediately or not.
}

type ModeType

type ModeType int

func (ModeType) String

func (c ModeType) String() string

type Option

type Option func(*Config)

func WithConfig

func WithConfig(model IConfig) Option

保存新配置数据

func WithFileName

func WithFileName(fileName string) Option

func WithNoAutoCreateFile

func WithNoAutoCreateFile() Option

当无配置文件时不自动创建配置文件

func WithPrefix

func WithPrefix(name string) Option

func WithWatcher

func WithWatcher() Option

监听配置文件变动

Jump to

Keyboard shortcuts

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