mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
- Rename BUILD_DATE to BUILDDATE in goxc - Update travis config - Follow linter recommendations for inbucket.go - Follow linter recommendations for config package - Follow linter recommendations for log package - Follow linter recommendations for pop3d package - Follow linter recommendations for smtpd package - Follow linter recommendations for web package - Fix Id -> ID in templates - Add shebang to REST demo scripts - Add or refine many comments
16 lines
398 B
Go
16 lines
398 B
Go
package web
|
|
|
|
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)
|
|
}
|