response

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2023 License: MIT Imports: 8 Imported by: 2

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 GetMessageFromBody added in v1.0.16

func GetMessageFromBody(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 Message added in v1.0.16

type Message 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"`  // 推荐链接
	Describe  string      `json:"describe,omitempty"`   // 关于这次响应的说明信息
	Message   interface{} `json:"message,omitempty"`    // 返回的具体数据
	Meta      interface{} `json:"meta,omitempty"`       // 数据meta
}

Data to be used by controllers.

func NewMessage added in v1.0.16

func NewMessage(data interface{}) *Message

NewMessage new实例

func (*Message) Error added in v1.0.16

func (d *Message) Error() error

type Option

type Option interface {
	Apply(*Message)
}

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