Skip to content

Commit 886c326

Browse files
authored
chore: fix go lint error (#40)
1 parent 051f0c7 commit 886c326

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+502
-579
lines changed

.github/workflows/build-and-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929
steps:
3030
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3131
- uses: ./tools/github-actions/setup-deps
32+
- run: make tools
3233
- run: make fmt
33-
# todo: 暂时关闭
34-
# - run: make go-lint
34+
- run: make go-lint
3535
- run: make build
3636

3737
Test:

cmd/main.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
package main
1919

2020
import (
21-
"fmt"
22-
"os"
21+
"fmt"
22+
"os"
2323

24-
"hertzbeat.apache.org/hertzbeat-collector-go/cmd/root"
25-
_ "hertzbeat.apache.org/hertzbeat-collector-go/internal/protocol/standard"
24+
"hertzbeat.apache.org/hertzbeat-collector-go/cmd/root"
25+
_ "hertzbeat.apache.org/hertzbeat-collector-go/internal/protocol/standard"
2626
)
2727

2828
func main() {
29-
30-
if err := root.GetRootCommand().Execute(); err != nil {
31-
_, _ = fmt.Fprintln(os.Stderr, err)
32-
os.Exit(1)
33-
}
29+
if err := root.GetRootCommand().Execute(); err != nil {
30+
_, _ = fmt.Fprintln(os.Stderr, err)
31+
os.Exit(1)
32+
}
3433
}

cmd/root/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
)
2727

2828
func GetRootCommand() *cobra.Command {
29-
3029
c := &cobra.Command{
3130
Use: "hertzbeat-collector-go",
3231
Short: "HertzBeat Collector Go",

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ require (
6464
github.com/yuin/gopher-lua v1.1.1 // indirect
6565
github.com/zeebo/xxh3 v1.0.2 // indirect
6666
go.uber.org/multierr v1.11.0 // indirect
67+
go.yaml.in/yaml/v2 v2.4.2 // indirect
6768
golang.org/x/mod v0.25.0 // indirect
6869
golang.org/x/net v0.41.0 // indirect
6970
golang.org/x/sync v0.15.0 // indirect
@@ -72,4 +73,5 @@ require (
7273
golang.org/x/tools v0.33.0 // indirect
7374
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
7475
google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
76+
sigs.k8s.io/yaml v1.6.0 // indirect
7577
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
350350
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
351351
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
352352
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
353+
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
354+
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
353355
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
354356
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
355357
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -517,3 +519,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
517519
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
518520
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
519521
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
522+
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
523+
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=

internal/banner/embed.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ type bannerVars struct {
5555
}
5656

5757
func New(srv *Config) *Runner {
58-
5958
return &Runner{
6059
Server: srv.Server,
6160
}
6261
}
6362

6463
func (r *Runner) PrintBanner(appName, port string) error {
65-
6664
r.Logger = r.Logger.WithName("banner").WithValues("runner", "banner")
6765

6866
data, err := EmbedLogo.ReadFile("banner.txt")

internal/cmd/server.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"syscall"
2929

3030
"github.com/spf13/cobra"
31+
32+
bannerouter "hertzbeat.apache.org/hertzbeat-collector-go/internal/banner"
3133
cfgloader "hertzbeat.apache.org/hertzbeat-collector-go/internal/config"
3234
"hertzbeat.apache.org/hertzbeat-collector-go/internal/job/collect"
3335
jobserver "hertzbeat.apache.org/hertzbeat-collector-go/internal/job/server"
@@ -37,13 +39,9 @@ import (
3739
collectortypes "hertzbeat.apache.org/hertzbeat-collector-go/internal/types/collector"
3840
configtypes "hertzbeat.apache.org/hertzbeat-collector-go/internal/types/config"
3941
collectorerr "hertzbeat.apache.org/hertzbeat-collector-go/internal/types/err"
40-
41-
bannerouter "hertzbeat.apache.org/hertzbeat-collector-go/internal/banner"
4242
)
4343

44-
var (
45-
cfgPath string
46-
)
44+
var cfgPath string
4745

4846
type Runner[I collectortypes.Info] interface {
4947
Start(ctx context.Context) error
@@ -52,7 +50,6 @@ type Runner[I collectortypes.Info] interface {
5250
}
5351

5452
func ServerCommand() *cobra.Command {
55-
5653
cmd := &cobra.Command{
5754
Use: "server",
5855
Aliases: []string{"server", "srv", "s"},
@@ -67,7 +64,6 @@ func ServerCommand() *cobra.Command {
6764
}
6865

6966
func getConfigByPath() (*configtypes.CollectorConfig, error) {
70-
7167
loader := cfgloader.New(cfgPath)
7268
cfg, err := loader.LoadConfig()
7369
if err != nil {
@@ -82,12 +78,10 @@ func getConfigByPath() (*configtypes.CollectorConfig, error) {
8278
}
8379

8480
func serverByCfg(cfg *configtypes.CollectorConfig, logOut io.Writer) *clrserver.Server {
85-
8681
return clrserver.New(cfg, logOut)
8782
}
8883

8984
func server(ctx context.Context, logOut io.Writer) error {
90-
9185
cfg, err := getConfigByPath()
9286
if err != nil {
9387
return err
@@ -110,7 +104,6 @@ func server(ctx context.Context, logOut io.Writer) error {
110104
}
111105

112106
func startRunners(ctx context.Context, cfg *clrserver.Server) error {
113-
114107
// Create transport server first
115108
transportRunner := transportserver.New(cfg)
116109

internal/cmd/version.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
)
2727

2828
func VersionCommand() *cobra.Command {
29-
3029
var output string
3130

3231
cmd := &cobra.Command{

internal/cmd/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"io"
2626
"runtime"
2727

28-
"gopkg.in/yaml.v3"
28+
"sigs.k8s.io/yaml"
2929
)
3030

3131
type Info struct {

internal/config/config.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"time"
2929

3030
"github.com/fsnotify/fsnotify"
31-
"gopkg.in/yaml.v3"
31+
"sigs.k8s.io/yaml"
3232

3333
"hertzbeat.apache.org/hertzbeat-collector-go/internal/constants"
3434
cfgtypes "hertzbeat.apache.org/hertzbeat-collector-go/internal/types/config"
@@ -50,7 +50,6 @@ type Loader struct {
5050

5151
// New creates a new configuration loader
5252
func New(cfgPath string) *Loader {
53-
5453
return &Loader{
5554
cfgPath: cfgPath,
5655
logger: logger.DefaultLogger(os.Stdout, loggertypes.LogLevelInfo).WithName("config-loader"),
@@ -285,7 +284,6 @@ func (l *Loader) WatchConfigAndReload(ctx context.Context) error {
285284
// when config file changes, it helps dynamically
286285
// adjust the log level for dynamic debugging
287286
func (l *Loader) reloadLogging(cfg *cfgtypes.CollectorConfig) error {
288-
289287
if cfg == nil {
290288
return errors.New("config is nil")
291289
}

0 commit comments

Comments
 (0)