123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- package config
- import (
- "fmt"
- "github.com/pkg/errors"
- "go-micro.dev/v4/config"
- "go-micro.dev/v4/config/source/env"
- )
- type Config struct {
- Port int
- Tracing TracingConfig
- Registry RegistryConfig
- Redis RedisConfig
- Database DatabaseConfig
- }
- type TracingConfig struct {
- Enable bool
- Jaeger JaegerConfig
- }
- type JaegerConfig struct {
- URL string
- }
- type RegistryConfig struct {
- Enable bool
- Consul ConsulConfig
- }
- type ConsulConfig struct {
- URL string
- }
- type DatabaseConfig struct {
- Enable bool
- Mysql MysqlConfig
- }
- type RedisConfig struct {
- Enable bool
- URL string
- Password string
- }
- type MysqlConfig struct {
- User string
- Password string
- Host string
- Port int
- DataBase string
- }
- var cfg *Config = &Config{
- Port: 50053,
- }
- func Address() string {
- return fmt.Sprintf(":%d", cfg.Port)
- }
- func Tracing() TracingConfig {
- return cfg.Tracing
- }
- func Registry() RegistryConfig {
- return cfg.Registry
- }
- func DataBase() DatabaseConfig {
- return cfg.Database
- }
- func RedisAddress() RedisConfig {
- return cfg.Redis
- }
- func Load() error {
- configor, err := config.NewConfig(config.WithSource(env.NewSource()))
- if err != nil {
- return errors.Wrap(err, "configor.New")
- }
- if err := configor.Load(); err != nil {
- return errors.Wrap(err, "configor.Load")
- }
- if err := configor.Scan(cfg); err != nil {
- return errors.Wrap(err, "configor.Scan")
- }
- return nil
- }
|