...

Source file src/github.com/gin-gonic/gin/render/render.go

Documentation: github.com/gin-gonic/gin/render

     1  // Copyright 2014 Manu Martinez-Almeida. All rights reserved.
     2  // Use of this source code is governed by a MIT style
     3  // license that can be found in the LICENSE file.
     4  
     5  package render
     6  
     7  import "net/http"
     8  
     9  // Render interface is to be implemented by JSON, XML, HTML, YAML and so on.
    10  type Render interface {
    11  	// Render writes data with custom ContentType.
    12  	Render(http.ResponseWriter) error
    13  	// WriteContentType writes custom ContentType.
    14  	WriteContentType(w http.ResponseWriter)
    15  }
    16  
    17  var (
    18  	_ Render     = JSON{}
    19  	_ Render     = IndentedJSON{}
    20  	_ Render     = SecureJSON{}
    21  	_ Render     = JsonpJSON{}
    22  	_ Render     = XML{}
    23  	_ Render     = String{}
    24  	_ Render     = Redirect{}
    25  	_ Render     = Data{}
    26  	_ Render     = HTML{}
    27  	_ HTMLRender = HTMLDebug{}
    28  	_ HTMLRender = HTMLProduction{}
    29  	_ Render     = YAML{}
    30  	_ Render     = Reader{}
    31  	_ Render     = AsciiJSON{}
    32  	_ Render     = ProtoBuf{}
    33  	_ Render     = TOML{}
    34  )
    35  
    36  func writeContentType(w http.ResponseWriter, value []string) {
    37  	header := w.Header()
    38  	if val := header["Content-Type"]; len(val) == 0 {
    39  		header["Content-Type"] = value
    40  	}
    41  }
    42  

View as plain text