config

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: LGPL-3.0 Imports: 13 Imported by: 5

Documentation

Index

Constants

View Source
const (
	MegaByte = 1024 * 1024
	NoDiags  = "no diagnostics"
)

Variables

This section is empty.

Functions

func BackToDir

func BackToDir(back int) (err error)

BackToDir 退回上层目录

func IsRunTest

func IsRunTest() bool

IsRunTest 是否测试模式下

func PrepareEnv

func PrepareEnv(size int)

PrepareEnv 初始化环境

func SetupLog

func SetupLog(cfg *LogConfig)

SetupLog 根据配置初始化日志单例

Types

type AppConfig

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

AppConfig App配置,包括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文件

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"`
	// contains filtered or unexported fields
}

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

func ReadConfigFile

func ReadConfigFile(file string, remain any) (*RootConfig, error)

ReadConfigFile 读取配置文件

func (*RootConfig) ParseAppRemain added in v1.4.4

func (c *RootConfig) ParseAppRemain(remain any) error

ParseAppRemain 解析剩下的配置

func (*RootConfig) ParseFile added in v1.4.4

func (c *RootConfig) ParseFile(force bool) error

ParseFile 解析主要配置

func (*RootConfig) ParseRemain added in v1.4.4

func (c *RootConfig) ParseRemain(remain any) error

ParseRemain 解析剩下的配置

Jump to

Keyboard shortcuts

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