本文整理匯總了Golang中github.com/antonholmquist/jason.Object.GetObject方法的典型用法代碼示例。如果您正苦於以下問題:Golang Object.GetObject方法的具體用法?Golang Object.GetObject怎麽用?Golang Object.GetObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/antonholmquist/jason.Object
的用法示例。
在下文中一共展示了Object.GetObject方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CheckAPIKey
// CheckAPIKey performs a test API call with the API key
// provided in the configuration file to determine if the
// service should be enabled.
func (yt *YouTube) CheckAPIKey() error {
var (
response *http.Response
v *jason.Object
err error
)
if viper.GetString("api_keys.youtube") == "" {
return errors.New("No YouTube API key has been provided")
}
url := "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=KQY9zrjPBjo&key=%s"
response, err = http.Get(fmt.Sprintf(url, viper.GetString("api_keys.youtube")))
defer response.Body.Close()
if err != nil {
return err
}
if v, err = jason.NewObjectFromReader(response.Body); err != nil {
return err
}
if v, err = v.GetObject("error"); err == nil {
message, _ := v.GetString("message")
code, _ := v.GetInt64("code")
errArray, _ := v.GetObjectArray("errors")
reason, _ := errArray[0].GetString("reason")
return fmt.Errorf("%d: %s (reason: %s)", code, message, reason)
}
return nil
}
示例2: GetJsonPage
// Return page data from JSON, or nil if page is "-1", i.e., not found.
// Assumes only a single page was requested.
func GetJsonPage(json *jason.Object) *jason.Object {
pages, err := json.GetObject("query", "pages")
if err != nil {
panic(err)
}
for key, value := range pages.Map() {
if key == "-1" {
return nil
} else {
valueObj, err := value.Object()
if err != nil {
panic(err)
}
return valueObj
}
}
panic("getJsonPage fallthrough")
}