Created
May 20, 2016 08:39
-
-
Save johnsonz/ba3f67390cd5a5cbf190717476d2816c to your computer and use it in GitHub Desktop.
go解析JSON文件到struct类型
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func ParseConfig() { | |
currentDir, err := filepath.Abs(filepath.Dir(os.Args[0])) | |
if err != nil { | |
glog.Fatalf("get current directory err: %v", err) | |
} | |
jsontext, err := ioutil.ReadFile(currentDir + "\\" + configName) | |
if err != nil { | |
glog.Fatalf("read config.json file err: %v", err) | |
} | |
err = json.Unmarshal(jsontext, &config) | |
if err != nil { | |
glog.Fatalf("paser config.json err: %v", err) | |
} | |
glog.Infoln("parse config.json sucessfully") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment