Answer the question
In order to leave comments, you need to log in
How to compose a type struct for this json?
Hello. There is json
{
"MailConfig" : {
"username": "*****@gmail.com",
"password": "*****",
"host": "smtp.gmail.com",
"port": "587",
},
"MailTo" : [
"*****@gmail.com",
"*****@yandex.ru",
],
"Types" : [
"Debug",
"Info",
"Warn",
"Error",
"Fatal",
],
"EmailSend" : {
"Debug": false,
"Info": false,
"Warn": false,
"Error": false,
"Fatal": true,
},
"RedisConfig" : {
"Addr": "localhost:6379",
"Password": "*****",
},
"MysqlConfig" : {
"user" : "root",
"pass" : "*****",
"DB" : "log"
}
}
package main
import (
"encoding/json"
"io/ioutil"
"log"
)
func main() {
bs, err := ioutil.ReadFile("log.json")
if err != nil {
log.Panicln(err)
}
b := []byte(bs)
type Message struct {
MailConfig, RedisConfig, MysqlConfig map[string]string
MailTo []string
Types []string
EmailSend map[string]bool
}
var m Message
err = json.Unmarshal(b, &m)
if err != nil {
log.Panicln(err)
}
log.Println(m)
}
2015/11/05 00:18:33 invalid character '}' looking for beginning of object key string
panic: invalid character '}' looking for beginning of object key string
goroutine 1 [running]:
log.Panicln(0x1843ff40, 0x1, 0x1)
/usr/lib/go/src/log/log.go:334 +0xa5
main.main()
/home/v-smerti/localhost/api/src/microService/config/main.go:28 +0x1d1
exit status 2
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question