controllers

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const (
	HTTP_MODE = iota
	RPC_MODE
	CLI_MODE
)

Variables

View Source
var (
	DEBUG      = false
	LOG_ACCESS = true
	LOG_ERROR  = true
)

Functions

This section is empty.

Types

type BaseController

type BaseController struct {
	RW    http.ResponseWriter
	R     *http.Request
	RBody []byte
	IR    *iRequest
	Ctx   context.Context

	Mode int

	Controller string
	Action     string
	Uri        string
	Debug      bool
	// contains filtered or unexported fields
}

func (*BaseController) AddLog

func (this *BaseController) AddLog(k string, v interface{})

在业务日志中添加自定义字段

func (*BaseController) Cost

func (this *BaseController) Cost() int64

func (*BaseController) GenLog

func (this *BaseController) GenLog() map[string]interface{}

获取日志内容

func (*BaseController) GetArray

func (this *BaseController) GetArray(key string) []string

获取数组类型参数

func (*BaseController) GetBool

func (this *BaseController) GetBool(key string, defaultValues ...bool) bool

获取bool型参数

func (*BaseController) GetCookie

func (this *BaseController) GetCookie(key string) string

以下 GetX 方法用于获取参数

func (*BaseController) GetErrorResponse

func (this *BaseController) GetErrorResponse(err interface{}) (int, string, map[string]interface{})

根据捕获的错误获取需要返回的错误码、错误信息及数据

func (*BaseController) GetFile

func (this *BaseController) GetFile(key string) (multipart.File, *multipart.FileHeader, error)

获取上传文件

func (*BaseController) GetHeader

func (this *BaseController) GetHeader(key string) string

func (*BaseController) GetInt

func (this *BaseController) GetInt(key string, defaultValues ...int) int

获取Int型参数

func (*BaseController) GetInt64

func (this *BaseController) GetInt64(key string, defaultValues ...int64) int64

func (*BaseController) GetIp

func (this *BaseController) GetIp() string

func (*BaseController) GetMap

func (this *BaseController) GetMap(key string) lib.MAP

获取json字符串并转换为MAP

func (*BaseController) GetParams

func (this *BaseController) GetParams() map[string]string

获取所有参数

func (*BaseController) GetRequestUri

func (this *BaseController) GetRequestUri() string

func (*BaseController) GetRpcContent

func (this *BaseController) GetRpcContent() string

func (*BaseController) GetSlice

func (this *BaseController) GetSlice(key string, separators ...string) []string

获取指定字符连接的字符串并转换成[]string

func (*BaseController) GetSliceInt

func (this *BaseController) GetSliceInt(key string, separators ...string) []int

获取指定字符连接的字符串并转换成[]int

func (*BaseController) GetString

func (this *BaseController) GetString(key string, defaultValues ...string) string

获取string类型参数

func (*BaseController) GetUA

func (this *BaseController) GetUA() string

func (*BaseController) Init

func (this *BaseController) Init()

默认的初始化方法,可通过在项目中重写此方法实现公共入口方法

func (*BaseController) OmitLog

func (this *BaseController) OmitLog(v string)

在业务日志中删除字段(比如密码等敏感字段)

func (*BaseController) Prepare

func (this *BaseController) Prepare(rw http.ResponseWriter, r *http.Request, controller, action string)

func (*BaseController) PrepareCli

func (this *BaseController) PrepareCli(r url.Values, controller, action string)

func (*BaseController) PrepareRpc

func (this *BaseController) PrepareRpc(r url.Values, ctx context.Context, controller, action string)

func (*BaseController) Redirect

func (this *BaseController) Redirect(url string, codes ...int)

重定向URL

func (*BaseController) Render

func (this *BaseController) Render(data ...interface{})

接口正常输出json, 若要改变返回json格式,可在业务代码中重写此方法

func (*BaseController) RenderError

func (this *BaseController) RenderError(err interface{})

接口异常输出json,在HttpApiServer中回调, 若要改变返回json格式,可在业务代码中重写此方法

func (*BaseController) RenderHtml

func (this *BaseController) RenderHtml(file string)

func (*BaseController) RenderJson

func (this *BaseController) RenderJson(json string)

输出JSON

func (*BaseController) RenderResponser

func (this *BaseController) RenderResponser(errno, errmsg, retdata interface{}) string

格式化输出

func (*BaseController) RenderStatus

func (this *BaseController) RenderStatus(code int)

输出HTTP状态码

func (*BaseController) RenderString

func (this *BaseController) RenderString(data string)

输出字符串

func (*BaseController) SetCookie

func (this *BaseController) SetCookie(key, val string, lifetime int, options ...interface{})

lifetime<0时删除cookie options: domain,secure,httponly,path

func (*BaseController) SetHeader

func (this *BaseController) SetHeader(key, val string)

func (*BaseController) SetHeaders

func (this *BaseController) SetHeaders(headers http.Header)

Jump to

Keyboard shortcuts

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