github.com/timoth-y/kicksware-api/order-service@v0.0.0-20201002192818-87b546a7ae5a/env/serviceConfig.go (about) 1 package env 2 3 import ( 4 "io/ioutil" 5 6 "github.com/golang/glog" 7 "github.com/timoth-y/kicksware-api/service-common/core/meta" 8 "gopkg.in/yaml.v2" 9 ) 10 11 type ServiceConfig struct { 12 Common CommonConfig `yaml:"commonConfig"` 13 Security SecurityConfig `yaml:"securityConfig"` 14 Auth AuthConfig `yaml:"authConfig"` 15 Mongo DataStoreConfig `yaml:"mongoConfig"` 16 Postgres DataStoreConfig `yaml:"postgresConfig"` 17 Redis DataStoreConfig `yaml:"redisConfig"` 18 } 19 20 type CommonConfig struct { 21 Host string `yaml:"host"` 22 HostName string `yaml:"hostname"` 23 UsedDB string `yaml:"usedDB"` 24 ContentType string `yaml:"contentType"` 25 InnerServiceFormat string `yaml:"innerServiceFormat"` 26 } 27 28 type SecurityConfig struct { 29 TLSCertificate *meta.TLSCertificate `yaml:"tlsCertificate"` 30 } 31 32 type DataStoreConfig struct { 33 URL string `yaml:"URL"` 34 TLS *meta.TLSCertificate `yaml:"TLS"` 35 Database string `yaml:"database"` 36 Collection string `yaml:"collection"` 37 Login string `yaml:"login"` 38 Password string `yaml:"password"` 39 Timeout int `yaml:"timeout"` 40 } 41 42 type AuthConfig struct { 43 PublicKeyPath string `yaml:"publicKeyPath"` 44 AuthEndpoint string `yaml:"authEndpoint"` 45 TLSCertificate *meta.TLSCertificate `yaml:"tlsCertificate"` 46 } 47 48 func ReadServiceConfig(filename string) (sc ServiceConfig, err error) { 49 file, err := ioutil.ReadFile(filename); if err != nil { 50 glog.Fatalln(err) 51 return 52 } 53 54 err = yaml.Unmarshal(file, &sc); if err != nil { 55 glog.Fatalln(err) 56 return 57 } 58 return 59 }