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.

62 lignes
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. } `json:Rpn`
  15. LeanWork struct {
  16. MD5Key string `json:MD5Key`
  17. } `json:LeanWork`
  18. DB struct {
  19. Driver string `json:Driver`
  20. User string `json:User`
  21. Pass string `json:Pass`
  22. Schema string `json:Schema`
  23. } `json:DB`
  24. }
  25. var Config AppConfig
  26. func readConfig() error {
  27. log.Println("Read configration for production ")
  28. return readConfigFile("config.json")
  29. }
  30. func readConfigForTest() error {
  31. log.Println("Read configration for Test ")
  32. return readConfigFile("config.test.json")
  33. }
  34. func readConfigFile(file string) error {
  35. log.Printf("Read configration from %s", file)
  36. body, err := ioutil.ReadFile(file)
  37. if err != nil {
  38. log.Fatal("Fatal error Cannot read config ..")
  39. return err
  40. }
  41. err = json.Unmarshal(body, &Config)
  42. if err != nil {
  43. log.Fatal("cannot read config into json")
  44. return err
  45. }
  46. j, err := json.MarshalIndent(Config, "", "\t")
  47. if err != nil {
  48. log.Fatal("cannot print back to json")
  49. return err
  50. }
  51. fmt.Println(string(j))
  52. return err
  53. }