payment gateway for rpn cn
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.2KB

  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/ioutil"
  6. "log"
  7. )
  8. type AppConfig struct {
  9. Rpn struct {
  10. Url string `json:Url`
  11. UrlTest string `json:UrlTest`
  12. MD5P2P string `json:MD5P2P`
  13. MD5FAT string `json:MD5FAT`
  14. MIDP2P string `json:MIDP2P`
  15. MIDFAT string `json:MIDFAT`
  16. } `json:Rpn`
  17. LeanWork struct {
  18. MD5Key string `json:MD5Key`
  19. } `json:LeanWork`
  20. DB struct {
  21. Driver string `json:Driver`
  22. User string `json:User`
  23. Pass string `json:Pass`
  24. Schema string `json:Schema`
  25. } `json:DB`
  26. }
  27. var Config AppConfig
  28. func readConfig() error {
  29. log.Println("Read configration for production ")
  30. return readConfigFile("config.json")
  31. }
  32. func readConfigForTest() error {
  33. log.Println("Read configration for Test ")
  34. return readConfigFile("config.test.json")
  35. }
  36. func readConfigFile(file string) error {
  37. log.Printf("Read configration from %s", file)
  38. body, err := ioutil.ReadFile(file)
  39. if err != nil {
  40. log.Fatal("Fatal error Cannot read config ..")
  41. return err
  42. }
  43. err = json.Unmarshal(body, &Config)
  44. if err != nil {
  45. log.Fatal("cannot read config into json")
  46. return err
  47. }
  48. j, err := json.MarshalIndent(Config, "", "\t")
  49. if err != nil {
  50. log.Fatal("cannot print back to json")
  51. return err
  52. }
  53. fmt.Println(string(j))
  54. return err
  55. }