partner

package module
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MulanPSL-2.0 Imports: 23 Imported by: 0

README

gin-partner

usage

go get -u gitee.com/binny_w/gin-partner

import "gitee.com/binny_w/gin-partner"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cors

func Cors() gin.HandlerFunc

func RateLimit

func RateLimit(redis *util.Redis, rate uint, period time.Duration) gin.HandlerFunc

func WriteJsonError

func WriteJsonError(c *gin.Context, code uint, msg string)

func WriteJsonSuccess

func WriteJsonSuccess(c *gin.Context, data any)

Types

type CommonModel

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

func NewCommonModel

func NewCommonModel() *CommonModel

func (*CommonModel) ClearGinHandler added in v0.0.7

func (m *CommonModel) ClearGinHandler(method string)

func (*CommonModel) GinHandlers added in v0.0.7

func (m *CommonModel) GinHandlers() map[string]map[string][]gin.HandlerFunc

func (*CommonModel) RegisterGinHandler added in v0.0.7

func (m *CommonModel) RegisterGinHandler(method, path string, handlers ...gin.HandlerFunc) error

func (*CommonModel) UnregisterGinHandler added in v0.0.7

func (m *CommonModel) UnregisterGinHandler(method, path string)

func (*CommonModel) UseGinMiddlewares added in v0.0.7

func (m *CommonModel) UseGinMiddlewares(method, path string, handlers ...gin.HandlerFunc) error

type Config

type Config struct {
	V *viper.Viper
}

func NewConfig

func NewConfig(onChange func(e fsnotify.Event)) *Config

func (*Config) Get

func (c *Config) Get(key string) any

func (*Config) GetAll

func (c *Config) GetAll() map[string]any

func (*Config) GetBool

func (c *Config) GetBool(key string) bool

func (*Config) GetInt

func (c *Config) GetInt(key string) int

func (*Config) GetInt64

func (c *Config) GetInt64(key string) int64

func (*Config) GetIntSlice

func (c *Config) GetIntSlice(key string) []int

func (*Config) GetStrMap

func (c *Config) GetStrMap(key string) map[string]any

func (*Config) GetStrSlice

func (c *Config) GetStrSlice(key string) []string

func (*Config) GetString

func (c *Config) GetString(key string) string

func (*Config) LoadFromFile

func (c *Config) LoadFromFile(filePath, fileType string) error

func (*Config) LoadFromRemote

func (c *Config) LoadFromRemote(provider, endpoint, path, cType string) error

func (*Config) SetDefault

func (c *Config) SetDefault(key string, val any)

type Engine

type Engine struct {
	E *gin.Engine
}

func NewEngine

func NewEngine(mode, logFile string, logFormatter gin.LogFormatter) *Engine

func (*Engine) RegisterRouter added in v0.0.7

func (e *Engine) RegisterRouter(group *gin.RouterGroup, method, path string, handlers ...gin.HandlerFunc) gin.IRoutes

func (*Engine) RouterGroup

func (e *Engine) RouterGroup(path string, handlers ...gin.HandlerFunc) *gin.RouterGroup

func (*Engine) RouterWithModel

func (e *Engine) RouterWithModel(group *gin.RouterGroup, model Model)

func (*Engine) Run

func (e *Engine) Run(addr string, onClose func())

func (*Engine) UseMiddlewares added in v0.0.7

func (e *Engine) UseMiddlewares(middlewares ...gin.HandlerFunc)

type IP2Region added in v0.0.7

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

func NewIP2Region added in v0.0.7

func NewIP2Region(xdbFile string) (*IP2Region, error)

func (*IP2Region) Close added in v0.0.7

func (i *IP2Region) Close()

func (*IP2Region) Search added in v0.0.7

func (i *IP2Region) Search(ip string) (string, error)

type Logger

type Logger struct {
	L *zap.Logger
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger(filePath string, options ...zap.Option) *Logger

func (*Logger) Close

func (l *Logger) Close()

func (*Logger) DPanic

func (l *Logger) DPanic(msg string, fields ...zap.Field)

func (*Logger) Debug

func (l *Logger) Debug(msg string, fields ...zap.Field)

func (*Logger) Error

func (l *Logger) Error(msg string, fields ...zap.Field)

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, fields ...zap.Field)

func (*Logger) Info

func (l *Logger) Info(msg string, fields ...zap.Field)

func (*Logger) Panic

func (l *Logger) Panic(msg string, fields ...zap.Field)

func (*Logger) Warn

func (l *Logger) Warn(msg string, fields ...zap.Field)

type Model

type Model interface {
	GinHandlers() map[string]map[string][]gin.HandlerFunc
}

type QueryKeyword

type QueryKeyword struct {
	Page     string
	PageSize string
	OrderBy  string
	SoColumn string
	SoWord   string
}

func (*QueryKeyword) Words added in v0.0.11

func (kw *QueryKeyword) Words() []string

