Documentation ¶
Index ¶
- Constants
- func ContentType(cType string) string
- func SetContentType(w http.ResponseWriter, cType string)
- type DefaultResponseHandler
- type IModelAndView
- type Response
- func BadRequest(msg string) Response
- func Created(data interface{}) Response
- func Error(httpStatus int, err error) Response
- func InternalError(err error) Response
- func ModelAndView(model interface{}, view string) Response
- func New(data interface{}) Response
- func Ok() Response
- func Redirect(location string) Response
- type ResponseHandler
Constants ¶
View Source
const ( // ContentBinaryHeaderValue header value for binary data. ContentBinaryHeaderValue = "application/octet-stream" // ContentWebassemblyHeaderValue header value for web assembly files. ContentWebassemblyHeaderValue = "application/wasm" // ContentHTMLHeaderValue is the string of text/html response header's content type value. ContentHTMLHeaderValue = "text/html" // ContentJSONHeaderValue header value for JSON data. ContentJSONHeaderValue = "application/json" // ContentJSONProblemHeaderValue header value for JSON API problem error. // Read more at: https://tools.ietf.org/html/rfc7807 ContentJSONProblemHeaderValue = "application/problem+json" // ContentXMLProblemHeaderValue header value for XML API problem error. // Read more at: https://tools.ietf.org/html/rfc7807 ContentXMLProblemHeaderValue = "application/problem+xml" // ContentJavascriptHeaderValue header value for JSONP & Javascript data. ContentJavascriptHeaderValue = "application/javascript" // ContentTextHeaderValue header value for Text data. ContentTextHeaderValue = "text/plain" // ContentXMLHeaderValue header value for XML data. ContentXMLHeaderValue = "text/xml" // ContentXMLUnreadableHeaderValue obselete header value for XML. ContentXMLUnreadableHeaderValue = "application/xml" // ContentMarkdownHeaderValue custom key/content type, the real is the text/html. ContentMarkdownHeaderValue = "text/markdown" // ContentYAMLHeaderValue header value for YAML data. ContentYAMLHeaderValue = "application/x-yaml" // ContentFormHeaderValue header value for post form data. ContentFormHeaderValue = "application/x-www-form-urlencoded" // ContentFormMultipartHeaderValue header value for post multipart form data. ContentFormMultipartHeaderValue = "multipart/form-data" //need additional implement ContentRedirect = "redirect" )
View Source
const (
ContentTypeHeaderKey string = "Content-Type"
)
Variables ¶
This section is empty.
Functions ¶
func ContentType ¶
func SetContentType ¶
func SetContentType(w http.ResponseWriter, cType string)
Types ¶
type DefaultResponseHandler ¶ added in v1.3.2
type DefaultResponseHandler struct {
// contains filtered or unexported fields
}
func NewDefaultResponseHandler ¶ added in v1.3.2
func NewDefaultResponseHandler(w http.ResponseWriter) *DefaultResponseHandler
func (*DefaultResponseHandler) Do ¶ added in v1.3.6
func (d *DefaultResponseHandler) Do(response Response) bool
type IModelAndView ¶ added in v1.2.7
type IModelAndView interface { SetModel(model interface{}) IModelAndView SetAttributes(key string, value interface{}) IModelAndView SetView(file string) IModelAndView SetFS(fs fs.FS, file string) IModelAndView Compile() (raw string, err error) Response() Response Write(w http.ResponseWriter) }
Template
func Model ¶ added in v1.2.7
func Model() IModelAndView
type Response ¶
type Response interface { //build response Status(httpCode int) Response Data(data interface{}) Response Message(msg string) Response ContentType(cType string) Response GetStatus() int GetData() interface{} GetMessage() string GetContentType() string //set content-type Html() Response YAML() Response XML() Response TEXT() Response //write value Write(w http.ResponseWriter) WriteHtml(w http.ResponseWriter) WriteYAML(w http.ResponseWriter) WriteXML(w http.ResponseWriter) WriteTEXT(w http.ResponseWriter) //refer http action Forward(w http.ResponseWriter) }
Response define standard response function
func BadRequest ¶
func InternalError ¶
func ModelAndView ¶ added in v1.2.7
type ResponseHandler ¶ added in v1.3.2
Click to show internal directories.
Click to hide internal directories.