Original post

So I’m trying to get data from an http url and I made a Song struct with some json fields, so basically I enter a search term and it’s supposed to give me back the artist and the name of the song, the problem is there is a dash between the artist and song that I just don’t know how to remove. Can anyone help?

package main import ( “encoding/json” “fmt” “io/ioutil” “log” “net/http” “os” )

func main() {

var input string fmt.Print(“Please select a search term: “) fmt.Scanf(“%s”, &input)

var data Song response, err := http.Get(“https://searchly.asuarez.dev/api/v1/song/search?query=” + input) if err != nil { fmt.Print(err.Error()) os.Exit(1) } defer response.Body.Close() if response.StatusCode != 200 { log.Fatal(“Didn’t get 200”) }

responseData, err := ioutil.ReadAll(response.Body) if err != nil { log.Fatal(err) }

json.Unmarshal(responseData, &data) fmt.Println(string(responseData))

//str = strings.Replace(data.Response.Results, “-“,” “, -1) fmt.Println(data.Response.Results[0])

}

type Song struct { Error bool json:"error" Response struct { Results []struct { Name string json:"name" } json:"results" } json:"response" }

submitted by /u/asabeh11
[link] [comments]