-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add yaml support #165
add yaml support #165
Conversation
types/encoder.go
Outdated
return json.NewEncoder(writer).Encode(v) | ||
} | ||
|
||
func YamlEncoder(writer io.Writer, v interface{}) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to YAML, not Yaml
parse/parse.go
Outdated
return "json" | ||
} | ||
|
||
func isYaml(req *http.Request) bool { | ||
return req.Header.Get("Accept") == "application/yaml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A client can send multiple Accept headers to say different content types they accept. So you need to see if it's in one of the headers
api/writer/json.go
Outdated
AddCommonResponseHeader(apiContext) | ||
apiContext.Response.Header().Set("content-type", "application/json") | ||
if j.Type == "json" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can the type just have j.ContentType and just set content-type = j.ContentType
api/writer/json.go
Outdated
@@ -13,26 +12,32 @@ import ( | |||
"github.com/sirupsen/logrus" | |||
) | |||
|
|||
type JSONResponseWriter struct { | |||
type JSONOrYAMLResponseWriter struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This really has nothing to do with JSONorYaml now. Can you rename to EncodingResponseWriter
No description provided.