toolgo

package module
v1.0.3 Latest Latest
Warning

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

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

README

toolgo

可以直接集成到项目中用于读取配置文件、打印日志等,方便快捷。

配置文件可以为toml、yaml等其他格式。默认包含Logger日志模块,也可以自己重新定义。格式如下:

[Logger]
LogLevel = "debug"
FilePath = "logs/demo.log"

[Config]
Name = "Demo"
Addr = "127.0.0.1"
Port = 8888

使用时传递配置文件路径和配置结构,然后调用初始化。示例代码:

type DemoConfig struct {
	Name string
	Addr string
	Port int
}

var demoConfig DemoConfig

func main() {
	toolgo.Default().
		SetConfigFilePath("conf/conf.toml").
		SetConfig(&demoConfig).
		Init()

	logger.Debugf("this is a debug message")
	logger.Errorf("this is a error message")
	logger.Debugf("config:%+v", demoConfig)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLog added in v1.0.3

func InitLog(level, filePath string) (err error)

Types

type Conf

type Conf struct {
	ConfigFile ConfigFileConf `mapstructure:"-"`
	Logger     LoggerConf
	Config     interface{}
}

func Default added in v1.0.3

func Default() *Conf

func GetDefaultConf deprecated

func GetDefaultConf() *Conf

Deprecated: use Default instead

func (*Conf) Init

func (c *Conf) Init()

func (*Conf) SetConfig

func (c *Conf) SetConfig(config interface{}) *Conf

func (*Conf) SetConfigFilePath

func (c *Conf) SetConfigFilePath(path string) *Conf

func (*Conf) SetLogFilePath

func (c *Conf) SetLogFilePath(path string) *Conf

type ConfigFileConf

type ConfigFileConf struct {
	FilePath string
}

type LoggerConf

type LoggerConf struct {
	LogLevel         string
	FilePath         string
	FileMaxAge       int // 文件最大保存时间(天)
	FileRotationTime int // 日志切割时间间隔(小时)
}

Directories

Path Synopsis
gin

Jump to

Keyboard shortcuts

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