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