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.

69 lines
1.4KB

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