config

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package config provide confg file read and unmarshal

Index

Constants

View Source
const EnvConfigEnv = "ENV_CONFIG_ENV"

EnvConfigEnv 配置文件环境

View Source
const EnvConfigFile = "ENV_CONFIG_FILE"

EnvConfigFile 配置文件环境变量名称

Variables

This section is empty.

Functions

func InitNacos

func InitNacos[T any](cfg *Nacos, appCfg T)

InitNacos 初始化nacos配置中心,cfg是nacos配置,appCfg是应用配置对象,从nacos拉取到的配置会解析到appCfg

func LoadConfig

func LoadConfig[T any](c T, dir ...string)

LoadConfig 读取解析配置文件

Types

type App

type App struct {
	// 应用id
	ID string `mapstructure:"id"`
	// 服务权重
	Weight int `mapstructure:"weight"`
	// Mode debug, release
	Mode    string `mapstructure:"mode"`
	Port    uint16 `mapstructure:"port"`
	RootDir string `mapstructure:"root_dir"`
	Cors    *Cors  `mapstructure:"cors"`
}

type Cors

type Cors struct {
	AllowOrigin      []string `mapstructure:"allow_origin"`
	AllowMethods     []string `mapstructure:"allow_methods"`
	AllowHeaders     []string `mapstructure:"allow_headers"`
	AllowCredentials bool     `mapstructure:"allow_credentials"`
}

type DB

type DB struct {
	DSN             string `mapstructure:"dsn"`
	Host            string `mapstructure:"host"`
	Port            uint16 `mapstructure:"port"`
	Username        string `mapstructure:"username"`
	Password        string `mapstructure:"password"`
	DbName          string `mapstructure:"db_name"`
	Charset         string `mapstructure:"charset"`
	Timezone        string `mapstructure:"timezone"`
	MaxIdleConns    int    `mapstructure:"max_idle_conns"`
	MaxOpenConns    int    `mapstructure:"max_open_conns"`
	ConnMaxLifeTime int    `mapstructure:"conn_max_life_time"`
}

type Mode

type Mode string

type Nacos

type Nacos struct {
	DataID string        `mapstructure:"data_id"`
	Group  string        `mapstructure:"group"`
	Client NacosClient   `mapstructure:"client"`
	Server []NacosServer `mapstructure:"server"`
}

Nacos 配置

type NacosClient

type NacosClient struct {
	NamespaceID         string `mapstructure:"namespace_id"`
	AccessKey           string `mapstructure:"access_key"`
	SecretKey           string `mapstructure:"secret_key"`
	Username            string `mapstructure:"username"`
	Password            string `mapstructure:"password"`
	NotLoadCacheAtStart bool   `mapstructure:"not_load_cache_at_start"`
	LogLevel            string `mapstructure:"log_level"`
}

type NacosServer

type NacosServer struct {
	IP   string `mapstructure:"ip"`
	Port uint16 `mapstructure:"port"`
}

type Otel

type Otel struct {
	TraceExporterURL string `mapstructure:"trace_exporter_url"`
}

Otel opentelemetry配置

type Redis

type Redis struct {
	Host string `mapstructure:"host"`
	Port uint16 `mapstructure:"port"`
	User string `mapstructure:"user"`
	Pass string `mapstructure:"pass"`
	Db   uint   `mapstructure:"db"`
}

type RocketMq

type RocketMq struct {
	Endpoint      string `mapstructure:"endpoint"`
	AccessKey     string `mapstructure:"access_key"`
	SecretKey     string `mapstructure:"secret_key"`
	Transaction   bool   `mapstructure:"transaction"`
	ProducerTopic string `mapstructure:"producer_topic"`
}

Jump to

Keyboard shortcuts

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