darenliang/jikan-go

jikan.Search literal.Get undefined

Closed this issue · 4 comments

Error

jikan.Search literal.Get undefined (type jikan.Search has no field or method Get)

What I did

I copy-pasted the Nested Data with Type Assertions Example
and ran go run main.go

Thanks for letting me know!

I've changed the way jikan-go works a few days ago, can you confirm that you have the latest version? I should have indicated somewhere that big changes were made.

The old version had separate function names with structs as a parameter, while the new version uses function Get() on a receiver.

Old version:

anime, _ := jikan.GetAnime(jikan.Anime{ID: 1})

New version:

anime, _ := jikan.Anime{ID: 1}.Get()

from go mod vendor:

github.com/darenliang/jikan-go v0.0.0-20191111221916-d0d13e1ff382

Commit d0d13e1 is indeed the latest version.

From the error I can only deduce that the Get() method is not defined.

When checking out commit 40fc402 (last commit on old version) I've tried running the new example and got this error: ./main.go:9:71: jikan.Search literal.Get undefined (type jikan.Search has no field or method Get) which is identical.

If the following code runs without error (old example that shouldn't work on the new version), there is a chance that your version isn't up to date.

package main

import (
	"fmt"
	"github.com/darenliang/jikan-go"
)

func main() {
	search, _ := jikan.GetSearch(jikan.Search{Type: "anime", Q: "FMAB", OrderBy: "score"})

	// Get first anime from results
	firstAnime := search["results"].([]interface{})[0].(map[string]interface{})

	// Make type assertions
	fmt.Println("Title: " + firstAnime["title"].(string))
	fmt.Printf("Members: %v thousand\n", firstAnime["members"].(float64)/1000)
}

I think in the event I ran go mod today I may have updated to the correct version, and everything is working as expected.