authcheck

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 8

Documentation

Overview

@Author daixk 2025/12/22 15:56:00

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetErrorCodeAndMessage

func GetErrorCodeAndMessage(err error) (int, string)

GetErrorCodeAndMessage maps core errors to stable integration responses. GetErrorCodeAndMessage 将核心错误映射为稳定的集成层响应。

func GetManager

func GetManager(authType string) (*manager.Manager, error)

GetManager resolves manager by auth type GetManager 根据 authType 获取对应的 Manager。

func NeedAuth

func NeedAuth(req Request) bool

NeedAuth reports whether request needs auth checks NeedAuth 判断请求是否需要执行认证检查。

Types

type LogicType

type LogicType string

LogicType defines auth check logic type LogicType 定义认证检查逻辑类型。

const (
	// LogicOr means any permission or role is enough LogicOr 表示任一权限或角色满足即可。
	LogicOr LogicType = "OR"
	// LogicAnd means all permissions or roles are required LogicAnd 表示必须满足全部权限或角色。
	LogicAnd LogicType = "AND"
)

type Request

type Request struct {
	// TokenValue is the request token TokenValue 是当前请求携带的 Token。
	TokenValue string
	// CheckLogin indicates whether login state must be checked CheckLogin 表示是否必须校验登录态。
	CheckLogin bool
	// CheckDisable indicates whether account disable state must be checked CheckDisable 表示是否校验账号封禁状态。
	CheckDisable bool
	// Permissions lists required permissions Permissions 表示本次请求需要的权限列表。
	Permissions []string
	// Roles lists required roles Roles 表示本次请求需要的角色列表。
	Roles []string
	// LogicType controls AND/OR checks for permissions and roles LogicType 控制权限和角色的 AND/OR 逻辑。
	LogicType LogicType
	// LoginError is returned when IsLogin is false LoginError 是登录态校验失败时返回的错误。
	LoginError error
}

Request describes one integration auth check Request 描述一次集成层认证检查。

type Result

type Result struct {
	// LoginID is resolved lazily only when needed LoginID 仅在需要时才解析。
	LoginID string
}

Result stores useful auth check output Result 保存认证检查后可复用的结果。

func Check

func Check(ctx context.Context, mgr *manager.Manager, req Request) (*Result, error)

Check performs common integration auth checks Check 执行集成层公共认证检查。

Jump to

Keyboard shortcuts

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