MCPcopy Create free account
hub / github.com/DOSNetwork/core / LoadConfig

Function LoadConfig

configuration/config.go:39–68  ·  view source on GitHub ↗

LoadConfig loads configuration file from path.

(path string, c interface{})

Source from the content-addressed store, hash-verified

37
38// LoadConfig loads configuration file from path.
39func LoadConfig(path string, c interface{}) (err error) {
40 var jsonFile *os.File
41 var byteValue []byte
42
43 fmt.Println("Path ", path)
44 // Open our jsonFile
45 jsonFile, err = os.Open(path)
46 // if we os.Open returns an error then handle it
47 if err != nil {
48 fmt.Println("LoadConfig error ", err)
49 return
50 }
51 fmt.Println("Successfully Opened json")
52 // defer the closing of our jsonFile so that we can parse it later on
53 defer jsonFile.Close()
54
55 // read our opened xmlFile as a byte array.
56 byteValue, err = ioutil.ReadAll(jsonFile)
57 if err != nil {
58 fmt.Println("ReadAll error ", err)
59 return
60 }
61
62 err = json.Unmarshal(byteValue, &c)
63 if err != nil {
64 fmt.Println("Unmarshal error ", err)
65 return
66 }
67 return
68}
69
70// LoadConfig loads configuration file from path.
71func (c *Config) LoadConfig() (err error) {

Callers 2

TestLoadConfigFunction · 0.85
LoadConfigMethod · 0.85

Calls 2

UnmarshalMethod · 0.80
CloseMethod · 0.45

Tested by 1

TestLoadConfigFunction · 0.68