server

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2018 License: GPL-3.0 Imports: 17 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort

func Abort(w http.ResponseWriter, f string, args ...interface{})

Abort 返回结果,支持json

func AddFilter

func AddFilter(filter Filter)

AddFilter 添加过滤函数.

func NameToPath

func NameToPath(name string, depth int) string

NameToPath 类名转路径

func ParseFormVars

func ParseFormVars(req *http.Request, result interface{}) error

ParseFormVars 解析并验证Form表单中参数.

func ParseHeaderVars

func ParseHeaderVars(req *http.Request, result interface{}) error

ParseHeaderVars 解析并验证头中参数.

func ParseJSONVars

func ParseJSONVars(req *http.Request, result interface{}) error

ParseJSONVars 解析并验证Body中的Json参数.

func ParseURLVars

func ParseURLVars(req *http.Request, result interface{}) error

ParseURLVars 解析并验证头中参数.

func Register

func Register(obj interface{}) error

Register 只要struct实现了Get(),Post(),Delete(),Put()接口就可以自动注册

func RegisterHandler added in v1.2.0

func RegisterHandler(call func(http.ResponseWriter, *http.Request), method, path string) error

RegisterHandler 注册自定义url完全匹配.

func RegisterMust added in v1.6.2

func RegisterMust(obj interface{})

RegisterMust 只要struct实现了Get(),Post(),Delete(),Put()接口就可以自动注册, 如果添加失败panic.

func RegisterPath

func RegisterPath(obj interface{}, path string) error

RegisterPath 注册url完全匹配.

func RegisterPathMust added in v1.6.2

func RegisterPathMust(obj interface{}, path string)

RegisterPathMust 注册url完全匹配,如果遇到错误panic.

func RegisterPrefix

func RegisterPrefix(obj interface{}, path string) error

RegisterPrefix 注册url前缀.

func RegisterPrefixMust added in v1.6.2

func RegisterPrefixMust(obj interface{}, path string)

RegisterPrefixMust 注册url前缀并保证成功.

func SendData added in v1.1.1

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

SendData 为bootstrap-talbe客户端分页返回结果.

func SendErrorDetail

func SendErrorDetail(w http.ResponseWriter, status int, data interface{}, f string, args ...interface{})

SendErrorDetail 返回详细的错误信息,支持json

func SendResponse

func SendResponse(w http.ResponseWriter, status int, f string, args ...interface{})

SendResponse 返回结果,支持json

func SendResponseData

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

SendResponseData 返回结果,支持json

func SendResponseOK

func SendResponseOK(w http.ResponseWriter)

SendResponseOK 返回成功结果.

func SendRows

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

SendRows 为bootstrap-talbe返回结果,根据条件查找,total是总记录数,rows是数据

func Start

func Start(addr string) (net.Listener, error)

Start 启动httpServer.

func UnmarshalForm

func UnmarshalForm(req *http.Request, postion VariablePostion, result interface{}) error

UnmarshalForm 解析form中或者url中参数, 只支持int和string.

func UnmarshalJSON

func UnmarshalJSON(req *http.Request, result interface{}) error

UnmarshalJSON 解析body中的json数据.

func UnmarshalValidate

func UnmarshalValidate(req *http.Request, postion VariablePostion, result interface{}) error

UnmarshalValidate 解析并检证参数.

Types

type Filter

type Filter func(http.ResponseWriter, *http.Request) *http.Request

Filter 请求过滤, 如果返回结果为nil,直接返回,不再进行后续处理.

type Method

type Method int

Method 请求方式.

const (
	//GET http method.
	GET Method = iota
	//POST http method.
	POST
	//PUT http method.
	PUT
	//DELETE http method.
	DELETE
	//RESTful any method, may be get,post,put or delete.
	RESTful
)

func NewMethod added in v1.2.4

func NewMethod(m string) Method

NewMethod 转换字符串method到Method类型.

func (Method) String

func (m Method) String() string

String 类型转字符串

type Response

type Response struct {
	Status  int
	Message string      `json:",omitempty"`
	Data    interface{} `json:",omitempty"`
}

Response 通用返回结果

type VariablePostion

type VariablePostion int

VariablePostion 变量位置.

const (
	//URI 参数在uri里.
	URI VariablePostion = iota
	//HEADER 参数在头里.
	HEADER
	//JSON 参数在body的json里.
	JSON
	//FORM 参数在form表单中.
	FORM
)

func (VariablePostion) String

func (p VariablePostion) String() string

String 类型转字符串

Jump to

Keyboard shortcuts

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