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.

67 lines
1.6 KiB

  1. package main
  2. import (
  3. "encoding/json"
  4. "io/ioutil"
  5. )
  6. //MongoConfig stores the configuration of mongodb to connect
  7. type MongoConfig struct {
  8. IP string `json:"ip"`
  9. Database string `json:"database"`
  10. }
  11. //ServerConfig reads the server configuration
  12. type ServerConfig struct {
  13. ServerIP string `json:"serverIP"`
  14. ServerPort string `json:"serverPort"`
  15. WebServerPort string `json:"webserverPort"`
  16. AllowedIPs []string `json:"allowedIPs"`
  17. BlockedIPs []string `json:"blockedIPs"`
  18. }
  19. //Config reads the config
  20. type Config struct {
  21. User string `json:"user"`
  22. Pass string `json:"pass"`
  23. Host string `json:"host"`
  24. Port string `json:"port"`
  25. GenesisTx string `json:"genesisTx"`
  26. GenesisBlock string `json:"genesisBlock"`
  27. StartFromBlock int64 `json:"startFromBlock"`
  28. Server ServerConfig `json:"server"`
  29. Mongodb MongoConfig `json:"mongodb"`
  30. }
  31. var config Config
  32. func readConfig(path string) {
  33. file, err := ioutil.ReadFile(path)
  34. check(err)
  35. content := string(file)
  36. json.Unmarshal([]byte(content), &config)
  37. }
  38. /*
  39. var mongoConfig MongoConfig
  40. func readMongodbConfig(path string) {
  41. file, e := ioutil.ReadFile(path)
  42. if e != nil {
  43. fmt.Println("error:", e)
  44. }
  45. content := string(file)
  46. json.Unmarshal([]byte(content), &mongoConfig)
  47. }
  48. var serverConfig ServerConfig
  49. func readServerConfig(path string) {
  50. file, err := ioutil.ReadFile(path)
  51. if err != nil {
  52. fmt.Println("error: ", err)
  53. }
  54. content := string(file)
  55. json.Unmarshal([]byte(content), &serverConfig)
  56. }
  57. */