go-bitbucket icon indicating copy to clipboard operation
go-bitbucket copied to clipboard

Question about repositories.ListForAccount()

Open uggla opened this issue 6 years ago • 3 comments

Hello @ktrysmt ,

A question about repositories.ListForAccount() method. Is it normal that this method is returning an interface{} ? Note : I would expect to have a []string with repo names.

Maybe it is because this method is not finalized ? Any other reasons ?

In order to get the list of repo names, I did the following ugly code (just for testing). But maybe there is another smart way or magic method to get this ?

	res2, err2 := c.Repositories.ListForTeam(opt2)
	if err2 != nil {
		panic(err2)
	}

	repos := show_repo(res2)
	fmt.Printf("%#v\n", repos) // Just to debug content
func show_repo(data interface{}) []string {
	var output []string // New slice

	repos := data.(map[string]interface{})["values"].([]interface{})

	// Loop on slice
	for i := 0; i < len(repos); i++ {
		output = append(output, repos[i].(map[string]interface{})["name"].(string))
	}
	return output
}

uggla avatar Aug 09 '18 12:08 uggla

@uggla Perhaps this might be useful.

  • https://godoc.org/github.com/jeremywohl/flatten

ktrysmt avatar Aug 10 '18 05:08 ktrysmt

@ktrysmt thx. In fact the underlying question is will you accept PR that will change the behavior of these methods ? If yes we (@Xx-Parks-xX and I) will open a couple of PRs.

uggla avatar Aug 10 '18 08:08 uggla

@uggla Basically PR is welcomed. If there are any points to worry about, we can discuss it at that time.

ktrysmt avatar Aug 10 '18 12:08 ktrysmt