config

package
v3.0.4 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseConfigFromBytesToDst added in v3.0.3

func ParseConfigFromBytesToDst(format string, source []byte, dst interface{}) (interface{}, error)

ParseConfigFromBytesToDst 从字符串解析配置到目标结构

format 内容格式,支持: json|yaml|toml

source 配置源字符

dst 目标结构

@return 返回值与参数dst类型相同,需要进行断言

func PrintTemplateConfig

func PrintTemplateConfig(format string, writeToFile ...string)

PrintTemplateConfig 打印配置信息模板

format 内容格式,支持: json|yaml|toml

writeToFile 写入到目标文件(可选)

func Set added in v3.0.3

func Set(conf *Config)

Set 设置配置

Types

type Config

type Config struct {
	HttpServer       HttpServerConf    `yaml:"http_conf" toml:"http_conf" json:"http_conf"`                            //http服务配置
	LoggerConf       logger.Conf       `yaml:"logger_conf" toml:"logger_conf" json:"logger_conf"`                      //日志配置
	DBConf           db.Conf           `yaml:"db_conf" toml:"db_conf" json:"db_conf"`                                  //数据库配置
	RedisConf        redis.Conf        `yaml:"redis_conf" toml:"redis_conf" json:"redis_conf"`                         //redis配置(standalone)
	RedisClusterConf redis.ClusterConf `yaml:"redis_cluster_conf" toml:"redis_cluster_conf" json:"redis_cluster_conf"` //redis配置(cluster)
	NatsConf         nats.Conf         `yaml:"nats_conf" toml:"nats_conf" json:"nats_conf"`                            //nats配置
	JwtConf          *jwt.Conf         `yaml:"jwt_conf" toml:"jwt_conf" json:"jwt_conf"`                               //jwt配置
	EmailConf        email.Conf        `yaml:"email_conf" toml:"email_conf" json:"email_conf"`                         //邮件配置
	KafkaConf        KafkaExtraConf    `yaml:"kafka_conf" toml:"kafka_conf" json:"kafka_conf"`                         //kafka配置
	EtcdConf         etcd.Conf         `yaml:"etcd_conf" toml:"etcd_conf" json:"etcd_conf"`                            //etcd配置
}

Config 配置

func Get added in v3.0.1

func Get() *Config

Get 获取配置

func ParseConfigFromBytes added in v3.0.1

func ParseConfigFromBytes(format string, source []byte) (*Config, error)

ParseConfigFromBytes 从字符串解析配置

format 内容格式,支持: json|yaml|toml

source 配置源字符

type HttpServerConf

type HttpServerConf struct {
	Debug              bool           `yaml:"debug" toml:"debug" json:"debug" default:"false"`                              //是否是debug模式
	Addr               string         `yaml:"addr" toml:"addr" json:"addr" default:":8080"`                                 //监听地址
	Swagger            SwaggerConf    `yaml:"swagger_conf" toml:"swagger_conf" json:"swagger_conf"`                         //swagger文档配置
	Prometheus         PrometheusConf `yaml:"prometheus_conf" toml:"prometheus_conf" json:"prometheus_conf"`                //prometheus配置
	WebSocketRoutePath string         `yaml:"websocket_route_path" toml:"websocket_route_path" json:"websocket_route_path"` //websocket路由
}

HttpServerConf http服务配置

type KafkaExtraConf added in v3.0.1

type KafkaExtraConf struct {
	Conf    kafka.Conf `yaml:"conf" toml:"conf" json:"conf"`          //配置
	Topic   string     `yaml:"topic" toml:"topic" json:"topic"`       //主题
	GroupID string     `yaml:"groupID" toml:"groupID" json:"groupID"` //分组id
}

type PrometheusConf

type PrometheusConf struct {
	Enable     bool   `yaml:"enable" toml:"enable" json:"enable" default:"false"`                   //是否启用
	Addr       string `yaml:"addr" toml:"addr" json:"addr" default:":19100"`                        //监听地址
	AccessPath string `yaml:"access_path" toml:"access_path" json:"access_path" default:"/metrics"` //路由地址
}

type SwaggerConf

type SwaggerConf struct {
	Enable      bool   `yaml:"enable" toml:"enable" json:"enable" default:"false"`      //是否启用
	RedocUIPath string `yaml:"redoc_ui_path" toml:"redoc_ui_path" json:"redoc_ui_path"` //ui页面文件路径,如/path/to/docs.html,注意文件名必须是docs.html
	JsonPath    string `yaml:"json_path" toml:"json_path" json:"json_path"`             //json文件路径
	FaviconPath string `yaml:"favicon_path" toml:"favicon_path" json:"favicon_path"`    //浏览器页签图标文件路径
}

Jump to

Keyboard shortcuts

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