Martini 라이브러리를 사용하여 매우 간단한 Go 앱을 작성했습니다. 나는 마티니 JSON으로 렌더링 할 수있는지도를 반환하려면 다음 코드를 사용하고Go 인터페이스 메소드 사용
{
error: "Document Not Found",
code: 404
}
: 간단한 REST API를 예제를 함께 넣어 때 나는 오류가 같이 발생했을 때 사용자에게 다시 JSON 데이터를 렌더링하고 싶었다. 패키지 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
}
나는 시도하고
fmt.Println(ErrJson.RenderErr(400))
그러나 나는 다음과 같은 오류 얻을 사용하여이 방법을 테스트 :
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
내가 힘든 시간을 보내고 있습니다을 이 오류가 무엇을 말하는지 정확히 알아 냈습니다.
아! 나는 지금 본다. 자원을 가져 주셔서 감사합니다. –