Golang Response Snippets: JSON, XML and more
Last updated:
Taking inspiration from the Rails layouts and rendering guide, I thought it'd be a nice idea to build a snippet collection illustrating some common HTTP responses for Go web applications.
- Sending Headers Only
- Rendering Plain Text
- Rendering JSON
- Rendering XML
- Serving a File
- Rendering a HTML Template
- Rendering a HTML Template to a String
- Using Layouts and Nested Templates
Sending Headers Only
Rendering Plain Text
Rendering JSON
Rendering XML
Serving a File
Rendering a HTML Template
Rendering a HTML Template to a String
Instead of passing in the http.ResponseWriter
when executing your template (like in the above snippet)
use a buffer instead: