Skip to content

sardine-ai/errmsg

Repository files navigation

errmsg

CircleCI codecov

This library wraps errors from golang's json package and famous go-playground/validator library. The idea is to provide error message that is more friendly for consumer of your json APIs.

For instance, instead of json: cannot unmarshal string into Go struct field birthday.birthday.month of type int8 (error message from json pkg) this library says 'birthday.month' should be integer but received string.

Note for go-playground/validator one can just use translation: eg https://github.com/go-playground/validator/blob/master/_examples/translations/main.go

Usage

Simply wrap error from json package or validator library

err := json.Unmarshal([]byte(input), &struct)
errmsg.Message(err)
err := validate.Struct(r)
errmsg.Message(err)

About

provide more user friendly error message for your json apis

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages