Skip to content

Instantly share code, notes, and snippets.

@kkdai
Created December 10, 2019 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkdai/58e776a1387d3db2c032492269601d58 to your computer and use it in GitHub Desktop.
Save kkdai/58e776a1387d3db2c032492269601d58 to your computer and use it in GitHub Desktop.
func parseVideoInfo(videoInfo string) error {
answer, err := url.ParseQuery(videoInfo)
if err != nil {
return err
}
status, ok := answer["status"]
if !ok {
err = fmt.Errorf("no response status found in the server's answer")
return err
}
if status[0] == "fail" {
reason, ok := answer["reason"]
if ok {
err = fmt.Errorf("'fail' response status found in the server's answer, reason: '%s'", reason[0])
} else {
err = errors.New(fmt.Sprint("'fail' response status found in the server's answer, no reason given"))
}
return err
}
if status[0] != "ok" {
err = fmt.Errorf("non-success response status found in the server's answer (status: '%s')", status)
return err
}
///.... Continue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment