config

package
v0.0.0-...-76722b0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB
View Source
var (
	RDB redis.UniversalClient
)

Functions

func InitDB

func InitDB()

func InitRedis

func InitRedis()

Types

type ClusterConfig

type ClusterConfig struct {
	Addrs    []string `yaml:"addrs"`
	Password string   `yaml:"password"`
	ReadOnly bool     `yaml:"read_only"`
}

type Config

type Config struct {
	Server struct {
		Port int `yaml:"port"`
		Cors struct {
			AllowedOrigins []string `yaml:"allowed_origins"`
			AllowedMethods []string `yaml:"allowed_methods"`
			AllowedHeaders []string `yaml:"allowed_headers"`
		} `yaml:"cors"`
	} `yaml:"server"`

	Database struct {
		Driver   string `yaml:"driver"`
		Host     string `yaml:"host"`
		Port     int    `yaml:"port"`
		Username string `yaml:"username"`
		Password string `yaml:"password"`
		DBName   string `yaml:"dbname"`
		Params   string `yaml:"params"`
	} `yaml:"database"`

	Redis struct {
		Mode    string        `yaml:"mode"`
		Single  SingleConfig  `yaml:"single"`
		Cluster ClusterConfig `yaml:"cluster"`
	} `yaml:"redis"`
	// contains filtered or unexported fields
}

func GetConfig

func GetConfig() *Config

GetConfig 返回配置单例

func (*Config) GetDSN

func (c *Config) GetDSN() string

GetDSN 获取数据库连接字符串

func (*Config) Load

func (c *Config) Load() error

Load 加载配置文件

func (*Config) Watch

func (c *Config) Watch()

Watch 监听配置文件变化

type RedisConfig

type RedisConfig struct {
	Mode    string        `yaml:"mode"`
	Single  SingleConfig  `yaml:"single"`
	Cluster ClusterConfig `yaml:"cluster"`
}

type SingleConfig

type SingleConfig struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	Password string `yaml:"password"`
	DB       int    `yaml:"db"`
}

Jump to

Keyboard shortcuts

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