config

package
v0.0.0-...-ae01125 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load[C any](path string, c *C) error

Load 初始化读取配置

func LoadAndWatch

func LoadAndWatch[C any](path string, c *C) error

LoadAndWatch 初始化读取配置,并监控配置变化

Types

type Config

type Config struct {
	Server   Server   `json:"server" mapstructure:"server"`     // 服务端配置
	Log      Log      `json:"log" mapstructure:"log"`           // Log 日志配置
	Database Database `json:"database" mapstructure:"database"` // 数据库配置
}

Config 通用配置模版

type Database

type Database struct {
	MySQL    MySQL    `json:"mysql" mapstructure:"mysql"`       // MySQL 数据库配置
	Postgres Postgres `json:"postgres" mapstructure:"postgres"` // Postgres 数据库配置
	Redis    Redis    `json:"redis" mapstructure:"redis"`       // Redis 数据库配置
}

Database 数据库通用配置模版

type Env

type Env string

Env 运行环境

const (
	DEV  Env = "dev"  // 开发环境
	Test Env = "test" // 测试环境
	Prod Env = "prod" // 生产环境
)

type Log

type Log struct {
	Path       string     `json:"path" mapstructure:"path"`               // 日志存放路径
	Type       LogType    `json:"type" mapstructure:"type"`               // 日志类型。stdout:标准输出,file:文件输出
	Filename   string     `json:"filename" mapstructure:"filename"`       // 日志文件名
	Level      slog.Level `json:"level" mapstructure:"level"`             // 日志级别。-4:debug, 0:info, 4:warn, 8:error
	MaxSize    int        `json:"max_size" mapstructure:"max_size"`       // 单个日志文件最大大小,单位:MB
	MaxBackups int        `json:"max_backups" mapstructure:"max_backups"` // 最多保存多少个日志文件
	MaxAge     int        `json:"max_age" mapstructure:"max_age"`         // 最多保存多长时间的日志文件,单位:天
}

Log 日志配置

type LogType

type LogType string

LogType 日志类型

const (
	Stdout LogType = "stdout" // 标准输出
	File   LogType = "file"   // 文件输出
)

type MySQL

type MySQL struct {
	Host     string `json:"host" mapstructure:"host"`
	Port     string `json:"port" mapstructure:"port"`
	UserName string `json:"username" mapstructure:"username"`
	Password string `json:"password" mapstructure:"password"`
	Database string `json:"database" mapstructure:"database"`
}

MySQL 数据库配置

type Postgres

type Postgres struct {
	Host     string `json:"host" mapstructure:"host"`
	Port     string `json:"port" mapstructure:"port"`
	UserName string `json:"username" mapstructure:"username"`
	Password string `json:"password" mapstructure:"password"`
	Database string `json:"database" mapstructure:"database"`
}

Postgres 数据库配置

type Redis

type Redis struct {
	Host     string `json:"host" mapstructure:"host"`
	Port     int    `json:"port" mapstructure:"port"`
	Password string `json:"password" mapstructure:"password"`
	Database int    `json:"database" mapstructure:"database"`
}

Redis 数据库配置

type Server

type Server struct {
	Host             string `json:"host" mapstructure:"host"`                         // host
	Port             string `json:"port" mapstructure:"port"`                         // 端口
	Version          string `json:"version" mapstructure:"version"`                   // 服务版本
	BasePath         string `json:"base_path" mapstructure:"base_path"`               // 根路径
	Env              Env    `json:"env" mapstructure:"env"`                           // 所属环境
	Monitor          bool   `json:"monitor" mapstructure:"monitor"`                   // 是否开启可视化监控
	GlobalLimiterMax int    `json:"globalLimiterMax" mapstructure:"globalLimiterMax"` // 全局限流器最大值
}

Server 服务配置

Jump to

Keyboard shortcuts

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