Skip to content

Commit b636718

Browse files
committed
chore!: update to golangci-lint-action 7
1 parent b250bd9 commit b636718

7 files changed

Lines changed: 26 additions & 23 deletions

File tree

.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

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 & 5 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) {

phpmainthread.go

Lines changed: 1 addition & 1 deletion
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)

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

worker_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package frankenphp_test
22

33
import (
44
"fmt"
5+
"github.com/stretchr/testify/require"
56
"io"
67
"log"
78
"net/http"
@@ -139,7 +140,8 @@ func ExampleServeHTTP_workers() {
139140
}
140141

141142
func TestWorkerHasOSEnvironmentVariableInSERVER(t *testing.T) {
142-
os.Setenv("CUSTOM_OS_ENV_VARIABLE", "custom_env_variable_value")
143+
require.NoError(t, os.Setenv("CUSTOM_OS_ENV_VARIABLE", "custom_env_variable_value"))
144+
143145
runTest(t, func(handler func(http.ResponseWriter, *http.Request), _ *httptest.Server, i int) {
144146
req := httptest.NewRequest("GET", "http://example.com/worker.php", nil)
145147
w := httptest.NewRecorder()

0 commit comments

Comments
 (0)