From 731c827892f5b1eac9f58fc65cef32fa1908972c Mon Sep 17 00:00:00 2001 From: Erik Bender Date: Thu, 6 Feb 2020 07:50:21 +0100 Subject: [PATCH] add yaml negotitation (#2220) Co-authored-by: thinkerou --- context.go | 5 +++++ context_test.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index ee202d1..1c1b963 100644 --- a/context.go +++ b/context.go @@ -970,6 +970,7 @@ type Negotiate struct { HTMLData interface{} JSONData interface{} XMLData interface{} + YAMLData interface{} Data interface{} } @@ -988,6 +989,10 @@ func (c *Context) Negotiate(code int, config Negotiate) { data := chooseData(config.XMLData, config.Data) c.XML(code, data) + case binding.MIMEYAML: + data := chooseData(config.YAMLData, config.Data) + c.YAML(code, data) + default: c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server")) // nolint: errcheck } diff --git a/context_test.go b/context_test.go index df2d954..4380fb5 100644 --- a/context_test.go +++ b/context_test.go @@ -1114,7 +1114,7 @@ func TestContextNegotiationWithJSON(t *testing.T) { c.Request, _ = http.NewRequest("POST", "", nil) c.Negotiate(http.StatusOK, Negotiate{ - Offered: []string{MIMEJSON, MIMEXML}, + Offered: []string{MIMEJSON, MIMEXML, MIMEYAML}, Data: H{"foo": "bar"}, }) @@ -1129,7 +1129,7 @@ func TestContextNegotiationWithXML(t *testing.T) { c.Request, _ = http.NewRequest("POST", "", nil) c.Negotiate(http.StatusOK, Negotiate{ - Offered: []string{MIMEXML, MIMEJSON}, + Offered: []string{MIMEXML, MIMEJSON, MIMEYAML}, Data: H{"foo": "bar"}, })