Closed loretoparisi closed 7 years ago
@loretoparisi thanks for reporting the issue.
cc @guohuang
Welcome!
I also suggest to add this example, that for go
beginners like me, took half a day to complete it!
/*
* Musixmatch Go Client
* @uses Swagger generated Go client
* @author Loreto Parisi (loreto at musixmatch dot com)
* @see https://developer.musixmatch.com/documentation
* @copy 2016 Musixmatch Spa
*/
package main
import (
"fmt"
"bytes"
"encoding/json"
"./swagger"
"io"
"io/ioutil"
"os"
)
func jsonPrettyPrint(in string) string {
var out bytes.Buffer
err := json.Indent(&out, []byte(in), "", "\t")
if err != nil {
return in
}
return out.String()
}
func main() {
albumApi := swagger.NewAlbumApi()
configuration := albumApi.Configuration
configuration.SetDebug(true)
configuration.APIKey["apikey"] = "YOUR_API_KEY"
var albumId = "14250417"
jsonResponse, response, _ := albumApi.AlbumGetGet(albumId,"json","")
defer response.Body.Close()
// stay away of ioutil.ReadAll memory leaks
htmlData, err := ioutil.ReadAll(io.LimitReader(response.Body, 2048))
// unmarshall struct to json
b, err := json.Marshal(jsonResponse.Message)
if err != nil {
fmt.Println(err)
return
}
var c = jsonPrettyPrint( string(b) )
fmt.Println(c)
}
@loretoparisi I tried using Go version 1.7.1 on windows, I couldn't reproduce the compilation issue that you have, the function GetAPIKeyWithPrefix
is only returning string, not []string, so i don't know what the issue is.
Closing this as there's no further update.
When generating the
go-client-generated.zip
from editor.swagger.io I get several error in the generated code likeswagger/album_api.go:139: cannot use a.Configuration.GetAPIKeyWithPrefix("apikey") (type string) as type []string in assignment
due to a bad assign to
[]string
literal of astring
. I'm pretty new togo
, so I'm not sure if this is due to a recent go compiler (See later).Description
Swagger-codegen version
I'm using
and latest swagger codegen from editor.swagger.io.
Swagger declaration file content or url
The file is available online at https://playground.musixmatch.com/swagger.json.
Command line used for generation
Steps to reproduce
Related issues
Suggest a Fix
The fix is to replace this assignment
with
I have achieved this from this example of usage of
url.Values{}
.