123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package config
- import (
- "github.com/pkg/errors"
- "go-micro.dev/v4/config"
- "go-micro.dev/v4/config/source/env"
- )
- type Config struct {
- Address string
- Tracing TracingConfig
- Registry RegistryConfig
- Redis RedisConfig
- AuthorizationService string
- }
- 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 RedisConfig struct {
- Enable bool
- URL string
- Password string
- }
- var cfg *Config = &Config{
- Address: ":8080",
- AuthorizationService: "authorizationservice",
- }
- func Get() Config {
- return *cfg
- }
- func Address() string {
- return cfg.Address
- }
- func Tracing() TracingConfig {
- return cfg.Tracing
- }
- func Registry() RegistryConfig {
- return cfg.Registry
- }
- 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
- }
|