|
- package main
-
- import (
- "encoding/json"
- "io/ioutil"
- "log"
- )
-
- type AppConfig struct {
- Rpn struct {
- Url string `json:Url`
- UrlTest string `json:UrlTest`
- MD5P2P string `json:MD5P2P`
- MD5FAT string `json:MD5FAT`
- MIDP2P string `json:MIDP2P`
- MIDFAT string `json:MIDFAT`
- UrlCallBack string `json:UrlCallBack`
- } `json:Rpn`
- LeanWork struct {
- MD5P2P string `json:MD5P2P`
- MD5FAT string `json:MD5FA5`
- } `json:LeanWork`
- DB struct {
- Driver string `json:Driver`
- User string `json:User`
- Pass string `json:Pass`
- Schema string `json:Schema`
- } `json:DB`
- Server struct {
- Host string `json:Host`
- Port string `json:Port`
- } `json:Server`
- }
-
- var Config AppConfig
-
- func readConfig() error {
- log.Println("Read configration for production ")
- return readConfigFile("config.json")
- }
-
- func readConfigForTest() error {
- log.Println("Read configration for Test ")
- return readConfigFile("config.test.json")
- }
-
- func readConfigFile(file string) error {
-
- log.Printf("Read configration from %s", file)
- body, err := ioutil.ReadFile(file)
- if err != nil {
- log.Fatal("Fatal error Cannot read config ..")
- return err
- }
- err = json.Unmarshal(body, &Config)
- if err != nil {
- log.Fatal("cannot read config into json")
- return err
- }
-
- j, err := json.MarshalIndent(Config, "", "\t")
- if err != nil {
- log.Fatal("cannot print back to json")
- return err
- }
- log.Println(string(j))
- return err
- }
|