Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issues from Previous Pull Request #2

Merged
merged 10 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: latest
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
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
files: coverage.out
token: ${{ secrets.CODECOV_TOKEN }}
slug: snapp-incubator/nats-blackbox-exporter
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
.idea/

# config
config.yaml
config.yaml

.DS_Store
35 changes: 8 additions & 27 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
# ---
# 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:
enable:
- gofmt
- govet
- revive
- staticcheck
- errcheck
Binary file removed internal/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions internal/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"`
}
)

Expand Down
4 changes: 2 additions & 2 deletions internal/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions internal/client/client.go → internal/natsclient/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package natsclient

import (
"time"
Expand All @@ -7,7 +7,7 @@ import (
"go.uber.org/zap"
)

type Client struct {
type NatsClient struct {
Conn *nats.Conn
Logger *zap.Logger
Config Config
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package natsclient

import "time"

Expand Down
Loading