resp

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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 ContentType(cType string) string

func SetContentType

func SetContentType(w http.ResponseWriter, cType string)

Types

type IModelAndView added in v1.2.7

type IModelAndView interface {
	SetModel(model interface{}) IModelAndView
	SetAttributes(key string, value interface{}) IModelAndView
	SetView(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)
}

func BadRequest

func BadRequest(msg string) Response

func Created

func Created(data interface{}) Response

func Error

func Error(httpStatus int, err error) Response

func InternalError

func InternalError(err error) Response

func ModelAndView added in v1.2.7

func ModelAndView(model interface{}, view string) Response

func New

func New(data interface{}) Response

func Ok

func Ok() Response

func Redirect

func Redirect(location string) Response

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL