From 93b1ce745f8df27e20d69c9f78edae5247b5cc79 Mon Sep 17 00:00:00 2001 From: shantuo Date: Tue, 11 Jun 2019 15:35:05 -0700 Subject: [PATCH] doc: add guide to use the `wire:"-"` tag (#195) --- docs/guide.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/guide.md b/docs/guide.md index a3157ee7..c1a15af8 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -300,6 +300,21 @@ func injectFooBar() 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 Occasionally, it is useful to bind a basic value (usually `nil`) to a type.