conf

package
v0.0.0-...-f4276bb Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Name string `json:"name" toml:"name"`
}

type Config

type Config struct {
	App *App `json:"app" toml:"app"`
	// [mysql]
	MySQL *MySQL `json:"mysql" toml:"mysql"`
	//
	MongoDB *mongodb `json:"mongo" toml:"mongo"`
	// [http]
	Http *Http `json:"http" toml:"http"`
	// [grpc]
	Grpc *Grpc `json:"grpc" toml:"grpc"`
	// 程序接入Jaeger配置
	Jaeger *jaeger `toml:"jaeger"`
}

程序的配置对象 config --> object

func C

func C() *Config

把全局对象保护起来

func DefaultConfig

func DefaultConfig() *Config

func LoadConfigFromEnv

func LoadConfigFromEnv() (*Config, error)

通过环境变量读取配置 采用第三方库: "github.com/caarlos0/env/v6" 读取环境变量 环境变量 ---> config object

func LoadConfigFromToml

func LoadConfigFromToml(path string) (*Config, error)

toml 文件加载 使用到的第三方库: "github.com/BurntSushi/toml"

func (*Config) String

func (c *Config) String() string

格式化成一个json

type Grpc

type Grpc struct {
	Host string `json:"host" toml:"host" env:"MCENTER_GRPC_HOST"`
	Port int    `json:"port" toml:"port" env:"MCENTER_GRPC_PORT"`
}

func NewDefaultGrpc

func NewDefaultGrpc() *Grpc

func (*Grpc) Address

func (h *Grpc) Address() string

type Http

type Http struct {
	Host string `json:"host" toml:"host" env:"HTTP_HOST"`
	Port int    `json:"port" toml:"port" env:"HTTP_PORT"`
}

func (*Http) Address

func (h *Http) Address() string

type MySQL

type MySQL struct {
	Host     string `json:"host" toml:"host" env:"MYSQL_HOST"`
	Port     int    `json:"port" toml:"port" env:"MYSQL_PORT"`
	DB       string `json:"db" toml:"db" env:"MYSQL_DB"`
	Username string `json:"username" toml:"username" env:"MYSQL_USERNAME"`
	Password string `json:"password" toml:"password" env:"MYSQL_PASSWORD"`

	// 高级参数
	MaxOpenConn int `toml:"max_open_conn" env:"MYSQL_MAX_OPEN_CONN"`
	MaxIdleConn int `toml:"max_idle_conn" env:"MYSQL_MAX_IDLE_CONN"`
	MaxLifeTime int `toml:"max_life_time" env:"MYSQL_MAX_LIFE_TIME"`
	MaxIdleTime int `toml:"max_idle_time" env:"MYSQL_MAX_IDLE_TIME"`
	// contains filtered or unexported fields
}

func (*MySQL) Close

func (m *MySQL) Close() error

func (*MySQL) GetConnPool

func (m *MySQL) GetConnPool() (*sql.DB, error)

func (*MySQL) ORM

func (m *MySQL) ORM() *gorm.DB

Jump to

Keyboard shortcuts

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