Adding the Config loader library
This commit is contained in:
commit
e24ee32685
23
main.go
Normal file
23
main.go
Normal file
@ -0,0 +1,23 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Requires a struct to be passed via address eg. Load(&interfaceName), and the name/location of the config file.
|
||||
func Load(s interface{}, configFile string) {
|
||||
filePtr, err := os.Open(configFile)
|
||||
defer filePtr.Close()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
decoder := json.NewDecoder(filePtr)
|
||||
err = decoder.Decode(&s)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user