This question already has an answer here:
I have the following code snippent:
type ErrorCode string
const (
INVALID_REQUEST ErrorCode = "INVALID_REQUEST"
)
type Response struct {
ErrorCode string `json:"errorCode"`
}
func BuildResponseError(errorCode ErrorCode) string {
user := &Response{ErrorCode: string(errorCode)}
response, err := json.Marshal(user)
if err != nil {
log.Println(err)
return `{"errorCode":"bad_request"}`
}
return string(response)
}
I can call function BuildResponseError like that:
BuildResponseError("wrong_request")
Is there a way to disable this implicit type conversion? I want to call this function only like this, using a enum value:
BuildResponseError(INVALID_REQUEST)
</div>