doc: add guide to use the wire:"-" tag (#195)

This commit is contained in:
shantuo
2019-06-11 15:35:05 -07:00
committed by GitHub
parent 000df02f3d
commit 93b1ce745f

View File

@@ -300,6 +300,21 @@ func injectFooBar() FooBar {
And similarly if the injector needed a `*FooBar`. And similarly if the injector needed a `*FooBar`.
It is sometimes useful to prevent certain fields from being filled in by the
injector, especially when passing `*` to `wire.Struct`. You can tag a field with
`` `wire:"-"` `` to have Wire ignore such fields. For example:
```go
type Foo struct {
mu sync.Mutex `wire:"-"`
Bar Bar
}
```
When you provide the `Foo` type using `wire.Struct(new(Foo), "*")`, Wire will
automatically omit the `mu` field. Additionally, it is an error to explicitly
specify a prevented field as in `wire.Struct(new(Foo), "mu")`.
### Binding Values ### Binding Values
Occasionally, it is useful to bind a basic value (usually `nil`) to a type. Occasionally, it is useful to bind a basic value (usually `nil`) to a type.