config

package
v0.0.0-...-68d4bda Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

lib/config/fx.go

Index

Constants

View Source
const (
	LogLevelDebug string = "debug"
	LogLevelTrace string = "trace"
	LogLevelInfo  string = "info"
	LogLevelWarn  string = "warn"
	LogLevelError string = "error"
	LogLevelFatal string = "fatal"
)

Variables

View Source
var Module = fx.Module("config", fx.Provide(LoadConfigFromYAML))

Functions

This section is empty.

Types

type Config

type Config struct {
	MySQL  MySQLConfig  `yaml:"mysql"`
	Redis  RedisConfig  `yaml:"redis"`
	Task   TaskConfig   `yaml:"task"`
	Logger LoggerConfig `yaml:"logger"`
	Server ServerConfig `yaml:"server"`
}

Config 结构体,包含 MySQL 和 Redis 配置

func LoadConfigFromYAML

func LoadConfigFromYAML(filepath ConfigFile) (*Config, error)

读取 YAML 配置文件

type ConfigFile

type ConfigFile string

type LoggerConfig

type LoggerConfig struct {
	Filename       string `yaml:"filename"`
	ErrFileName    string `yaml:"err_filename"`
	AccessFileName string `yaml:"access_filename"`
	LogLevel       string `yaml:"log_level"`
}

TaskConfig 结构体,包含 Task配置

type MySQLConfig

type MySQLConfig struct {
	Host           string        `yaml:"host"`
	Port           int           `yaml:"port"`
	Username       string        `yaml:"username"`
	Password       string        `yaml:"password"`
	DBName         string        `yaml:"dbname"`
	Charset        string        `yaml:"charset"`
	ConnectTimeout time.Duration `yaml:"connect_timeout"`
	ReadTimeout    time.Duration `yaml:"read_timeout"`
	WriteTimeout   time.Duration `yaml:"write_timeout"`
}

MySQLConfig 结构体,包含 MySQL 配置项和超时设置

type RedisConfig

type RedisConfig struct {
	Host           string        `yaml:"host"`
	Port           int           `yaml:"port"`
	Password       string        `yaml:"password"`
	DB             int           `yaml:"db"`
	ConnectTimeout time.Duration `yaml:"connect_timeout"`
	ReadTimeout    time.Duration `yaml:"read_timeout"`
	WriteTimeout   time.Duration `yaml:"write_timeout"`
}

RedisConfig 结构体,包含 Redis 配置项和超时设置

type ServerConfig

type ServerConfig struct {
	ListenAddr string `yaml:"listen_addr"`
}

type TaskConfig

type TaskConfig struct {
	ThreadNum int `yaml:"thread_num"`
}

TaskConfig 结构体,包含 Task配置

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