diff --git a/hero/dependency_test.go b/hero/dependency_test.go index b90e341e..0a20c35f 100644 --- a/hero/dependency_test.go +++ b/hero/dependency_test.go @@ -77,6 +77,11 @@ func TestDependency(t *testing.T) { }, Expected: false, }, + { + + Dependency: map[string]string{"test": "value"}, + Expected: map[string]string{"test": "value"}, + }, } testDependencies(t, tests) diff --git a/hero/handler_test.go b/hero/handler_test.go index 2f240d58..cfc28bcc 100644 --- a/hero/handler_test.go +++ b/hero/handler_test.go @@ -204,12 +204,15 @@ type testMessage struct { Body string } +type myMap map[string]*testMessage + func TestDependentDependencies(t *testing.T) { b := New() b.Register(&testServiceImpl{prefix: "prefix:"}) b.Register(func(service testService) testMessage { return testMessage{Body: service.Say("it is a deep") + " dependency"} }) + b.Register(myMap{"test": &testMessage{Body: "value"}}) var ( h1 = b.Handler(func(msg testMessage) string { return msg.Body @@ -217,15 +220,20 @@ func TestDependentDependencies(t *testing.T) { h2 = b.Handler(func(reuse testService) string { return reuse.Say("message") }) + h3 = b.Handler(func(m myMap) string { + return m["test"].Body + }) ) app := iris.New() app.Get("/h1", h1) app.Get("/h2", h2) + app.Get("/h3", h3) e := httptest.New(t, app) e.GET("/h1").Expect().Status(httptest.StatusOK).Body().Equal("prefix: it is a deep dependency") e.GET("/h2").Expect().Status(httptest.StatusOK).Body().Equal("prefix: message") + e.GET("/h3").Expect().Status(httptest.StatusOK).Body().Equal("value") } func TestHandlerPathParams(t *testing.T) { diff --git a/hero/reflect.go b/hero/reflect.go index 4619c91b..b81a3652 100644 --- a/hero/reflect.go +++ b/hero/reflect.go @@ -231,8 +231,10 @@ func isZero(v reflect.Value) bool { return len(v.Interface().(net.IP)) == 0 } - zero := reflect.Zero(v.Type()) - return v.Interface() == zero.Interface() + // zero := reflect.Zero(v.Type()) + // return v.Interface() == zero.Interface() + + return v.IsZero() } // IsNil same as `reflect.IsNil` but a bit safer to use, returns false if not a correct type.