November 2018
Intermediate to advanced
346 pages
8h 12m
English
The second concept integral to Wire is injectors. Injectors are where the magic happens. They are functions that we (developers) define that Wire uses as a base for its code generation.
For example, if we want to have a function that can create an instance of our service's REST server, including initializing and injecting all the required dependencies, we can achieve this with the following function:
func initializeServer() (*rest.Server, error) { wire.Build(wireSet) return nil, nil}
That probably feels like a big sell for such a simple function, especially as it does not seem to do anything (that is, returns nil, nil). But that is all we need to write; the code generator will turn it into the following:
func ...Read now
Unlock full access