api

package
v0.0.0-...-1ae172a Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionId = "sessionId"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

type Api struct {
	Method  string
	Path    string
	Handler Handler
}

Api 单个api

func NewApi

func NewApi(method, path string, handler Handler) *Api

type ApiGroup

type ApiGroup interface {
	Apis() []*Api
}

ApiGroup 一个api分组下的所有api

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

func NewAuth

func NewAuth(conf *config.ServerConfig) *Auth

func (*Auth) Authenticate

func (a *Auth) Authenticate(c *Context) (*types.User, error)

Authenticate 认证, a. 通过session获取用户信息 b. todo: 通过用户token认证

func (*Auth) Authorize

func (a *Auth) Authorize(c *Context, perm *AuthPerm) (bool, error)

Authorize 鉴权,用户是否有该perm权限

type AuthPerm

type AuthPerm struct {
	Scope   string
	ScopeId uint
	Role    string
}

AuthPerm 鉴权所需要的权限

type Context

type Context struct {
	*gin.Context
	User   *types.User
	Models *model.Models
}

func (*Context) CreateAudit

func (c *Context) CreateAudit(ao *types.AuditOperate)

CreateAudit 审计操作入库

func (*Context) Response

func (c *Context) Response(err error, data any) *utils.Response

func (*Context) ResponseError

func (c *Context) ResponseError(err error) *utils.Response

func (*Context) ResponseOK

func (c *Context) ResponseOK(data any) *utils.Response

type Handler

type Handler interface {
	// Auth 当前api是否需要认证,以及鉴权所需要的权限
	Auth(c *Context) (bool, *AuthPerm, error)
	// Handle api处理逻辑
	Handle(c *Context) *utils.Response
}

Jump to

Keyboard shortcuts

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