I would like to load json configuration file to go lang app. Configuration data is array since it needs to be dynamically set.
[ { "key": "A", "data": [1, 2, 3]}, { "key": "B", "data": [1, 2]}, { "key": "C", "data": [1, 3]} ]
And tried to load like this.
package main
import (
"flag"
"fmt"
"os"
"encoding/json"
)
type ColInfo struct {
key string `json:"key"`
col []int `json:"data"`
}
type Config struct {
colInfos []ColInfo
}
func main() {
flag.Parse()
file, _ := os.Open("col.conf")
decoder := json.Marshal(file)
configuration := Config{}
if err := decoder.Decode(&configuration); err != nil {
fmt.Println(err)
}
println( configuration.colInfos[0].key)
}
Here is error I've got
./test2.go:23: multiple-value json.Marshal() in single-value context
What am i wrong with this?