1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

Refactor web package into two packages: httpd and webui

This commit is contained in:
James Hillyerd
2016-02-24 22:18:30 -08:00
parent 0b32af5495
commit 8e084b5697
12 changed files with 112 additions and 92 deletions

15
httpd/rest.go Normal file
View File

@@ -0,0 +1,15 @@
package httpd
import (
"encoding/json"
"net/http"
)
// RenderJSON sets the correct HTTP headers for JSON, then writes the specified
// data (typically a struct) encoded in JSON
func RenderJSON(w http.ResponseWriter, data interface{}) error {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("Expires", "-1")
enc := json.NewEncoder(w)
return enc.Encode(data)
}