Compare commits
2 Commits
b0e34e34fa
...
eb9f28e341
| Author | SHA1 | Date | |
|---|---|---|---|
| eb9f28e341 | |||
| 4919334aaa |
@@ -1,7 +1,7 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
|
||||
# Build stage
|
||||
FROM golang:1.22-alpine AS builder
|
||||
FROM golang:1.24-alpine AS builder
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go mod files and download dependencies
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
"strconv"
|
||||
"crypto/rand"
|
||||
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/go-redis/redis/v8"
|
||||
@@ -52,7 +52,7 @@ func main() {
|
||||
opts.AddBroker(fmt.Sprintf("tcp://%s:%s", mqttHost, mqttPort))
|
||||
opts.SetUsername(mqttUser)
|
||||
opts.SetPassword(mqttPass)
|
||||
opts.SetClientID("mqtt_presence_redis_go")
|
||||
opts.SetClientID(fmt.Sprintf("mqtt_presence_redis_go_%s", randomString()))
|
||||
|
||||
// Handlers
|
||||
opts.SetDefaultPublishHandler(func(client mqtt.Client, msg mqtt.Message) {
|
||||
@@ -114,10 +114,11 @@ func getEnv(key, defaultVal string) string {
|
||||
return defaultVal
|
||||
}
|
||||
|
||||
func atoi(s string) int {
|
||||
i, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return 0
|
||||
func randomString() string {
|
||||
b := make([]byte, 4)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
log.Printf("Failed to generate random string: %v", err)
|
||||
return ""
|
||||
}
|
||||
return i
|
||||
return hex.EncodeToString(b)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user