From 83d835c06f7a9af8d781ad77d7ed732d37c6a502 Mon Sep 17 00:00:00 2001 From: Muhammad Surya Date: Thu, 24 Jan 2019 07:06:48 +0700 Subject: [PATCH 1/2] fix: unexported field should be ignored --- container.go | 6 ++++++ go.mod | 7 +++++++ go.sum | 6 ++++++ wire_test.go | 1 + 4 files changed, 20 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/container.go b/container.go index 0d19fc0..157c37a 100644 --- a/container.go +++ b/container.go @@ -95,6 +95,12 @@ func (container Container) Connect(val interface{}, id ...string) { for i := 0; i < rt.NumField(); i++ { sf := rt.Field(i) + + // skip unexported field + if sf.Name[0] >= 'a' && sf.Name[0] <= 'z' { + continue + } + if tval, ok := sf.Tag.Lookup(tag); ok { if tval == "-" { diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..1ea487e --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module github.com/Fs02/wire + +require ( + github.com/davecgh/go-spew v1.1.0 + github.com/pmezard/go-difflib v1.0.0 + github.com/stretchr/testify v1.2.2 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..311e617 --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= diff --git a/wire_test.go b/wire_test.go index cd14c0a..489565a 100644 --- a/wire_test.go +++ b/wire_test.go @@ -14,6 +14,7 @@ type Valuer interface { type ComponentA struct { Value1 string Value2 int + value3 interface{} // unexported } func (c ComponentA) Value() string { From b13ac64bf4098936e50545205b7364e7a56ee6b3 Mon Sep 17 00:00:00 2001 From: Muhammad Surya Date: Thu, 24 Jan 2019 07:09:14 +0700 Subject: [PATCH 2/2] target test for go 1.9 and 1.11 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4c42619..a776151 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: go go: + - "1.9.x" - "1.10.x" + - "1.11.x" install: - go get -u github.com/golang/dep/cmd/dep before_script: