Skip to content

Commit 85196e1

Browse files
jrouzierinverseJeGoi
authored andcommitted
Update to golang 1.24.1 and update tests to pass go vet ./...
1 parent 5d69fb6 commit 85196e1

File tree

15 files changed

+65
-60
lines changed

15 files changed

+65
-60
lines changed

config.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ LOCAL_REGISTRY = packetfence
5252
#
5353
# Golang
5454
#
55-
GOVERSION = go1.23.4
55+
GOVERSION = go1.24.1
5656
PF_BINARIES = pfhttpd pfqueue-go pfdhcp pfdns pfstats pfdetect galera-autofix pfacct pfcron mysql-probe pfconnector sdnotify-proxy
5757
PF_GO_CMDS = pfcrypt pfkafka
5858

containers/pfsetacls/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.23.1-bookworm AS build
1+
FROM golang:1.24.1-bookworm AS build
22

33
ENV SEMAPHORE_VERSION="development" SEMAPHORE_ARCH="linux_amd64" \
44
SEMAPHORE_CONFIG_PATH="${SEMAPHORE_CONFIG_PATH:-/etc/semaphore}" \

go/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ go-env:
1212
.PHONY: test
1313
test:
1414
/usr/local/pf/t/pfconfig-test ;\
15-
PF_SYSTEM_INIT_KEY=$$(cat ../t/data/system_init_key) PFCONFIG_PROTO=unix PFCONFIG_TESTING=y $(GO) test -count=1 ./...
15+
GODEBUG=randseednop=0 PF_SYSTEM_INIT_KEY=$$(cat ../t/data/system_init_key) PFCONFIG_PROTO=unix PFCONFIG_TESTING=y $(GO) test -count=1 ./...
1616

