Commit Graph

127 Commits

Author SHA1 Message Date
Chris Lewis
3e60790b34 Remove dead code from parse.go (google/go-cloud#48) 2018-11-13 13:16:45 -08:00
Ross Light
e9a61ba66b goose: require pointer for first argument to goose.Bind (google/go-cloud#31)
Fixes google/go-cloud#15
2018-11-13 13:16:45 -08:00
Ross Light
962288c10a goose: s/Use/Build/
Fixes google/go-cloud#6
2018-11-13 13:16:45 -08:00
Ross Light
cc91a772b0 goose: add test that disambiguate contains the base name
No behavior change, just more unit testing.

Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Chris Lewis <cflewis@google.com>
2018-11-13 13:16:45 -08:00
Ross Light
3c0eaf830e goose: refactor *gen.inject
The function had grown too long. Several related cleanups:

- Factored out the function return value logic, which had been
  duplicated between providers and injectors.
- Moved code generation for different provider call types into separate
  functions. This moves injector-specific state to a new type
  injectorGen to keep the parameter count down.
- Since it's infeasible to keep the "shadow pass" collecting import
  identifiers in sync the spread out logic, the injector code
  generation is just run twice, with initial output discarded.
- Removed the zero value logic left over from Optional.

Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-13 13:16:45 -08:00
Ross Light
10676a814b goose: add goose.Value directive
Subsumes previous usage of goose.Optional.

Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-13 13:16:45 -08:00
Ross Light
235a7d8f80 goose: allow non-injector code to live along with injectors
Previously, goose would ignore declarations in the //+build gooseinject
files that were not injectors. This meant that if you wanted to write
application-specific providers, you would need to place them in a
separate file, away from the goose injectors. This means that a typical
application would have three handwritten files: one for the abstract
business logic, one for the platform-specific providers, one for the
platform-specific injector declarations.

This change allows the two platform-specific files to be merged into
one: the //+build gooseinject file. goose will now copy these
declarations out to goose_gen.go. This requires a bit of hackery, since
the generated file may have different identifiers for the imported
packages, so goose will do some light AST rewriting to address these
cases.

(Historical note: this was the first change made externally, so also in
here are the copyright headers and other housekeeping changes.)

Reviewed-by: Tuo Shan <shantuo@google.com>
Reviewed-by: kokoro <noreply+kokoro@google.com>
2018-11-13 13:15:58 -08:00
Ross Light
f8e446fa17 goose: use marker functions instead of comments
To avoid making this CL too large, I did not migrate the existing goose
comments through the repository.  This will be addressed in a subsequent
CL.

Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:56 -08:00
Ross Light
13698e656a goose: clean up comments into full sentences
Capitalize and end with period where missing.

Reviewed-by: Chris Lewis <cflewis@google.com>
2018-11-12 14:09:56 -08:00
Ross Light
3345599aaf goose: remove optional directive
This introduces some short-term pain in practice, but I aim to fix that
with the goose.Value directive.

Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:56 -08:00
Ross Light
cfc6111ea5 goose: add show command
Lists provider sets in packages given on the command line, including
outputs grouped by what is needed to obtain them.

The goose package now exports the loading phase as an API.

Example output: https://paste.googleplex.com/5509965720584192

Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:56 -08:00
Ross Light
2044e2213b goose: add struct field injection
This makes options structs and application structs much simpler to
inject.

Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:56 -08:00
Ross Light
ccf63fec5d goose: support provider cleanup functions
Documented and updated appropriate providers to reflect.

Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:56 -08:00
Ross Light
1380f96c06 goose: add interface binding
An interface binding instructs goose that a concrete type should be used
to satisfy a dependency on an interface type. goose could determine this
implicitly, but having an explicit directive makes the provider author's
intent clear and allows different concrete types to satisfy different
smaller interfaces.

Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:56 -08:00
Ross Light
73d4c0f0fc goose: allow multiple arguments to use and import
Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:56 -08:00
Chris Lewis
5261a8a8bb Make golint happy.
This CL makes golint happy by adding comments and removing underscores.
Code cultivation!

Reviewed-by: Ross Light <light@google.com>
2018-11-12 14:09:56 -08:00
Ross Light
89371e16bd goose: use same directive parsing code during inject
Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:56 -08:00
Ross Light
479a501c08 goose: add optional provider inputs
Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:55 -08:00
Ross Light
c594f05699 goose: strip vendor from generated import paths
This allows goose to work more gracefully in a vgo setting.

Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:55 -08:00
Ross Light
9af97a68c4 goose: split into multiple files
No functional change, just to make future diffs easier.

Reviewed-by: Tuo Shan <shantuo@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
2018-11-12 14:09:55 -08:00
Ross Light
cb1853b1af goose: use readable variable names
Names are inferred from types most of the time, but have a fallback for
a non-named type. Names are now also disambiguated from symbols in the
same scope.

Reviewed-by: Tuo Shan <shantuo@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
2018-11-12 14:09:55 -08:00
Ross Light
50dbe5a65d goose: add a test for imports across packages
Reviewed-by: Tuo Shan <shantuo@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
2018-11-12 14:09:55 -08:00
Ross Light
b92ac73ae3 goose: read tests from testdata
Since tests are all written in terms of Go source, it makes tests easier
to write.  They still need to be arranged in a GOPATH for go build, but
tests that just call Generate can operate in-place because I've faked
the filesystem.

Reviewed-by: Tuo Shan <shantuo@google.com>
Reviewed-by: Herbie Ong <herbie@google.com>
2018-11-12 14:09:55 -08:00
Ross Light
c9506b42e5 goose: skip function body type-checking
Learn this one weird trick to make goose an order of magnitude faster!

Reviewed-by: Herbie Ong <herbie@google.com>
Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:55 -08:00
Ross Light
34987b6bee goose: use function name as implicit provider set
Single-element provider sets are frequently useful enough to warrant
being a default.  Larger groupings within a package are less frequent.

Reviewed-by: Herbie Ong <herbie@google.com>
Reviewed-by: Tuo Shan <shantuo@google.com>
2018-11-12 14:09:55 -08:00
Ross Light
4abf804032 goose: rename module to provider set
It is more descriptive of what it is, as well as avoids confusion with
Go modules in the versioning sense.

Reviewed-by: Herbie Ong <herbie@google.com>
2018-11-12 14:09:55 -08:00
Ross Light
26c8618466 goose: dependency injection proof of concept
See documentation and demo for usage and known limitations.

Reviewed-by: Herbie Ong <herbie@google.com>
2018-11-12 14:09:55 -08:00