This question already has an answer here:
- How to get JSON response from http.Get 4 answers
I am a beginner to Golang. Can you help me with call of function. Here is an example:
package main
import (
"fmt"
"net/http"
)
type Info struct {
Name string `json:"name"`
Year float64 `json:"year,string"`
}
func (b *Base) GetInfo() (Info, error) {
var resp Info
path := "example.com"
return resp, http.Get(path)
}
func main() {
test, err := Base.GetInfo()
fmt.Println(test, err)
}
Output:
{Name Bob Year 10}
How I can get only "Bob"
?
And If my response contains more objects example
{Name Bob Year 10}{Name Jane Year 2}.
How I can get only names? Didnt understand how to decode it or call.
</div>