servers

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attachment added in v0.2.4

func Attachment(w http.ResponseWriter, filename string, data []byte)

Attachment attachment application/octet-stream;charset=utf-8

func JSON

func JSON(w http.ResponseWriter, statusCode int, data ...interface{})

JSON 返回json信息,带标准回复

func JSONCustom

func JSONCustom(w http.ResponseWriter, code Code, data ...interface{})

JSONCustom http.StatusBadRequest式应答,自定义code,提供给前端

func JSONDetail

func JSONDetail(w http.ResponseWriter, err error, data ...interface{})

JSONDetail http.StatusBadRequest式应答,含detail字段,用于debug

func JSONs added in v0.2.3

func JSONs(w http.ResponseWriter, httpCode int, code Code, data ...interface{})

JSONs 标准http status code应答

Types

type Code

type Code interface {
	fmt.Stringer
	Value() int
}

Code code interface

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message,omitempty"`
	Detail  string      `json:"detail,omitempty"`
	Data    interface{} `json:"data"`
}

Response 回复基本格式

Jump to

Keyboard shortcuts

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