AcceptEncoder creates an new encoder for w based on the acceptHeader, the edit mode and the codecs that are available.
(w http.ResponseWriter, acceptHeader string, edit EditMode, codecs Codecs)
| 78 | // AcceptEncoder creates an new encoder for w based on the acceptHeader, the edit mode and |
| 79 | // the codecs that are available. |
| 80 | func AcceptEncoder(w http.ResponseWriter, acceptHeader string, edit EditMode, codecs Codecs) Encoder { |
| 81 | // TODO: add some hook to be able to tune this from the codec package |
| 82 | if acceptHeader == "text/html" && edit { |
| 83 | formCodec, ok := codecs.Codecs["application/x-www-form-urlencoded"] |
| 84 | if !ok { |
| 85 | return &noEncoder{missingEncoder: "application/x-www-form-urlencoded"} |
| 86 | } |
| 87 | return formCodec.NewEncoder(w) |
| 88 | } |
| 89 | |
| 90 | encoder, ok := codecs.Codecs[acceptHeader] |
| 91 | if !ok { |
| 92 | return &noEncoder{missingEncoder: acceptHeader} |
| 93 | } |
| 94 | |
| 95 | return encoder.NewEncoder(w) |
| 96 | } |
| 97 | |
| 98 | type noEncoder struct { |
| 99 | missingEncoder string |
no outgoing calls
no test coverage detected