github.com/Bio-core/jtree@v0.0.0-20190705165106-1d7a7e7d6272/conf/config.go (about) 1 package conf 2 3 import ( 4 "io/ioutil" 5 "log" 6 "path/filepath" 7 8 yaml "gopkg.in/yaml.v2" 9 ) 10 11 //Conf is an object created by the conf.yaml file 12 type Conf struct { 13 Database Database 14 Keycloak Keycloak 15 App App 16 } 17 18 //Database Config Object 19 type Database struct { 20 Host string 21 Name string 22 Selectuser string 23 Selectpass string 24 Updateuser string 25 Updatepass string 26 } 27 28 //Keycloak Config Object 29 type Keycloak struct { 30 Host string 31 } 32 33 //App Config Object 34 type App struct { 35 Port int 36 Host string 37 } 38 39 //GetConf fills the conf struct 40 func (c *Conf) GetConf() *Conf { 41 path, _ := filepath.Abs("./conf/conf.yaml") 42 yamlFile, err := ioutil.ReadFile(path) 43 if err != nil { 44 log.Printf("yamlFile.Get err #%v ", err) 45 } 46 err = yaml.Unmarshal(yamlFile, c) 47 if err != nil { 48 log.Fatalf("Unmarshal: %v", err) 49 } 50 51 return c 52 }