mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 06:16:37 +08:00
299ac30ee4
- Purify core micro-kernel by removing context hardcoded helpers and reverse dependencies - Eliminate init() side effects in infra plugins with reversible lifecycle disposal - Completely isolate plugins by removing cross-plugin imports and using core/contracts - Introduce TaskService and RiskControlService contracts for unified cross-plugin APIs - Regenerate Swagger documentation and update developer guide matrix - Achieve 0 violations in check_cordis_architecture.sh and 100% test pass
69 lines
1.7 KiB
Go
69 lines
1.7 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"Wavelet/pkg/buildinfo"
|
|
"Wavelet/pkg/config"
|
|
"Wavelet/pkg/logger"
|
|
"Wavelet/pkg/trace"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|