Documentation ¶
Overview ¶
Package gores http response utility library for GO
Index ¶
- Constants
- func Download(w http.ResponseWriter, r *http.Request, path string, name string) error
- func Error(w http.ResponseWriter, code int, message string)
- func File(w http.ResponseWriter, r *http.Request, path string) error
- func HTML(w http.ResponseWriter, code int, html string)
- func JSON(w http.ResponseWriter, code int, i interface{}) error
- func JSONIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string) error
- func JSONP(w http.ResponseWriter, code int, callback string, i interface{}) error
- func MustDownload(w http.ResponseWriter, r *http.Request, path string, name string)
- func MustFile(w http.ResponseWriter, r *http.Request, path string)
- func MustJSON(w http.ResponseWriter, code int, i interface{})
- func MustJSONIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string)
- func MustJSONP(w http.ResponseWriter, code int, callback string, i interface{})
- func MustXML(w http.ResponseWriter, code int, i interface{})
- func MustXMLIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string)
- func NoContent(w http.ResponseWriter)
- func String(w http.ResponseWriter, code int, s string)
- func XML(w http.ResponseWriter, code int, i interface{}) error
- func XMLIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string) error
Constants ¶
const ( CONNECT = "CONNECT" DELETE = "DELETE" GET = "GET" HEAD = "HEAD" OPTIONS = "OPTIONS" PATCH = "PATCH" POST = "POST" PUT = "PUT" TRACE = "TRACE" )
HTTP Methods
const ( ApplicationJSON = "application/json" ApplicationJSONCharsetUTF8 = ApplicationJSON + "; " + CharsetUTF8 ApplicationJavaScript = "application/javascript" ApplicationJavaScriptCharsetUTF8 = ApplicationJavaScript + "; " + CharsetUTF8 ApplicationXML = "application/xml" ApplicationXMLCharsetUTF8 = ApplicationXML + "; " + CharsetUTF8 ApplicationForm = "application/x-www-form-urlencoded" ApplicationProtobuf = "application/protobuf" ApplicationMsgpack = "application/msgpack" TextHTML = "text/html" TextHTMLCharsetUTF8 = TextHTML + "; " + CharsetUTF8 TextPlain = "text/plain" TextPlainCharsetUTF8 = TextPlain + "; " + CharsetUTF8 MultipartForm = "multipart/form-data" )
Media Types
const ( AcceptEncoding = "Accept-Encoding" Authorization = "Authorization" ContentDisposition = "Content-Disposition" ContentEncoding = "Content-Encoding" ContentLength = "Content-Length" ContentType = "Content-Type" Location = "Location" Upgrade = "Upgrade" Vary = "Vary" WWWAuthenticate = "WWW-Authenticate" XForwardedFor = "X-Forwarded-For" XRealIP = "X-Real-IP" )
Headers
const ( // CharsetUTF8 utf8 character set CharsetUTF8 = "charset=utf-8" // WebSocket web socket protocol WebSocket = "websocket" )
Variables ¶
This section is empty.
Functions ¶
func Download ¶
Download the client is prompted to save the file with provided `name`, name can be empty, in that case name of the file is used.
func Error ¶
func Error(w http.ResponseWriter, code int, message string)
Error sends a error response with a status code
func HTML ¶
func HTML(w http.ResponseWriter, code int, html string)
HTML sends an HTTP response with status code.
func JSON ¶
func JSON(w http.ResponseWriter, code int, i interface{}) error
JSON sends a JSON response with status code.
func JSONIndent ¶
JSONIndent sends a JSON response with status code, but it applies prefix and indent to format the output.
func JSONP ¶
func JSONP(w http.ResponseWriter, code int, callback string, i interface{}) error
JSONP sends a JSONP response with status code. It uses `callback` to construct the JSONP payload.
func MustDownload ¶ added in v1.2.2
MustDownload calls Download and panics on error
func MustFile ¶ added in v1.2.2
func MustFile(w http.ResponseWriter, r *http.Request, path string)
MustFile calls File and panics on error
func MustJSON ¶ added in v1.2.2
func MustJSON(w http.ResponseWriter, code int, i interface{})
MustJSON calls JSON and panics on error
func MustJSONIndent ¶ added in v1.2.2
func MustJSONIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string)
MustJSONIndent calls JSONIndent and panics on error
func MustJSONP ¶ added in v1.2.2
func MustJSONP(w http.ResponseWriter, code int, callback string, i interface{})
MustJSONP calls JSONP and panics on error
func MustXML ¶ added in v1.2.2
func MustXML(w http.ResponseWriter, code int, i interface{})
MustXML calls XML and panics on error
func MustXMLIndent ¶ added in v1.2.2
func MustXMLIndent(w http.ResponseWriter, code int, i interface{}, prefix string, indent string)
MustXMLIndent calls XMLIndent and panics on error
func NoContent ¶
func NoContent(w http.ResponseWriter)
NoContent sends a response with no body and a status code.
func String ¶
func String(w http.ResponseWriter, code int, s string)
String sends a string response with status code.
Types ¶
This section is empty.