Skip to content

Commit

Permalink
fix(routingoption): doesn't support to delete metadata by key
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlangzi committed Dec 25, 2024
1 parent 60b8952 commit eeb94dd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
19 changes: 19 additions & 0 deletions binder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package htmx

import (
"net/http"
"net/http/httptest"
"testing"
)

func TestBinder(t *testing.T) {
mux := http.NewServeMux()
srv := httptest.NewServer(mux)
defer srv.Close()

app := New(WithMux(mux))

app.Start()
defer app.Close()

}
9 changes: 1 addition & 8 deletions routing_option.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package htmx

import "reflect"

type RoutingOptions struct {
metadata map[string]any
viewer Viewer
Expand Down Expand Up @@ -53,12 +51,7 @@ func WithMetadata(key string, value any) RoutingOption {
ro.metadata = make(map[string]any)
}

v := reflect.ValueOf(value)
if v.IsZero() {
delete(ro.metadata, key)
} else {
ro.metadata[key] = value
}
ro.metadata[key] = value
}
}

Expand Down
4 changes: 2 additions & 2 deletions routing_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func TestRoutingOption(t *testing.T) {
WithNavigation("admin", "ha-dash", "admin:view"))

app.Get("/invalid", func(c *Context) error {

data := map[string]any{
"s1": c.Routing.Options.GetString("s1"),
"i1": c.Routing.Options.GetInt("i1"),
Expand All @@ -63,7 +62,8 @@ func TestRoutingOption(t *testing.T) {
}

return c.View(data)
}, WithMetadata("s1", time.Now()), WithMetadata("i1", "v100"))
}, WithMetadata("s1", time.Now()), WithMetadata("i1", "v100"),
WithNavigation("admin", "ha-dash", "admin:view"))

app.Start()
defer app.Close()
Expand Down

0 comments on commit eeb94dd

Please sign in to comment.