Skip to content

Commit b31eebf

Browse files
committed
fix: rename package to query_to_header to match plugin import path
Traefik's Yaegi-based plugin loader derives the import alias from the last segment of the module path (query-to-header -> query_to_header) and fails with "undefined: query_to_header" if the declared package name doesn't match exactly. The package was previously named traefik_query_to_header.
1 parent 387929e commit b31eebf

3 files changed

Lines changed: 25 additions & 22 deletions

File tree

AGENTS.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ is only a compile-correctness check.
2626

2727
## Architecture
2828

29-
Everything lives in a single package, `traefik_query_to_header` (package name uses underscores
30-
because the module path `query-to-header` is not a valid Go identifier):
29+
Everything lives in a single package, `query_to_header`. The package name must exactly match
30+
the import path's last segment with hyphens converted to underscores
31+
(`query-to-header``query_to_header`) — Traefik's Yaegi-based plugin loader derives the
32+
import alias from the path and fails with `undefined: query_to_header` if the declared package
33+
name doesn't match.
3134

3235
- **`query_to_header.go`** — the entire plugin:
3336
- `Config` / `Mapping` — JSON-tagged structs populated by Traefik from the dynamic

query_to_header.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// Package traefik_query_to_header is a Traefik middleware plugin that
1+
// Package query_to_header is a Traefik middleware plugin that
22
// copies values from incoming request query parameters into HTTP request
33
// headers before the request reaches the next handler in the chain.
4-
package traefik_query_to_header
4+
package query_to_header
55

66
import (
77
"context"

query_to_header_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
package traefik_query_to_header_test
1+
package query_to_header_test
22

33
import (
44
"context"
55
"net/http"
66
"net/http/httptest"
77
"testing"
88

9-
traefik_query_to_header "github.com/muench-dev/query-to-header"
9+
"github.com/muench-dev/query-to-header"
1010
)
1111

1212
func TestNew_RejectsNilConfig(t *testing.T) {
1313
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
1414

15-
if _, err := traefik_query_to_header.New(context.Background(), next, nil, "test"); err == nil {
15+
if _, err := query_to_header.New(context.Background(), next, nil, "test"); err == nil {
1616
t.Fatal("expected an error for a nil config, got none")
1717
}
1818
}
1919

2020
func TestNew_RejectsIncompleteMapping(t *testing.T) {
2121
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
22-
cfg := &traefik_query_to_header.Config{
23-
Mappings: []traefik_query_to_header.Mapping{{Query: "token"}},
22+
cfg := &query_to_header.Config{
23+
Mappings: []query_to_header.Mapping{{Query: "token"}},
2424
}
2525

26-
if _, err := traefik_query_to_header.New(context.Background(), next, cfg, "test"); err == nil {
26+
if _, err := query_to_header.New(context.Background(), next, cfg, "test"); err == nil {
2727
t.Fatal("expected an error for a mapping missing a header name, got none")
2828
}
2929
}
3030

3131
func TestServeHTTP_SetsHeaderFromQuery(t *testing.T) {
32-
cfg := &traefik_query_to_header.Config{
33-
Mappings: []traefik_query_to_header.Mapping{
32+
cfg := &query_to_header.Config{
33+
Mappings: []query_to_header.Mapping{
3434
{Query: "token", Header: "X-Token"},
3535
},
3636
}
@@ -40,7 +40,7 @@ func TestServeHTTP_SetsHeaderFromQuery(t *testing.T) {
4040
gotHeader = req.Header.Get("X-Token")
4141
})
4242

43-
handler, err := traefik_query_to_header.New(context.Background(), next, cfg, "test")
43+
handler, err := query_to_header.New(context.Background(), next, cfg, "test")
4444
if err != nil {
4545
t.Fatalf("unexpected error: %v", err)
4646
}
@@ -56,8 +56,8 @@ func TestServeHTTP_SetsHeaderFromQuery(t *testing.T) {
5656
}
5757

5858
func TestServeHTTP_PrefixesValueWithBearer(t *testing.T) {
59-
cfg := &traefik_query_to_header.Config{
60-
Mappings: []traefik_query_to_header.Mapping{
59+
cfg := &query_to_header.Config{
60+
Mappings: []query_to_header.Mapping{
6161
{Query: "token", Header: "Authorization", Bearer: true},
6262
},
6363
}
@@ -67,7 +67,7 @@ func TestServeHTTP_PrefixesValueWithBearer(t *testing.T) {
6767
gotHeader = req.Header.Get("Authorization")
6868
})
6969

70-
handler, err := traefik_query_to_header.New(context.Background(), next, cfg, "test")
70+
handler, err := query_to_header.New(context.Background(), next, cfg, "test")
7171
if err != nil {
7272
t.Fatalf("unexpected error: %v", err)
7373
}
@@ -83,8 +83,8 @@ func TestServeHTTP_PrefixesValueWithBearer(t *testing.T) {
8383
}
8484

8585
func TestServeHTTP_DoesNotOverwriteExistingHeaderByDefault(t *testing.T) {
86-
cfg := &traefik_query_to_header.Config{
87-
Mappings: []traefik_query_to_header.Mapping{
86+
cfg := &query_to_header.Config{
87+
Mappings: []query_to_header.Mapping{
8888
{Query: "token", Header: "X-Token"},
8989
},
9090
}
@@ -94,7 +94,7 @@ func TestServeHTTP_DoesNotOverwriteExistingHeaderByDefault(t *testing.T) {
9494
gotHeader = req.Header.Get("X-Token")
9595
})
9696

97-
handler, err := traefik_query_to_header.New(context.Background(), next, cfg, "test")
97+
handler, err := query_to_header.New(context.Background(), next, cfg, "test")
9898
if err != nil {
9999
t.Fatalf("unexpected error: %v", err)
100100
}
@@ -111,8 +111,8 @@ func TestServeHTTP_DoesNotOverwriteExistingHeaderByDefault(t *testing.T) {
111111
}
112112

113113
func TestServeHTTP_RemovesQueryParamWhenConfigured(t *testing.T) {
114-
cfg := &traefik_query_to_header.Config{
115-
Mappings: []traefik_query_to_header.Mapping{
114+
cfg := &query_to_header.Config{
115+
Mappings: []query_to_header.Mapping{
116116
{Query: "token", Header: "X-Token", Remove: true},
117117
},
118118
}
@@ -122,7 +122,7 @@ func TestServeHTTP_RemovesQueryParamWhenConfigured(t *testing.T) {
122122
gotQuery = req.URL.RawQuery
123123
})
124124

125-
handler, err := traefik_query_to_header.New(context.Background(), next, cfg, "test")
125+
handler, err := query_to_header.New(context.Background(), next, cfg, "test")
126126
if err != nil {
127127
t.Fatalf("unexpected error: %v", err)
128128
}

0 commit comments

Comments
 (0)