Created
January 10, 2020 02:31
-
-
Save soeirosantos/52b922992ebbdb8f19664e9dc903b56f to your computer and use it in GitHub Desktop.
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
{ | |
"db_url": "127.0.0.1", | |
"db_port": 8080, | |
"db_username": "foo", | |
"db_password": "bar" | |
} |
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 main | |
import ( | |
"bufio" | |
"encoding/json" | |
"os" | |
) | |
type dbConfig struct { | |
Url string `json:"db_url"` | |
Port int `json:"db_port"` | |
Username string `json:"db_username"` | |
Password string `json:"db_password"` | |
} | |
func main() { | |
f, err := os.Open("./config.json") | |
if err != nil { | |
panic(err) | |
} | |
r := bufio.NewReader(f) | |
decoder := json.NewDecoder(r) | |
c := dbConfig{} | |
err = decoder.Decode(&c) | |
println(c.Url) | |
println(c.Port) | |
println(c.Username) | |
println(c.Password) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment