biz

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProvideRedisClient

func ProvideRedisClient() *redis.Client

ProvideRedisClient 提供 Redis 客户端单例以供同步使用

Types

type Logger

type Logger struct {
	LoggerDAL *dal.Logger
}

Logger management

func (*Logger) Query

Query loggers from the data access object based on the provided parameters and options.

type Login

type Login struct {
	Cache       cachex.Cacher
	Auth        jwtx.Auther
	UserDAL     *dal.User
	UserRoleDAL *dal.UserRole
	MenuDAL     *dal.Menu
	UserBIZ     *User
	AuditLogBIZ *opsBiz.AuditLog
}

Login management for RBAC

func (*Login) GetCaptcha

func (a *Login) GetCaptcha(ctx context.Context) (*schema.Captcha, error)

This function generates a new captcha ID and returns it as a `schema.Captcha` struct. The length of the captcha is determined by the `config.C.Util.Captcha.Length` configuration value.

func (*Login) GetUserInfo

func (a *Login) GetUserInfo(ctx context.Context) (*schema.User, error)

Get user info

func (*Login) Login

func (a *Login) Login(ctx context.Context, formItem *schema.LoginForm) (*schema.LoginToken, error)

func (*Login) Logout

func (a *Login) Logout(ctx context.Context) error

func (*Login) LogoutWithRefreshToken

func (a *Login) LogoutWithRefreshToken(ctx context.Context, accessToken string, refreshToken string) error

LogoutWithRefreshToken logs out and revokes both access token and refresh token

func (*Login) ParseUserID

func (a *Login) ParseUserID(c *gin.Context) (string, error)

func (*Login) QueryMenus

func (a *Login) QueryMenus(ctx context.Context) (schema.Menus, error)

Query menus based on user permissions

func (*Login) RefreshToken

func (a *Login) RefreshToken(ctx context.Context) (*schema.LoginToken, error)

func (*Login) RefreshTokenWithRefreshToken

func (a *Login) RefreshTokenWithRefreshToken(ctx context.Context, refreshToken string) (*schema.LoginToken, error)

RefreshTokenWithRefreshToken uses a refresh token to get new access token (and new refresh token)

func (*Login) ResponseCaptcha

func (a *Login) ResponseCaptcha(ctx context.Context, w http.ResponseWriter, id string, reload bool) error

Response captcha image

func (*Login) UpdatePassword

func (a *Login) UpdatePassword(ctx context.Context, updateItem *schema.UpdateLoginPassword) error

Change login password

func (*Login) UpdateUser

func (a *Login) UpdateUser(ctx context.Context, updateItem *schema.UpdateCurrentUser) error

Update current user info

type Menu struct {
	Cache           cachex.Cacher
	Trans           *util.Trans
	MenuDAL         *dal.Menu
	MenuResourceDAL *dal.MenuResource
	RoleMenuDAL     *dal.RoleMenu
}

Menu management for RBAC

func (a *Menu) Create(ctx context.Context, formItem *schema.MenuForm) (*schema.Menu, error)

Create a new menu in the data access object.

func (a *Menu) Delete(ctx context.Context, id string) error

Delete the specified menu from the data access object.

func (a *Menu) Get(ctx context.Context, id string) (*schema.Menu, error)

Get the specified menu from the data access object.

func (a *Menu) InitFromFile(ctx context.Context, menuFile string) error

Query menus from the data access object based on the provided parameters and options.

func (a *Menu) Update(ctx context.Context, id string, formItem *schema.MenuForm) error

Update the specified menu in the data access object.

type OAuth

type OAuth struct {
	Cache               cachex.Cacher
	Trans               *util.Trans
	ExternalIdentityDAL *dal.ExternalIdentity
	UserDAL             *dal.User
	UserRoleDAL         *dal.UserRole
	TenantDAL           *dal.Tenant
	TenantModelDAL      *dal.TenantModel
	RoleDAL             *dal.Role
	LoginBIZ            *Login
	HTTPClient          *http.Client
}

func (*OAuth) BuildLoginURL

func (a *OAuth) BuildLoginURL(ctx context.Context, provider, redirect string) (string, error)

func (*OAuth) ExchangeTicket

func (a *OAuth) ExchangeTicket(ctx context.Context, ticket string) (*schema.LoginToken, error)

func (*OAuth) GetEnabledProviders

func (a *OAuth) GetEnabledProviders(ctx context.Context) []schema.OAuthProvider

func (*OAuth) HandleCallback

func (a *OAuth) HandleCallback(ctx context.Context, provider, code, state string) (string, error)

func (*OAuth) ResolveProfile

func (a *OAuth) ResolveProfile(ctx context.Context, profile schema.OAuthProfile) (*schema.OAuthResolveResult, error)

type Role

type Role struct {
	Cache       cachex.Cacher
	Trans       *util.Trans
	RoleDAL     *dal.Role
	RoleMenuDAL *dal.RoleMenu
	UserRoleDAL *dal.UserRole
	AuditLogBIZ *opsBiz.AuditLog
}

Role management for RBAC

func (*Role) Create

func (a *Role) Create(ctx context.Context, formItem *schema.RoleForm) (*schema.Role, error)

Create a new role in the data access object.

func (*Role) Delete

func (a *Role) Delete(ctx context.Context, id string) error

Delete the specified role from the data access object.

func (*Role) Get

func (a *Role) Get(ctx context.Context, id string) (*schema.Role, error)

Get the specified role from the data access object.

func (*Role) Query

Query roles from the data access object based on the provided parameters and options.

func (*Role) Update

func (a *Role) Update(ctx context.Context, id string, formItem *schema.RoleForm) error

Update the specified role in the data access object.

type Tenant

type Tenant struct {
	Trans       *util.Trans
	TenantDAL   *dal.Tenant
	UserDAL     *dal.User
	RedisClient *redis.Client
	AuditLogBIZ *opsBiz.AuditLog
}

Tenant management for RBAC

func (*Tenant) Create

func (a *Tenant) Create(ctx context.Context, formItem *schema.TenantForm) (*schema.Tenant, error)

Create a new tenant in the data access object.

func (*Tenant) Delete

func (a *Tenant) Delete(ctx context.Context, id string) error

Delete the specified tenant from the data access object.

func (*Tenant) Get

func (a *Tenant) Get(ctx context.Context, id string) (*schema.Tenant, error)

Get the specified tenant from the data access object.

func (*Tenant) Query

Query tenants from the data access object based on the provided parameters and options.

func (*Tenant) Update

func (a *Tenant) Update(ctx context.Context, id string, formItem *schema.TenantForm) error

Update the specified tenant in the data access object.

type TenantEndpoint

type TenantEndpoint struct {
	Trans             *util.Trans
	TenantEndpointDAL *dal.TenantEndpoint
	RedisClient       *redis.Client
	AuditLogBIZ       *opsBiz.AuditLog
}

TenantEndpoint 租户端点绑定业务逻辑类

func (*TenantEndpoint) GetAllowedEndpointIDs

func (a *TenantEndpoint) GetAllowedEndpointIDs(ctx context.Context, tenantCode, modelID string) ([]string, error)

GetAllowedEndpointIDs 查询租户指定模型下已经允许的端点 ID 列表

func (*TenantEndpoint) SaveEndpoints

func (a *TenantEndpoint) SaveEndpoints(ctx context.Context, tenantCode, modelID string, endpointIDs []string, creator string) error

SaveEndpoints 在事务中保存允许的端点白名单,并在成功后同步至 Redis

type TenantModel

type TenantModel struct {
	Trans          *util.Trans
	TenantModelDAL *dal.TenantModel
	RedisClient    *redis.Client
	AuditLogBIZ    *opsBiz.AuditLog
}

TenantModel management for RBAC

func (*TenantModel) ExecTrans

func (a *TenantModel) ExecTrans(ctx context.Context, fn func(context.Context) error) error

Transaction helper to allow transactional execution

func (*TenantModel) GetAuthorizedModelIDs

func (a *TenantModel) GetAuthorizedModelIDs(ctx context.Context, tenantCode string) ([]string, error)

GetAuthorizedModelIDs returns all model IDs authorized for the tenant.

func (*TenantModel) SaveBindings

func (a *TenantModel) SaveBindings(ctx context.Context, tenantCode string, modelIDs []string, creator string) error

SaveBindings deletes old bindings of the tenant and inserts new ones inside a transaction.

type User

type User struct {
	Cache       cachex.Cacher
	Trans       *util.Trans
	UserDAL     *dal.User
	UserRoleDAL *dal.UserRole
	AuditLogBIZ *opsBiz.AuditLog
}

User management for RBAC

func (*User) Create

func (a *User) Create(ctx context.Context, formItem *schema.UserForm) (*schema.User, error)

Create a new user in the data access object.

func (*User) Delete

func (a *User) Delete(ctx context.Context, id string) error

Delete the specified user from the data access object.

func (*User) Get

func (a *User) Get(ctx context.Context, id string) (*schema.User, error)

Get the specified user from the data access object.

func (*User) GetRoleIDs

func (a *User) GetRoleIDs(ctx context.Context, id string) ([]string, error)

func (*User) Query

Query users from the data access object based on the provided parameters and options.

func (*User) ResetPassword

func (a *User) ResetPassword(ctx context.Context, id string) error

func (*User) Update

func (a *User) Update(ctx context.Context, id string, formItem *schema.UserForm) error

Update the specified user in the data access object.

type UserAPIKey

type UserAPIKey struct {
	Trans         *util.Trans
	UserAPIKeyDAL *dal.UserAPIKey
	UserDAL       *dal.User
	RedisClient   *redis.Client
	AuditLogBIZ   *opsBiz.AuditLog
}

UserAPIKey 业务逻辑处理结构体

func (*UserAPIKey) Create

func (a *UserAPIKey) Create(ctx context.Context, formItem *schema.UserAPIKeyForm) (*schema.UserAPIKey, error)

Create 创建用户 API Key(仅在此接口返回新生成的明文 API Key 供前台复制)

func (*UserAPIKey) Delete

func (a *UserAPIKey) Delete(ctx context.Context, id string) error

Delete 逻辑删除用户 API Key

func (*UserAPIKey) Get

func (a *UserAPIKey) Get(ctx context.Context, id string) (*schema.UserAPIKey, error)

Get 获取单条 API Key 记录(已掩码脱敏)

func (*UserAPIKey) GetPlaintext

func (a *UserAPIKey) GetPlaintext(ctx context.Context, id string) (string, error)

GetPlaintext 获取单条 API Key 的明文(用于复制操作) 安全考虑:仅允许管理员或密钥所属用户获取明文

func (*UserAPIKey) Query

Query 分页查询用户 API Key 列表(已掩码脱敏)

func (*UserAPIKey) Update

func (a *UserAPIKey) Update(ctx context.Context, id string, formItem *schema.UserAPIKeyForm) error

Update 更新用户 API Key(支持更新 Name, Status, Credits, ExpiresAt, Description)

Jump to

Keyboard shortcuts

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