endpoint

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2025 License: MIT Imports: 11 Imported by: 0

README

接口管理

CREATE TABLE `endpoints` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `uuid` varchar(100) DEFAULT NULL,
  `service` varchar(100) DEFAULT NULL comment '服务',
  `version` varchar(100) DEFAULT NULL comment '版本',
  `resource` varchar(100) DEFAULT NULL comment '资源名称',
  `action` varchar(100) DEFAULT NULL comment '资源对于的动作即操作',
  `access_mode` tinyint(1) DEFAULT NULL comment '0-读 1-读写',
  `action_label` varchar(200) DEFAULT NULL,
  `function_name` varchar(100) DEFAULT NULL comment '对于的接口函数名称',
  `path` varchar(200) DEFAULT NULL,
  `method` varchar(100) DEFAULT NULL,
  `description` text,
  `required_auth` tinyint(1) DEFAULT NULL,
  `required_code` tinyint(1) DEFAULT NULL,
  `required_perm` tinyint(1) DEFAULT NULL,
  `required_role` json DEFAULT NULL,
  `required_audit` tinyint(1) DEFAULT NULL,
  `required_namespace` tinyint(1) DEFAULT NULL,
  `extras` json DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_endpoints_uuid` (`uuid`),
  KEY `idx_endpoints_created_at` (`created_at`),
  KEY `idx_endpoints_deleted_at` (`deleted_at`),
  KEY `idx_endpoints_service` (`service`),
  KEY `idx_endpoints_resource` (`resource`),
  KEY `idx_endpoints_action` (`action`),
  KEY `idx_endpoints_access_mode` (`access_mode`),
  KEY `idx_endpoints_action_label` (`action_label`),
  KEY `idx_endpoints_path` (`path`),
  KEY `idx_endpoints_method` (`method`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Documentation

Index

Constants

View Source
const (
	// AccessModeRead 只读模式
	AccessModeRead = iota
	// AccessModeReadWrite 读写模式
	AccessModeReadWrite
)
View Source
const (
	MetaRequiredAuthKey      = "required_auth"
	MetaRequiredCodeKey      = "required_code"
	MetaRequiredPermKey      = "required_perm"
	MetaRequiredRoleKey      = "required_role"
	MetaRequiredAuditKey     = "required_audit"
	MetaRequiredNamespaceKey = "required_namespace"
	MetaResourceKey          = "resource"
	MetaActionKey            = "action"
)
View Source
const (
	AppName = "endpoint"
)

Variables

This section is empty.

Functions

func GetRouteMeta

func GetRouteMeta[T any](m map[string]any, key string) T

func IsEndpointExist

func IsEndpointExist(set *types.Set[*Endpoint], target *Endpoint) bool

Types

type AccessMode

type AccessMode int8

type DescribeEndpointRequest

type DescribeEndpointRequest struct {
	apps.GetRequest
}

type Endpoint

type Endpoint struct {
	apps.ResourceMeta
	RouteEntry `bson:",inline" validate:"required"`
}

func NewEndpoint

func NewEndpoint() *Endpoint

func (*Endpoint) IsMatched

func (e *Endpoint) IsMatched(service, method, path string) bool

func (*Endpoint) SetRouteEntry

func (e *Endpoint) SetRouteEntry(v RouteEntry) *Endpoint

func (*Endpoint) String

func (e *Endpoint) String() string

func (*Endpoint) TableName

func (e *Endpoint) TableName() string

type QueryEndpointRequest

type QueryEndpointRequest struct {
	Services []string `form:"services" json:"services"`
}

func NewQueryEndpointRequest

func NewQueryEndpointRequest() *QueryEndpointRequest

func (*QueryEndpointRequest) IsMatchAllService

func (r *QueryEndpointRequest) IsMatchAllService() bool

func (*QueryEndpointRequest) WithService

func (r *QueryEndpointRequest) WithService(services ...string) *QueryEndpointRequest

type RegistryEndpointRequest

type RegistryEndpointRequest struct {
	Items []*RouteEntry `json:"items"`
}

func NewRegistryEndpointRequest

func NewRegistryEndpointRequest() *RegistryEndpointRequest

func (*RegistryEndpointRequest) AddItem

func (*RegistryEndpointRequest) Validate

func (r *RegistryEndpointRequest) Validate() error

type RouteEntry

type RouteEntry struct {
	// 该功能属于那个服务
	UUID string `json:"uuid" bson:"uuid" gorm:"column:uuid;type:varchar(100);uniqueIndex" optional:"true" description:"路由UUID"`
	// 该功能属于那个服务
	Service string `` /* 129-byte string literal not displayed */
	// 服务那个版本的功能
	Version string `` /* 139-byte string literal not displayed */
	// 资源名称
	Resource string `json:"resource" bson:"resource" gorm:"column:resource;type:varchar(100);index" description:"资源名称"`
	// 资源操作
	Action string `json:"action" bson:"action" gorm:"column:action;type:varchar(100);index" description:"资源操作"`
	// 读或者写
	AccessMode AccessMode `` /* 128-byte string literal not displayed */
	// 操作标签
	ActionLabel string `json:"action_label" gorm:"column:action_label;type:varchar(200);index" optional:"true" description:"资源标签"`
	// 函数名称
	FunctionName string `` /* 131-byte string literal not displayed */
	// HTTP path 用于自动生成http api
	Path string `json:"path" bson:"path" gorm:"column:path;type:varchar(200);index" description:"接口的路径"`
	// HTTP method 用于自动生成http api
	Method string `json:"method" bson:"method" gorm:"column:method;type:varchar(100);index" description:"接口的方法"`
	// 接口说明
	Description string `json:"description" bson:"description" gorm:"column:description;type:text" optional:"true" description:"接口说明"`
	// 是否校验用户身份 (acccess_token 校验)
	RequiredAuth bool `` /* 163-byte string literal not displayed */
	// 验证码校验(开启双因子认证需要) (code 校验)
	RequiredCode bool `` /* 174-byte string literal not displayed */
	// 开启鉴权
	RequiredPerm bool `` /* 128-byte string literal not displayed */
	// ACL模式下, 允许的通过的身份标识符, 比如角色, 用户类型之类
	RequiredRole []string `` /* 207-byte string literal not displayed */
	// 是否开启操作审计, 开启后这次操作将被记录
	RequiredAudit bool `` /* 178-byte string literal not displayed */
	// 名称空间不能为空
	RequiredNamespace bool `` /* 155-byte string literal not displayed */
	// 扩展信息
	Extras map[string]string `json:"extras" bson:"extras" gorm:"column:extras;serializer:json;type:json" optional:"true" description:"扩展信息"`
}

RouteEntry 路由条目

func NewEntryFromRestRequest

func NewEntryFromRestRequest(req *restful.Request) *RouteEntry

func NewEntryFromRestRoute

func NewEntryFromRestRoute(route restful.Route) *RouteEntry

func NewEntryFromRestRouteReader

func NewEntryFromRestRouteReader(route restful.RouteReader) *RouteEntry

func NewEntryFromRestfulContainer

func NewEntryFromRestfulContainer(c *restful.Container) (entries []*RouteEntry)

NewEntryFromRestfulContainer 获取 container 里的所有路由条目

func NewRouteEntry

func NewRouteEntry() *RouteEntry

func (*RouteEntry) AddRequiredRole

func (r *RouteEntry) AddRequiredRole(roles ...string) *RouteEntry

func (*RouteEntry) BuildUUID

func (r *RouteEntry) BuildUUID() *RouteEntry

func (*RouteEntry) HasRequiredRole

func (r *RouteEntry) HasRequiredRole() bool

func (*RouteEntry) IsRequireRole

func (r *RouteEntry) IsRequireRole(target string) bool

func (*RouteEntry) LoadMeta

func (r *RouteEntry) LoadMeta(meta map[string]any)

func (*RouteEntry) SetExtensionFromMap

func (r *RouteEntry) SetExtensionFromMap(m map[string]string) *RouteEntry

func (*RouteEntry) SetLabel

func (r *RouteEntry) SetLabel(value string) *RouteEntry

func (*RouteEntry) SetRequiredAuth

func (r *RouteEntry) SetRequiredAuth(v bool) *RouteEntry

func (*RouteEntry) SetRequiredCode

func (r *RouteEntry) SetRequiredCode(v bool) *RouteEntry

func (*RouteEntry) SetRequiredPerm

func (r *RouteEntry) SetRequiredPerm(v bool) *RouteEntry

func (*RouteEntry) UniquePath

func (r *RouteEntry) UniquePath() string

UniquePath todo

type Service

type Service interface {
	// RegistryEndpoint 注册 api 接口
	RegistryEndpoint(context.Context, *RegistryEndpointRequest) (*types.Set[*Endpoint], error)
	// QueryEndpoint 查询 API 接口列表
	QueryEndpoint(context.Context, *QueryEndpointRequest) (*types.Set[*Endpoint], error)
	// DescribeEndpoint 查询 API 接口详情
	DescribeEndpoint(context.Context, *DescribeEndpointRequest) (*Endpoint, error)
}

func GetService

func GetService() Service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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