1717
CMDS = $(wildcard cmd/*)
1818
ALL_BINARIES = $(patsubst cmd/%, %, $(CMDS))

go/chisel/share/cio/logger.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
)
88

9-
//Logger is pkg/log Logger with prefixing and 2 log levels
9+
// Logger is pkg/log Logger with prefixing and 2 log levels
1010
type Logger struct {
1111
Info, Debug bool
1212
//internal
@@ -30,7 +30,8 @@ func NewLoggerFlag(prefix string, flag int) *Logger {
3030
}
3131

3232
func (l *Logger) Printf(f string, args ...interface{}) {
33-
l.logger.Printf(l.prefix+": "+f, args...)
33+
f = l.prefix + ": " + f
34+
l.logger.Printf(f, args...)
3435
}
3536

3637
func (l *Logger) Infof(f string, args ...interface{}) {
@@ -47,7 +48,7 @@ func (l *Logger) Debugf(f string, args ...interface{}) {
4748

4849
func (l *Logger) IfDebug(f func() string) {
4950
if l.IsDebug() {
50-
l.logger.Printf(l.prefix + ": " + f())
51+
l.logger.Printf("%s", l.prefix+": "+f())
5152
}
5253
}
5354

go/cmd/pfacct/timeBalance_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package main
22

33
import (
4-
"github.com/inverse-inc/go-utils/mac"
54
"testing"
5+
6+
"github.com/inverse-inc/go-utils/mac"
67
)
78

89
func TestMacSesssion(t *testing.T) {
@@ -14,15 +15,15 @@ func TestMacSesssion(t *testing.T) {
1415

1516
mac, err := mac.NewFromString("99:77:55:44:33:22")
1617
if err != nil {
17-
t.Fatalf(err.Error())
18+
t.Fatalf("%s", err.Error())
1819
}
1920

2021
if _, err := pfAcct.Db.Exec("DELETE FROM node WHERE mac = ?", mac.String()); err != nil {
21-
t.Fatalf(err.Error())
22+
t.Fatalf("%s", err.Error())
2223
}
2324

2425
if _, err := pfAcct.Db.Exec("INSERT INTO node (mac, time_balance, bandwidth_balance) VALUES (?, ?, ?)", mac.String(), 100, 100); err != nil {
25-
t.Fatalf(err.Error())
26+
t.Fatalf("%s", err.Error())
2627
}
2728

2829
pfAcct.setNodeSessionCache(sessionId, &nodeSession{timeBalance: 100, bandwidthBalance: 100})
@@ -45,7 +46,7 @@ func TestMacSesssion(t *testing.T) {
4546
}
4647

4748
if updated, err := pfAcct.SoftNodeTimeBalanceUpdate(mac, 100); err != nil {
48-
t.Fatalf(err.Error())
49+
t.Fatalf("%s", err.Error())
4950
} else if !updated {
5051
t.Fatalf("SoftNodeTimeBalanceUpdate failed for '%s'", mac)
5152
}

go/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/inverse-inc/packetfence/go
22

3-
go 1.23.4
3+
go 1.24.1
44

55
require (
66
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible // indirect

go/logging/logging.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package logging
22

33
import (
44
"context"
5-
log "github.com/inconshreveable/log15"
6-
"github.com/nu7hatch/gouuid"
75
"os"
86
"strconv"
7+
8+
log "github.com/inconshreveable/log15"
9+
uuid "github.com/nu7hatch/gouuid"
910
)
1011

1112
const requestUuidKey = "request-uuid"
@@ -54,6 +55,5 @@ func AddToLogContext(ctx context.Context, args ...interface{}) context.Context {
5455
key = o
5556
}
5657
}
57-
context.WithValue(ctx, additionnalLogElementsKey, additionnalLogElements)
58-
return ctx
58+
return context.WithValue(ctx, additionnalLogElementsKey, additionnalLogElements)
5959
}

go/pfconfigdriver/fetch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func FetchSocket(ctx context.Context, payload string) []byte {
133133
c := connectSocket(ctx)
134134

135135
// Send our query in the socket
136-
fmt.Fprintf(c, payload)
136+
io.WriteString(c, payload)
137137

138138
var buf bytes.Buffer
139139
buf.ReadFrom(c)

go/plugin/caddy2/api-aaa/api-aaa.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ func (h ApiAAAHandler) handleLogin(w http.ResponseWriter, r *http.Request, p htt
236236
res, _ := json.Marshal(map[string]string{
237237
"token": token,
238238
})
239-
fmt.Fprintf(w, string(res))
239+
w.Write(res)
240240
} else {
241241
w.WriteHeader(http.StatusUnauthorized)
242242
res, _ := json.Marshal(map[string]string{
243243
"message": err.Error(),
244244
})
245-
fmt.Fprintf(w, string(res))
245+
w.Write(res)
246246
}
247247
}
248248

@@ -281,13 +281,13 @@ func (h ApiAAAHandler) handleTokenInfo(w http.ResponseWriter, r *http.Request, p
281281
res, _ := json.Marshal(map[string]interface{}{
282282
"item": prettyInfo,
283283
})
284-
fmt.Fprintf(w, string(res))
284+
w.Write(res)
285285
} else {
286286
w.WriteHeader(http.StatusNotFound)
287287
res, _ := json.Marshal(map[string]string{
288288
"message": "Couldn't find any information for the current token. Either it is invalid or it has expired.",
289289
})
290-
fmt.Fprintf(w, string(res))
290+
w.Write(res)
291291
}
292292
}
293293

@@ -322,7 +322,7 @@ func (h ApiAAAHandler) HandleAAA(w http.ResponseWriter, r *http.Request) bool {
322322
res, _ := json.Marshal(map[string]string{
323323
"message": err.Error(),
324324
})
325-
fmt.Fprintf(w, string(res))
325+
w.Write(res)
326326
return false
327327
}
328328
r.Header.Set("Authorization", "Bearer "+token)
@@ -340,7 +340,7 @@ func (h ApiAAAHandler) HandleAAA(w http.ResponseWriter, r *http.Request) bool {
340340
res, _ := json.Marshal(map[string]string{
341341
"message": err.Error(),
342342
})
343-
fmt.Fprintf(w, string(res))
343+
w.Write(res)
344344
return false
345345
}
346346

@@ -359,7 +359,7 @@ func (h ApiAAAHandler) HandleAAA(w http.ResponseWriter, r *http.Request) bool {
359359
res, _ := json.Marshal(map[string]string{
360360
"message": err.Error(),
361361
})
362-
fmt.Fprintf(w, string(res))
362+
w.Write(res)
363363
return false
364364
}
365365
}

go/plugin/caddy2/api/dal_admin_api_audit_log.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func outputResult(w http.ResponseWriter, body RespBody) {
4545
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
4646
w.WriteHeader(body.Status)
4747
res, _ := json.Marshal(body)
48-
fmt.Fprintf(w, string(res))
48+
w.Write(res)
4949
}
5050

5151
func (a *AdminApiAuditLog) List(w http.ResponseWriter, r *http.Request, p httprouter.Params) {

go/plugin/caddy2/api/fleetdm_events.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package api
33
import (
44
"context"
55
"encoding/json"
6-
"fmt"
7-
"github.com/inverse-inc/packetfence/go/pfqueueclient"
8-
"github.com/julienschmidt/httprouter"
96
"io/ioutil"
107
"net/http"
8+
9+
"github.com/inverse-inc/packetfence/go/pfqueueclient"
10+
"github.com/julienschmidt/httprouter"
1111
)
1212

1313
func (h APIHandler) Policy(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
@@ -17,7 +17,7 @@ func (h APIHandler) Policy(w http.ResponseWriter, r *http.Request, p httprouter.
1717
res, _ := json.Marshal(map[string]string{
1818
"message": "Failed to read request body: " + err.Error(),
1919
})
20-
fmt.Fprintf(w, string(res))
20+
w.Write(res)
2121
return
2222
}
2323
defer r.Body.Close()
@@ -33,15 +33,15 @@ func (h APIHandler) Policy(w http.ResponseWriter, r *http.Request, p httprouter.
3333
res, _ := json.Marshal(map[string]string{
3434
"message": "failed to write policy violation event to pfqueue: " + err.Error(),
3535
})
36-
fmt.Fprintf(w, string(res))
36+
w.Write(res)
3737
return
3838
}
3939

4040
w.WriteHeader(http.StatusAccepted)
4141
res, _ := json.Marshal(map[string]string{
4242
"task_key": taskKey,
4343
})
44-
fmt.Fprintf(w, string(res))
44+
w.Write(res)
4545
return
4646
}
4747

@@ -52,7 +52,7 @@ func (h APIHandler) CVE(w http.ResponseWriter, r *http.Request, p httprouter.Par
5252
res, _ := json.Marshal(map[string]string{
5353
"message": "Failed to read request body: " + err.Error(),
5454
})
55-
fmt.Fprintf(w, string(res))
55+
w.Write(res)
5656
return
5757
}
5858
defer r.Body.Close()
@@ -68,14 +68,14 @@ func (h APIHandler) CVE(w http.ResponseWriter, r *http.Request, p httprouter.Par
6868
res, _ := json.Marshal(map[string]string{
6969
"message": "failed to write CVE event to pfqueue: " + err.Error(),
7070
})
71-
fmt.Fprintf(w, string(res))
71+
w.Write(res)
7272
return
7373
}
7474

7575
w.WriteHeader(http.StatusAccepted)
7676
res, _ := json.Marshal(map[string]string{
7777
"task_key": taskKey,
7878
})
79-
fmt.Fprintf(w, string(res))
79+
w.Write(res)
8080
return
8181
}

go/plugin/caddy2/api/ntlm.go

+16-18
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"fmt"
8-
"github.com/inverse-inc/packetfence/go/ntlm"
9-
"github.com/julienschmidt/httprouter"
107
"net/http"
118
"os"
9+
10+
"github.com/inverse-inc/packetfence/go/ntlm"
11+
"github.com/julienschmidt/httprouter"
1212
)
1313

1414
type PasswordChangeEvent struct {
@@ -42,7 +42,7 @@ func (h APIHandler) eventReport(w http.ResponseWriter, r *http.Request, p httpro
4242
Message: "Unable to connect to pfconfig service",
4343
}
4444
j, _ := json.Marshal(res)
45-
fmt.Fprintf(w, string(j))
45+
w.Write(j)
4646
return
4747
}
4848

@@ -57,7 +57,7 @@ func (h APIHandler) eventReport(w http.ResponseWriter, r *http.Request, p httpro
5757
Message: "Unknown payload format, expected Domain and Events JSON",
5858
}
5959
j, _ := json.Marshal(res)
60-
fmt.Fprintf(w, string(j))
60+
w.Write(j)
6161
return
6262
}
6363

@@ -76,7 +76,7 @@ func (h APIHandler) eventReport(w http.ResponseWriter, r *http.Request, p httpro
7676
Message: "Unknown domain " + req.Domain + ", record not found",
7777
}
7878
j, _ := json.Marshal(res)
79-
fmt.Fprintf(w, string(j))
79+
w.Write(j)
8080
return
8181
}
8282

@@ -88,7 +88,7 @@ func (h APIHandler) eventReport(w http.ResponseWriter, r *http.Request, p httpro
8888
Message: "Unable to find listening port for domain " + req.Domain,
8989
}
9090
j, _ := json.Marshal(res)
91-
fmt.Fprintf(w, string(j))
91+
w.Write(j)
9292
return
9393
}
9494

@@ -100,7 +100,7 @@ func (h APIHandler) eventReport(w http.ResponseWriter, r *http.Request, p httpro
100100
Message: err.Error(),
101101
}
102102
j, _ := json.Marshal(res)
103-
fmt.Fprintf(w, string(j))
103+
w.Write(j)
104104
return
105105
}
106106

@@ -110,8 +110,7 @@ func (h APIHandler) eventReport(w http.ResponseWriter, r *http.Request, p httpro
110110
Message: "Event reported",
111111
}
112112
j, _ := json.Marshal(res)
113-
fmt.Fprintf(w, string(j))
114-
113+
w.Write(j)
115114
}
116115

117116
func (h APIHandler) ntlmTest(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
@@ -134,7 +133,7 @@ func (h APIHandler) ntlmTest(w http.ResponseWriter, r *http.Request, p httproute
134133
Message: "Unable to connect to pfconfig service",
135134
}
136135
j, _ := json.Marshal(res)
137-
fmt.Fprintf(w, string(j))
136+
w.Write(j)
138137
return
139138
}
140139

@@ -149,7 +148,7 @@ func (h APIHandler) ntlmTest(w http.ResponseWriter, r *http.Request, p httproute
149148
Message: "Unknown payload format, expected JSON format with id and password",
150149
}
151150
j, _ := json.Marshal(res)
152-
fmt.Fprintf(w, string(j))
151+
w.Write(j)
153152
return
154153
}
155154

@@ -168,7 +167,7 @@ func (h APIHandler) ntlmTest(w http.ResponseWriter, r *http.Request, p httproute
168167
Message: "Unknown domain " + req.Id + ", record not found",
169168
}
170169
j, _ := json.Marshal(res)
171-
fmt.Fprintf(w, string(j))
170+
w.Write(j)
172171
return
173172
}
174173

@@ -180,7 +179,7 @@ func (h APIHandler) ntlmTest(w http.ResponseWriter, r *http.Request, p httproute
180179
Message: "Unable to find listening port for domain " + req.Id,
181180
}
182181
j, _ := json.Marshal(res)
183-
fmt.Fprintf(w, string(j))
182+
w.Write(j)
184183
return
185184
}
186185

@@ -192,7 +191,7 @@ func (h APIHandler) ntlmTest(w http.ResponseWriter, r *http.Request, p httproute
192191
Message: err.Error(),
193192
}
194193
j, _ := json.Marshal(res)
195-
fmt.Fprintf(w, string(j))
194+
w.Write(j)
196195
return
197196
}
198197

@@ -203,7 +202,7 @@ func (h APIHandler) ntlmTest(w http.ResponseWriter, r *http.Request, p httproute
203202
Message: "Machine account check failed",
204203
}
205204
j, _ := json.Marshal(res)
206-
fmt.Fprintf(w, string(j))
205+
w.Write(j)
207206
return
208207
}
209208

@@ -213,6 +212,5 @@ func (h APIHandler) ntlmTest(w http.ResponseWriter, r *http.Request, p httproute
213212
Message: "Machine account test OK",
214213
}
215214
j, _ := json.Marshal(res)
216-
fmt.Fprintf(w, string(j))
217-
215+
w.Write(j)
218216
}

0 commit comments

Comments
 (0)