mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
c9b702d234
Architecture: - Move GetFromContext/SetToContext from plugins/domain/auth to pkg/util - Move auth context key constants to core/contracts (AuthUserObjKey, AuthTokenAuthKey, etc.) - Add AuthUserIDKey, AuthUserNameKey, GetCurrentUserID, RevokeToken to contracts.AuthService - All 4 domain plugin Apply() methods now resolve AuthService via core.Using IoC - Plugin route middleware uses authSvc.RequireAuthMiddleware() cast to gin.HandlerFunc - DisallowTokenAuth added to AuthService contract Migration: - Replace cmd/app.go SetMigrationRunner bridge with gooseEngine implementing core.MigrationEngine - Remove cmd/root.go PreRun migration hooks and runMigrations() function - Migrations now run via core.App.Start() → RunMigrations() Events: - Add complete domain event topic catalog and payload DTOs to core/contracts/events.go - 15 event topics across auth, user, admin, upload, message_gateway, risk_control Downstream: - Create downstream/ directory with README and custom_example plugin scaffold CI: - Update Makefile code-check architecture guards for Cordis layering - Enforce: core no gin/gorm/asynq, contracts no plugins/, pkg no plugins/, domain no cross-domain
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
// Copyright 2025 linux.do
|
|
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/Rain-kl/Wavelet/pkg/buildinfo"
|
|
"github.com/Rain-kl/Wavelet/pkg/config"
|
|
"github.com/Rain-kl/Wavelet/pkg/logger"
|
|
"github.com/Rain-kl/Wavelet/pkg/trace"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
const traceShutdownTimeout = 10 * time.Second
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "wavelet",
|
|
PersistentPreRun: func(_ *cobra.Command, _ []string) {
|
|
logger.Init(logger.Config{
|
|
Level: config.Config.Log.Level,
|
|
Format: config.Config.Log.Format,
|
|
Output: config.Config.Log.Output,
|
|
FilePath: config.Config.Log.FilePath,
|
|
MaxSize: config.Config.Log.MaxSize,
|
|
MaxAge: config.Config.Log.MaxAge,
|
|
MaxBackups: config.Config.Log.MaxBackups,
|
|
Compress: config.Config.Log.Compress,
|
|
})
|
|
trace.Init(trace.Config{
|
|
AppName: config.Config.App.AppName,
|
|
SamplingRate: config.Config.Otel.SamplingRate,
|
|
TracerName: config.Config.Otel.TracerName,
|
|
})
|
|
},
|
|
PersistentPostRun: func(_ *cobra.Command, _ []string) {
|
|
shutdownTraceProvider()
|
|
},
|
|
Run: func(_ *cobra.Command, args []string) {
|
|
// 无参数时默认以融合模式启动所有服务
|
|
allCmd.Run(allCmd, args)
|
|
},
|
|
}
|
|
|
|
func shutdownTraceProvider() {
|
|
ctx, cancel := context.WithTimeout(context.Background(), traceShutdownTimeout)
|
|
defer cancel()
|
|
trace.Shutdown(ctx)
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.Version = buildinfo.Version
|
|
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
|
|
|
// 集中将子命令注册到根命令,以解决 Cobra 的 unknown command 校验限制
|
|
rootCmd.AddCommand(allCmd, apiCmd, workerCmd, schedulerCmd)
|
|
}
|
|
|
|
// Execute 执行根命令
|
|
func Execute() {
|
|
if err := rootCmd.Execute(); err != nil {
|
|
log.Fatalf("[CMD] execute failed; %s\n", err)
|
|
}
|
|
} |