Skip to content

Commit

Permalink
Merge branch 'initial-dev' of https://github.com/snapp-incubator/nats…
Browse files Browse the repository at this point in the history
…-blackbox-exporter into initial-metric
  • Loading branch information
kianaza committed May 20, 2024
2 parents 54cfd04 + 5691919 commit 044abe4
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 49 deletions.
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
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(logger, natsConfig)
client := natsclient.New(logger, natsConfig)

natsClient.StartMessaging()
client.StartMessaging()

sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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/metric"
"github.com/snapp-incubator/nats-blackbox-exporter/internal/natsclient"
"github.com/tidwall/pretty"
)

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,9 +3,9 @@ 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/metric"
"github.com/snapp-incubator/nats-blackbox-exporter/internal/natsclient"
)

// Default return default configuration.
Expand All @@ -15,7 +15,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
23 changes: 18 additions & 5 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 Down Expand Up @@ -51,12 +51,25 @@ func connect(logger *zap.Logger, cfg Config) *nats.Conn {
return nc
}

func (c *Client) StartMessaging() {
func (c *NatsClient) StartMessaging() {
go c.Subscribe("")
go c.Publish("")
}

func (c *Client) Publish(subject string) {
func New(nc *nats.Conn, logger *zap.Logger, cfg Config) *NatsClient {
return &NatsClient{
Conn: nc,
Logger: logger,
Config: cfg,
}
}

func (c *NatsClient) StartMessaging() {
go c.Subscribe("")
go c.Publish("")
}

func (c *NatsClient) Publish(subject string) {
if subject == "" {
subject = c.Config.DefaultSubject
}
Expand All @@ -82,7 +95,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
File renamed without changes.

0 comments on commit 044abe4

Please sign in to comment.