add FieldsOf to inject fields of a struct directly (#138)
This commit is contained in:
38
internal/wire/testdata/FieldsOfCycle/foo/foo.go
vendored
Normal file
38
internal/wire/testdata/FieldsOfCycle/foo/foo.go
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(injectedBaz())
|
||||
}
|
||||
|
||||
type Foo int
|
||||
type Baz int
|
||||
|
||||
type Bar struct {
|
||||
Bz Baz
|
||||
}
|
||||
|
||||
func provideFoo(_ Baz) Foo {
|
||||
return 0
|
||||
}
|
||||
|
||||
func provideBar(_ Foo) Bar {
|
||||
return Bar{}
|
||||
}
|
||||
26
internal/wire/testdata/FieldsOfCycle/foo/wire.go
vendored
Normal file
26
internal/wire/testdata/FieldsOfCycle/foo/wire.go
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
func injectedBaz() Baz {
|
||||
wire.Build(provideFoo, provideBar, wire.FieldsOf(new(Bar), "Bz"))
|
||||
return 0
|
||||
}
|
||||
1
internal/wire/testdata/FieldsOfCycle/pkg
vendored
Normal file
1
internal/wire/testdata/FieldsOfCycle/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
example.com/foo
|
||||
5
internal/wire/testdata/FieldsOfCycle/want/wire_errs.txt
vendored
Normal file
5
internal/wire/testdata/FieldsOfCycle/want/wire_errs.txt
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
example.com/foo/wire.go:x:y: cycle for example.com/foo.Bar:
|
||||
example.com/foo.Bar (example.com/foo.provideBar) ->
|
||||
example.com/foo.Foo (example.com/foo.provideFoo) ->
|
||||
example.com/foo.Baz (example.com/foo.Bar.Bz) ->
|
||||
example.com/foo.Bar
|
||||
32
internal/wire/testdata/FieldsOfImportedStruct/bar/bar.go
vendored
Normal file
32
internal/wire/testdata/FieldsOfImportedStruct/bar/bar.go
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bar
|
||||
|
||||
import (
|
||||
"example.com/foo"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
V int
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Cfg *Config
|
||||
F *foo.Service
|
||||
}
|
||||
|
||||
func New(cfg *Config, f *foo.Service) *Service {
|
||||
return &Service{Cfg: cfg, F: f}
|
||||
}
|
||||
36
internal/wire/testdata/FieldsOfImportedStruct/baz/baz.go
vendored
Normal file
36
internal/wire/testdata/FieldsOfImportedStruct/baz/baz.go
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package baz
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"example.com/bar"
|
||||
"example.com/foo"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Foo *foo.Config
|
||||
Bar *bar.Config
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Foo *foo.Service
|
||||
Bar *bar.Service
|
||||
}
|
||||
|
||||
func (m *Service) String() string {
|
||||
return fmt.Sprintf("%d %d", m.Foo.Cfg.V, m.Bar.Cfg.V)
|
||||
}
|
||||
27
internal/wire/testdata/FieldsOfImportedStruct/foo/foo.go
vendored
Normal file
27
internal/wire/testdata/FieldsOfImportedStruct/foo/foo.go
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package foo
|
||||
|
||||
type Config struct {
|
||||
V int
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Cfg *Config
|
||||
}
|
||||
|
||||
func New(cfg *Config) *Service {
|
||||
return &Service{Cfg: cfg}
|
||||
}
|
||||
49
internal/wire/testdata/FieldsOfImportedStruct/main/wire.go
vendored
Normal file
49
internal/wire/testdata/FieldsOfImportedStruct/main/wire.go
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"example.com/bar"
|
||||
"example.com/baz"
|
||||
"example.com/foo"
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
func newBazService(*baz.Config) *baz.Service {
|
||||
wire.Build(
|
||||
baz.Service{},
|
||||
wire.FieldsOf(
|
||||
new(*baz.Config),
|
||||
"Foo",
|
||||
"Bar",
|
||||
),
|
||||
foo.New,
|
||||
bar.New,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
cfg := &baz.Config{
|
||||
Foo: &foo.Config{1},
|
||||
Bar: &bar.Config{2},
|
||||
}
|
||||
svc := newBazService(cfg)
|
||||
fmt.Println(svc.String())
|
||||
}
|
||||
1
internal/wire/testdata/FieldsOfImportedStruct/pkg
vendored
Normal file
1
internal/wire/testdata/FieldsOfImportedStruct/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
example.com/main
|
||||
1
internal/wire/testdata/FieldsOfImportedStruct/want/program_out.txt
vendored
Normal file
1
internal/wire/testdata/FieldsOfImportedStruct/want/program_out.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1 2
|
||||
38
internal/wire/testdata/FieldsOfImportedStruct/want/wire_gen.go
vendored
Normal file
38
internal/wire/testdata/FieldsOfImportedStruct/want/wire_gen.go
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate wire
|
||||
//+build !wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"example.com/bar"
|
||||
"example.com/baz"
|
||||
"example.com/foo"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func newBazService(config *baz.Config) *baz.Service {
|
||||
fooConfig := config.Foo
|
||||
service := foo.New(fooConfig)
|
||||
barConfig := config.Bar
|
||||
barService := bar.New(barConfig, service)
|
||||
bazService := &baz.Service{
|
||||
Foo: service,
|
||||
Bar: barService,
|
||||
}
|
||||
return bazService
|
||||
}
|
||||
|
||||
// wire.go:
|
||||
|
||||
func main() {
|
||||
cfg := &baz.Config{
|
||||
Foo: &foo.Config{1},
|
||||
Bar: &bar.Config{2},
|
||||
}
|
||||
svc := newBazService(cfg)
|
||||
fmt.Println(svc.String())
|
||||
}
|
||||
29
internal/wire/testdata/FieldsOfStruct/foo/foo.go
vendored
Normal file
29
internal/wire/testdata/FieldsOfStruct/foo/foo.go
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2018 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type S struct {
|
||||
Foo string
|
||||
}
|
||||
|
||||
func provideS() S {
|
||||
return S{Foo: "Hello, World!"}
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(injectedMessage())
|
||||
}
|
||||
28
internal/wire/testdata/FieldsOfStruct/foo/wire.go
vendored
Normal file
28
internal/wire/testdata/FieldsOfStruct/foo/wire.go
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2018 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
wire.Build(
|
||||
provideS,
|
||||
wire.FieldsOf(new(S), "Foo"))
|
||||
return ""
|
||||
}
|
||||
1
internal/wire/testdata/FieldsOfStruct/pkg
vendored
Normal file
1
internal/wire/testdata/FieldsOfStruct/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
example.com/foo
|
||||
1
internal/wire/testdata/FieldsOfStruct/want/program_out.txt
vendored
Normal file
1
internal/wire/testdata/FieldsOfStruct/want/program_out.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Hello, World!
|
||||
14
internal/wire/testdata/FieldsOfStruct/want/wire_gen.go
vendored
Normal file
14
internal/wire/testdata/FieldsOfStruct/want/wire_gen.go
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate wire
|
||||
//+build !wireinject
|
||||
|
||||
package main
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func injectedMessage() string {
|
||||
s := provideS()
|
||||
string2 := s.Foo
|
||||
return string2
|
||||
}
|
||||
29
internal/wire/testdata/FieldsOfStructPointer/foo/foo.go
vendored
Normal file
29
internal/wire/testdata/FieldsOfStructPointer/foo/foo.go
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2018 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type S struct {
|
||||
Foo string
|
||||
}
|
||||
|
||||
func provideS() *S {
|
||||
return &S{Foo: "Hello, World!"}
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(injectedMessage())
|
||||
}
|
||||
28
internal/wire/testdata/FieldsOfStructPointer/foo/wire.go
vendored
Normal file
28
internal/wire/testdata/FieldsOfStructPointer/foo/wire.go
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
// Copyright 2018 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
func injectedMessage() string {
|
||||
wire.Build(
|
||||
provideS,
|
||||
wire.FieldsOf(new(*S), "Foo"))
|
||||
return ""
|
||||
}
|
||||
1
internal/wire/testdata/FieldsOfStructPointer/pkg
vendored
Normal file
1
internal/wire/testdata/FieldsOfStructPointer/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
example.com/foo
|
||||
1
internal/wire/testdata/FieldsOfStructPointer/want/program_out.txt
vendored
Normal file
1
internal/wire/testdata/FieldsOfStructPointer/want/program_out.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Hello, World!
|
||||
14
internal/wire/testdata/FieldsOfStructPointer/want/wire_gen.go
vendored
Normal file
14
internal/wire/testdata/FieldsOfStructPointer/want/wire_gen.go
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate wire
|
||||
//+build !wireinject
|
||||
|
||||
package main
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func injectedMessage() string {
|
||||
s := provideS()
|
||||
string2 := s.Foo
|
||||
return string2
|
||||
}
|
||||
32
internal/wire/testdata/FieldsOfValueStruct/bar/bar.go
vendored
Normal file
32
internal/wire/testdata/FieldsOfValueStruct/bar/bar.go
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bar
|
||||
|
||||
import (
|
||||
"example.com/foo"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
V int
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Cfg *Config
|
||||
F *foo.Service
|
||||
}
|
||||
|
||||
func New(cfg *Config, f *foo.Service) *Service {
|
||||
return &Service{Cfg: cfg, F: f}
|
||||
}
|
||||
36
internal/wire/testdata/FieldsOfValueStruct/baz/baz.go
vendored
Normal file
36
internal/wire/testdata/FieldsOfValueStruct/baz/baz.go
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package baz
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"example.com/bar"
|
||||
"example.com/foo"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Foo *foo.Config
|
||||
Bar *bar.Config
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Foo *foo.Service
|
||||
Bar *bar.Service
|
||||
}
|
||||
|
||||
func (m *Service) String() string {
|
||||
return fmt.Sprintf("%d %d", m.Foo.Cfg.V, m.Bar.Cfg.V)
|
||||
}
|
||||
27
internal/wire/testdata/FieldsOfValueStruct/foo/foo.go
vendored
Normal file
27
internal/wire/testdata/FieldsOfValueStruct/foo/foo.go
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package foo
|
||||
|
||||
type Config struct {
|
||||
V int
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
Cfg *Config
|
||||
}
|
||||
|
||||
func New(cfg *Config) *Service {
|
||||
return &Service{Cfg: cfg}
|
||||
}
|
||||
49
internal/wire/testdata/FieldsOfValueStruct/main/wire.go
vendored
Normal file
49
internal/wire/testdata/FieldsOfValueStruct/main/wire.go
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2019 The Wire Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//+build wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"example.com/bar"
|
||||
"example.com/baz"
|
||||
"example.com/foo"
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
func newBazService() *baz.Service {
|
||||
wire.Build(
|
||||
baz.Service{},
|
||||
wire.Value(&baz.Config{
|
||||
Foo: &foo.Config{1},
|
||||
Bar: &bar.Config{2},
|
||||
}),
|
||||
wire.FieldsOf(
|
||||
new(*baz.Config),
|
||||
"Foo",
|
||||
"Bar",
|
||||
),
|
||||
foo.New,
|
||||
bar.New,
|
||||
)
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
svc := newBazService()
|
||||
fmt.Println(svc.String())
|
||||
}
|
||||
1
internal/wire/testdata/FieldsOfValueStruct/pkg
vendored
Normal file
1
internal/wire/testdata/FieldsOfValueStruct/pkg
vendored
Normal file
@@ -0,0 +1 @@
|
||||
example.com/main
|
||||
1
internal/wire/testdata/FieldsOfValueStruct/want/program_out.txt
vendored
Normal file
1
internal/wire/testdata/FieldsOfValueStruct/want/program_out.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
1 2
|
||||
42
internal/wire/testdata/FieldsOfValueStruct/want/wire_gen.go
vendored
Normal file
42
internal/wire/testdata/FieldsOfValueStruct/want/wire_gen.go
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate wire
|
||||
//+build !wireinject
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"example.com/bar"
|
||||
"example.com/baz"
|
||||
"example.com/foo"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func newBazService() *baz.Service {
|
||||
config := _wireConfigValue
|
||||
fooConfig := config.Foo
|
||||
service := foo.New(fooConfig)
|
||||
barConfig := config.Bar
|
||||
barService := bar.New(barConfig, service)
|
||||
bazService := &baz.Service{
|
||||
Foo: service,
|
||||
Bar: barService,
|
||||
}
|
||||
return bazService
|
||||
}
|
||||
|
||||
var (
|
||||
_wireConfigValue = &baz.Config{
|
||||
Foo: &foo.Config{1},
|
||||
Bar: &bar.Config{2},
|
||||
}
|
||||
)
|
||||
|
||||
// wire.go:
|
||||
|
||||
func main() {
|
||||
svc := newBazService()
|
||||
fmt.Println(svc.String())
|
||||
}
|
||||
@@ -28,22 +28,28 @@ import (
|
||||
type MainConfig struct {
|
||||
Foo *foo.Config
|
||||
Bar *bar.Config
|
||||
Baz *baz.Config
|
||||
baz *baz.Config
|
||||
}
|
||||
|
||||
type MainService struct {
|
||||
Foo *foo.Service
|
||||
Bar *bar.Service
|
||||
Baz *baz.Service
|
||||
baz *baz.Service
|
||||
}
|
||||
|
||||
func (m *MainService) String() string {
|
||||
return fmt.Sprintf("%d %d %d", m.Foo.Cfg.V, m.Bar.Cfg.V, m.Baz.Cfg.V)
|
||||
return fmt.Sprintf("%d %d %d", m.Foo.Cfg.V, m.Bar.Cfg.V, m.baz.Cfg.V)
|
||||
}
|
||||
|
||||
func newMainService(*foo.Config, *bar.Config, *baz.Config) *MainService {
|
||||
func newMainService(MainConfig) *MainService {
|
||||
wire.Build(
|
||||
MainService{},
|
||||
wire.FieldsOf(
|
||||
new(MainConfig),
|
||||
"Foo",
|
||||
"Bar",
|
||||
"baz",
|
||||
),
|
||||
foo.New,
|
||||
bar.New,
|
||||
baz.New,
|
||||
@@ -52,11 +58,11 @@ func newMainService(*foo.Config, *bar.Config, *baz.Config) *MainService {
|
||||
}
|
||||
|
||||
func main() {
|
||||
cfg := &MainConfig{
|
||||
cfg := MainConfig{
|
||||
Foo: &foo.Config{1},
|
||||
Bar: &bar.Config{2},
|
||||
Baz: &baz.Config{3},
|
||||
baz: &baz.Config{3},
|
||||
}
|
||||
svc := newMainService(cfg.Foo, cfg.Bar, cfg.Baz)
|
||||
svc := newMainService(cfg)
|
||||
fmt.Println(svc.String())
|
||||
}
|
||||
|
||||
@@ -14,14 +14,17 @@ import (
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func newMainService(config *foo.Config, barConfig *bar.Config, bazConfig *baz.Config) *MainService {
|
||||
func newMainService(mainConfig MainConfig) *MainService {
|
||||
config := mainConfig.Foo
|
||||
service := foo.New(config)
|
||||
barConfig := mainConfig.Bar
|
||||
barService := bar.New(barConfig, service)
|
||||
bazConfig := mainConfig.baz
|
||||
bazService := baz.New(bazConfig, barService)
|
||||
mainService := &MainService{
|
||||
Foo: service,
|
||||
Bar: barService,
|
||||
Baz: bazService,
|
||||
baz: bazService,
|
||||
}
|
||||
return mainService
|
||||
}
|
||||
@@ -31,25 +34,25 @@ func newMainService(config *foo.Config, barConfig *bar.Config, bazConfig *baz.Co
|
||||
type MainConfig struct {
|
||||
Foo *foo.Config
|
||||
Bar *bar.Config
|
||||
Baz *baz.Config
|
||||
baz *baz.Config
|
||||
}
|
||||
|
||||
type MainService struct {
|
||||
Foo *foo.Service
|
||||
Bar *bar.Service
|
||||
Baz *baz.Service
|
||||
baz *baz.Service
|
||||
}
|
||||
|
||||
func (m *MainService) String() string {
|
||||
return fmt.Sprintf("%d %d %d", m.Foo.Cfg.V, m.Bar.Cfg.V, m.Baz.Cfg.V)
|
||||
return fmt.Sprintf("%d %d %d", m.Foo.Cfg.V, m.Bar.Cfg.V, m.baz.Cfg.V)
|
||||
}
|
||||
|
||||
func main() {
|
||||
cfg := &MainConfig{
|
||||
cfg := MainConfig{
|
||||
Foo: &foo.Config{1},
|
||||
Bar: &bar.Config{2},
|
||||
Baz: &baz.Config{3},
|
||||
baz: &baz.Config{3},
|
||||
}
|
||||
svc := newMainService(cfg.Foo, cfg.Bar, cfg.Baz)
|
||||
svc := newMainService(cfg)
|
||||
fmt.Println(svc.String())
|
||||
}
|
||||
|
||||
@@ -69,3 +69,9 @@ func provideOneOfTwo() OneOfTwo {
|
||||
func provideTwoOfTwo() TwoOfTwo {
|
||||
return 1
|
||||
}
|
||||
|
||||
type S struct {
|
||||
Cfg Config
|
||||
}
|
||||
|
||||
type Config int
|
||||
|
||||
@@ -29,6 +29,7 @@ func injectBar() Bar {
|
||||
wire.Value("unused"), // not needed -> error
|
||||
unusedSet, // nothing in set is needed -> error
|
||||
wire.Bind((*Fooer)(nil), (*Foo)(nil)), // binding to Fooer is not needed -> error
|
||||
wire.FieldsOf(new(S), "Cfg"), // S.Cfg not needed -> error
|
||||
)
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -4,4 +4,6 @@ example.com/foo/wire.go:x:y: inject injectBar: unused provider "provideUnused"
|
||||
|
||||
example.com/foo/wire.go:x:y: inject injectBar: unused value of type string
|
||||
|
||||
example.com/foo/wire.go:x:y: inject injectBar: unused interface binding to type example.com/foo.Fooer
|
||||
example.com/foo/wire.go:x:y: inject injectBar: unused interface binding to type example.com/foo.Fooer
|
||||
|
||||
example.com/foo/wire.go:x:y: inject injectBar: unused field "example.com/foo.S".Cfg
|
||||
Reference in New Issue
Block a user