I have written a very simple Go app using the Martini library. When putting together a simple REST API example I wanted to render JSON data back to the user when an error occurred like:
{
error: "Document Not Found",
code: 404
}
I'm using the following code to return a map that Martini can render into JSON. package ErrorResponces
import "net/http"
type ErrJson interface {
RenderErr(v int)
}
func RenderErr(v int) map [string]interface{} {
var returnMap = map[string]interface{} {
"error": http.StatusText(v),
"code": v,
}
return returnMap
}
Later in my controller code I try and test this method using
fmt.Println(ErrJson.RenderErr(400))
However I get the following error:
controllers\FoodController.go:25: cannot use 400 (type int) as type ErrorResponces.ErrJson in function argument: int does not implement ErrorResponces.ErrJson (missing RenderErr method)
controllers\FoodController.go:25: not enough arguments in call to ErrorResponces.ErrJson.RenderErr controllers\FoodController.go:25: ErrorResponces.ErrJson.RenderErr(400) used as value
I'm having a hard time figuring out exactly what this error is talking about.