以下代码有错误:
错误:
controllers/controllers.go:80:53: 不能在 services.GetCharactersID 的参数中使用 c.Param(id) (type string) 作为 int 类型 controllers/controllers.go:80:54: undefined: id)
func GetCharactersID (c *gin.Context) {
characters, err := services.GetCharactersID(c.Param("id"))
if err!=nil {
response:= domain.Response{Mensaje:err.Error()}
c.JSON(http.StatusInternalServerError,response)
return
}
c.JSON (http.StatusOK,characters)
}
//Services
func GetCharactersID (id int) (domain.Characters,error) {
var err error
characterss,err := GetCharactersID(id)
s := strconv.Itoa(id)
ts := "my_hashjavi"
hash := GetHashString(ts+private_key+public_key)
var url string = "https://gateway.marvel.com:443/v1/public"
url += "/characters" + "/"
url+= s + "?"
url += "ts="+ts
url += "&apikey="+ public_key
url += "&hash="+ hash
resp,err1 := http.Get(url)
Data, err2 := ioutil.ReadAll(resp.Body)
if err1 != nil || err2 != nil {
err= errors.New("Error al obtener los personajes")
return characterss,err
}
json.Unmarshal(Data,&characterss)
return characterss , nil
}