Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/json"
- "fmt"
- "io/ioutil"
- "log"
- )
- type ObjectType struct {
- Database DatabasesType
- }
- type DatabasesType struct {
- Type string
- Host string
- Username string
- Password string
- }
- func main() {
- file, e := ioutil.ReadFile("./configuration.json")
- if e != nil {
- panic(e)
- }
- fmt.Printf("%s\n", string(file))
- var dbType ObjectType
- err := json.Unmarshal(file, &dbType)
- if err != nil {
- log.Println(err)
- }
- fmt.Printf("type : %s\n", dbType.Database.Type)
- fmt.Printf("host : %s\n", dbType.Database.Host)
- fmt.Printf("username : %s\n", dbType.Database.Username)
- fmt.Printf("password : %s\n", dbType.Database.Password)
- }
Add Comment
Please, Sign In to add comment