response

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 9 Imported by: 343

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Failed

func Failed(w http.ResponseWriter, err error)

Failed use to response error messge

func GetDataFromBody added in v0.1.2

func GetDataFromBody(body io.ReadCloser, v interface{}) error

GetDataFromBody 获取body中的数据

func Success

func Success(w http.ResponseWriter, data interface{})

Success use to response success data

Types

type Data

type Data struct {
	Code      *int        `json:"code"`                // 自定义返回码  0:表示正常
	Type      string      `json:"type,omitempty"`      // 数据类型, 可以缺省
	Namespace string      `json:"namespace,omitempty"` // 异常的范围
	Reason    string      `json:"reason,omitempty"`    // 异常原因
	Message   string      `json:"message,omitempty"`   // 关于这次响应的说明信息
	Data      interface{} `json:"data,omitempty"`      // 返回的具体数据
	Meta      interface{} `json:"meta,omitempty"`      // 数据meta
}

Data to be used by controllers.

func NewData added in v0.1.2

func NewData(data interface{}) *Data

NewData new实例

type Response

type Response interface {
	http.ResponseWriter
	http.Flusher
	// Status returns the status code of the response or 0 if the response has
	// not been written
	Status() int
	// Written returns whether or not the ResponseWriter has been written.
	Written() bool
	// Size returns the size of the response body.
	Size() int
	// Before allows for a function to be called before the ResponseWriter has been written to. This is
	// useful for setting headers or any other operations that must happen before a response has been written.
	Before(func(Response))
}

Response is a wrapper around http.ResponseWriter that provides extra information about the response. It is recommended that middleware handlers use this construct to wrap a responsewriter if the functionality calls for it.

func NewResponse

func NewResponse(rw http.ResponseWriter) Response

NewResponse creates a ResponseWriter that wraps an http.ResponseWriter

Jump to

Keyboard shortcuts

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