config

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: LGPL-3.0 Imports: 12 Imported by: 5

Documentation

Index

Constants

View Source
const MegaByte = 1024 * 1024

Variables

This section is empty.

Functions

func BackToAppDir

func BackToAppDir() error

BackToAppDir 如果在子目录下运行,需要先退回上层目录

func BackToDir

func BackToDir(back int) (dir string, err error)

BackToDir 退回上层目录

func IsRunTest

func IsRunTest() bool

IsRunTest 是否测试模式下

func PrepareEnv

func PrepareEnv(size int)

PrepareEnv 初始化环境

func PrepareFlags

func PrepareFlags()

PrepareFlags 解析命令行参数

func SetupConfig

func SetupConfig(options any)

SetupConfig 根据不同场景初始化

func SetupLog

func SetupLog()

func Verbose

func Verbose() bool

Verbose 是否输出详细信息

Types

type AppConfig

type AppConfig struct {
	Name    string `hcl:"name,optional" json:"name,omitempty"`
	Version string `hcl:"version,optional" json:"version,omitempty"`
}

AppConfig App配置,包括App名称和自定义配置

func GetAppSettings

func GetAppSettings() *AppConfig

GetAppSettings 返回App配置单例

type ArgList

type ArgList struct {
	Convert func(string) string
	// contains filtered or unexported fields
}

func NewArgList

func NewArgList(conv func(string) string) *ArgList

func ReadArgs

func ReadArgs(uniq bool, conv func(string) string) *ArgList

ReadArgs 读取命令行参数,不包括命名参数,且必须将命名参数放在前面

func (*ArgList) Add

func (t *ArgList) Add(args []string, uniq bool) int

Add 增加一些参数

func (*ArgList) Count

func (t *ArgList) Count(arg string) int

Count 获得此参数计数

func (*ArgList) Has

func (t *ArgList) Has(arg string) bool

Has 是否含有此参数

func (*ArgList) Size

func (t *ArgList) Size() int

Size 参数元素个数

type LogConfig

type LogConfig struct {
	LogLevel string `hcl:"log_level,optional" json:"log_level,omitempty"`
	LogFile  string `hcl:"log_file,optional" json:"log_file,omitempty"`
	LogDir   string `hcl:"log_dir,optional" json:"log_dir,omitempty"`
}

LogConfig 日志配置,指定文件夹或URL文件

func GetLogSettings

func GetLogSettings() *LogConfig

GetLogSettings 返回日志配置单例

type RootConfig

type RootConfig struct {
	Debug  bool       `hcl:"debug" json:"debug"`
	App    *AppConfig `hcl:"app,block" json:"app"`
	Log    *LogConfig `hcl:"log,block" json:"log,omitempty"`
	Remain hcl.Body   `hcl:",remain"`
}

RootConfig 顶层配置,包含其他配置块

func GetTheSettings

func GetTheSettings() *RootConfig

GetTheSettings 返回主配置单例

func ParseConfigFile

func ParseConfigFile(options any) (*RootConfig, error)

ParseConfigFile 读取默认配置文件

func ReadConfigFile

func ReadConfigFile(cfgFile string, verbose bool, others any) (*RootConfig, error)

ReadConfigFile 读取配置文件

Jump to

Keyboard shortcuts

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