render.go 607 B

123456789101112131415161718192021222324252627282930
  1. package render
  2. import (
  3. "net/http"
  4. )
  5. // Render http reponse render.
  6. type Render interface {
  7. // Render render it to http response writer.
  8. Render(http.ResponseWriter) error
  9. // WriteContentType write content-type to http response writer.
  10. WriteContentType(w http.ResponseWriter)
  11. }
  12. var (
  13. _ Render = JSON{}
  14. _ Render = MapJSON{}
  15. _ Render = XML{}
  16. _ Render = String{}
  17. _ Render = Redirect{}
  18. _ Render = Data{}
  19. _ Render = PB{}
  20. )
  21. func writeContentType(w http.ResponseWriter, value []string) {
  22. header := w.Header()
  23. if val := header["Content-Type"]; len(val) == 0 {
  24. header["Content-Type"] = value
  25. }
  26. }