Created
July 26, 2016 10:52
-
-
Save petruisfan/610a639cab2bec3988c711e0a5d268a8 to your computer and use it in GitHub Desktop.
Config json file reader for go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package config | |
import ( | |
"encoding/json" | |
"fmt" | |
"os" | |
) | |
type Configuration struct { | |
MongoHostname string | |
MongoUsername string | |
MongoPassword string | |
MongoDatabase string | |
MongoAuthDatabase string | |
MongoFilesCollection string | |
MongoHashesCollection string | |
} | |
func Read() Configuration { | |
file, err := os.Open("/etc/config.json") | |
if err != nil { | |
panic("Config file not found!") | |
} | |
decoder := json.NewDecoder(file) | |
configuration := Configuration{} | |
err = decoder.Decode(&configuration) | |
if err != nil { | |
fmt.Println("error:", err) | |
} | |
return configuration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment