From 2f907250e5e6faef8779e34dbfb6276afe827f3e Mon Sep 17 00:00:00 2001 From: kianaza <70883712+kianaza@users.noreply.github.com> Date: Sun, 19 May 2024 23:57:11 +0330 Subject: [PATCH 01/10] Delete internal/.DS_Store --- internal/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 internal/.DS_Store diff --git a/internal/.DS_Store b/internal/.DS_Store deleted file mode 100644 index 7ee04fa20b2c0f41d8492b2f2d9b2ebc0630a371..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!Ab)$5S`H?1us4JBIFAM{~(rn@Z2Ae)>?$cg`)TTk)NpV&5WgM_gq9~mdwj0 zZ?egQO)?^)i;w3!k(r20QHaXQh_QLJ>mtaPK(#U6hC?*+?g^ zvX$ZdDat*{?U$KNpWGh27w~sSYbE#dgxi6;!?TtBkgGSpxHfpYR3H^d1yX@j;0y}j z%%)AR9n+@*sX!`lP=NbGK_S+_=4e|7oTUK337XAN=T(?7C9noINA$qdLxCQukz%Na zqrC*L1~x|z7megY}s= Ifio!Z4Y80j4FCWD From 884762215863dd47b229b1a63e2b605719302752 Mon Sep 17 00:00:00 2001 From: kianaza Date: Mon, 20 May 2024 00:00:04 +0330 Subject: [PATCH 02/10] fix: change client's name --- internal/cmd/main.go | 6 +++--- internal/config/config.go | 6 +++--- internal/config/default.go | 4 ++-- internal/{client => natsClient}/client.go | 14 +++++++------- internal/{client => natsClient}/config.go | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) rename internal/{client => natsClient}/client.go (87%) rename internal/{client => natsClient}/config.go (94%) diff --git a/internal/cmd/main.go b/internal/cmd/main.go index 606bf0e..4a56b35 100644 --- a/internal/cmd/main.go +++ b/internal/cmd/main.go @@ -5,17 +5,17 @@ import ( "os/signal" "syscall" - "github.com/snapp-incubator/nats-blackbox-exporter/internal/client" "github.com/snapp-incubator/nats-blackbox-exporter/internal/config" + "github.com/snapp-incubator/nats-blackbox-exporter/internal/natsClient" "go.uber.org/zap" ) func main(cfg config.Config, logger *zap.Logger) { natsConfig := cfg.NATS - natsClient := client.New(client.Connect(logger, natsConfig), logger, natsConfig) + client := natsClient.New(natsClient.Connect(logger, natsConfig), logger, natsConfig) - natsClient.StartMessaging() + client.StartMessaging() sig := make(chan os.Signal, 1) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) diff --git a/internal/config/config.go b/internal/config/config.go index 12ce330..7f3f031 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -10,8 +10,8 @@ import ( "github.com/knadh/koanf/providers/file" "github.com/knadh/koanf/providers/structs" "github.com/knadh/koanf/v2" - "github.com/snapp-incubator/nats-blackbox-exporter/internal/client" "github.com/snapp-incubator/nats-blackbox-exporter/internal/logger" + "github.com/snapp-incubator/nats-blackbox-exporter/internal/natsClient" "github.com/tidwall/pretty" ) @@ -23,8 +23,8 @@ const ( type ( // Config holds all configurations. Config struct { - Logger logger.Config `json:"logger,omitempty" koanf:"logger"` - NATS client.Config `json:"nats,omitempty" koanf:"nats"` + Logger logger.Config `json:"logger,omitempty" koanf:"logger"` + NATS natsClient.Config `json:"nats,omitempty" koanf:"nats"` } ) diff --git a/internal/config/default.go b/internal/config/default.go index b7ac57c..a66a123 100644 --- a/internal/config/default.go +++ b/internal/config/default.go @@ -3,8 +3,8 @@ package config import ( "time" - "github.com/snapp-incubator/nats-blackbox-exporter/internal/client" "github.com/snapp-incubator/nats-blackbox-exporter/internal/logger" + "github.com/snapp-incubator/nats-blackbox-exporter/internal/natsClient" ) // Default return default configuration. @@ -14,7 +14,7 @@ func Default() Config { Logger: logger.Config{ Level: "debug", }, - NATS: client.Config{ + NATS: natsClient.Config{ URL: "localhost:4222", PublishInterval: 2 * time.Second, RequestTimeout: 50 * time.Millisecond, diff --git a/internal/client/client.go b/internal/natsClient/client.go similarity index 87% rename from internal/client/client.go rename to internal/natsClient/client.go index 285137d..c1f3823 100644 --- a/internal/client/client.go +++ b/internal/natsClient/client.go @@ -1,4 +1,4 @@ -package client +package natsClient import ( "time" @@ -7,7 +7,7 @@ import ( "go.uber.org/zap" ) -type Client struct { +type NatsClient struct { Conn *nats.Conn Logger *zap.Logger Config Config @@ -34,20 +34,20 @@ func Connect(logger *zap.Logger, cfg Config) *nats.Conn { return nc } -func New(nc *nats.Conn, logger *zap.Logger, cfg Config) *Client { - return &Client{ +func New(nc *nats.Conn, logger *zap.Logger, cfg Config) *NatsClient { + return &NatsClient{ Conn: nc, Logger: logger, Config: cfg, } } -func (c *Client) StartMessaging() { +func (c *NatsClient) StartMessaging() { go c.Subscribe("") go c.Publish("") } -func (c *Client) Publish(subject string) { +func (c *NatsClient) Publish(subject string) { if subject == "" { subject = c.Config.DefaultSubject } @@ -69,7 +69,7 @@ func (c *Client) Publish(subject string) { } } -func (c *Client) Subscribe(subject string) { +func (c *NatsClient) Subscribe(subject string) { if subject == "" { subject = c.Config.DefaultSubject } diff --git a/internal/client/config.go b/internal/natsClient/config.go similarity index 94% rename from internal/client/config.go rename to internal/natsClient/config.go index f178c7b..dc9bd29 100644 --- a/internal/client/config.go +++ b/internal/natsClient/config.go @@ -1,4 +1,4 @@ -package client +package natsClient import "time" From c4fedc288ad07bd892aef5d3bf71961780719c4f Mon Sep 17 00:00:00 2001 From: kianaza Date: Mon, 20 May 2024 00:00:28 +0330 Subject: [PATCH 03/10] fix: add DS_Store to gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b25e0c6..3f7c05a 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,6 @@ .idea/ # config -config.yaml \ No newline at end of file +config.yaml + +.DS_Store \ No newline at end of file From 75eb74bbfcd067e26ff80f4f90618e123d7b4620 Mon Sep 17 00:00:00 2001 From: kianaza Date: Mon, 20 May 2024 00:13:36 +0330 Subject: [PATCH 04/10] fix: uncommenting golangci --- .golangci.yml | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index bbc4e3a..45839d5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,27 +1,3 @@ -# --- -# linters: -# enable-all: true -# disable: -# - depguard -# # we don't use json with camel-case -# - tagliatelle -# - nolintlint -# # it should improve to support more known patterns -# - varnamelen -# - ireturn -# # deprecated linters -# - maligned -# - scopelint -# - golint -# - ifshort -# - interfacer -# - exhaustivestruct -# - nosnakecase -# - varcheck -# - deadcode -# - structcheck -# - gomnd -# - execinquery -# # temporarily disabled -# - tagalign -# - gochecknoglobals +--- +linters: + disable-all: true From d342c793bc2388fda81958c9f7c2e1f99293408e Mon Sep 17 00:00:00 2001 From: kianaza Date: Mon, 20 May 2024 18:28:18 +0330 Subject: [PATCH 05/10] fix: upgrade golint and codecov --- .github/workflows/ci.yaml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e138029..7079c7f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,20 +7,22 @@ name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v4 with: version: latest test: name: test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 with: go-version: 1.22 - run: go test -v ./... -covermode=atomic -coverprofile=coverage.out - - uses: codecov/codecov-action@v1 + - uses: codecov/codecov-action@v4.0.1 with: - files: coverage.out \ No newline at end of file + files: coverage.out + token: ${{ secrets.CODECOV_TOKEN }} + slug: snapp-incubator/nats-blackbox-exporter \ No newline at end of file From 5832af1e8e96815cc88e965eac13c32926d200da Mon Sep 17 00:00:00 2001 From: kianaza Date: Mon, 20 May 2024 18:50:58 +0330 Subject: [PATCH 06/10] feat: Simplify linter configuration and fix related issues --- .github/workflows/ci.yaml | 13 ++++++++----- .golangci.yml | 7 ++++++- internal/cmd/main.go | 4 ++-- internal/config/config.go | 4 ++-- internal/config/default.go | 4 ++-- internal/natsClient/client.go | 2 +- internal/natsClient/config.go | 2 +- 7 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7079c7f..f9a82a9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,11 +7,14 @@ name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: golangci-lint - uses: golangci/golangci-lint-action@v4 - with: - version: latest + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '1.20' + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.58 test: name: test runs-on: ubuntu-latest diff --git a/.golangci.yml b/.golangci.yml index 45839d5..a674881 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,8 @@ --- linters: - disable-all: true + enable: + - gofmt + - govet + - revive + - staticcheck + - errcheck \ No newline at end of file diff --git a/internal/cmd/main.go b/internal/cmd/main.go index 4a56b35..eb60349 100644 --- a/internal/cmd/main.go +++ b/internal/cmd/main.go @@ -6,14 +6,14 @@ import ( "syscall" "github.com/snapp-incubator/nats-blackbox-exporter/internal/config" - "github.com/snapp-incubator/nats-blackbox-exporter/internal/natsClient" + "github.com/snapp-incubator/nats-blackbox-exporter/internal/natsclient" "go.uber.org/zap" ) func main(cfg config.Config, logger *zap.Logger) { natsConfig := cfg.NATS - client := natsClient.New(natsClient.Connect(logger, natsConfig), logger, natsConfig) + client := natsclient.New(natsclient.Connect(logger, natsConfig), logger, natsConfig) client.StartMessaging() diff --git a/internal/config/config.go b/internal/config/config.go index 7f3f031..ae5b09b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -11,7 +11,7 @@ import ( "github.com/knadh/koanf/providers/structs" "github.com/knadh/koanf/v2" "github.com/snapp-incubator/nats-blackbox-exporter/internal/logger" - "github.com/snapp-incubator/nats-blackbox-exporter/internal/natsClient" + "github.com/snapp-incubator/nats-blackbox-exporter/internal/natsclient" "github.com/tidwall/pretty" ) @@ -24,7 +24,7 @@ type ( // Config holds all configurations. Config struct { Logger logger.Config `json:"logger,omitempty" koanf:"logger"` - NATS natsClient.Config `json:"nats,omitempty" koanf:"nats"` + NATS natsclient.Config `json:"nats,omitempty" koanf:"nats"` } ) diff --git a/internal/config/default.go b/internal/config/default.go index a66a123..3924ee3 100644 --- a/internal/config/default.go +++ b/internal/config/default.go @@ -4,7 +4,7 @@ import ( "time" "github.com/snapp-incubator/nats-blackbox-exporter/internal/logger" - "github.com/snapp-incubator/nats-blackbox-exporter/internal/natsClient" + "github.com/snapp-incubator/nats-blackbox-exporter/internal/natsclient" ) // Default return default configuration. @@ -14,7 +14,7 @@ func Default() Config { Logger: logger.Config{ Level: "debug", }, - NATS: natsClient.Config{ + NATS: natsclient.Config{ URL: "localhost:4222", PublishInterval: 2 * time.Second, RequestTimeout: 50 * time.Millisecond, diff --git a/internal/natsClient/client.go b/internal/natsClient/client.go index c1f3823..de3a5e5 100644 --- a/internal/natsClient/client.go +++ b/internal/natsClient/client.go @@ -1,4 +1,4 @@ -package natsClient +package natsclient import ( "time" diff --git a/internal/natsClient/config.go b/internal/natsClient/config.go index dc9bd29..357d69e 100644 --- a/internal/natsClient/config.go +++ b/internal/natsClient/config.go @@ -1,4 +1,4 @@ -package natsClient +package natsclient import "time" From 9f9cb9723abe7b3177bde2683b37b79c1b9ca65f Mon Sep 17 00:00:00 2001 From: kianaza Date: Mon, 20 May 2024 18:59:41 +0330 Subject: [PATCH 07/10] fix: Fix go version --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f9a82a9..798920b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,7 +10,7 @@ - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: '1.20' + go-version: '1.22' - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: From e0d174adfe055c42d5e101cfeed1bc0b04daa86a Mon Sep 17 00:00:00 2001 From: kianaza Date: Mon, 20 May 2024 19:06:03 +0330 Subject: [PATCH 08/10] fix: Fix package name --- internal/{natsClient => client}/client.go | 0 internal/{natsClient => client}/config.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename internal/{natsClient => client}/client.go (100%) rename internal/{natsClient => client}/config.go (100%) diff --git a/internal/natsClient/client.go b/internal/client/client.go similarity index 100% rename from internal/natsClient/client.go rename to internal/client/client.go diff --git a/internal/natsClient/config.go b/internal/client/config.go similarity index 100% rename from internal/natsClient/config.go rename to internal/client/config.go From 19452b3aaa884d0490b3203a4cc7fa1efb680b2b Mon Sep 17 00:00:00 2001 From: kianaza Date: Mon, 20 May 2024 19:06:21 +0330 Subject: [PATCH 09/10] fix: Fix package name --- internal/{config => natsconfig}/config.go | 0 internal/{config => natsconfig}/default.go | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename internal/{config => natsconfig}/config.go (100%) rename internal/{config => natsconfig}/default.go (100%) diff --git a/internal/config/config.go b/internal/natsconfig/config.go similarity index 100% rename from internal/config/config.go rename to internal/natsconfig/config.go diff --git a/internal/config/default.go b/internal/natsconfig/default.go similarity index 100% rename from internal/config/default.go rename to internal/natsconfig/default.go From 5691919daf7f68ae06d7c330f58eb33dbeace754 Mon Sep 17 00:00:00 2001 From: kianaza Date: Mon, 20 May 2024 19:09:22 +0330 Subject: [PATCH 10/10] fix: Fix package name --- internal/{natsconfig => config}/config.go | 0 internal/{natsconfig => config}/default.go | 0 internal/{client => natsclient}/client.go | 0 internal/{client => natsclient}/config.go | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename internal/{natsconfig => config}/config.go (100%) rename internal/{natsconfig => config}/default.go (100%) rename internal/{client => natsclient}/client.go (100%) rename internal/{client => natsclient}/config.go (100%) diff --git a/internal/natsconfig/config.go b/internal/config/config.go similarity index 100% rename from internal/natsconfig/config.go rename to internal/config/config.go diff --git a/internal/natsconfig/default.go b/internal/config/default.go similarity index 100% rename from internal/natsconfig/default.go rename to internal/config/default.go diff --git a/internal/client/client.go b/internal/natsclient/client.go similarity index 100% rename from internal/client/client.go rename to internal/natsclient/client.go diff --git a/internal/client/config.go b/internal/natsclient/config.go similarity index 100% rename from internal/client/config.go rename to internal/natsclient/config.go