Files
mc-gateway/plugin/api/api.go
tursom 629d6d5dbc
Some checks failed
Go / build (.exe, 386, windows, windows-386) (push) Has been cancelled
Go / build (.exe, amd64, windows, windows-amd64) (push) Has been cancelled
Go / build (.exe, arm64, windows, windows-arm64) (push) Has been cancelled
Go / build (386, freebsd, freebsd-386) (push) Has been cancelled
Go / build (386, linux, linux-386) (push) Has been cancelled
Go / build (386, netbsd, netbsd-386) (push) Has been cancelled
Go / build (386, openbsd, openbsd-386) (push) Has been cancelled
Go / build (386, plan9, plan9-386) (push) Has been cancelled
Go / build (amd64, darwin, darwin-amd64) (push) Has been cancelled
Go / build (amd64, dragonfly, dragonfly-amd64) (push) Has been cancelled
Go / build (amd64, freebsd, freebsd-amd64) (push) Has been cancelled
Go / build (amd64, illumos, illumos-amd64) (push) Has been cancelled
Go / build (amd64, linux, linux-amd64) (push) Has been cancelled
Go / build (amd64, netbsd, netbsd-amd64) (push) Has been cancelled
Go / build (amd64, openbsd, openbsd-amd64) (push) Has been cancelled
Go / build (amd64, plan9, plan9-amd64) (push) Has been cancelled
Go / build (amd64, solaris, solaris-amd64) (push) Has been cancelled
Go / build (arm, 6, linux, linux-armv6) (push) Has been cancelled
Go / build (arm, 7, linux, linux-armv7) (push) Has been cancelled
Go / build (arm, freebsd, freebsd-arm) (push) Has been cancelled
Go / build (arm, netbsd, netbsd-arm) (push) Has been cancelled
Go / build (arm, openbsd, openbsd-arm) (push) Has been cancelled
Go / build (arm, plan9, plan9-arm) (push) Has been cancelled
Go / build (arm64, darwin, darwin-arm64) (push) Has been cancelled
Go / build (arm64, freebsd, freebsd-arm64) (push) Has been cancelled
Go / build (arm64, linux, linux-arm64) (push) Has been cancelled
Go / build (arm64, netbsd, netbsd-arm64) (push) Has been cancelled
Go / build (arm64, openbsd, openbsd-arm64) (push) Has been cancelled
Go / build (loong64, linux, linux-loong64) (push) Has been cancelled
Go / build (mips, linux, linux-mips) (push) Has been cancelled
Go / build (mips64, linux, linux-mips64) (push) Has been cancelled
Go / build (mips64le, linux, linux-mips64le) (push) Has been cancelled
Go / build (mipsle, linux, linux-mipsle) (push) Has been cancelled
Go / build (ppc64, aix, aix-ppc64) (push) Has been cancelled
Go / build (ppc64, linux, linux-ppc64) (push) Has been cancelled
Go / build (ppc64, openbsd, openbsd-ppc64) (push) Has been cancelled
Go / build (ppc64le, linux, linux-ppc64le) (push) Has been cancelled
Go / build (riscv64, freebsd, freebsd-riscv64) (push) Has been cancelled
Go / build (riscv64, linux, linux-riscv64) (push) Has been cancelled
Go / build (riscv64, openbsd, openbsd-riscv64) (push) Has been cancelled
Go / build (s390x, linux, linux-s390x) (push) Has been cancelled
Go / merge-artifacts (push) Has been cancelled
Docker Image / docker (push) Has been cancelled
feat(plugin): add governance release gates
2026-06-26 12:09:20 +08:00

108 lines
2.9 KiB
Go

package api
import (
"net"
"sync"
)
type (
Plugin interface {
// Init 初始化插件
// 返回错误表示初始化失败,插件将不会被启用
Init(gateway Gateway) error
// Destroy 销毁插件
// 返回错误表示销毁失败,通常是资源释放失败
// 但插件仍然会被标记为已销毁,后续调用 Init() 会重新初始化
Destroy() error
// NewConfigObj 创建插件配置对象
NewConfigObj() any
// ReloadConfig 重新加载插件配置
// config 是 NewConfigObj() 返回的对象
// 如果返回错误,则表示配置加载失败,插件将不会被启用
ReloadConfig(config any) error
}
PreflightCheck struct {
Code string `json:"code"`
Severity string `json:"severity"`
Message string `json:"message"`
}
PreflightContext struct {
PluginID string `json:"plugin_id"`
ArtifactID string `json:"artifact_id"`
Profile string `json:"profile"`
Action string `json:"action"`
Config map[string]any `json:"config,omitempty"`
Scope any `json:"scope,omitempty"`
Rollout any `json:"rollout,omitempty"`
RuntimeLimits any `json:"runtime_limits,omitempty"`
Features []string `json:"features,omitempty"`
}
PreflightResult struct {
Checks []PreflightCheck `json:"checks"`
}
SelfTestProfile struct {
Name string `json:"name"`
}
SelfTestResult struct {
Checks []PreflightCheck `json:"checks"`
}
PreflightChecker interface {
Preflight(context any) (PreflightResult, error)
}
SelfTester interface {
SelfTest(profile SelfTestProfile) (SelfTestResult, error)
}
Gateway interface {
HandleConn(conn net.Conn)
ExitWaitGroup() *sync.WaitGroup
Hook(hook string, handler any) error
}
AbstractPlugin struct{}
)
// Init 初始化插件
// 返回错误表示初始化失败,插件将不会被启用
func (p AbstractPlugin) Init(gateway Gateway) error {
return nil // 默认实现,返回 nil 表示初始化成功
}
// Destroy 销毁插件
// 返回错误表示销毁失败,通常是资源释放失败
// 但插件仍然会被标记为已销毁,后续调用 Init() 会重新初始化
func (p AbstractPlugin) Destroy() error {
return nil // 默认实现,返回 nil 表示销毁成功
}
// NewConfigObj 创建插件配置对象
func (p AbstractPlugin) NewConfigObj() any {
return struct{}{} // 默认实现,返回一个空结构体
}
// ReloadConfig 重新加载插件配置
// config 是 NewConfigObj() 返回的对象
// 如果返回错误,则表示配置加载失败,插件将不会被启用
func (p AbstractPlugin) ReloadConfig(config any) error {
return nil // 默认实现,返回 nil 表示配置加载成功
}
func RegisterHookHandler[Accept, Handle any](
gateway Gateway,
hook HookType[Accept, Handle],
accept Accept,
handler Handle,
) error {
return gateway.Hook(hook.key, HookHandler[Accept, Handle]{accept, handler})
}