本文整理汇总了Golang中github.com/jmcvetta/napping.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
args := os.Args
if len(args) != 3 {
fmt.Println("Give me a URL, and a name and off we go.")
return
}
url := args[1]
fmt.Println(url)
name := args[2]
var result map[string]interface{}
var w writeAndPrint
response, err := napping.Get(url, nil, &result, nil)
if err != nil {
fmt.Println(err)
return
}
if response.Status() != 200 {
fmt.Printf("Could not download JSON. Sorry. \n The Server responded with: \n %v \n And HTTP status code: %v", response.RawText(), response.Status())
}
err = generator.WriteGo(result, name, w)
if err != nil {
fmt.Print(err)
}
}
示例2: GetImageDetails
func (api *DockerApi) GetImageDetails(fqImageName string) (*ApiDockerImage, error) {
url := strings.Join(
[]string{
api.configFile.DockerEndpoint,
"images",
fqImageName,
"json",
},
"/",
)
// For testing, also need to `import "encoding/json"`
// result := map[string]json.RawMessage{}
result := ApiDockerImage{}
Logger.Trace("GetImageDetails Api call to:", url)
if resp, err := napping.Get(url, nil, &result, nil); err != nil {
Logger.Error("Error while getting Image information from docker,", err)
return nil, err
} else {
switch resp.Status() {
case 200:
Logger.Trace(result)
return &result, nil
case 404:
Logger.Debug("Image not found")
return nil, nil
}
return nil, nil
}
}
示例3: Find
func Find(externalId string, externalSource string) *FindResult {
var result *FindResult
cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath, "cache"))
key := fmt.Sprintf("com.tmdb.find.%s.%s", externalSource, externalId)
if err := cacheStore.Get(key, &result); err != nil {
rateLimiter.Call(func() {
urlValues := napping.Params{
"api_key": apiKey,
"external_source": externalSource,
}.AsUrlValues()
resp, err := napping.Get(
tmdbEndpoint+"find/"+externalId,
&urlValues,
&result,
nil,
)
if err != nil {
log.Error(err.Error())
xbmc.Notify("Quasar", "Failed Find call, check your logs.", config.AddonIcon())
} else if resp.Status() != 200 {
message := fmt.Sprintf("Find call bad status: %d", resp.Status())
log.Error(message)
xbmc.Notify("Quasar", message, config.AddonIcon())
}
cacheStore.Set(key, result, 365*24*time.Hour)
})
}
return result
}
示例4: ListEntities
func ListEntities(endpoint string, params napping.Params) []*Entity {
var wg sync.WaitGroup
entities := make([]*Entity, popularMoviesMaxPages*moviesPerPage)
params["api_key"] = apiKey
params["language"] = "en"
wg.Add(popularMoviesMaxPages)
for i := 0; i < popularMoviesMaxPages; i++ {
go func(page int) {
defer wg.Done()
var tmp *EntityList
tmpParams := napping.Params{
"page": strconv.Itoa(popularMoviesStartPage + page),
}
for k, v := range params {
tmpParams[k] = v
}
p := tmpParams.AsUrlValues()
rateLimiter.Call(func() {
napping.Get(
tmdbEndpoint+endpoint,
&p,
&tmp,
nil,
)
})
for i, entity := range tmp.Results {
entities[page*moviesPerPage+i] = entity
}
}(i)
}
wg.Wait()
return entities
}
示例5: ListMoviesComplete
func ListMoviesComplete(endpoint string, params napping.Params) Movies {
movies := make(Movies, popularMoviesMaxPages*moviesPerPage)
params["api_key"] = apiKey
wg := sync.WaitGroup{}
for i := 0; i < popularMoviesMaxPages; i++ {
wg.Add(1)
go func(page int) {
defer wg.Done()
var tmp *EntityList
tmpParams := napping.Params{
"page": strconv.Itoa(popularMoviesStartPage + page),
}
for k, v := range params {
tmpParams[k] = v
}
rateLimiter.Call(func() {
napping.Get(
tmdbEndpoint+endpoint,
&tmpParams,
&tmp,
nil,
)
})
for i, movie := range tmp.Results {
movies[page*moviesPerPage+i] = GetMovie(movie.Id, params["language"])
}
}(i)
}
wg.Wait()
return movies
}
示例6: ListShows
func ListShows(endpoint string, params napping.Params, page int) (shows Shows) {
var results *EntityList
params["page"] = strconv.Itoa(startPage + page)
params["api_key"] = apiKey
p := params.AsUrlValues()
rateLimiter.Call(func() {
resp, err := napping.Get(
tmdbEndpoint + endpoint,
&p,
&results,
nil,
)
if err != nil {
log.Error(err.Error())
xbmc.Notify("Quasar", "ListShows failed, check your logs.", config.AddonIcon())
} else if resp.Status() != 200 {
message := fmt.Sprintf("ListShows bad status: %d", resp.Status())
log.Error(message)
xbmc.Notify("Quasar", message, config.AddonIcon())
}
})
if results != nil {
for _, show := range results.Results {
shows = append(shows, GetShow(show.Id, params["language"]))
}
}
return shows
}
示例7: getMovieById
func getMovieById(movieId string, language string) *Movie {
var movie *Movie
cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath, "cache"))
key := fmt.Sprintf("com.tmdb.movie.%s.%s", movieId, language)
if err := cacheStore.Get(key, &movie); err != nil {
rateLimiter.Call(func() {
urlValues := napping.Params{
"api_key": apiKey,
"append_to_response": "credits,images,alternative_titles,translations,external_ids,trailers",
"language": language,
}.AsUrlValues()
napping.Get(
tmdbEndpoint+"movie/"+movieId,
&urlValues,
&movie,
nil,
)
if movie != nil {
cacheStore.Set(key, movie, cacheTime)
}
})
}
if movie == nil {
return nil
}
switch t := movie.RawPopularity.(type) {
case string:
popularity, _ := strconv.ParseFloat(t, 64)
movie.Popularity = popularity
case float64:
movie.Popularity = t
}
return movie
}
示例8: GetSeason
func GetSeason(showId int, seasonNumber int, language string) *Season {
var season *Season
cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath, "cache"))
key := fmt.Sprintf("com.tmdb.season.%d.%d.%s", showId, seasonNumber, language)
if err := cacheStore.Get(key, &season); err != nil {
rateLimiter.Call(func() {
urlValues := napping.Params{
"api_key": apiKey,
"append_to_response": "credits,images,videos,external_ids",
"language": language,
}.AsUrlValues()
resp, err := napping.Get(
fmt.Sprintf("%stv/%d/season/%d", tmdbEndpoint, showId, seasonNumber),
&urlValues,
&season,
nil,
)
if err != nil {
panic(err)
}
if resp.Status() != 200 {
panic(errors.New(fmt.Sprintf("Bad status: %d", resp.Status())))
}
})
season.EpisodeCount = len(season.Episodes)
if season != nil {
cacheStore.Set(key, season, cacheTime)
}
}
if season == nil {
return nil
}
return season
}
示例9: GetList
func GetList(listId string, language string, page int) Movies {
var results *List
listResultsPerPage := config.Get().ResultsPerPage
rateLimiter.Call(func() {
urlValues := napping.Params{
"api_key": apiKey,
}.AsUrlValues()
resp, err := napping.Get(
tmdbEndpoint+"list/"+listId,
&urlValues,
&results,
nil,
)
if err != nil {
log.Error(err.Error())
xbmc.Notify("Quasar", "GetList failed, check your logs.", config.AddonIcon())
} else if resp.Status() != 200 {
message := fmt.Sprintf("GetList bad status: %d", resp.Status())
log.Error(message)
xbmc.Notify("Quasar", message, config.AddonIcon())
}
})
tmdbIds := make([]int, 0, listResultsPerPage)
for i, movie := range results.Items {
if i < page*listResultsPerPage {
continue
}
tmdbIds = append(tmdbIds, movie.Id)
if i >= (startPage+page)*listResultsPerPage-1 {
break
}
}
return GetMovies(tmdbIds, language)
}
示例10: Find
func Find(externalId string, externalSource string) *FindResult {
var result *FindResult
cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath, "cache"))
key := fmt.Sprintf("com.tmdb.find.%s.%s", externalSource, externalId)
if err := cacheStore.Get(key, &result); err != nil {
rateLimiter.Call(func() {
urlValues := napping.Params{
"api_key": apiKey,
"external_source": externalSource,
}.AsUrlValues()
resp, err := napping.Get(
tmdbEndpoint+"find/"+externalId,
&urlValues,
&result,
nil,
)
if err != nil {
panic(err)
}
if resp.Status() != 200 {
panic(errors.New(fmt.Sprintf("Bad status: %d", resp.Status())))
}
cacheStore.Set(key, result, 365*24*time.Hour)
})
}
return result
}
示例11: GetList
func GetList(listId string, language string) Movies {
var results *List
rateLimiter.Call(func() {
urlValues := napping.Params{
"api_key": apiKey,
}.AsUrlValues()
resp, err := napping.Get(
tmdbEndpoint+"list/"+listId,
&urlValues,
&results,
nil,
)
if err != nil {
panic(err)
}
if resp.Status() != 200 {
panic(errors.New(fmt.Sprintf("Bad status: %d", resp.Status())))
}
})
tmdbIds := make([]int, 0, len(results.Items))
for _, movie := range results.Items {
tmdbIds = append(tmdbIds, movie.Id)
}
return GetMovies(tmdbIds, language)
}
示例12: SearchShows
func SearchShows(query string, language string) Shows {
var results EntityList
rateLimiter.Call(func() {
urlValues := napping.Params{
"api_key": apiKey,
"query": query,
}.AsUrlValues()
resp, err := napping.Get(
tmdbEndpoint+"search/tv",
&urlValues,
&results,
nil,
)
if err != nil {
panic(err)
}
if resp.Status() != 200 {
panic(errors.New(fmt.Sprintf("Bad status: %d", resp.Status())))
}
})
tmdbIds := make([]int, 0, len(results.Results))
for _, entity := range results.Results {
tmdbIds = append(tmdbIds, entity.Id)
}
return GetShows(tmdbIds, language)
}
示例13: SearchShows
func SearchShows(query string, language string, page int) Shows {
var results EntityList
rateLimiter.Call(func() {
urlValues := napping.Params{
"api_key": apiKey,
"query": query,
"page": strconv.Itoa(startPage + page),
}.AsUrlValues()
resp, err := napping.Get(
tmdbEndpoint+"search/tv",
&urlValues,
&results,
nil,
)
if err != nil {
log.Error(err.Error())
xbmc.Notify("Quasar", "SearchShows failed, check your logs.", config.AddonIcon())
} else if resp.Status() != 200 {
message := fmt.Sprintf("SearchShows bad status: %d", resp.Status())
log.Error(message)
xbmc.Notify("Quasar", message, config.AddonIcon())
}
})
tmdbIds := make([]int, 0, len(results.Results))
for _, entity := range results.Results {
tmdbIds = append(tmdbIds, entity.Id)
}
return GetShows(tmdbIds, language)
}
示例14: GetShow
func GetShow(showId int, language string) *Show {
var show *Show
cacheStore := cache.NewFileStore(path.Join(config.Get().ProfilePath, "cache"))
key := fmt.Sprintf("com.tmdb.show.%d.%s", showId, language)
if err := cacheStore.Get(key, &show); err != nil {
rateLimiter.Call(func() {
napping.Get(
tmdbEndpoint+"tv/"+strconv.Itoa(showId),
&napping.Params{"api_key": apiKey, "append_to_response": "credits,images,alternative_titles,translations,external_ids", "language": language},
&show,
nil,
)
})
if show != nil {
cacheStore.Set(key, show, cacheTime)
}
}
if show == nil {
return nil
}
switch t := show.RawPopularity.(type) {
case string:
if popularity, err := strconv.ParseFloat(t, 64); err == nil {
show.Popularity = popularity
}
case float64:
show.Popularity = t
}
return show
}
示例15: TrendingShows
func TrendingShows() ShowList {
var shows ShowList
napping.Get(fmt.Sprintf("%s/shows/trending.json/%s", ENDPOINT, APIKEY), nil, &shows, nil)
for _, show := range shows {
sanitizeIds(show)
}
return shows
}