本文整理匯總了Golang中github.com/antonholmquist/jason.Object.GetInt64方法的典型用法代碼示例。如果您正苦於以下問題:Golang Object.GetInt64方法的具體用法?Golang Object.GetInt64怎麽用?Golang Object.GetInt64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/antonholmquist/jason.Object
的用法示例。
在下文中一共展示了Object.GetInt64方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getTrack
func (sc *SoundCloud) getTrack(obj *jason.Object, offset time.Duration, submitter *gumble.User) (bot.Track, error) {
title, _ := obj.GetString("title")
idInt, _ := obj.GetInt64("id")
id := strconv.FormatInt(idInt, 10)
url, _ := obj.GetString("permalink_url")
author, _ := obj.GetString("user", "username")
authorURL, _ := obj.GetString("user", "permalink_url")
durationMS, _ := obj.GetInt64("duration")
duration, _ := time.ParseDuration(fmt.Sprintf("%dms", durationMS))
thumbnail, err := obj.GetString("artwork_url")
if err != nil {
// Track has no artwork, using profile avatar instead.
thumbnail, _ = obj.GetString("user", "avatar_url")
}
return bot.Track{
ID: id,
URL: url,
Title: title,
Author: author,
AuthorURL: authorURL,
Submitter: submitter.Name,
Service: sc.ReadableName,
Filename: id + ".track",
ThumbnailURL: thumbnail,
Duration: duration,
PlaybackOffset: offset,
Playlist: nil,
}, nil
}
示例3: GetTracks
// GetTracks uses the passed URL to find and return
// tracks associated with the URL. An error is returned
// if any error occurs during the API call.
func (mc *Mixcloud) GetTracks(url string, submitter *gumble.User) ([]interfaces.Track, error) {
var (
apiURL string
err error
resp *http.Response
v *jason.Object
tracks []interfaces.Track
)
apiURL = strings.Replace(url, "www", "api", 1)
// Track playback offset is not present in Mixcloud URLs,
// so we can safely assume that users will not request
// a playback offset in the URL.
offset, _ := time.ParseDuration("0s")
resp, err = http.Get(apiURL)
defer resp.Body.Close()
if err != nil {
return nil, err
}
v, err = jason.NewObjectFromReader(resp.Body)
if err != nil {
return nil, err
}
id, _ := v.GetString("slug")
trackURL, _ := v.GetString("url")
title, _ := v.GetString("name")
author, _ := v.GetString("user", "username")
authorURL, _ := v.GetString("user", "url")
durationSecs, _ := v.GetInt64("audio_length")
duration, _ := time.ParseDuration(fmt.Sprintf("%ds", durationSecs))
thumbnail, err := v.GetString("pictures", "large")
if err != nil {
// Track has no artwork, using profile avatar instead.
thumbnail, _ = v.GetString("user", "pictures", "large")
}
track := bot.Track{
ID: id,
URL: trackURL,
Title: title,
Author: author,
AuthorURL: authorURL,
Submitter: submitter.Name,
Service: mc.ReadableName,
ThumbnailURL: thumbnail,
Filename: id + ".track",
Duration: duration,
PlaybackOffset: offset,
Playlist: nil,
}
tracks = append(tracks, track)
return tracks, nil
}