type Rbac added in v0.0.5

type Rbac struct {
	Adapter    *gormadapter.Adapter
	Enforcer   *casbin.SyncedCachedEnforcer
	SuperAdmin string
	UserNone   string
}

Rbac RBAC结构体

func NewRbac added in v0.0.5

func NewRbac(mysqlDsn string, expire time.Duration, superAdmin, userNone string) (*Rbac, error)

NewRbac 创建一个实例

func (*Rbac) AddPermissionForRole added in v0.0.5

func (r *Rbac) AddPermissionForRole(role string, vals ...string) (bool, error)

AddPermissionForRole 给角色添加一个资源的操作权限

func (*Rbac) AddPermissionsForRole added in v0.0.5

func (r *Rbac) AddPermissionsForRole(role string, permissions ...[]string) (bool, error)

AddPermissionsForRole 给角色或用户,添加一个或多个资源的操作权限

func (*Rbac) AddRoles added in v0.0.6

func (r *Rbac) AddRoles(roles ...string) (bool, error)

AddRoles 添加一个或多个角色

func (*Rbac) AddRolesForUser added in v0.0.5

func (r *Rbac) AddRolesForUser(user string, roles ...string) (bool, error)

AddRolesForUser 向用户(或角色)绑定一个或多个角色

func (*Rbac) ClearPermissionsForRole added in v0.0.5

func (r *Rbac) ClearPermissionsForRole(role string) (bool, error)

ClearPermissionsForRole 清空角色的权限

func (*Rbac) ClearRolesForUser added in v0.0.5

func (r *Rbac) ClearRolesForUser(user string) (bool, error)

ClearRolesForUser 清空用户的角色

func (*Rbac) DeletePermissionForRole added in v0.0.5

func (r *Rbac) DeletePermissionForRole(role string, vals ...string) (bool, error)

DeletePermissionForRole 删除角色对资源的操作权限

func (*Rbac) DeleteRoles added in v0.0.5

func (r *Rbac) DeleteRoles(roles ...string) error

DeleteRoles 删除一个或多个角色

func (*Rbac) DeleteRolesForUser added in v0.0.5

func (r *Rbac) DeleteRolesForUser(user string, roles ...string) error

DeleteRolesForUser 删除用户的一个或多个角色

func (*Rbac) DeleteUsers added in v0.0.5

func (r *Rbac) DeleteUsers(users ...string) error

DeleteUsers 删除一个或多个用户

func (*Rbac) Enforce added in v0.0.5

func (r *Rbac) Enforce(role string, vals ...any) (bool, error)

Enforce 验证某个用户或角色,能否对资源进行某项操作

func (*Rbac) GetAllRoles added in v0.0.5

func (r *Rbac) GetAllRoles() ([]string, error)

GetAllRoles 获得全部角色名

func (*Rbac) GetImplicitRolesForUser added in v0.0.5

func (r *Rbac) GetImplicitRolesForUser(user string) ([]string, error)

GetImplicitRolesForUser 获得用户的角色(一个或多个,包含隐式层级)

func (*Rbac) GetPermissionsForRole added in v0.0.5

func (r *Rbac) GetPermissionsForRole(role string) ([][]string, error)

GetPermissionsForRole 获取角色的权限,不包含隐式

func (*Rbac) GetRolesForUser added in v0.0.5

func (r *Rbac) GetRolesForUser(user string) ([]string, error)

GetRolesForUser 获得用户的角色(一个或多个)

func (*Rbac) HasPermissionForRole added in v0.0.6

func (r *Rbac) HasPermissionForRole(role string, vals ...string) (bool, error)

HasPermissionForRole 角色或用户,对某资料是否有操作权限(不包含隐式)

func (*Rbac) HasRoleForUser added in v0.0.6

func (r *Rbac) HasRoleForUser(user, role string) (bool, error)

HasRoleForUser 用户是否属于某角色(不包含隐式)

type TableModel

type TableModel struct {
	Table        *util2.MysqlTable
	OrderBys     map[string]string
	InfoFixer    func(c *gin.Context, row *util2.MysqlRow) error
	QueryFixer   func(c *gin.Context, k string, v []string, p []any) (w, k1 string, p1 []any, ctn bool, err error)
	ListFixer    func(c *gin.Context, row *util2.MysqlRow) error
	InsertFixer  func(c *gin.Context, row *util2.MysqlRow) error
	UpdateFixer  func(c *gin.Context, row *util2.MysqlRow) error
	QueryKeyword *QueryKeyword
	CommonModel
	Alias          string
	OrderByDefault string
	SoColumns      []string
	PageSizeMax    int64
}

func NewTableModel

func NewTableModel(mt *util2.MysqlTable, alias string, qkd *QueryKeyword) *TableModel

func NewTableModelEasy added in v0.0.3

func NewTableModelEasy(tableName string, db *util2.MysqlClient) *TableModel

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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