This commit is contained in:
ryan
2026-06-16 09:20:18 +08:00
parent bfa00ae6ac
commit c6df73e522
17 changed files with 183 additions and 25 deletions
+14
View File
@@ -5,7 +5,9 @@
package cmd
import (
"context"
"log"
"time"
"github.com/Rain-kl/Wavelet/internal/buildinfo"
"github.com/Rain-kl/Wavelet/internal/config"
@@ -15,6 +17,8 @@ import (
"github.com/spf13/cobra"
)
const traceShutdownTimeout = 10 * time.Second
var rootCmd = &cobra.Command{
Use: "wavelet",
PersistentPreRun: func(_ *cobra.Command, _ []string) {
@@ -31,11 +35,15 @@ var rootCmd = &cobra.Command{
trace.Init(trace.Config{
AppName: config.Config.App.AppName,
SamplingRate: config.Config.Otel.SamplingRate,
TracerName: config.Config.Otel.TracerName,
})
},
PreRun: func(_ *cobra.Command, _ []string) {
migrator.Migrate()
},
PersistentPostRun: func(_ *cobra.Command, _ []string) {
shutdownTraceProvider()
},
Run: func(_ *cobra.Command, args []string) {
// 无参数时默认以融合模式启动所有服务
if len(args) == 0 {
@@ -58,6 +66,12 @@ var rootCmd = &cobra.Command{
},
}
func shutdownTraceProvider() {
ctx, cancel := context.WithTimeout(context.Background(), traceShutdownTimeout)
defer cancel()
trace.Shutdown(ctx)
}
func init() {
rootCmd.Version = buildinfo.Version
rootCmd.CompletionOptions.DisableDefaultCmd = true