feat: 补齐模块接口契约与管理 API 文档

This commit is contained in:
Nixevol
2026-09-30 06:36:28 +08:00
parent dd5a331db2
commit 22c56d1f35
23 changed files with 1782 additions and 3 deletions
+17 -1
View File
@@ -29,7 +29,7 @@ func cmdServe(_ []string) error {
}
func runServe(ctx context.Context, cfg config.Config) error {
wire()
deps := wire()
if err := os.MkdirAll(cfg.DataDir, 0o755); err != nil {
return fmt.Errorf("mkdir data_dir: %w", err)
@@ -41,6 +41,22 @@ func runServe(ctx context.Context, cfg config.Config) error {
}
defer func() { _ = db.Close() }()
// 启动恢复入口已挂上(假实现为空操作);M 线替换 message.Service 后生效。
if recoverErr := deps.Messages.RecoverOnStart(ctx); recoverErr != nil {
return fmt.Errorf("message recover: %w", recoverErr)
}
// 其余 deps 供后续 admin / broker / httpx 接线;此处显式引用避免未使用告警。
_ = deps.Identity
_ = deps.Groups
_ = deps.Presence
_ = deps.Downlink
_ = deps.Conns
_ = deps.Uplink
_ = deps.HashPool
_ = deps.SessionTokens
_ = deps.APITokens
_ = deps.LoginLocks
mux := http.NewServeMux()
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
+44 -2
View File
@@ -1,4 +1,46 @@
package main
// wire 组装各业务模块。T0.1 仅占位,T0.4 起由各线注册。
func wire() {}
import (
"git.asio.asia/nixevol/NixMsg/internal/app/group"
"git.asio.asia/nixevol/NixMsg/internal/app/identity"
"git.asio.asia/nixevol/NixMsg/internal/app/message"
"git.asio.asia/nixevol/NixMsg/internal/app/port"
"git.asio.asia/nixevol/NixMsg/internal/app/presence"
"git.asio.asia/nixevol/NixMsg/internal/auth"
)
// appDeps 是 serve 组装出的模块依赖。各线在后续任务中替换假实现为真实实现。
type appDeps struct {
HashPool auth.HashPool
SessionTokens auth.SessionTokens
APITokens auth.APITokens
LoginLocks auth.LoginLocks
Messages message.Service
Identity identity.Service
Groups group.Service
Presence presence.Service
Uplink port.UplinkHandler
Downlink port.Downlink
Conns port.ConnControl
}
// wire 组装各业务模块的骨架依赖(T0.4:假实现;后续各线替换)。
func wire() appDeps {
return appDeps{
HashPool: auth.NewStubHashPool(),
SessionTokens: auth.NewStubSessionTokens(),
APITokens: auth.NewStubAPITokens(),
LoginLocks: auth.NewStubLoginLocks(),
Messages: message.NewStub(),
Identity: identity.NewStub(),
Groups: group.NewStub(),
Presence: presence.NewStub(),
Uplink: port.StubUplinkHandler{},
Downlink: &port.StubDownlink{},
Conns: &port.StubConnControl{},
}
}
+16
View File
@@ -0,0 +1,16 @@
package main
import "testing"
func TestWireAssemblesStubs(t *testing.T) {
d := wire()
if d.HashPool == nil || d.SessionTokens == nil || d.APITokens == nil || d.LoginLocks == nil {
t.Fatal("auth deps missing")
}
if d.Messages == nil || d.Identity == nil || d.Groups == nil || d.Presence == nil {
t.Fatal("app deps missing")
}
if d.Uplink == nil || d.Downlink == nil || d.Conns == nil {
t.Fatal("port deps missing")
}
}