response

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: MIT Imports: 7 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 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"`    // 数据类型, 可以缺省
	Message string      `json:"message,omitempty"` // 关于这次响应的说明信息
	Data    interface{} `json:"data,omitempty"`    // 返回的具体数据
}

Data to be used by controllers.

type PageData

type PageData struct {
	*request.PageRequest

	TotalCount uint        `json:"total"` // 总共多少条
	List       interface{} `json:"list"`  // 页面数据
}

PageData 数据分页数据

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