Golang newbie here
I'm trying to parse from a .json file (in the same directory as the Go code) into a struct holding other structs and the closest I can get to success is a struct containing boolean false, which sounds broken to me.
Here's what I have in my Go code so far
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
)
type App struct {
Name string `json:"app:name"`
}
type Database struct {
Type string `json:"database:type"`
Name string `json:"database:name"`
User string `json:"database:user"`
Password string `json:"database:password"`
}
type Environment struct {
Mode string `json:"environment:mode"`
Debug bool `json:"environment:debug"`
}
type Config struct {
Environment Environment
App App
Database Database
}
func main() {
config, err := ioutil.ReadFile("config.json")
if err != nil {
fmt.Errorf("Error reading config file: %s", err)
}
var appSettings Config
json.Unmarshal(config, &appSettings)
fmt.Print(appSettings)
}
and here's the contents of my .json file
{
"App": {
"Name": "My_Project"
},
"Database": {
"Type": "postgres",
"Name": "my_project_db_name",
"User": "my_project_db_user",
"Password": "secret"
},
"Environment": {
"Mode": "development",
"Debug": true
}
}
EDIT:
Here's the result of the print at the end of main()
{{ false} {} { }}
I have already validated the json content which is fine. The struct names and properties are being exported. Can you see what I'm doing wrong?
"environment:mode"do? why the "environment:"? Just drop all your tags, read the documentation and the examples once more.