// DecodeMap decodes a JSON document into a Go native object func DecodeMap(docMap map[string]interface{}, obj interface{}) error { if err := mapstructure.DecodePath(docMap, obj); err != nil { tracelog.ERROR(err, "utils", "Decode, Decoding Mapped Doc") return err } if tracelog.LogLevel() == tracelog.LEVEL_TRACE { helper.LogModel(obj, true) } return nil }
// ReadConfig used to read json to config func ReadConfig(file string) (*Setting, error) { configFile, err := os.Open(file) config, err := ioutil.ReadAll(configFile) if err != nil { return nil, err } configFile.Close() docMap := make(map[string]interface{}) if err := json.Unmarshal(config, &docMap); err != nil { return nil, err } setting := &Setting{} err = mapstructure.DecodePath(docMap, setting) return setting, err }