Files
OpenFlare/cmd/flared/main.go
T
ryan 86fad02c41 errorlint 12→1:3 处 cmd 入口 err!=context.Canceled→errors.Is(防御性,当前 runner 不 wrap 语义不变);2 处 strconv.NumError 断言、1 处 viper 断言、2 处 ==io.EOF、2 处 ==redis.Nil、1 处 ==gorm.ErrRecordNotFound→errors.As/Is;8 处 %v→%w 保留错误链。刻意保留 telegram.go 单处 %v(原始错误仅作上下文文本,wrap 会改变 errors.Is 匹配语义)。
Result: {"status":"keep","total_issues":22,"golint_canonicalheader":0,"golint_errname":1,"golint_errorlint":1,"golint_forcetypeassert":3,"golint_gosec":0,"golint_intrange":0,"golint_modernize":3,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":3,"golint_recvcheck":7,"golint_usestdlibvars":0,"golint_wastedassign":0,"golint_total":21,"eslint_problems":1,"eslint_errors":0,"eslint_warnings":1,"tsc_errors":0,"measure_s":46}
2026-08-16 17:52:03 +08:00

75 lines
2.1 KiB
Go

// Command flared runs the OpenFlare tunnel client daemon.
package main
import (
"context"
"errors"
"flag"
"log/slog"
"os"
"os/signal"
"syscall"
edgelogging "github.com/Rain-kl/Wavelet/internal/apps/edge/logging"
"github.com/Rain-kl/Wavelet/internal/apps/flared/config"
"github.com/Rain-kl/Wavelet/internal/apps/flared/flared"
"github.com/Rain-kl/Wavelet/internal/apps/flared/frpc"
"github.com/Rain-kl/Wavelet/internal/apps/flared/heartbeat"
"github.com/Rain-kl/Wavelet/internal/apps/flared/httpclient"
"github.com/Rain-kl/Wavelet/internal/apps/flared/sync"
"github.com/Rain-kl/Wavelet/internal/apps/flared/wsclient"
)
func main() {
edgelogging.Setup(edgelogging.Options{})
configPath := flag.String("config", "./flared.json", "flared config path")
flag.Parse()
cfg, err := config.Load(*configPath)
if err != nil {
slog.Error("load flared config failed", "error", err)
os.Exit(1)
}
slog.Info("flared config loaded",
"server", cfg.ServerURL,
"frpc_path", cfg.FrpcPath,
"data_dir", cfg.DataDir,
"heartbeat_interval", cfg.HeartbeatInterval,
"sync_interval", cfg.SyncInterval,
)
frpcManager := frpc.NewManager(cfg)
_ = frpcManager.LoadState()
slog.Info("detected frpc version", "version", frpcManager.GetVersion(context.Background()))
httpClient := httpclient.New(cfg.ServerURL, cfg.InitialAuthToken(), cfg.RequestTimeout.Duration())
wsClient := wsclient.New(cfg.ServerURL, cfg.InitialAuthToken(), cfg.RequestTimeout.Duration())
syncService := sync.New(httpClient, frpcManager, cfg)
heartbeatService := heartbeat.New(httpClient, frpcManager, cfg)
runner := &flared.Runner{
Config: cfg,
FrpcManager: frpcManager,
HTTPClient: httpClient,
WebSocketService: wsClient,
HeartbeatService: heartbeatService,
SyncService: syncService,
}
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
slog.Info("flared process started")
if err := runner.Run(ctx); err != nil && !errors.Is(err, context.Canceled) {
slog.Error("flared process exited with error", "error", err)
stop()
os.Exit(1)
}
stop()
slog.Info("flared process stopped")
}