response

package
v2.0.14 Latest Latest
Warning

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

Go to latest
Published: May 11, 2024 License: MIT Imports: 8 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Failed

func Failed(w http.ResponseWriter, err error, opts ...Option)

Failed use to response error messge

func GetDataFromBody

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

GetDataFromBody 获取body中的数据

func Success

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

Success use to response success data

Types

type Data

type Data struct {
	RequestId string      `json:"request_id,omitempty"` // 请求Id
	Code      *int        `json:"code"`                 // 自定义返回码  0:表示正常
	Type      string      `json:"type,omitempty"`       // 数据类型, 可以缺省
	Namespace string      `json:"namespace,omitempty"`  // 异常的范围
	Reason    string      `json:"reason,omitempty"`     // 异常原因
	Recommend string      `json:"recommend,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

func NewData(data interface{}) *Data

NewData new实例

func (*Data) Error

func (d *Data) Error() error

type DesenseObj added in v2.0.8

type DesenseObj interface {
	Desense()
}

type Option

type Option interface {
	Apply(*Data)
}

Option configures how we set up the data.

func WithMeta

func WithMeta(meta interface{}) Option

func WithRecommend

func WithRecommend(msg string) Option

func WithRequestId

func WithRequestId(rid string) Option

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