Skip to content

Commit

Permalink
fix failing linter
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene committed Dec 11, 2024
1 parent f183783 commit 3044374
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 29 deletions.
9 changes: 2 additions & 7 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ func main() {
ctx, cancel := context.WithCancel(ctx)
defer cancel()

// Set up signal handling
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

logger := slog.New(slog.NewTextHandler(os.Stdout, nil))

// Loading .env file to environment
err := godotenv.Load()
if err != nil {
panic(err)
Expand All @@ -44,26 +42,23 @@ func main() {

cfgH, err := config.LoadHTTPConfig(env.Options{Prefix: httpPrefix})
if err != nil {
logger.Error("Failed to load HTTP configuration", slog.Any("error", err))
logger.Error("Failed to load HTTP configuration", slog.Any("error", err))
os.Exit(1)
}

// Create proxy service
service, err := proxy.NewService(ctx, cfgM,cfgH, logger)
service, err := proxy.NewService(ctx, cfgM, cfgH, logger)
if err != nil {
logger.Error("failed to create proxy service", "error", err)
os.Exit(1)
}

// Start the service
go func() {
if err := start(ctx, service); err != nil {
logger.Error("service error", "error", err)
cancel()
}
}()

// Wait for signal
<-sigChan
cancel()
}
Expand Down
27 changes: 9 additions & 18 deletions proxy/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ type RegistryClient struct {
config *config.MQTTProxyConfig
}

func NewMQTTClient(config *config.MQTTProxyConfig) (*RegistryClient, error) {
fmt.Printf("config is %+v\n", config)
func NewMQTTClient(cfg *config.MQTTProxyConfig) (*RegistryClient, error) {
opts := mqtt.NewClientOptions().
AddBroker(config.BrokerURL).
SetClientID(fmt.Sprintf("Proplet-%s", config.PropletID)).
SetUsername(config.PropletID).
SetPassword(config.Password).
AddBroker(cfg.BrokerURL).
SetClientID(fmt.Sprintf("Proplet-%s", cfg.PropletID)).
SetUsername(cfg.PropletID).
SetPassword(cfg.Password).
SetCleanSession(true).
SetAutoReconnect(true).
SetConnectTimeout(10 * time.Second).

Check failure on line 27 in proxy/mqtt/mqtt.go

View workflow job for this annotation

GitHub Actions / Lint and Build

Magic number: 10, in <argument> detected (mnd)
Expand All @@ -40,7 +39,7 @@ func NewMQTTClient(config *config.MQTTProxyConfig) (*RegistryClient, error) {

return &RegistryClient{
client: client,
config: config,
config: cfg,
}, nil
}

Expand All @@ -61,7 +60,6 @@ func (c *RegistryClient) Connect(ctx context.Context) error {

func (c *RegistryClient) Subscribe(ctx context.Context, containerChan chan<- string) error {
subTopic := fmt.Sprintf("channels/%s/message/registry/proplet", c.config.ChannelID)
fmt.Printf("subtopic is %+v\n", subTopic)
handler := func(client mqtt.Client, msg mqtt.Message) {
data := msg.Payload()

Expand Down Expand Up @@ -95,7 +93,6 @@ func (c *RegistryClient) Subscribe(ctx context.Context, containerChan chan<- str
return nil
}

// PublishContainer publishes container data to the server channel
func (c *RegistryClient) PublishContainer(ctx context.Context, containerData []byte) error {
pubTopic := fmt.Sprintf("channels/%s/messages/registry/server", c.config.ChannelID)

Expand All @@ -113,17 +110,11 @@ func (c *RegistryClient) PublishContainer(ctx context.Context, containerData []b
}

func (c *RegistryClient) Disconnect(ctx context.Context) error {
disconnectChan := make(chan error, 1)

go func() {
c.client.Disconnect(250)
disconnectChan <- nil
}()

select {
case err := <-disconnectChan:
return err
case <-ctx.Done():
return ctx.Err()
default:
c.client.Disconnect(250)

Check failure on line 117 in proxy/mqtt/mqtt.go

View workflow job for this annotation

GitHub Actions / Lint and Build

Magic number: 250, in <argument> detected (mnd)
return nil
}
}
4 changes: 0 additions & 4 deletions proxy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ func NewService(ctx context.Context, cfgM *config.MQTTProxyConfig, cfgH *config.
}, nil
}

// MQTTClient returns the MQTT client
func (s *ProxyService) MQTTClient() *mqtt.RegistryClient {
return s.mqttClient
}

// ContainerChan returns the container channel
func (s *ProxyService) ContainerChan() chan string {
return s.containerChan
}

// StreamHTTP handles the HTTP stream processing
func (s *ProxyService) StreamHTTP(ctx context.Context, errs chan error) {
for {
select {
Expand All @@ -67,7 +64,6 @@ func (s *ProxyService) StreamHTTP(ctx context.Context, errs chan error) {
}
}

// StreamMQTT handles the MQTT stream processing
func (s *ProxyService) StreamMQTT(ctx context.Context, errs chan error) {
for {
select {
Expand Down

0 comments on commit 3044374

Please sign in to comment.