admin

package
v0.0.0-...-074ff86 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActionName = "_action"

请求标识变量名

View Source
var Db *sql.DB
View Source
var DefaultDispatcher = &defaultDispatcher{HandleMethod: make(map[string]DefaultDispatcherHandleMethod)}
View Source
var LogCallback func(content LogContent)
View Source
var NoCheckLoginRequestIds = []int{1}

无需登录的请求ID

View Source
var OnlyLoginRequestIds = []int{2, 3, 4}

无需检查权限/只需要登录的请求ID

View Source
var TokenName = "_token"

请求token变量名

Functions

func AddNoCheckLoginRequestId

func AddNoCheckLoginRequestId(ids ...int)

添加无需登录的请求ID

func AddOnlyLoginRequestId

func AddOnlyLoginRequestId(ids ...int)

添加无需检查权限/只需要登录的请求ID

func AllDispatcher

func AllDispatcher() map[string]Dispatch

func AllDispatcherLength

func AllDispatcherLength() int

func RegisterDefaultDispatcherHandleMethod

func RegisterDefaultDispatcherHandleMethod(methods map[string]DefaultDispatcherHandleMethod)

注册默认调度器请求处理方法

func RegisterDispatch

func RegisterDispatch(dispatcher Dispatch)

func RegisterLogCallback

func RegisterLogCallback(callback func(content LogContent))

注册密码生成器

func RegisterPassword

func RegisterPassword(password Password)

注册密码生成器

func SetDb

func SetDb(d *sql.DB)

设置数据库操作对象

Types

type Context

type Context struct {
	Action             string
	Token              string
	HttpResponseWriter http.ResponseWriter
	HttpRequest        *http.Request
	Request            *request.Model
	User               *user.Model
	Response           *Response
}

func NewContext

func NewContext(rw http.ResponseWriter, r *http.Request) *Context

请求入口方法

func (*Context) Form

func (c *Context) Form(parameter interface{}) error

func (*Context) Input

func (c *Context) Input(name string, def ...string) string

func (*Context) InputInt

func (c *Context) InputInt(name string, def ...int) (int, error)

func (*Context) Output

func (c *Context) Output() error

func (*Context) SetResponse

func (c *Context) SetResponse(r *Response)

type DefaultDispatcherHandleMethod

type DefaultDispatcherHandleMethod func(*Context) (interface{}, error)

type Dispatch

type Dispatch interface {
	// 调度器标识
	Key() string
	// 调度器名称
	Name() string
	// 调度器描述
	Description() string
	// 请求调度方法
	Call(*Context) (interface{}, error)
}

调度器接口

func GetDispatcher

func GetDispatcher(type_ string) (Dispatch, error)

type LogContent

type LogContent struct {
	// 用户
	User *user.Model
	// 请求
	Request *request.Model
	// 响应
	Response *Response
	// 响应时间
	Time time.Time
}

type Password

type Password interface {
	Hash(password []byte) []byte
	Verify(password, hash []byte) bool
}

密码生成器接口

var Passworder Password

type PasswordDefault

type PasswordDefault struct {
}

默认密码生成器

func (*PasswordDefault) Hash

func (p *PasswordDefault) Hash(password []byte) []byte

func (*PasswordDefault) Verify

func (p *PasswordDefault) Verify(password, hash []byte) bool

type Response

type Response struct {
	Status string      `json:"status"`
	Info   string      `json:"info"`
	Data   interface{} `json:"data"`
}

系统对外响应

func (Response) Json

func (r Response) Json() []byte

func (Response) JsonResponse

func (r Response) JsonResponse(w io.Writer) error

Jump to

Keyboard shortcuts

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