#Migration guide to v1 ## Context.Bind() **Old:**`c.Bind(obj) bool` ```go var json Object if c.Bind(&json) { // read json } ``` **New:**`c.Bind(obj) error` ```go var json Object if c.Bind(&json) == nil { // read json } ``` ##Context.Error() **Old:** `c.Error(error, interface{})` ```go c.Error(errors.New("my error"), nil) c.Error(errors.New("my error"), "some metadata") ``` **New:** `c.Error(error) *Error` ```go c.Error(errors.New("my error")) c.Error(errors.New("my error").SetMeta("some metadata") ``` ##Context.ErrorTyped() **Old:** `c.ErrorTyped(error, int, interface{})` ```go c.ErrorTyped(errors.New("my error"), ErrorTypeExternal, nil) c.ErrorTyped(errors.New("my error"), ErrorTypeInternal, "some metadata") ``` **New:** `c.Error(error) *Error` ```go c.Error(errors.New("my error")).SetType(ErrorTypePublic) c.Error(errors.New("my error")). SetType(ErrorTypeInternal). SetMeta("some metadata") // or // err :=c.Error(errors.New("my error")) // err.Type = ErrorTypeInternal // err.Meta = "some metadata" ``` ##Context.Fail() **Old:** `c.Fail(int, error)` ```go c.Fail(200, errors.New("this is an error")) ``` **New:** `c.AbortWithError(int, error) *Error` ```go c.AbortWithError(200, errors.New("this is an error")) ``` ##c.Render() **Old:** `c.Render(int, render.Render, ..interface{})` ```go c.Render(200, render.JSON, data) c.Render(200, render.XML, data) ``` **New:** `c.Render(int, render.Render)` ```go c.Render(200, render.JSON{data}) c.Render(200, render.XML{data}) ``` ##c.HTMLString() **Old:** `c.HTMLString(int, string, ...interface{})` ```go c.HTMLString(200, " %s ", unsafeString) ``` **New:** (removed) ```go c.Header("Content-Type", "text/html") c.String(200, " %s ", unsafeString) ``` ##c.Get() **Old:** `c.Get(key string) (interface{}, error)` ```go if value, err := c.Get(key string); err != nil { // read value } ``` **New:** `c.Get(key string) (interface{}, bool)` ```go if value, ok := c.Get(key string); ok { // read value } ``` ##c.Engine **Old:** `c.Engine` **New:** `c.engine` It can not longer be used, since it is an unexported variable. ##RouterGroup.Handle() **Old:** `group.Handle(string, string, gin.HandlerChain)` ```go handler := func(c *gin.Context) { // request handler } group.Handle("GET", "/path", gin.HandlerChain{handler}) ``` **New:** `group.Handle(string, string, ...gin.HandlerFunc)` ```go handler := func(c *gin.Context) { // request handler } group.Handle("GET", "/path", handler) ``` ##RouterGroup.LINK() / UNLINK() **Old:** ```go group.LINK("/path", handler) group.UNLINK("/path", handler) ``` **New:** (removed) ```go group.Handle("LINK", "/path", handler) group.Handle("UNLINK", "/path", handler) ``` ##Router settings RedirectTrailingSlash RedirectFixedPath HandleMethodNotAllowed **Old:** ```go router := gin.New() router.Router.RedirectTrailingSlash = false router.Router.RedirectFixedPath = false router.Router.HandleMethodNotAllowed = false ``` **New:** ```go router := gin.New() router.RedirectTrailingSlash = false router.RedirectFixedPath = false router.HandleMethodNotAllowed = false ```