Skip to content

Commit

Permalink
refactor(go): Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
rkettelerij committed Sep 25, 2024
1 parent 4bed603 commit 0aeece5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
8 changes: 4 additions & 4 deletions internal/engine/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/go-chi/chi/v5"
)

// Serve static assets either from local storage or through reverse proxy
func newResourcesEndpoint(e *Engine) {
// Serve static assets either from local storage or through reverse proxy
resourcesDir := ""
if e.Config.Resources.Directory != nil {
resourcesDir = *e.Config.Resources.Directory
Expand All @@ -28,9 +28,9 @@ func newResourcesEndpoint(e *Engine) {
}
}

func proxy(reverseProxy func(w http.ResponseWriter, r *http.Request, target *url.URL, prefer204 bool, overwrite string),
resourcesURL string) func(w http.ResponseWriter, r *http.Request) {
type reverseProxy func(w http.ResponseWriter, r *http.Request, target *url.URL, prefer204 bool, overwrite string)

func proxy(rp reverseProxy, resourcesURL string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
resourcePath, _ := url.JoinPath("/", chi.URLParam(r, "*"))
target, err := url.ParseRequestURI(resourcesURL + resourcePath)
Expand All @@ -39,6 +39,6 @@ func proxy(reverseProxy func(w http.ResponseWriter, r *http.Request, target *url
RenderProblem(ProblemServerError, w)
return
}
reverseProxy(w, r, target, true, "")
rp(w, r, target, true, "")
}
}
30 changes: 0 additions & 30 deletions internal/ogc/features/domain/props_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,33 +241,3 @@ func TestSetRelation(t *testing.T) {
})
}
}

func TestKeys(t *testing.T) {
tests := []struct {
name string
inOrder bool
data map[string]any
expected []string
}{
{
name: "Unordered keys",
inOrder: false,
data: map[string]any{"key2": "value2", "key1": "value1"},
expected: []string{"key1", "key2"}, // sorted alphabetically
},
{
name: "Ordered keys",
inOrder: true,
data: map[string]any{"key1": "value1", "key2": "value2"},
expected: []string{"key1", "key2"}, // insertion order maintained
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewFeaturePropertiesWithData(tt.inOrder, tt.data)
keys := p.Keys()
assert.Equal(t, tt.expected, keys)
})
}
}

0 comments on commit 0aeece5

Please sign in to comment.