I have the following function declararion, which works and prints out correctly.
import (
"fmt"
"github.com/google/go-github/github"
)
func LatestTag(user, project string) {
client := github.NewClient(nil)
releases, _, err := client.Repositories.ListTags(user, project, nil)
if err != nil {
fmt.Printf("error: %v
", err)
} else {
release := releases[0]
fmt.Printf("Version: %+v
", *release.Name)
}
}
EDIT
I have modified the function to return a string (I don't think this is right) but hopefully it can help shed some light on what I am trying to do.
import (
"fmt"
"github.com/google/go-github/github"
)
func LatestTag(user, project string) string {
client := github.NewClient(nil)
releases, _, err := client.Repositories.ListTags(user, project, nil)
var release string
if err != nil {
fmt.Printf("error: %v
", err)
} else {
release := releases[0]
}
return *release.Name
}
I would like to return the value of *release.Name
rather than just print it out so that I can access the value from another function but I don't understand how returning works in this case (very new to Go).
I was thinking I could just return the struct as a string but get errors when I run it.
release.Name undefined (type string has no field or method Name)
Which makes me think that I'm not approaching this correctly. Can somebody point me in the right direction?