Skip to content

Commit 8092f4a

Browse files
authored
chore!: update to golangci-lint-action 7 (#1508)
1 parent b250bd9 commit 8092f4a

File tree

14 files changed

+42
-52
lines changed

14 files changed

+42
-52
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868
- name: Run integrations tests
6969
run: ./reload_test.sh
7070
- name: Lint Go code
71-
uses: golangci/golangci-lint-action@v6
71+
uses: golangci/golangci-lint-action@v7
7272
if: matrix.php-versions == '8.4'
7373
with:
7474
version: latest

caddy/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (admin *FrankenPHPAdmin) restartWorkers(w http.ResponseWriter, r *http.Requ
4444
return nil
4545
}
4646

47-
func (admin *FrankenPHPAdmin) threads(w http.ResponseWriter, r *http.Request) error {
47+
func (admin *FrankenPHPAdmin) threads(w http.ResponseWriter, _ *http.Request) error {
4848
debugState := frankenphp.DebugState()
4949
prettyJson, err := json.MarshalIndent(debugState, "", " ")
5050
if err != nil {

cgi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func packCgiVariable(key *C.zend_string, value string) C.ht_key_value_pair {
168168
return C.ht_key_value_pair{key, toUnsafeChar(value), C.size_t(len(value))}
169169
}
170170

171-
func addHeadersToServer(thread *phpThread, fc *frankenPHPContext, trackVarsArray *C.zval) {
171+
func addHeadersToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
172172
for field, val := range fc.request.Header {
173173
if k := mainThread.commonHeaders[field]; k != nil {
174174
v := strings.Join(val, ", ")
@@ -197,7 +197,7 @@ func go_register_variables(threadIndex C.uintptr_t, trackVarsArray *C.zval) {
197197
fc := thread.getRequestContext()
198198

199199
addKnownVariablesToServer(thread, fc, trackVarsArray)
200-
addHeadersToServer(thread, fc, trackVarsArray)
200+
addHeadersToServer(fc, trackVarsArray)
201201

202202
// The Prepared Environment is registered last and can overwrite any previous values
203203
addPreparedEnvToServer(fc, trackVarsArray)

frankenphp.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ type contextKeyStruct struct{}
5555
var contextKey = contextKeyStruct{}
5656

5757
var (
58-
InvalidRequestError = errors.New("not a FrankenPHP request")
59-
AlreadyStartedError = errors.New("FrankenPHP is already started")
60-
InvalidPHPVersionError = errors.New("FrankenPHP is only compatible with PHP 8.2+")
61-
MainThreadCreationError = errors.New("error creating the main thread")
62-
RequestContextCreationError = errors.New("error during request context creation")
63-
ScriptExecutionError = errors.New("error during PHP script execution")
64-
NotRunningError = errors.New("FrankenPHP is not running. For proper configuration visit: https://frankenphp.dev/docs/config/#caddyfile-config")
58+
ErrInvalidRequest = errors.New("not a FrankenPHP request")
59+
ErrAlreadyStarted = errors.New("FrankenPHP is already started")
60+
ErrInvalidPHPVersion = errors.New("FrankenPHP is only compatible with PHP 8.2+")
61+
ErrMainThreadCreation = errors.New("error creating the main thread")
62+
ErrRequestContextCreation = errors.New("error during request context creation")
63+
ErrScriptExecution = errors.New("error during PHP script execution")
64+
ErrNotRunning = errors.New("FrankenPHP is not running. For proper configuration visit: https://frankenphp.dev/docs/config/#caddyfile-config")
6565

6666
isRunning bool
6767

@@ -189,7 +189,7 @@ func calculateMaxThreads(opt *opt) (int, int, int, error) {
189189
return opt.numThreads, numWorkers, opt.maxThreads, nil
190190
}
191191

192-
if !numThreadsIsSet && !maxThreadsIsSet {
192+
if !numThreadsIsSet {
193193
if numWorkers >= maxProcs {
194194
// Start at least as many threads as workers, and keep a free thread to handle requests in non-worker mode
195195
opt.numThreads = numWorkers + 1
@@ -218,7 +218,7 @@ func calculateMaxThreads(opt *opt) (int, int, int, error) {
218218
// Init starts the PHP runtime and the configured workers.
219219
func Init(options ...Option) error {
220220
if isRunning {
221-
return AlreadyStartedError
221+
return ErrAlreadyStarted
222222
}
223223
isRunning = true
224224

@@ -265,7 +265,7 @@ func Init(options ...Option) error {
265265
config := Config()
266266

267267
if config.Version.MajorVersion < 8 || (config.Version.MajorVersion == 8 && config.Version.MinorVersion < 2) {
268-
return InvalidPHPVersionError
268+
return ErrInvalidPHPVersion
269269
}
270270

271271
if config.ZTS {
@@ -381,7 +381,7 @@ func updateServerContext(thread *phpThread, fc *frankenPHPContext, isWorkerReque
381381
)
382382

383383
if ret > 0 {
384-
return RequestContextCreationError
384+
return ErrRequestContextCreation
385385
}
386386

387387
return nil
@@ -390,12 +390,12 @@ func updateServerContext(thread *phpThread, fc *frankenPHPContext, isWorkerReque
390390
// ServeHTTP executes a PHP script according to the given context.
391391
func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
392392
if !isRunning {
393-
return NotRunningError
393+
return ErrNotRunning
394394
}
395395

396396
fc, ok := fromContext(request.Context())
397397
if !ok {
398-
return InvalidRequestError
398+
return ErrInvalidRequest
399399
}
400400

401401
fc.responseWriter = responseWriter

frankenphp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ func testFileUpload(t *testing.T, opts *testOptions) {
754754
_, err := part.Write([]byte("bar"))
755755
require.NoError(t, err)
756756

757-
writer.Close()
757+
require.NoError(t, writer.Close())
758758

759759
req := httptest.NewRequest("POST", "http://example.com/file-upload.php", requestBody)
760760
req.Header.Add("Content-Type", writer.FormDataContentType())

internal/watcher/watcher.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,23 @@ var failureMu = sync.Mutex{}
3737
var watcherIsActive = atomic.Bool{}
3838

3939
var (
40+
ErrAlreadyStarted = errors.New("the watcher is already running")
41+
ErrUnableToStartWatching = errors.New("unable to start the watcher")
42+
4043
// the currently active file watcher
4144
activeWatcher *watcher
4245
// after stopping the watcher we will wait for eventual reloads to finish
4346
reloadWaitGroup sync.WaitGroup
4447
// we are passing the logger from the main package to the watcher
45-
logger *zap.Logger
46-
AlreadyStartedError = errors.New("the watcher is already running")
47-
UnableToStartWatching = errors.New("unable to start the watcher")
48+
logger *zap.Logger
4849
)
4950

5051
func InitWatcher(filePatterns []string, callback func(), zapLogger *zap.Logger) error {
5152
if len(filePatterns) == 0 {
5253
return nil
5354
}
5455
if watcherIsActive.Load() {
55-
return AlreadyStartedError
56+
return ErrAlreadyStarted
5657
}
5758
watcherIsActive.Store(true)
5859
logger = zapLogger
@@ -142,7 +143,7 @@ func startSession(w *watchPattern) (C.uintptr_t, error) {
142143
}
143144
logger.Error("couldn't start watching", zap.String("dir", w.dir))
144145

145-
return watchSession, UnableToStartWatching
146+
return watchSession, ErrUnableToStartWatching
146147
}
147148

148149
func stopSession(session C.uintptr_t) {
@@ -186,7 +187,6 @@ func listenForFileEvents(triggerWatcher chan string, stopWatcher chan struct{})
186187
for {
187188
select {
188189
case <-stopWatcher:
189-
break
190190
case lastChangedFile = <-triggerWatcher:
191191
timer.Reset(debounceDuration)
192192
case <-timer.C:

metrics.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
const (
1212
StopReasonCrash = iota
1313
StopReasonRestart
14-
StopReasonShutdown
14+
//StopReasonShutdown
1515
)
1616

1717
type StopReason int
@@ -74,9 +74,9 @@ func (n nullMetrics) StartWorkerRequest(string) {
7474
func (n nullMetrics) Shutdown() {
7575
}
7676

77-
func (n nullMetrics) QueuedWorkerRequest(name string) {}
77+
func (n nullMetrics) QueuedWorkerRequest(string) {}
7878

79-
func (n nullMetrics) DequeuedWorkerRequest(name string) {}
79+
func (n nullMetrics) DequeuedWorkerRequest(string) {}
8080

8181
func (n nullMetrics) QueuedRequest() {}
8282
func (n nullMetrics) DequeuedRequest() {}
@@ -127,9 +127,10 @@ func (m *PrometheusMetrics) StopWorker(name string, reason StopReason) {
127127
m.totalWorkers.WithLabelValues(name).Dec()
128128
m.readyWorkers.WithLabelValues(name).Dec()
129129

130-
if reason == StopReasonCrash {
130+
switch reason {
131+
case StopReasonCrash:
131132
m.workerCrashes.WithLabelValues(name).Inc()
132-
} else if reason == StopReasonRestart {
133+
case StopReasonRestart:
133134
m.workerRestarts.WithLabelValues(name).Inc()
134135
}
135136
}

phpmainthread.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func drainPHPThreads() {
107107

108108
func (mainThread *phpMainThread) start() error {
109109
if C.frankenphp_new_main_thread(C.int(mainThread.numThreads)) != 0 {
110-
return MainThreadCreationError
110+
return ErrMainThreadCreation
111111
}
112112

113113
mainThread.state.waitFor(stateReady)
@@ -144,15 +144,6 @@ func getInactivePHPThread() *phpThread {
144144
return nil
145145
}
146146

147-
func getPHPThreadAtState(state stateID) *phpThread {
148-
for _, thread := range phpThreads {
149-
if thread.state.is(state) {
150-
return thread
151-
}
152-
}
153-
return nil
154-
}
155-
156147
//export go_frankenphp_main_thread_is_ready
157148
func go_frankenphp_main_thread_is_ready() {
158149
mainThread.setAutomaticMaxThreads()

phpmainthread_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func allPossibleTransitions(worker1Path string, worker2Path string) []func(*phpT
220220

221221
func TestCorrectThreadCalculation(t *testing.T) {
222222
maxProcs := runtime.GOMAXPROCS(0) * 2
223-
oneWorkerThread := []workerOpt{workerOpt{num: 1}}
223+
oneWorkerThread := []workerOpt{{num: 1}}
224224

225225
// default values
226226
testThreadCalculation(t, maxProcs, maxProcs, &opt{})

phpthread.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func go_frankenphp_before_script_execution(threadIndex C.uintptr_t) *C.char {
149149
func go_frankenphp_after_script_execution(threadIndex C.uintptr_t, exitStatus C.int) {
150150
thread := phpThreads[threadIndex]
151151
if exitStatus < 0 {
152-
panic(ScriptExecutionError)
152+
panic(ErrScriptExecution)
153153
}
154154
thread.handler.afterScriptExecution(int(exitStatus))
155155

0 commit comments

Comments
 (0)