Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: various cleanups #1114

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions caddy/caddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ type FrankenPHPApp struct {
}

// CaddyModule returns the Caddy module information.
func (a FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
func (f FrankenPHPApp) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "frankenphp",
New: func() caddy.Module { return &a },
New: func() caddy.Module { return &f },
}
}

Expand Down Expand Up @@ -189,7 +189,7 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
}

if wc.FileName == "" {
return errors.New(`The "file" argument must be specified`)
return errors.New(`the "file" argument must be specified`)
}

if frankenphp.EmbeddedAppPath != "" && filepath.IsLocal(wc.FileName) {
Expand Down Expand Up @@ -592,7 +592,7 @@ func parsePhpServer(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)

// route to actually pass requests to PHP files;
// match only requests that are for PHP files
pathList := []string{}
var pathList []string
for _, ext := range extensions {
pathList = append(pathList, "*"+ext)
}
Expand Down
2 changes: 1 addition & 1 deletion caddy/php-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Executes a PHP script similarly to the CLI SAPI.`,
})
}

func cmdPHPCLI(fs caddycmd.Flags) (int, error) {
func cmdPHPCLI(caddycmd.Flags) (int, error) {
args := os.Args[2:]
if len(args) < 1 {
return 1, errors.New("the path to the PHP script is required")
Expand Down
2 changes: 1 addition & 1 deletion caddy/php-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func cmdPHPServer(fs caddycmd.Flags) (int, error) {

// route to actually pass requests to PHP files;
// match only requests that are for PHP files
pathList := []string{}
var pathList []string
for _, ext := range extensions {
pathList = append(pathList, "*"+ext)
}
Expand Down
4 changes: 2 additions & 2 deletions embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"time"
)

// The path of the embedded PHP application (empty if none)
// EmbeddedAppPath contains the path of the embedded PHP application (empty if none)
var EmbeddedAppPath string

//go:embed app.tar
Expand All @@ -35,7 +35,7 @@ func init() {
appPath := filepath.Join(os.TempDir(), "frankenphp_"+string(embeddedAppChecksum))

if err := untar(appPath); err != nil {
os.RemoveAll(appPath)
_ = os.RemoveAll(appPath)
panic(err)
}

Expand Down
8 changes: 3 additions & 5 deletions frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ var contextKey = contextKeyStruct{}

var (
InvalidRequestError = errors.New("not a FrankenPHP request")
AlreaydStartedError = errors.New("FrankenPHP is already started")
AlreadyStartedError = errors.New("FrankenPHP is already started")
InvalidPHPVersionError = errors.New("FrankenPHP is only compatible with PHP 8.2+")
ZendSignalsError = errors.New("Zend Signals are enabled, recompile PHP with --disable-zend-signals")
NotEnoughThreads = errors.New("the number of threads must be superior to the number of workers")
MainThreadCreationError = errors.New("error creating the main thread")
RequestContextCreationError = errors.New("error during request context creation")
RequestStartupError = errors.New("error during PHP request startup")
ScriptExecutionError = errors.New("error during PHP script execution")

requestChan chan *http.Request
Expand Down Expand Up @@ -280,7 +278,7 @@ func calculateMaxThreads(opt *opt) error {
// Init starts the PHP runtime and the configured workers.
func Init(options ...Option) error {
if requestChan != nil {
return AlreaydStartedError
return AlreadyStartedError
}

// Ignore all SIGPIPE signals to prevent weird issues with systemd: https://github.com/dunglas/frankenphp/issues/1020
Expand Down Expand Up @@ -371,7 +369,7 @@ func Shutdown() {

// Remove the installed app
if EmbeddedAppPath != "" {
os.RemoveAll(EmbeddedAppPath)
_ = os.RemoveAll(EmbeddedAppPath)
}

logger.Debug("FrankenPHP shut down")
Expand Down
4 changes: 2 additions & 2 deletions internal/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ var (
reloadWaitGroup sync.WaitGroup
// we are passing the logger from the main package to the watcher
logger *zap.Logger
AlreadyStartedError = errors.New("The watcher is already running")
UnableToStartWatching = errors.New("Unable to start the watcher")
AlreadyStartedError = errors.New("the watcher is already running")
UnableToStartWatching = errors.New("unable to start the watcher")
)

func InitWatcher(filePatterns []string, callback func(), zapLogger *zap.Logger) error {
Expand Down
19 changes: 10 additions & 9 deletions metrics.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package frankenphp

import (
"github.com/prometheus/client_golang/prometheus"
"path/filepath"
"regexp"
"sync"
"time"

"github.com/prometheus/client_golang/prometheus"
)

var metricsNameRegex = regexp.MustCompile(`\W+`)
Expand Down Expand Up @@ -43,19 +44,19 @@ type Metrics interface {

type nullMetrics struct{}

func (n nullMetrics) StartWorker(name string) {
func (n nullMetrics) StartWorker(string) {
}

func (n nullMetrics) ReadyWorker(name string) {
func (n nullMetrics) ReadyWorker(string) {
}

func (n nullMetrics) StopWorker(name string, reason StopReason) {
func (n nullMetrics) StopWorker(string, StopReason) {
}

func (n nullMetrics) TotalWorkers(name string, num int) {
func (n nullMetrics) TotalWorkers(string, int) {
}

func (n nullMetrics) TotalThreads(num int) {
func (n nullMetrics) TotalThreads(int) {
}

func (n nullMetrics) StartRequest() {
Expand All @@ -64,10 +65,10 @@ func (n nullMetrics) StartRequest() {
func (n nullMetrics) StopRequest() {
}

func (n nullMetrics) StopWorkerRequest(name string, duration time.Duration) {
func (n nullMetrics) StopWorkerRequest(string, time.Duration) {
}

func (n nullMetrics) StartWorkerRequest(name string) {
func (n nullMetrics) StartWorkerRequest(string) {
}

func (n nullMetrics) Shutdown() {
Expand Down Expand Up @@ -133,7 +134,7 @@ func (m *PrometheusMetrics) getIdentity(name string) (string, error) {
return actualName, nil
}

func (m *PrometheusMetrics) TotalWorkers(name string, num int) {
func (m *PrometheusMetrics) TotalWorkers(name string, _ int) {
m.mu.Lock()
defer m.mu.Unlock()

Expand Down
6 changes: 4 additions & 2 deletions request_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ func WithRequestResolvedDocumentRoot(documentRoot string) RequestOption {
}
}

// WithRequestSplitPath contains a list of split path strings.
//
// The path in the URL will be split into two, with the first piece ending
// with the value of SplitPath. The first piece will be assumed as the
// with the value of splitPath. The first piece will be assumed as the
// actual resource (CGI script) name, and the second piece will be set to
// PATH_INFO for the CGI script to use.
//
// Future enhancements should be careful to avoid CVE-2019-11043,
// which can be mitigated with use of a try_files-like behavior
// that 404s if the fastcgi path info is not found.
// that 404s if the FastCGI path info is not found.
func WithRequestSplitPath(splitPath []string) RequestOption {
return func(o *FrankenPHPContext) error {
o.splitPath = splitPath
Expand Down
4 changes: 2 additions & 2 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
workersAreReady atomic.Bool
workersAreDone atomic.Bool
workersDone chan interface{}
workers map[string]*worker = make(map[string]*worker)
workers = make(map[string]*worker)
)

func initWorkers(opt []workerOpt) error {
Expand Down Expand Up @@ -203,7 +203,7 @@ func drainWorkers() {
}

func restartWorkersOnFileChanges(workerOpts []workerOpt) error {
directoriesToWatch := []string{}
var directoriesToWatch []string
for _, w := range workerOpts {
directoriesToWatch = append(directoriesToWatch, w.watch...)
}
Expand Down
Loading