httpsvr

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	/*
		1: 登陆认证失败
		2:用户请求数据处理失败
		3:服务端处理失败
	*/
	StatusOK           = 0
	StatusInvalidSign  = 1000
	StatusLoginFailed  = 1003
	StatusAccessDenied = 1199
	// 请求参数合法性验证
	StatusNotLegalInput = 1201
	// json请求校验失败
	StatusBodyInvalid          = 1204
	StatusDataProcessingFailed = 3000
	StatusSaveDataFailed       = 3001
	StatusNotFound             = 3010
)
View Source
const (
	TypeJson  = "application/json; charset=UTF-8"
	TypePlain = "text/plain; charset=UTF-8"
	TypeHtml  = "text/html; charset=UTF-8"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIInfo

type APIInfo struct {
	Handler Handle
	Name    string
	// Perm 权限
	Perm uint
}

APIInfo api信息

type Context

type Context struct {
	Req         *http.Request
	Writer      *ResponseWriter
	Params      httprouter.Params
	Keys        map[string]interface{}
	Response    interface{}
	Begin       time.Time
	NoLog       bool
	OpLog       *bytes.Buffer
	Body        *bytes.Buffer
	BodyLen     int64
	BodyMap     map[string]interface{}
	ContextType string
	Perm        uint
}

Context http会话期间的session

func (*Context) RemoteAddr

func (ctx *Context) RemoteAddr(xff bool) string

RemoteAddr 获取客户端IP

func (*Context) ReqBody

func (ctx *Context) ReqBody(out interface{}) (ecode int, err error)

ReqBody 获取请求中的Body

func (*Context) Upload

func (ctx *Context) Upload(savedir, allowExt string) (string, string, error)

Upload 文件上传处理。兼容chunked方式。

不是chunk方式上传时,保存的文件名为随机生成。
chunk方式上传时,保存的文件名为提交的文件名。这种方式上传的文件名不能重名。
返回的参数:提交的文件名,保存的文件名,错误信息。当chunk方式上传时,在最后一个chunk请求处理
之前,返回的错误信息是:Chunking,表示chunk未完成。

type Handle

type Handle func(ctx *Context)

Handle 增加全局配置信息

type