payment gateway for rpn cn
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

70 lignes
1.5KB

  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. MD5P2P string `json:MD5P2P`
  11. MD5FAT string `json:MD5FAT`
  12. MIDP2P string `json:MIDP2P`
  13. MIDFAT string `json:MIDFAT`
  14. UrlCallBack string `json:UrlCallBack`
  15. } `json:Rpn`
  16. LeanWork struct {
  17. MD5P2P string `json:MD5P2P`
  18. MD5FAT string `json:MD5FA5`
  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. Server struct {
  27. Host string `json:Host`
  28. Port string `json:Port`
  29. } `json:Server`
  30. }
  31. var Config AppConfig
  32. func readConfig() error {
  33. log.Println("Read configration for production ")
  34. workingdir := getWorkingDir()
  35. return readConfigFile(workingdir + "/config.json")
  36. }
  37. func readConfigForTest() error {
  38. log.Println("Read configration for Test ")
  39. workingdir := getWorkingDir()
  40. return readConfigFile(workingdir + "/config.test.json")
  41. }
  42. func readConfigFile(file string) error {
  43. log.Printf("Read configration from %s", file)
  44. body, err := ioutil.ReadFile(file)
  45. if err != nil {
  46. log.Fatal("Fatal error Cannot read config ..")
  47. return err
  48. }
  49. err = json.Unmarshal(body, &Config)
  50. if err != nil {
  51. log.Fatal("cannot read config into json")
  52. return err
  53. }
  54. j, err := json.MarshalIndent(Config, "", "\t")
  55. if err != nil {
  56. log.Fatal("cannot print back to json")
  57. return err
  58. }
  59. log.Println(string(j))
  60. return err
  61. }