Skip to content

Instantly share code, notes, and snippets.

@petruisfan
Created July 26, 2016 10:52
Show Gist options
  • Save petruisfan/610a639cab2bec3988c711e0a5d268a8 to your computer and use it in GitHub Desktop.
Save petruisfan/610a639cab2bec3988c711e0a5d268a8 to your computer and use it in GitHub Desktop.
Config json file reader for go
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