Context Accepted is an exported variable

This commit is contained in:
Manu Mtz-Almeida 2015-04-07 23:28:36 +02:00
parent 408108f4e7
commit 1532be7c10

View File

@ -33,7 +33,7 @@ type Context struct {
Keys map[string]interface{} Keys map[string]interface{}
Errors errorMsgs Errors errorMsgs
accepted []string Accepted []string
} }
/************************************/ /************************************/
@ -43,7 +43,7 @@ type Context struct {
func (c *Context) reset() { func (c *Context) reset() {
c.Keys = nil c.Keys = nil
c.index = -1 c.index = -1
c.accepted = nil c.Accepted = nil
c.Errors = c.Errors[0:0] c.Errors = c.Errors[0:0]
} }
@ -293,14 +293,13 @@ func (c *Context) NegotiateFormat(offered ...string) string {
if len(offered) == 0 { if len(offered) == 0 {
log.Panic("you must provide at least one offer") log.Panic("you must provide at least one offer")
} }
if c.accepted == nil { if c.Accepted == nil {
c.accepted = parseAccept(c.Request.Header.Get("Accept")) c.Accepted = parseAccept(c.Request.Header.Get("Accept"))
} }
if len(c.accepted) == 0 { if len(c.Accepted) == 0 {
return offered[0] return offered[0]
}
} else { for _, accepted := range c.Accepted {
for _, accepted := range c.accepted {
for _, offert := range offered { for _, offert := range offered {
if accepted == offert { if accepted == offert {
return offert return offert
@ -309,8 +308,7 @@ func (c *Context) NegotiateFormat(offered ...string) string {
} }
return "" return ""
} }
}
func (c *Context) SetAccepted(formats ...string) { func (c *Context) SetAccepted(formats ...string) {
c.accepted = formats c.Accepted = formats
} }