use 🧩 for module workers

This commit is contained in:
DubbleClick
2025-04-24 18:24:30 +07:00
parent 78be813e00
commit 4cc8893ced
3 changed files with 12 additions and 12 deletions

View File

@@ -49,7 +49,7 @@ func init() {
}
type workerConfig struct {
// Name for the worker. Default: the filename for FrankenPHPApp workers, always prefixed with "m#" for FrankenPHPModule workers.
// Name for the worker. Default: the filename for FrankenPHPApp workers, always prefixed with "🧩 " for FrankenPHPModule workers.
Name string `json:"name,omitempty"`
// FileName sets the path to the worker script.
FileName string `json:"file_name,omitempty"`
@@ -318,8 +318,8 @@ func (f *FrankenPHPApp) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
}
wc.Name = name
}
if strings.HasPrefix(wc.Name, "m#") {
return fmt.Errorf("global worker names must not start with 'm#': %q", wc.Name)
if strings.HasPrefix(wc.Name, "🧩 ") {
return fmt.Errorf("global worker names must not start with '🧩 ': %q", wc.Name)
}
// check for duplicate workers
for _, existingWorker := range f.Workers {
@@ -499,7 +499,7 @@ func (f *FrankenPHPModule) ServeHTTP(w http.ResponseWriter, r *http.Request, _ c
}
func generateUniqueModuleWorkerName(filepath string) string {
name := "m#" + filepath
name := "🧩 " + filepath
i := 0
for {
nameExists := false
@@ -513,7 +513,7 @@ func generateUniqueModuleWorkerName(filepath string) string {
break
}
i++
name = fmt.Sprintf("m#%s_%d", filepath, i)
name = fmt.Sprintf("🧩 %s_%d", filepath, i)
}
return name
@@ -607,8 +607,8 @@ func (f *FrankenPHPModule) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
if wc.Name == "" {
wc.Name = generateUniqueModuleWorkerName(wc.FileName)
}
if !strings.HasPrefix(wc.Name, "m#") {
wc.Name = "m#" + wc.Name
if !strings.HasPrefix(wc.Name, "🧩 ") {
wc.Name = "🧩 " + wc.Name
}
// Check if a worker with this filename already exists in this module

View File

@@ -160,8 +160,8 @@ func TestModuleWorkersDifferentNamesSucceed(t *testing.T) {
// Verify that both workers were added to moduleWorkerConfigs
require.Len(t, moduleWorkerConfigs, 2, "Expected two workers to be added to moduleWorkerConfigs")
require.Equal(t, "m#test-worker-1", moduleWorkerConfigs[0].Name, "First worker should have the correct name")
require.Equal(t, "m#test-worker-2", moduleWorkerConfigs[1].Name, "Second worker should have the correct name")
require.Equal(t, "🧩 test-worker-1", moduleWorkerConfigs[0].Name, "First worker should have the correct name")
require.Equal(t, "🧩 test-worker-2", moduleWorkerConfigs[1].Name, "Second worker should have the correct name")
resetModuleWorkers()
}
@@ -267,8 +267,8 @@ func TestModuleWorkerWithCustomName(t *testing.T) {
require.Len(t, module.Workers, 1, "Expected one worker to be added to the module")
require.Equal(t, "../testdata/worker-with-env.php", module.Workers[0].FileName, "Worker should have the correct filename")
// Verify that the worker was added to moduleWorkerConfigs with the m# prefix
require.Equal(t, "m#custom-worker-name", module.Workers[0].Name, "Worker should have the custom name")
// Verify that the worker was added to moduleWorkerConfigs with the 🧩 prefix
require.Equal(t, "🧩 custom-worker-name", module.Workers[0].Name, "Worker should have the custom name")
resetModuleWorkers()
}

View File

@@ -69,7 +69,7 @@ func initWorkers(opt []workerOpt) error {
func getWorkerKey(name string, filename string) string {
key := filename
if strings.HasPrefix(name, "m#") {
if strings.HasPrefix(name, "🧩 ") {
key = name
}
return key