├── .codecov.yml ├── .contributebot ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── pull_request_template.md └── workflows │ └── tests.yml ├── AUTHORS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CONTRIBUTORS ├── LICENSE ├── README.md ├── _tutorial ├── README.md ├── main.go ├── wire.go └── wire_gen.go ├── cmd └── wire │ └── main.go ├── docs ├── best-practices.md ├── faq.md └── guide.md ├── go.mod ├── go.sum ├── internal ├── alldeps ├── check_api_change.sh ├── listdeps.sh ├── runtests.sh └── wire │ ├── analyze.go │ ├── copyast.go │ ├── errors.go │ ├── parse.go │ ├── testdata │ ├── BindInjectorArg │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── BindInjectorArgPointer │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── BindInterfaceWithValue │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── BuildTagsAllPackages │ │ ├── bar │ │ │ ├── bar.go │ │ │ └── bar_inject.go │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── Chain │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── Cleanup │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── CopyOtherDecls │ │ ├── foo │ │ │ └── foo.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── Cycle │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── DocComment │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── EmptyVar │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── ExampleWithMocks │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── ExportedValue │ │ ├── bar │ │ │ └── bar.go │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── ExportedValueDifferentPackage │ │ ├── bar │ │ │ └── bar.go │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── FieldsOfCycle │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── FieldsOfImportedStruct │ │ ├── bar │ │ │ └── bar.go │ │ ├── baz │ │ │ └── baz.go │ │ ├── foo │ │ │ └── foo.go │ │ ├── main │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── FieldsOfStruct │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── FieldsOfStructDoNotProvidePtrToField │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── FieldsOfStructPointer │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── FieldsOfValueStruct │ │ ├── bar │ │ │ └── bar.go │ │ ├── baz │ │ │ └── baz.go │ │ ├── foo │ │ │ └── foo.go │ │ ├── main │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── FuncArgProvider │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── Header │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── header │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── ImportedInterfaceBinding │ │ ├── bar │ │ │ ├── bar.go │ │ │ └── wire.go │ │ ├── foo │ │ │ └── foo.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── InjectInput │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── InjectInputConflict │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── InjectWithPanic │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── InjectorMissingCleanup │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── InjectorMissingError │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── InterfaceBinding │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── InterfaceBindingDoesntImplement │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── InterfaceBindingInvalidArg0 │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── InterfaceBindingNotEnoughArgs │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── InterfaceBindingReuse │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── InterfaceValue │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── InterfaceValueDoesntImplement │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── InterfaceValueInvalidArg0 │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── InterfaceValueNotEnoughArgs │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── InvalidInjector │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── MultipleArgsSameType │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── MultipleBindings │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── MultipleMissingInputs │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── MultipleSimilarPackages │ │ ├── bar │ │ │ └── bar.go │ │ ├── baz │ │ │ └── baz.go │ │ ├── foo │ │ │ └── foo.go │ │ ├── main │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── NamingWorstCase │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── NamingWorstCaseAllInOne │ │ ├── foo │ │ │ └── foo.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── NiladicIdentity │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── NiladicValue │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── NoImplicitInterface │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── NoInjectParamNames │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── NoopBuild │ │ ├── foo │ │ │ └── foo.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── PartialCleanup │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── PkgImport │ │ ├── anon1 │ │ │ └── anon1.go │ │ ├── anon2 │ │ │ └── anon2.go │ │ ├── bar │ │ │ └── bar.go │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── ProviderSetBindingMissingConcreteType │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── RelativePkg │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── ReservedKeywords │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── ReturnArgumentAsInterface │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── ReturnError │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── Struct │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── StructNotAStruct │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── StructPointer │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── StructWithPreventTag │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── TwoDeps │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── UnexportedStruct │ │ ├── bar │ │ │ └── bar.go │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── UnexportedValue │ │ ├── bar │ │ │ └── bar.go │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── UnusedProviders │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── ValueChain │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── ValueConversion │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── ValueFromFunctionScope │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── ValueIsInterfaceValue │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ └── wire_errs.txt │ ├── ValueIsStruct │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ ├── VarValue │ │ ├── foo │ │ │ ├── foo.go │ │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ │ ├── program_out.txt │ │ │ └── wire_gen.go │ └── Varargs │ │ ├── foo │ │ ├── foo.go │ │ └── wire.go │ │ ├── pkg │ │ └── want │ │ ├── program_out.txt │ │ └── wire_gen.go │ ├── wire.go │ └── wire_test.go └── wire.go /.codecov.yml: -------------------------------------------------------------------------------- 1 | comment: off 2 | coverage: 3 | status: 4 | project: 5 | default: 6 | target: 0 7 | threshold: null 8 | base: auto 9 | patch: 10 | default: 11 | target: 0 12 | threshold: null 13 | base: auto 14 | -------------------------------------------------------------------------------- /.contributebot: -------------------------------------------------------------------------------- 1 | { 2 | "issue_title_pattern": "^.*$", 3 | "pull_request_title_response": "Please edit the title of this pull request with the name of the affected component, or \"all\", followed by a colon, followed by a short summary of the change." 4 | } 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve Wire 4 | 5 | --- 6 | 7 | You can use `go bug` to have a cool, automatically filled out bug template, or 8 | fill out the template below. 9 | 10 | ### Describe the bug 11 | 12 | A clear and concise description of what the bug is. 13 | 14 | ### To Reproduce 15 | 16 | Steps to reproduce the behavior. 17 | 18 | ## Expected behavior 19 | 20 | A clear and concise description of what you expected to happen. 21 | 22 | ### Version 23 | 24 | Which version of Wire are you seeing the bug with? 25 | 26 | ### Additional context 27 | 28 | Add any other context about the problem here. 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | ### Is your feature request related to a problem? Please describe. 8 | 9 | A clear and concise description of what the problem is. Ex. I'm always 10 | frustrated when [...] 11 | 12 | ### Describe the solution you'd like 13 | 14 | A clear and concise description of what you want to happen. 15 | 16 | ### Describe alternatives you've considered 17 | 18 | A clear and concise description of any alternative solutions or features you've 19 | considered. 20 | 21 | ### Additional context 22 | 23 | Add any other context or screenshots about the feature request here. 24 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | Please reference any Issue related to this Pull Request. Example: `Fixes #1`. 2 | 3 | See 4 | [here](https://blog.github.com/2015-01-21-how-to-write-the-perfect-pull-request/) 5 | for tips on good Pull Request description. 6 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The Wire Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Wire Tests 16 | on: [push, pull_request] 17 | jobs: 18 | build: 19 | strategy: 20 | matrix: 21 | os: [ubuntu-latest, macos-latest, windows-latest] 22 | go-version: [1.22.x] 23 | runs-on: ${{ matrix.os }} 24 | steps: 25 | - name: Install Go 26 | uses: actions/setup-go@v2 27 | with: 28 | go-version: ${{ matrix.go-version }} 29 | - name: Checkout code 30 | uses: actions/checkout@v2 31 | with: 32 | fetch-depth: 2 # required for codecov 33 | - name: Run Tests 34 | shell: bash 35 | run: 'internal/runtests.sh' 36 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of Wire authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as one of 6 | # Organization's name 7 | # Individual's name 8 | # Individual's name 9 | # See CONTRIBUTORS for the meaning of multiple email addresses. 10 | 11 | # Please keep the list sorted. 12 | 13 | Google LLC 14 | ktr 15 | Kumbirai Tanekha 16 | Oleg Kovalov 17 | Yoichiro Shimizu 18 | Zachary Romero 19 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | This project is covered under the [Go Code of Conduct][]. In summary: 4 | 5 | - Treat everyone with respect and kindness. 6 | - Be thoughtful in how you communicate. 7 | - Don’t be destructive or inflammatory. 8 | - If you encounter an issue, please mail conduct@golang.org. 9 | 10 | [Go Code of Conduct]: https://golang.org/conduct 11 | -------------------------------------------------------------------------------- /_tutorial/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //go:build wireinject 16 | // +build wireinject 17 | 18 | // The build tag makes sure the stub is not built in the final build. 19 | package main 20 | 21 | import "github.com/google/wire" 22 | 23 | // InitializeEvent creates an Event. It will error if the Event is staffed with 24 | // a grumpy greeter. 25 | func InitializeEvent(phrase string) (Event, error) { 26 | wire.Build(NewEvent, NewGreeter, NewMessage) 27 | return Event{}, nil 28 | } 29 | -------------------------------------------------------------------------------- /_tutorial/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func InitializeEvent(phrase string) (Event, error) { 12 | message := NewMessage(phrase) 13 | greeter := NewGreeter(message) 14 | event, err := NewEvent(greeter) 15 | if err != nil { 16 | return Event{}, err 17 | } 18 | return event, nil 19 | } 20 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/google/wire 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/google/go-cmp v0.2.0 7 | github.com/google/subcommands v1.2.0 8 | github.com/pmezard/go-difflib v1.0.0 9 | golang.org/x/tools v0.17.0 10 | ) 11 | -------------------------------------------------------------------------------- /internal/alldeps: -------------------------------------------------------------------------------- 1 | github.com/google/subcommands 2 | github.com/google/wire 3 | github.com/pmezard/go-difflib 4 | golang.org/x/mod 5 | golang.org/x/tools 6 | -------------------------------------------------------------------------------- /internal/listdeps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2019 The Wire Authors 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -euo pipefail 17 | 18 | # To run this script manually to update alldeps: 19 | # 20 | # $ internal/listdeps.sh > internal/alldeps 21 | # 22 | # Important note: there are changes in module tooling behavior between go 1.11 23 | # and go 1.12; please make sure to use the same version of Go as used by Github 24 | # Actions (see .github/workflows/tests.yml) when updating the alldeps file. 25 | go list -deps -f '{{with .Module}}{{.Path}}{{end}}' ./... | sort | uniq 26 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArg/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(inject(Foo{"hello"}).Name) 23 | } 24 | 25 | type Fooer interface { 26 | Foo() string 27 | } 28 | 29 | type Foo struct { 30 | f string 31 | } 32 | 33 | func (f Foo) Foo() string { 34 | return f.f 35 | } 36 | 37 | type Bar struct { 38 | Name string 39 | } 40 | 41 | func NewBar(fooer Fooer) *Bar { 42 | return &Bar{Name: fooer.Foo()} 43 | } 44 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArg/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func inject(foo Foo) *Bar { 24 | wire.Build( 25 | NewBar, 26 | wire.Bind(new(Fooer), new(Foo)), 27 | ) 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArg/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArg/want/program_out.txt: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArg/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func inject(foo Foo) *Bar { 12 | bar := NewBar(foo) 13 | return bar 14 | } 15 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArgPointer/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(inject(&Foo{"hello"}).Name) 23 | } 24 | 25 | type Fooer interface { 26 | Foo() string 27 | } 28 | 29 | type Foo struct { 30 | f string 31 | } 32 | 33 | func (f *Foo) Foo() string { 34 | return f.f 35 | } 36 | 37 | type Bar struct { 38 | Name string 39 | } 40 | 41 | func NewBar(fooer Fooer) *Bar { 42 | return &Bar{Name: fooer.Foo()} 43 | } 44 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArgPointer/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func inject(foo *Foo) *Bar { 24 | wire.Build( 25 | NewBar, 26 | wire.Bind(new(Fooer), new(*Foo)), 27 | ) 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArgPointer/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArgPointer/want/program_out.txt: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInjectorArgPointer/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func inject(foo *Foo) *Bar { 12 | bar := NewBar(foo) 13 | return bar 14 | } 15 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInterfaceWithValue/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | func main() { 18 | w := inject() 19 | w.Write([]byte("Hello, World!")) 20 | } 21 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInterfaceWithValue/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "io" 21 | "os" 22 | 23 | "github.com/google/wire" 24 | ) 25 | 26 | func inject() io.Writer { 27 | wire.Build( 28 | wire.Value(os.Stdout), 29 | wire.Bind(new(io.Writer), new(*os.File)), 30 | ) 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInterfaceWithValue/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/BindInterfaceWithValue/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! -------------------------------------------------------------------------------- /internal/wire/testdata/BindInterfaceWithValue/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "io" 11 | "os" 12 | ) 13 | 14 | // Injectors from wire.go: 15 | 16 | func inject() io.Writer { 17 | file := _wireFileValue 18 | return file 19 | } 20 | 21 | var ( 22 | _wireFileValue = os.Stdout 23 | ) 24 | -------------------------------------------------------------------------------- /internal/wire/testdata/BuildTagsAllPackages/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build !wireinject 16 | 17 | // Package bar includes both wireinject and non-wireinject variants. 18 | package bar 19 | 20 | import "github.com/google/wire" 21 | 22 | // Set provides an unfriendly user greeting. 23 | var Set = wire.NewSet(wire.Value("Bah humbug! This is the wrong variant!")) 24 | -------------------------------------------------------------------------------- /internal/wire/testdata/BuildTagsAllPackages/bar/bar_inject.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package bar 18 | 19 | import "github.com/google/wire" 20 | 21 | // Set provides a friendly user greeting. 22 | var Set = wire.NewSet(wire.Value("Hello, World!")) 23 | -------------------------------------------------------------------------------- /internal/wire/testdata/BuildTagsAllPackages/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/BuildTagsAllPackages/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "example.com/bar" 21 | "github.com/google/wire" 22 | ) 23 | 24 | func injectedMessage() string { 25 | wire.Build(bar.Set) 26 | return "" 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/BuildTagsAllPackages/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/BuildTagsAllPackages/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/BuildTagsAllPackages/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage() string { 12 | string2 := _wireStringValue 13 | return string2 14 | } 15 | 16 | var ( 17 | _wireStringValue = "Hello, World!" 18 | ) 19 | -------------------------------------------------------------------------------- /internal/wire/testdata/Chain/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/google/wire" 21 | ) 22 | 23 | func main() { 24 | fmt.Println(injectFooBar()) 25 | } 26 | 27 | type Foo int 28 | type FooBar int 29 | 30 | var Set = wire.NewSet( 31 | provideFoo, 32 | provideFooBar) 33 | 34 | func provideFoo() Foo { 35 | return 41 36 | } 37 | 38 | func provideFooBar(foo Foo) FooBar { 39 | return FooBar(foo) + 1 40 | } 41 | -------------------------------------------------------------------------------- /internal/wire/testdata/Chain/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooBar() FooBar { 24 | wire.Build(Set) 25 | return 0 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/Chain/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/Chain/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/Chain/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFooBar() FooBar { 12 | foo := provideFoo() 13 | fooBar := provideFooBar(foo) 14 | return fooBar 15 | } 16 | -------------------------------------------------------------------------------- /internal/wire/testdata/Cleanup/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | bar, cleanup := injectBar() 23 | fmt.Println(*bar) 24 | cleanup() 25 | fmt.Println(*bar) 26 | } 27 | 28 | type Foo int 29 | type Bar int 30 | 31 | func provideFoo() (*Foo, func()) { 32 | foo := new(Foo) 33 | *foo = 42 34 | return foo, func() { *foo = 0 } 35 | } 36 | 37 | func provideBar(foo *Foo) (*Bar, func()) { 38 | bar := new(Bar) 39 | *bar = 77 40 | return bar, func() { 41 | if *foo == 0 { 42 | panic("foo cleaned up before bar") 43 | } 44 | *bar = 0 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /internal/wire/testdata/Cleanup/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectBar() (*Bar, func()) { 24 | wire.Build(provideFoo, provideBar) 25 | return nil, nil 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/Cleanup/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/Cleanup/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 77 2 | 0 3 | -------------------------------------------------------------------------------- /internal/wire/testdata/Cleanup/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectBar() (*Bar, func()) { 12 | foo, cleanup := provideFoo() 13 | bar, cleanup2 := provideBar(foo) 14 | return bar, func() { 15 | cleanup2() 16 | cleanup() 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /internal/wire/testdata/CopyOtherDecls/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | // All of the declarations are in one file. 18 | // Wire should copy non-injectors over, preserving imports. 19 | 20 | package main 21 | 22 | import ( 23 | "fmt" 24 | 25 | "github.com/google/wire" 26 | ) 27 | 28 | func main() { 29 | fmt.Println(injectedMessage()) 30 | } 31 | 32 | // provideMessage provides a friendly user greeting. 33 | func provideMessage() string { 34 | return "Hello, World!" 35 | } 36 | 37 | func injectedMessage() string { 38 | wire.Build(provideMessage) 39 | return "" 40 | } 41 | -------------------------------------------------------------------------------- /internal/wire/testdata/CopyOtherDecls/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/CopyOtherDecls/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/CopyOtherDecls/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "fmt" 11 | ) 12 | 13 | // Injectors from foo.go: 14 | 15 | func injectedMessage() string { 16 | string2 := provideMessage() 17 | return string2 18 | } 19 | 20 | // foo.go: 21 | 22 | func main() { 23 | fmt.Println(injectedMessage()) 24 | } 25 | 26 | // provideMessage provides a friendly user greeting. 27 | func provideMessage() string { 28 | return "Hello, World!" 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/Cycle/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedBaz()) 21 | } 22 | 23 | type Foo int 24 | type Bar int 25 | type Baz int 26 | 27 | func provideFoo(_ Baz) Foo { 28 | return 0 29 | } 30 | 31 | func provideBar(_ Foo) Bar { 32 | return 0 33 | } 34 | 35 | func provideBaz(_ Bar) Baz { 36 | return 0 37 | } 38 | -------------------------------------------------------------------------------- /internal/wire/testdata/Cycle/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedBaz() Baz { 24 | wire.Build(provideFoo, provideBar, provideBaz) 25 | return 0 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/Cycle/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/Cycle/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: cycle for example.com/foo.Bar: 2 | example.com/foo.Bar (example.com/foo.provideBar) -> 3 | example.com/foo.Foo (example.com/foo.provideFoo) -> 4 | example.com/foo.Baz (example.com/foo.provideBaz) -> 5 | example.com/foo.Bar -------------------------------------------------------------------------------- /internal/wire/testdata/DocComment/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | type ( 22 | Bar struct{} 23 | Foo struct{} 24 | ) 25 | 26 | func main() { 27 | fmt.Println("Hello, World") 28 | } 29 | -------------------------------------------------------------------------------- /internal/wire/testdata/DocComment/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | /* blockComment returns Foo and has a /*- style doc comment */ 24 | func blockComment() *Foo { 25 | panic(wire.Build(wire.Struct(new(Foo)))) 26 | } 27 | 28 | // lineComment returns Bar and has a //- style doc comment 29 | func lineComment() *Bar { 30 | panic(wire.Build(wire.Struct(new(Bar)))) 31 | } 32 | -------------------------------------------------------------------------------- /internal/wire/testdata/DocComment/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/DocComment/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/DocComment/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | /* blockComment returns Foo and has a /*- style doc comment */ 12 | func blockComment() *Foo { 13 | foo := &Foo{} 14 | return foo 15 | } 16 | 17 | // lineComment returns Bar and has a //- style doc comment 18 | func lineComment() *Bar { 19 | bar := &Bar{} 20 | return bar 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/EmptyVar/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(injectedMessage()) 23 | } 24 | 25 | var myFakeSet struct{} 26 | -------------------------------------------------------------------------------- /internal/wire/testdata/EmptyVar/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | wire.Build(myFakeSet) 25 | return "" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/EmptyVar/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/EmptyVar/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: var example.com/foo.myFakeSet struct{} is not a provider or a provider set -------------------------------------------------------------------------------- /internal/wire/testdata/ExampleWithMocks/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExampleWithMocks/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Real time greeting: Good day! It is [current time elided] 2 | Approach A 3 | Good day! It is 0001-01-01 00:00:00 +0000 UTC 4 | Good day! It is 2000-01-01 00:00:00 +0000 UTC 5 | Approach B 6 | Good day! It is 0001-01-01 00:00:00 +0000 UTC 7 | Good day! It is 1000-01-01 00:00:00 +0000 UTC 8 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExampleWithMocks/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | // initApp returns a real app. 12 | func initApp() *app { 13 | mainTimer := _wireRealTimeValue 14 | mainGreeter := greeter{ 15 | T: mainTimer, 16 | } 17 | mainApp := &app{ 18 | g: mainGreeter, 19 | } 20 | return mainApp 21 | } 22 | 23 | var ( 24 | _wireRealTimeValue = realTime{} 25 | ) 26 | 27 | // initMockedAppFromArgs returns an app with mocked dependencies provided via 28 | // arguments (Approach A). Note that the argument's type is the interface 29 | // type (timer), but the concrete mock type should be passed. 30 | func initMockedAppFromArgs(mt timer) *app { 31 | mainGreeter := greeter{ 32 | T: mt, 33 | } 34 | mainApp := &app{ 35 | g: mainGreeter, 36 | } 37 | return mainApp 38 | } 39 | 40 | // initMockedApp returns an app with its mocked dependencies, created 41 | // via providers (Approach B). 42 | func initMockedApp() *appWithMocks { 43 | mainMockTimer := newMockTimer() 44 | mainGreeter := greeter{ 45 | T: mainMockTimer, 46 | } 47 | mainApp := app{ 48 | g: mainGreeter, 49 | } 50 | mainAppWithMocks := &appWithMocks{ 51 | app: mainApp, 52 | mt: mainMockTimer, 53 | } 54 | return mainAppWithMocks 55 | } 56 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValue/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package bar 16 | 17 | import "github.com/google/wire" 18 | 19 | var Value = wire.Value(PublicMsg) 20 | 21 | var PublicMsg = "Hello, World!" 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValue/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValue/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "example.com/bar" 21 | "github.com/google/wire" 22 | ) 23 | 24 | func injectedMessage() string { 25 | wire.Build(bar.Value) 26 | return "" 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValue/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValue/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValue/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "example.com/bar" 11 | ) 12 | 13 | // Injectors from wire.go: 14 | 15 | func injectedMessage() string { 16 | string2 := _wireStringValue 17 | return string2 18 | } 19 | 20 | var ( 21 | _wireStringValue = bar.PublicMsg 22 | ) 23 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValueDifferentPackage/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package bar 16 | 17 | import ( 18 | "os" 19 | 20 | "github.com/google/wire" 21 | ) 22 | 23 | var Value = wire.Value(os.Stdout) 24 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValueDifferentPackage/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Fprintln(injectedFile(), "Hello, World!") 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValueDifferentPackage/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "os" 21 | 22 | "example.com/bar" 23 | "github.com/google/wire" 24 | ) 25 | 26 | func injectedFile() *os.File { 27 | wire.Build(bar.Value) 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValueDifferentPackage/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValueDifferentPackage/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ExportedValueDifferentPackage/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "os" 11 | ) 12 | 13 | // Injectors from wire.go: 14 | 15 | func injectedFile() *os.File { 16 | file := _wireFileValue 17 | return file 18 | } 19 | 20 | var ( 21 | _wireFileValue = os.Stdout 22 | ) 23 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfCycle/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(injectedBaz()) 23 | } 24 | 25 | type Foo int 26 | type Baz int 27 | 28 | type Bar struct { 29 | Bz Baz 30 | } 31 | 32 | func provideFoo(_ Baz) Foo { 33 | return 0 34 | } 35 | 36 | func provideBar(_ Foo) Bar { 37 | return Bar{} 38 | } 39 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfCycle/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedBaz() Baz { 24 | wire.Build(provideFoo, provideBar, wire.FieldsOf(new(Bar), "Bz")) 25 | return 0 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfCycle/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfCycle/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: cycle for example.com/foo.Bar: 2 | example.com/foo.Bar (example.com/foo.provideBar) -> 3 | example.com/foo.Foo (example.com/foo.provideFoo) -> 4 | example.com/foo.Baz (example.com/foo.Bar.Bz) -> 5 | example.com/foo.Bar -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfImportedStruct/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package bar 16 | 17 | import ( 18 | "example.com/foo" 19 | ) 20 | 21 | type Config struct { 22 | V int 23 | } 24 | 25 | type Service struct { 26 | Cfg *Config 27 | F *foo.Service 28 | } 29 | 30 | func New(cfg *Config, f *foo.Service) *Service { 31 | return &Service{Cfg: cfg, F: f} 32 | } 33 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfImportedStruct/baz/baz.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package baz 16 | 17 | import ( 18 | "fmt" 19 | 20 | "example.com/bar" 21 | "example.com/foo" 22 | ) 23 | 24 | type Config struct { 25 | Foo *foo.Config 26 | Bar *bar.Config 27 | } 28 | 29 | type Service struct { 30 | Foo *foo.Service 31 | Bar *bar.Service 32 | } 33 | 34 | func (m *Service) String() string { 35 | return fmt.Sprintf("%d %d", m.Foo.Cfg.V, m.Bar.Cfg.V) 36 | } 37 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfImportedStruct/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package foo 16 | 17 | type Config struct { 18 | V int 19 | } 20 | 21 | type Service struct { 22 | Cfg *Config 23 | } 24 | 25 | func New(cfg *Config) *Service { 26 | return &Service{Cfg: cfg} 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfImportedStruct/main/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | 22 | "example.com/bar" 23 | "example.com/baz" 24 | "example.com/foo" 25 | "github.com/google/wire" 26 | ) 27 | 28 | func newBazService(*baz.Config) *baz.Service { 29 | wire.Build( 30 | wire.Struct(new(baz.Service), "*"), 31 | wire.FieldsOf( 32 | new(*baz.Config), 33 | "Foo", 34 | "Bar", 35 | ), 36 | foo.New, 37 | bar.New, 38 | ) 39 | return nil 40 | } 41 | 42 | func main() { 43 | cfg := &baz.Config{ 44 | Foo: &foo.Config{1}, 45 | Bar: &bar.Config{2}, 46 | } 47 | svc := newBazService(cfg) 48 | fmt.Println(svc.String()) 49 | } 50 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfImportedStruct/pkg: -------------------------------------------------------------------------------- 1 | example.com/main 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfImportedStruct/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 1 2 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfImportedStruct/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "example.com/bar" 11 | "example.com/baz" 12 | "example.com/foo" 13 | "fmt" 14 | ) 15 | 16 | // Injectors from wire.go: 17 | 18 | func newBazService(config *baz.Config) *baz.Service { 19 | fooConfig := config.Foo 20 | service := foo.New(fooConfig) 21 | barConfig := config.Bar 22 | barService := bar.New(barConfig, service) 23 | bazService := &baz.Service{ 24 | Foo: service, 25 | Bar: barService, 26 | } 27 | return bazService 28 | } 29 | 30 | // wire.go: 31 | 32 | func main() { 33 | cfg := &baz.Config{ 34 | Foo: &foo.Config{1}, 35 | Bar: &bar.Config{2}, 36 | } 37 | svc := newBazService(cfg) 38 | fmt.Println(svc.String()) 39 | } 40 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStruct/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | type S struct { 20 | Foo string 21 | } 22 | 23 | func provideS() S { 24 | return S{Foo: "Hello, World!"} 25 | } 26 | 27 | func main() { 28 | fmt.Println(injectedMessage()) 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStruct/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | wire.Build( 25 | provideS, 26 | wire.FieldsOf(new(S), "Foo")) 27 | return "" 28 | } 29 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStruct/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStruct/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStruct/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage() string { 12 | s := provideS() 13 | string2 := s.Foo 14 | return string2 15 | } 16 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStructDoNotProvidePtrToField/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | type S struct { 20 | Foo string 21 | } 22 | 23 | func provideS() S { 24 | return S{Foo: "Hello, World!"} 25 | } 26 | 27 | func main() { 28 | fmt.Println("pointer to " + *injectedMessagePtr()) 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStructDoNotProvidePtrToField/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessagePtr() *string { 24 | // This shouldn't work; FieldsOf provides a pointer to the 25 | // field only when the struct type is a pointer to a struct. 26 | // See FieldsOfStructPointer for a working example using 27 | // a pointer to a struct. 28 | wire.Build( 29 | provideS, 30 | wire.FieldsOf(new(S), "Foo")) 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStructDoNotProvidePtrToField/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStructDoNotProvidePtrToField/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: inject injectedMessagePtr: no provider found for *string, output of injector -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStructPointer/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | type S struct { 20 | Foo string 21 | } 22 | 23 | func provideS() *S { 24 | return &S{Foo: "Hello, World!"} 25 | } 26 | 27 | func main() { 28 | fmt.Println(injectedMessage()) 29 | fmt.Println("pointer to " + *injectedMessagePtr()) 30 | } 31 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStructPointer/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | wire.Build( 25 | provideS, 26 | wire.FieldsOf(new(*S), "Foo")) 27 | return "" 28 | } 29 | 30 | func injectedMessagePtr() *string { 31 | wire.Build( 32 | provideS, 33 | wire.FieldsOf(new(*S), "Foo")) 34 | return nil 35 | } 36 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStructPointer/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStructPointer/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | pointer to Hello, World! 3 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfStructPointer/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage() string { 12 | s := provideS() 13 | string2 := s.Foo 14 | return string2 15 | } 16 | 17 | func injectedMessagePtr() *string { 18 | s := provideS() 19 | string2 := &s.Foo 20 | return string2 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfValueStruct/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package bar 16 | 17 | import ( 18 | "example.com/foo" 19 | ) 20 | 21 | type Config struct { 22 | V int 23 | } 24 | 25 | type Service struct { 26 | Cfg *Config 27 | F *foo.Service 28 | } 29 | 30 | func New(cfg *Config, f *foo.Service) *Service { 31 | return &Service{Cfg: cfg, F: f} 32 | } 33 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfValueStruct/baz/baz.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package baz 16 | 17 | import ( 18 | "fmt" 19 | 20 | "example.com/bar" 21 | "example.com/foo" 22 | ) 23 | 24 | type Config struct { 25 | Foo *foo.Config 26 | Bar *bar.Config 27 | } 28 | 29 | type Service struct { 30 | Foo *foo.Service 31 | Bar *bar.Service 32 | } 33 | 34 | func (m *Service) String() string { 35 | return fmt.Sprintf("%d %d", m.Foo.Cfg.V, m.Bar.Cfg.V) 36 | } 37 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfValueStruct/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package foo 16 | 17 | type Config struct { 18 | V int 19 | } 20 | 21 | type Service struct { 22 | Cfg *Config 23 | } 24 | 25 | func New(cfg *Config) *Service { 26 | return &Service{Cfg: cfg} 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfValueStruct/main/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | 22 | "example.com/bar" 23 | "example.com/baz" 24 | "example.com/foo" 25 | "github.com/google/wire" 26 | ) 27 | 28 | func newBazService() *baz.Service { 29 | wire.Build( 30 | wire.Struct(new(baz.Service), "*"), 31 | wire.Value(&baz.Config{ 32 | Foo: &foo.Config{1}, 33 | Bar: &bar.Config{2}, 34 | }), 35 | wire.FieldsOf( 36 | new(*baz.Config), 37 | "Foo", 38 | "Bar", 39 | ), 40 | foo.New, 41 | bar.New, 42 | ) 43 | return nil 44 | } 45 | 46 | func main() { 47 | svc := newBazService() 48 | fmt.Println(svc.String()) 49 | } 50 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfValueStruct/pkg: -------------------------------------------------------------------------------- 1 | example.com/main 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfValueStruct/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 1 2 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FieldsOfValueStruct/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "example.com/bar" 11 | "example.com/baz" 12 | "example.com/foo" 13 | "fmt" 14 | ) 15 | 16 | // Injectors from wire.go: 17 | 18 | func newBazService() *baz.Service { 19 | config := _wireConfigValue 20 | fooConfig := config.Foo 21 | service := foo.New(fooConfig) 22 | barConfig := config.Bar 23 | barService := bar.New(barConfig, service) 24 | bazService := &baz.Service{ 25 | Foo: service, 26 | Bar: barService, 27 | } 28 | return bazService 29 | } 30 | 31 | var ( 32 | _wireConfigValue = &baz.Config{ 33 | Foo: &foo.Config{1}, 34 | Bar: &bar.Config{2}, 35 | } 36 | ) 37 | 38 | // wire.go: 39 | 40 | func main() { 41 | svc := newBazService() 42 | fmt.Println(svc.String()) 43 | } 44 | -------------------------------------------------------------------------------- /internal/wire/testdata/FuncArgProvider/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | bar := injectBar(func() *Foo { return &Foo{42} }) 23 | fmt.Println(bar.Name) 24 | } 25 | 26 | type Foo struct { 27 | Val int 28 | } 29 | 30 | type Bar struct { 31 | Name string 32 | } 33 | 34 | func NewBar(f *Foo) *Bar { 35 | return &Bar{Name: fmt.Sprintf("foo value %d", f.Val)} 36 | } 37 | -------------------------------------------------------------------------------- /internal/wire/testdata/FuncArgProvider/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectBar(fn func() *Foo) *Bar { 24 | // fails because it doesn't identify fn as a Provider; see #723. 25 | panic(wire.Build(fn, NewBar)) 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/FuncArgProvider/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/FuncArgProvider/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: var fn func() *example.com/foo.Foo is not a provider or a provider set -------------------------------------------------------------------------------- /internal/wire/testdata/Header/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(injectFoo()) 23 | } 24 | 25 | type Foo int 26 | 27 | func provideFoo() Foo { 28 | return 41 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/Header/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFoo() Foo { 24 | wire.Build(provideFoo) 25 | return Foo(0) 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/Header/header: -------------------------------------------------------------------------------- 1 | // This is a sample header file. 2 | // 3 | -------------------------------------------------------------------------------- /internal/wire/testdata/Header/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/Header/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 41 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/Header/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // This is a sample header file. 2 | // 3 | // Code generated by Wire. DO NOT EDIT. 4 | 5 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 6 | //go:build !wireinject 7 | // +build !wireinject 8 | 9 | package main 10 | 11 | // Injectors from wire.go: 12 | 13 | func injectFoo() Foo { 14 | foo := provideFoo() 15 | return foo 16 | } 17 | -------------------------------------------------------------------------------- /internal/wire/testdata/ImportedInterfaceBinding/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | "example.com/foo" 21 | "github.com/google/wire" 22 | ) 23 | 24 | func main() { 25 | fmt.Println(injectFooer().Foo()) 26 | } 27 | 28 | type Bar string 29 | 30 | func (b *Bar) Foo() string { 31 | return string(*b) 32 | } 33 | 34 | func provideBar() *Bar { 35 | b := new(Bar) 36 | *b = "Hello, World!" 37 | return b 38 | } 39 | 40 | var Set = wire.NewSet( 41 | provideBar, 42 | wire.Bind(new(foo.Fooer), new(*Bar))) 43 | -------------------------------------------------------------------------------- /internal/wire/testdata/ImportedInterfaceBinding/bar/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "example.com/foo" 21 | "github.com/google/wire" 22 | ) 23 | 24 | func injectFooer() foo.Fooer { 25 | wire.Build(Set) 26 | return nil 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/ImportedInterfaceBinding/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package foo 16 | 17 | type Fooer interface { 18 | Foo() string 19 | } 20 | -------------------------------------------------------------------------------- /internal/wire/testdata/ImportedInterfaceBinding/pkg: -------------------------------------------------------------------------------- 1 | example.com/bar 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ImportedInterfaceBinding/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ImportedInterfaceBinding/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "example.com/foo" 11 | ) 12 | 13 | // Injectors from wire.go: 14 | 15 | func injectFooer() foo.Fooer { 16 | bar := provideBar() 17 | return bar 18 | } 19 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectInput/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/google/wire" 21 | ) 22 | 23 | func main() { 24 | fmt.Println(injectFooBar(40)) 25 | } 26 | 27 | type Foo int 28 | type Bar int 29 | type FooBar int 30 | 31 | var Set = wire.NewSet( 32 | provideBar, 33 | provideFooBar) 34 | 35 | func provideBar() Bar { 36 | return 2 37 | } 38 | 39 | func provideFooBar(foo Foo, bar Bar) FooBar { 40 | return FooBar(foo) + FooBar(bar) 41 | } 42 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectInput/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooBar(foo Foo) FooBar { 24 | wire.Build(Set) 25 | return 0 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectInput/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectInput/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectInput/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFooBar(foo Foo) FooBar { 12 | bar := provideBar() 13 | fooBar := provideFooBar(foo, bar) 14 | return fooBar 15 | } 16 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectInputConflict/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/google/wire" 21 | ) 22 | 23 | func main() { 24 | // I'm on the fence as to whether this should be an error (versus an 25 | // override). For now, I will make it an error that can be relaxed 26 | // later. 27 | fmt.Println(injectBar(40)) 28 | } 29 | 30 | type Foo int 31 | type Bar int 32 | 33 | var Set = wire.NewSet( 34 | provideFoo, 35 | provideBar) 36 | 37 | func provideFoo() Foo { 38 | return -888 39 | } 40 | 41 | func provideBar(foo Foo) Bar { 42 | return 2 43 | } 44 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectInputConflict/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectBar(foo Foo) Bar { 24 | wire.Build(Set) 25 | return 0 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectInputConflict/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectInputConflict/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: multiple bindings for example.com/foo.Foo 2 | current: 3 | <- provider "provideFoo" (example.com/foo/foo.go:x:y) 4 | <- provider set "Set" (example.com/foo/foo.go:x:y) 5 | previous: 6 | <- argument foo to injector function injectBar (example.com/foo/wire.go:x:y) -------------------------------------------------------------------------------- /internal/wire/testdata/InjectWithPanic/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | 23 | // provideMessage provides a friendly user greeting. 24 | func provideMessage() string { 25 | return "Hello, World!" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectWithPanic/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | panic(wire.Build(provideMessage)) 25 | } 26 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectWithPanic/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectWithPanic/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectWithPanic/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage() string { 12 | string2 := provideMessage() 13 | return string2 14 | } 15 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectorMissingCleanup/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | foo := injectFoo() 23 | fmt.Println(foo) 24 | } 25 | 26 | type Foo int 27 | 28 | func provideFoo() (Foo, func()) { 29 | return Foo(42), func() {} 30 | } 31 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectorMissingCleanup/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFoo() Foo { 24 | // provideFoo returns a cleanup, but injectFoo does not. 25 | wire.Build(provideFoo) 26 | return Foo(0) 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectorMissingCleanup/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectorMissingCleanup/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: inject injectFoo: provider for example.com/foo.Foo returns cleanup but injection does not return cleanup function -------------------------------------------------------------------------------- /internal/wire/testdata/InjectorMissingError/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | foo := injectFoo() 23 | fmt.Println(foo) 24 | } 25 | 26 | type Foo int 27 | 28 | func provideFoo() (Foo, error) { 29 | return Foo(42), nil 30 | } 31 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectorMissingError/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFoo() Foo { 24 | // provideFoo returns an error, but injectFoo does not. 25 | wire.Build(provideFoo) 26 | return Foo(0) 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectorMissingError/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InjectorMissingError/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: inject injectFoo: provider for example.com/foo.Foo returns error but injection not allowed to fail -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBinding/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/google/wire" 21 | ) 22 | 23 | func main() { 24 | fmt.Println(injectFooer().Foo()) 25 | } 26 | 27 | type Fooer interface { 28 | Foo() string 29 | } 30 | 31 | type Bar string 32 | 33 | func (b *Bar) Foo() string { 34 | return string(*b) 35 | } 36 | 37 | func provideBar() *Bar { 38 | b := new(Bar) 39 | *b = "Hello, World!" 40 | return b 41 | } 42 | 43 | var Set = wire.NewSet( 44 | provideBar, 45 | wire.Bind(new(Fooer), new(*Bar))) 46 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBinding/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooer() Fooer { 24 | wire.Build(Set) 25 | return nil 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBinding/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBinding/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBinding/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFooer() Fooer { 12 | bar := provideBar() 13 | return bar 14 | } 15 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingDoesntImplement/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(injectFooer().Foo()) 23 | } 24 | 25 | type Fooer interface { 26 | Foo() string 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingDoesntImplement/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooer() Fooer { 24 | // wrong: string doesn't implement Fooer. 25 | wire.Build(wire.Bind(new(Fooer), new(string))) 26 | return nil 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingDoesntImplement/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingDoesntImplement/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: string does not implement example.com/foo.Fooer -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingInvalidArg0/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(injectFooer().Foo()) 23 | } 24 | 25 | type Fooer interface { 26 | Foo() string 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingInvalidArg0/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooer() Fooer { 24 | // wrong: arg0 must be a pointer to an interface. 25 | wire.Build(wire.Bind("foo", "bar")) 26 | return nil 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingInvalidArg0/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingInvalidArg0/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: first argument to Bind must be a pointer to an interface type; found string -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingNotEnoughArgs/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(injectFooer().Foo()) 23 | } 24 | 25 | type Fooer interface { 26 | Foo() string 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingNotEnoughArgs/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooer() Fooer { 24 | // wrong: wire.Bind requires 2 args. 25 | wire.Build(wire.Bind(new(Fooer))) 26 | return nil 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingNotEnoughArgs/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingNotEnoughArgs/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: not enough arguments in call to wire.Bind 2 | have (*Fooer) 3 | want (interface{}, interface{}) -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingReuse/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooBar() FooBar { 24 | wire.Build( 25 | provideBar, 26 | provideFooBar, 27 | wire.Bind(new(Fooer), new(*Bar)), 28 | ) 29 | return FooBar{} 30 | } 31 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingReuse/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingReuse/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 1 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceBindingReuse/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFooBar() FooBar { 12 | bar := provideBar() 13 | fooBar := provideFooBar(bar, bar) 14 | return fooBar 15 | } 16 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValue/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "io/ioutil" 20 | ) 21 | 22 | func main() { 23 | r := injectedReader() 24 | buf, _ := ioutil.ReadAll(r) 25 | fmt.Println(string(buf)) 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValue/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "io" 21 | "strings" 22 | 23 | "github.com/google/wire" 24 | ) 25 | 26 | func injectedReader() io.Reader { 27 | wire.Build(wire.InterfaceValue(new(io.Reader), strings.NewReader("hello world"))) 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValue/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValue/want/program_out.txt: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValue/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "io" 11 | "strings" 12 | ) 13 | 14 | // Injectors from wire.go: 15 | 16 | func injectedReader() io.Reader { 17 | reader := _wireReaderValue 18 | return reader 19 | } 20 | 21 | var ( 22 | _wireReaderValue = strings.NewReader("hello world") 23 | ) 24 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueDoesntImplement/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueDoesntImplement/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | "io" 22 | ) 23 | 24 | func injectedMessage() string { 25 | // wrong: string doesn't implement io.Reader. 26 | wire.Build(wire.InterfaceValue(new(io.Reader), "bar")) 27 | return "" 28 | } 29 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueDoesntImplement/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueDoesntImplement/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: string does not implement io.Reader -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueInvalidArg0/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueInvalidArg0/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | // wrong: arg0 must be a pointer to an interface. 25 | wire.Build(wire.InterfaceValue("foo", "bar")) 26 | return "" 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueInvalidArg0/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueInvalidArg0/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: first argument to InterfaceValue must be a pointer to an interface type; found string -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueNotEnoughArgs/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueNotEnoughArgs/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | // wrong: InterfaceValue requires 2 args. 25 | wire.Build(wire.InterfaceValue("foo")) 26 | return "" 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueNotEnoughArgs/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InterfaceValueNotEnoughArgs/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: not enough arguments in call to wire.InterfaceValue 2 | have (string) 3 | want (interface{}, interface{}) -------------------------------------------------------------------------------- /internal/wire/testdata/InvalidInjector/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | foo := injectFoo() 23 | bar := injectBar() 24 | fmt.Println(foo) 25 | fmt.Println(bar) 26 | } 27 | 28 | type Foo int 29 | type Bar int 30 | 31 | func provideFoo() Foo { 32 | return Foo(42) 33 | } 34 | func provideBar() Bar { 35 | return Bar(99) 36 | } 37 | -------------------------------------------------------------------------------- /internal/wire/testdata/InvalidInjector/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFoo() Foo { 24 | // This non-call statement makes this an invalid injector. 25 | _ = 42 26 | panic(wire.Build(provideFoo)) 27 | } 28 | 29 | func injectBar() Bar { 30 | // Two call statements are also invalid. 31 | panic(wire.Build(provideBar)) 32 | panic(wire.Build(provideBar)) 33 | } 34 | -------------------------------------------------------------------------------- /internal/wire/testdata/InvalidInjector/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/InvalidInjector/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | a call to wire.Build indicates that this function is an injector, but injectors must consist of only the wire.Build call and an optional return 2 | 3 | a call to wire.Build indicates that this function is an injector, but injectors must consist of only the wire.Build call and an optional return -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleArgsSameType/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(inject("foo", "bar").A) 23 | } 24 | 25 | type Foo struct { 26 | A string 27 | } 28 | 29 | func provideFoo(a string) *Foo { 30 | return &Foo{A: a} 31 | } 32 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleArgsSameType/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func inject(a, b string) *Foo { 24 | // fail: can't have two args of the same type. 25 | panic(wire.Build(provideFoo)) 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleArgsSameType/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleArgsSameType/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: multiple bindings for string 2 | current: 3 | <- argument b to injector function inject (example.com/foo/wire.go:x:y) 4 | previous: 5 | <- argument a to injector function inject (example.com/foo/wire.go:x:y) -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleBindings/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "io" 19 | "strings" 20 | 21 | "github.com/google/wire" 22 | ) 23 | 24 | type context struct{} 25 | 26 | func main() {} 27 | 28 | type Foo string 29 | type Bar io.Reader 30 | 31 | var Set = wire.NewSet(provideFoo) 32 | var SuperSet = wire.NewSet(Set) 33 | var SetWithDuplicateBindings = wire.NewSet(Set, SuperSet) 34 | 35 | func provideFoo() Foo { 36 | return Foo("foo") 37 | } 38 | 39 | func provideFooAgain() Foo { 40 | return Foo("foo foo") 41 | } 42 | 43 | func provideBar() Bar { 44 | return io.Reader(strings.NewReader("hello")) 45 | } 46 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleBindings/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleMissingInputs/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectMissingOutputType()) 21 | fmt.Println(injectMultipleMissingTypes()) 22 | fmt.Println(injectMissingRecursiveType()) 23 | } 24 | 25 | type Foo int 26 | type Bar int 27 | type Baz int 28 | 29 | func provideBaz(foo Foo, bar Bar) Baz { 30 | return 0 31 | } 32 | 33 | type Zip int 34 | type Zap int 35 | type Zop int 36 | 37 | func provideZip(foo Foo) Zip { 38 | return 0 39 | } 40 | 41 | func provideZap(zip Zip) Zap { 42 | return 0 43 | } 44 | 45 | func provideZop(zap Zap) Zop { 46 | return 0 47 | } 48 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleMissingInputs/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectMissingOutputType() Foo { 24 | // Error: no provider for Foo. 25 | wire.Build() 26 | return Foo(0) 27 | } 28 | 29 | func injectMultipleMissingTypes() Baz { 30 | // Error: provideBaz needs Foo and Bar, both missing. 31 | wire.Build(provideBaz) 32 | return Baz(0) 33 | } 34 | 35 | func injectMissingRecursiveType() Zop { 36 | // Error: 37 | // Zop -> Zap -> Zip -> Foo 38 | // provideZop needs Zap, provideZap needs Zip, provideZip needs Foo, 39 | // which is missing. 40 | wire.Build(provideZop, provideZap, provideZip) 41 | return Zop(0) 42 | } 43 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleMissingInputs/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleMissingInputs/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: inject injectMissingOutputType: no provider found for example.com/foo.Foo, output of injector 2 | 3 | example.com/foo/wire.go:x:y: inject injectMultipleMissingTypes: no provider found for example.com/foo.Foo 4 | needed by example.com/foo.Baz in provider "provideBaz" (example.com/foo/foo.go:x:y) 5 | 6 | example.com/foo/wire.go:x:y: inject injectMultipleMissingTypes: no provider found for example.com/foo.Bar 7 | needed by example.com/foo.Baz in provider "provideBaz" (example.com/foo/foo.go:x:y) 8 | 9 | example.com/foo/wire.go:x:y: inject injectMissingRecursiveType: no provider found for example.com/foo.Foo 10 | needed by example.com/foo.Zip in provider "provideZip" (example.com/foo/foo.go:x:y) 11 | needed by example.com/foo.Zap in provider "provideZap" (example.com/foo/foo.go:x:y) 12 | needed by example.com/foo.Zop in provider "provideZop" (example.com/foo/foo.go:x:y) -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleSimilarPackages/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package bar 16 | 17 | import ( 18 | "example.com/foo" 19 | ) 20 | 21 | type Config struct { 22 | V int 23 | } 24 | 25 | type Service struct { 26 | Cfg *Config 27 | F *foo.Service 28 | } 29 | 30 | func New(cfg *Config, f *foo.Service) *Service { 31 | return &Service{Cfg: cfg, F: f} 32 | } 33 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleSimilarPackages/baz/baz.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package baz 16 | 17 | import ( 18 | "example.com/bar" 19 | ) 20 | 21 | type Config struct { 22 | V int 23 | } 24 | 25 | type Service struct { 26 | Cfg *Config 27 | B *bar.Service 28 | } 29 | 30 | func New(cfg *Config, b *bar.Service) *Service { 31 | return &Service{Cfg: cfg, B: b} 32 | } 33 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleSimilarPackages/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package foo 16 | 17 | type Config struct { 18 | V int 19 | } 20 | 21 | type Service struct { 22 | Cfg *Config 23 | } 24 | 25 | func New(cfg *Config) *Service { 26 | return &Service{Cfg: cfg} 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleSimilarPackages/pkg: -------------------------------------------------------------------------------- 1 | example.com/main 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleSimilarPackages/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/MultipleSimilarPackages/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "example.com/bar" 11 | "example.com/baz" 12 | "example.com/foo" 13 | "fmt" 14 | ) 15 | 16 | // Injectors from wire.go: 17 | 18 | func newMainService(mainConfig MainConfig) *MainService { 19 | config := mainConfig.Foo 20 | service := foo.New(config) 21 | barConfig := mainConfig.Bar 22 | barService := bar.New(barConfig, service) 23 | bazConfig := mainConfig.baz 24 | bazService := baz.New(bazConfig, barService) 25 | mainService := &MainService{ 26 | Foo: service, 27 | Bar: barService, 28 | baz: bazService, 29 | } 30 | return mainService 31 | } 32 | 33 | // wire.go: 34 | 35 | type MainConfig struct { 36 | Foo *foo.Config 37 | Bar *bar.Config 38 | baz *baz.Config 39 | } 40 | 41 | type MainService struct { 42 | Foo *foo.Service 43 | Bar *bar.Service 44 | baz *baz.Service 45 | } 46 | 47 | func (m *MainService) String() string { 48 | return fmt.Sprintf("%d %d %d", m.Foo.Cfg.V, m.Bar.Cfg.V, m.baz.Cfg.V) 49 | } 50 | 51 | func main() { 52 | cfg := MainConfig{ 53 | Foo: &foo.Config{1}, 54 | Bar: &bar.Config{2}, 55 | baz: &baz.Config{3}, 56 | } 57 | svc := newMainService(cfg) 58 | fmt.Println(svc.String()) 59 | } 60 | -------------------------------------------------------------------------------- /internal/wire/testdata/NamingWorstCase/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | stdcontext "context" 19 | "fmt" 20 | "os" 21 | ) 22 | 23 | type context struct{} 24 | 25 | func main() { 26 | c, err := inject(stdcontext.Background(), struct{}{}) 27 | if err != nil { 28 | fmt.Println("ERROR:", err) 29 | os.Exit(1) 30 | } 31 | fmt.Println(c) 32 | } 33 | 34 | func provide(ctx stdcontext.Context) (context, error) { 35 | return context{}, nil 36 | } 37 | -------------------------------------------------------------------------------- /internal/wire/testdata/NamingWorstCase/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | stdcontext "context" 21 | 22 | "github.com/google/wire" 23 | ) 24 | 25 | func inject(context stdcontext.Context, err struct{}) (context, error) { 26 | panic(wire.Build(provide)) 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/NamingWorstCase/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NamingWorstCase/want/program_out.txt: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NamingWorstCase/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | context2 "context" 11 | ) 12 | 13 | // Injectors from wire.go: 14 | 15 | func inject(context3 context2.Context, err2 struct{}) (context, error) { 16 | mainContext, err := provide(context3) 17 | if err != nil { 18 | return context{}, err 19 | } 20 | return mainContext, nil 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/NamingWorstCaseAllInOne/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NamingWorstCaseAllInOne/want/program_out.txt: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NamingWorstCaseAllInOne/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | context2 "context" 11 | "fmt" 12 | "os" 13 | "reflect" 14 | ) 15 | 16 | // Injectors from foo.go: 17 | 18 | func inject(context3 context2.Context, err2 struct{}) (context, error) { 19 | mainContext, err := Provide(context3) 20 | if err != nil { 21 | return context{}, err 22 | } 23 | return mainContext, nil 24 | } 25 | 26 | // foo.go: 27 | 28 | type context struct{} 29 | 30 | func main() { 31 | if _, ok := reflect.TypeOf(context{}).MethodByName("Provide"); !ok { 32 | fmt.Println("ERROR: context.Provide renamed") 33 | os.Exit(1) 34 | } 35 | c, err := inject(context2.Background(), struct{}{}) 36 | if err != nil { 37 | fmt.Println("ERROR:", err) 38 | os.Exit(1) 39 | } 40 | fmt.Println(c) 41 | } 42 | 43 | func Provide(context2_2 context2.Context) (context, error) { 44 | var context3 = context2.Background() 45 | _ = context2_2 46 | _ = context3 47 | return context{}, nil 48 | } 49 | 50 | func (context) Provide() { 51 | } 52 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicIdentity/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | 23 | // provideMessage provides a friendly user greeting. 24 | func provideMessage() string { 25 | return "Hello, World!" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicIdentity/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | wire.Build(provideMessage) 25 | return "" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicIdentity/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicIdentity/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicIdentity/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage() string { 12 | string2 := provideMessage() 13 | return string2 14 | } 15 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicValue/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicValue/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | wire.Build(wire.Value("Hello, World!")) 25 | return "" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicValue/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicValue/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NiladicValue/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage() string { 12 | string2 := _wireStringValue 13 | return string2 14 | } 15 | 16 | var ( 17 | _wireStringValue = "Hello, World!" 18 | ) 19 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoImplicitInterface/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectFooer().Foo()) 21 | } 22 | 23 | type Fooer interface { 24 | Foo() string 25 | } 26 | 27 | type Bar string 28 | 29 | func (b Bar) Foo() string { 30 | return string(b) 31 | } 32 | 33 | func provideBar() Bar { 34 | return "Hello, World!" 35 | } 36 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoImplicitInterface/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooer() Fooer { 24 | wire.Build(provideBar) 25 | return nil 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoImplicitInterface/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoImplicitInterface/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: inject injectFooer: no provider found for example.com/foo.Fooer, output of injector -------------------------------------------------------------------------------- /internal/wire/testdata/NoInjectParamNames/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | stdcontext "context" 19 | "fmt" 20 | "os" 21 | ) 22 | 23 | type context struct{} 24 | 25 | func main() { 26 | c, err := inject(stdcontext.Background(), struct{}{}) 27 | if err != nil { 28 | fmt.Println("ERROR:", err) 29 | os.Exit(1) 30 | } 31 | fmt.Println(c) 32 | } 33 | 34 | func provide(ctx stdcontext.Context) (context, error) { 35 | return context{}, nil 36 | } 37 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoInjectParamNames/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | stdcontext "context" 21 | 22 | "github.com/google/wire" 23 | ) 24 | 25 | // The notable characteristic of this test is that there are no 26 | // parameter names on the inject stub. 27 | 28 | func inject(stdcontext.Context, struct{}) (context, error) { 29 | wire.Build(provide) 30 | return context{}, nil 31 | } 32 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoInjectParamNames/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoInjectParamNames/want/program_out.txt: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoInjectParamNames/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | context2 "context" 11 | ) 12 | 13 | // Injectors from wire.go: 14 | 15 | func inject(contextContext context2.Context, arg struct{}) (context, error) { 16 | mainContext, err := provide(contextContext) 17 | if err != nil { 18 | return context{}, err 19 | } 20 | return mainContext, nil 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoopBuild/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println("Hello, World!") 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoopBuild/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoopBuild/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/NoopBuild/want/wire_gen.go: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/wire/e57deea2f8bbe2386b756f2555e02de33e20a3f0/internal/wire/testdata/NoopBuild/want/wire_gen.go -------------------------------------------------------------------------------- /internal/wire/testdata/PartialCleanup/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectBaz() (Baz, func(), error) { 24 | wire.Build(provideFoo, provideBar, provideBaz) 25 | return 0, nil, nil 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/PartialCleanup/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/PartialCleanup/want/program_out.txt: -------------------------------------------------------------------------------- 1 | true 2 | true true true 3 | -------------------------------------------------------------------------------- /internal/wire/testdata/PartialCleanup/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectBaz() (Baz, func(), error) { 12 | foo, cleanup := provideFoo() 13 | bar, cleanup2, err := provideBar(foo) 14 | if err != nil { 15 | cleanup() 16 | return 0, nil, err 17 | } 18 | baz, err := provideBaz(bar) 19 | if err != nil { 20 | cleanup2() 21 | cleanup() 22 | return 0, nil, err 23 | } 24 | return baz, func() { 25 | cleanup2() 26 | cleanup() 27 | }, nil 28 | } 29 | -------------------------------------------------------------------------------- /internal/wire/testdata/PkgImport/anon1/anon1.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package anon1 16 | -------------------------------------------------------------------------------- /internal/wire/testdata/PkgImport/anon2/anon2.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package anon2 16 | -------------------------------------------------------------------------------- /internal/wire/testdata/PkgImport/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package bar 16 | 17 | type Bar int 18 | 19 | func ProvideBar() Bar { 20 | return 1 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/PkgImport/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | "example.com/bar" 21 | "github.com/google/wire" 22 | ) 23 | 24 | func main() { 25 | fmt.Println(injectFooBar()) 26 | } 27 | 28 | type Foo int 29 | type FooBar int 30 | 31 | var Set = wire.NewSet( 32 | provideFoo, 33 | bar.ProvideBar, 34 | provideFooBar) 35 | 36 | func provideFoo() Foo { 37 | return 41 38 | } 39 | 40 | func provideFooBar(foo Foo, barVal bar.Bar) FooBar { 41 | return FooBar(foo) + FooBar(barVal) 42 | } 43 | -------------------------------------------------------------------------------- /internal/wire/testdata/PkgImport/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | _ "example.com/anon1" // intentionally duplicated 21 | _ "example.com/anon1" // intentionally duplicated 22 | _ "example.com/anon2" 23 | "github.com/google/wire" 24 | ) 25 | 26 | func injectFooBar() FooBar { 27 | wire.Build(Set) 28 | return 0 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/PkgImport/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/PkgImport/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/PkgImport/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "example.com/bar" 11 | ) 12 | 13 | import ( 14 | _ "example.com/anon1" 15 | _ "example.com/anon2" 16 | ) 17 | 18 | // Injectors from wire.go: 19 | 20 | func injectFooBar() FooBar { 21 | foo := provideFoo() 22 | barBar := bar.ProvideBar() 23 | fooBar := provideFooBar(foo, barBar) 24 | return fooBar 25 | } 26 | -------------------------------------------------------------------------------- /internal/wire/testdata/ProviderSetBindingMissingConcreteType/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFoo() *foo { 24 | wire.Build(setC) 25 | return nil 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/ProviderSetBindingMissingConcreteType/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ProviderSetBindingMissingConcreteType/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/foo.go:x:y: wire.Bind of concrete type "*example.com/foo.foo" to interface "example.com/foo.fooer", but setB does not include a provider for "*example.com/foo.foo" -------------------------------------------------------------------------------- /internal/wire/testdata/RelativePkg/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | 23 | // provideMessage provides a friendly user greeting. 24 | func provideMessage() string { 25 | return "Hello, World!" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/RelativePkg/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | wire.Build(provideMessage) 25 | return "" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/RelativePkg/pkg: -------------------------------------------------------------------------------- 1 | ./foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/RelativePkg/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/RelativePkg/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage() string { 12 | string2 := provideMessage() 13 | return string2 14 | } 15 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReservedKeywords/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | i := injectInterface() 23 | fmt.Println(i) 24 | } 25 | 26 | type Interface int 27 | type Select int 28 | 29 | func provideInterface(s Select) Interface { 30 | return Interface(int(s) + 1) 31 | } 32 | 33 | func provideSelect() Select { 34 | return Select(41) 35 | } 36 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReservedKeywords/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | // Wire tries to disambiguate the variable "select" by prepending 24 | // the package name; this package-scoped variable conflicts with that 25 | // and forces a different name. 26 | var mainSelect = 0 27 | 28 | func injectInterface() Interface { 29 | // interface and select are Go reserved words, so 30 | // Wire should avoid using them as variable names. 31 | panic(wire.Build(provideInterface, provideSelect)) 32 | } 33 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReservedKeywords/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReservedKeywords/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReservedKeywords/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectInterface() Interface { 12 | select2 := provideSelect() 13 | mainInterface := provideInterface(select2) 14 | return mainInterface 15 | } 16 | 17 | // wire.go: 18 | 19 | // Wire tries to disambiguate the variable "select" by prepending 20 | // the package name; this package-scoped variable conflicts with that 21 | // and forces a different name. 22 | var mainSelect = 0 23 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnArgumentAsInterface/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectStringer("Hello, World!")) 21 | } 22 | 23 | type MyString string 24 | 25 | func (s MyString) String() string { return string(s) } 26 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnArgumentAsInterface/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "fmt" 21 | 22 | "github.com/google/wire" 23 | ) 24 | 25 | func injectStringer(s MyString) fmt.Stringer { 26 | wire.Build(wire.Bind(new(fmt.Stringer), new(MyString))) 27 | return nil 28 | } 29 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnArgumentAsInterface/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnArgumentAsInterface/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnArgumentAsInterface/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | import ( 10 | "fmt" 11 | ) 12 | 13 | // Injectors from wire.go: 14 | 15 | func injectStringer(s MyString) fmt.Stringer { 16 | return s 17 | } 18 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnError/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "errors" 19 | "fmt" 20 | "strings" 21 | 22 | "github.com/google/wire" 23 | ) 24 | 25 | func main() { 26 | foo, err := injectFoo() 27 | fmt.Println(foo) // should be zero, the injector should ignore provideFoo's return value. 28 | if err == nil { 29 | fmt.Println("") 30 | } else { 31 | fmt.Println(strings.Contains(err.Error(), "there is no Foo")) 32 | } 33 | } 34 | 35 | type Foo int 36 | 37 | func provideFoo() (Foo, error) { 38 | return 42, errors.New("there is no Foo") 39 | } 40 | 41 | var Set = wire.NewSet(provideFoo) 42 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnError/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFoo() (Foo, error) { 24 | wire.Build(Set) 25 | return 0, nil 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnError/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnError/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 0 2 | true 3 | -------------------------------------------------------------------------------- /internal/wire/testdata/ReturnError/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFoo() (Foo, error) { 12 | foo, err := provideFoo() 13 | if err != nil { 14 | return 0, err 15 | } 16 | return foo, nil 17 | } 18 | -------------------------------------------------------------------------------- /internal/wire/testdata/Struct/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "sync" 20 | 21 | "github.com/google/wire" 22 | ) 23 | 24 | func main() { 25 | fb := injectFooBar() 26 | pfb := injectPartFooBar() 27 | fmt.Println(fb.Foo, fb.Bar) 28 | fmt.Println(pfb.Foo, pfb.Bar) 29 | } 30 | 31 | type Foo int 32 | type Bar int 33 | 34 | type FooBar struct { 35 | mu sync.Mutex `wire:"-"` 36 | Foo Foo 37 | Bar Bar 38 | } 39 | 40 | func provideFoo() Foo { 41 | return 41 42 | } 43 | 44 | func provideBar() Bar { 45 | return 1 46 | } 47 | 48 | var Set = wire.NewSet( 49 | wire.Struct(new(FooBar), "*"), 50 | provideFoo, 51 | provideBar) 52 | 53 | var PartSet = wire.NewSet( 54 | wire.Struct(new(FooBar), "Foo"), 55 | provideFoo, 56 | ) 57 | -------------------------------------------------------------------------------- /internal/wire/testdata/Struct/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooBar() FooBar { 24 | wire.Build(Set) 25 | return FooBar{} 26 | } 27 | 28 | func injectPartFooBar() FooBar { 29 | wire.Build(PartSet) 30 | return FooBar{} 31 | } 32 | -------------------------------------------------------------------------------- /internal/wire/testdata/Struct/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/Struct/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 41 1 2 | 41 0 3 | -------------------------------------------------------------------------------- /internal/wire/testdata/Struct/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFooBar() FooBar { 12 | foo := provideFoo() 13 | bar := provideBar() 14 | fooBar := FooBar{ 15 | Foo: foo, 16 | Bar: bar, 17 | } 18 | return fooBar 19 | } 20 | 21 | func injectPartFooBar() FooBar { 22 | foo := provideFoo() 23 | fooBar := FooBar{ 24 | Foo: foo, 25 | } 26 | return fooBar 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructNotAStruct/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | fmt.Println(inject(A{"Hello"})) 23 | } 24 | 25 | type A struct { 26 | B string 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructNotAStruct/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func inject(a A) string { 24 | wire.Build(wire.Struct(new(*A), "*")) 25 | return "" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructNotAStruct/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructNotAStruct/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: first argument to Struct must be a pointer to a named struct; found **example.com/foo.A -------------------------------------------------------------------------------- /internal/wire/testdata/StructPointer/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/google/wire" 21 | ) 22 | 23 | func main() { 24 | fb := injectFooBar() 25 | e := injectEmptyStruct() 26 | fmt.Printf("%d %d %v\n", fb.Foo, fb.Bar, e) 27 | } 28 | 29 | type Foo int 30 | type Bar int 31 | 32 | type FooBar struct { 33 | Foo Foo 34 | Bar Bar 35 | } 36 | 37 | type Empty struct{} 38 | 39 | func provideFoo() Foo { 40 | return 41 41 | } 42 | 43 | func provideBar() Bar { 44 | return 1 45 | } 46 | 47 | var Set = wire.NewSet( 48 | wire.Struct(new(FooBar), "*"), 49 | provideFoo, 50 | provideBar) 51 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructPointer/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooBar() *FooBar { 24 | wire.Build(Set) 25 | return nil 26 | } 27 | 28 | func injectEmptyStruct() *Empty { 29 | wire.Build(wire.Struct(new(Empty))) 30 | return nil 31 | } 32 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructPointer/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructPointer/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 41 1 &{} 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructPointer/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFooBar() *FooBar { 12 | foo := provideFoo() 13 | bar := provideBar() 14 | fooBar := &FooBar{ 15 | Foo: foo, 16 | Bar: bar, 17 | } 18 | return fooBar 19 | } 20 | 21 | func injectEmptyStruct() *Empty { 22 | empty := &Empty{} 23 | return empty 24 | } 25 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructWithPreventTag/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "sync" 20 | 21 | "github.com/google/wire" 22 | ) 23 | 24 | func main() { 25 | pfb := injectPartFooBar() 26 | fmt.Println(pfb.Foo) 27 | } 28 | 29 | type Foo int 30 | 31 | type FooBar struct { 32 | mu sync.Mutex `wire:"-"` 33 | Foo Foo 34 | } 35 | 36 | func provideFoo() Foo { 37 | return 42 38 | } 39 | 40 | func provideMutex() sync.Mutex { 41 | return sync.Mutex{} 42 | } 43 | 44 | var ProhibitSet = wire.NewSet( 45 | wire.Struct(new(FooBar), "mu", "Foo"), 46 | provideMutex, 47 | provideFoo, 48 | ) 49 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructWithPreventTag/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectPartFooBar() FooBar { 24 | wire.Build(ProhibitSet) 25 | return FooBar{} 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructWithPreventTag/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/StructWithPreventTag/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/foo.go:x:y: "mu" is prevented from injecting by wire -------------------------------------------------------------------------------- /internal/wire/testdata/TwoDeps/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/google/wire" 21 | ) 22 | 23 | func main() { 24 | fmt.Println(injectFooBar()) 25 | } 26 | 27 | type Foo int 28 | type Bar int 29 | type FooBar int 30 | 31 | func provideFoo() Foo { 32 | return 40 33 | } 34 | 35 | func provideBar() Bar { 36 | return 2 37 | } 38 | 39 | func provideFooBar(foo Foo, bar Bar) FooBar { 40 | return FooBar(foo) + FooBar(bar) 41 | } 42 | 43 | var Set = wire.NewSet( 44 | provideFoo, 45 | provideBar, 46 | provideFooBar) 47 | -------------------------------------------------------------------------------- /internal/wire/testdata/TwoDeps/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooBar() FooBar { 24 | wire.Build(Set) 25 | return 0 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/TwoDeps/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/TwoDeps/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/TwoDeps/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFooBar() FooBar { 12 | foo := provideFoo() 13 | bar := provideBar() 14 | fooBar := provideFooBar(foo, bar) 15 | return fooBar 16 | } 17 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedStruct/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package bar 16 | 17 | var foo struct { 18 | X int 19 | } 20 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedStruct/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Printf("%v\n", injectedBar()) 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedStruct/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "example.com/bar" 21 | "github.com/google/wire" 22 | ) 23 | 24 | func injectedBar() string { 25 | // Fails because bar.foo is unexported. 26 | wire.Build(bar.foo.X) 27 | return "" 28 | } 29 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedStruct/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedStruct/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: foo not exported by package bar -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedValue/bar/bar.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package bar 16 | 17 | import "github.com/google/wire" 18 | 19 | var Value = wire.Value(privateMsg) 20 | 21 | var privateMsg = "Hello, World!" 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedValue/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedValue/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "example.com/bar" 21 | "github.com/google/wire" 22 | ) 23 | 24 | func injectedMessage() string { 25 | // Fails because bar.Value references unexported bar.privateMsg. 26 | wire.Build(bar.Value) 27 | return "" 28 | } 29 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedValue/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnexportedValue/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: inject injectedMessage: value string can't be used: uses unexported identifier privateMsg -------------------------------------------------------------------------------- /internal/wire/testdata/UnusedProviders/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/UnusedProviders/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: inject injectFooBar: unused provider set "unusedSet" 2 | 3 | example.com/foo/wire.go:x:y: inject injectFooBar: unused provider "main.provideUnused" 4 | 5 | example.com/foo/wire.go:x:y: inject injectFooBar: unused value of type string 6 | 7 | example.com/foo/wire.go:x:y: inject injectFooBar: unused interface binding to type example.com/foo.Fooer 8 | 9 | example.com/foo/wire.go:x:y: inject injectFooBar: unused field "example.com/foo.S".Cfg -------------------------------------------------------------------------------- /internal/wire/testdata/ValueChain/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | 20 | "github.com/google/wire" 21 | ) 22 | 23 | func main() { 24 | fmt.Println(injectFooBar()) 25 | } 26 | 27 | type Foo int 28 | type FooBar int 29 | 30 | var Set = wire.NewSet( 31 | wire.Value(Foo(41)), 32 | provideFooBar) 33 | 34 | func provideFooBar(foo Foo) FooBar { 35 | return FooBar(foo) + 1 36 | } 37 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueChain/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFooBar() FooBar { 24 | wire.Build(Set) 25 | return 0 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueChain/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueChain/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueChain/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFooBar() FooBar { 12 | foo := _wireFooValue 13 | fooBar := provideFooBar(foo) 14 | return fooBar 15 | } 16 | 17 | var ( 18 | _wireFooValue = Foo(41) 19 | ) 20 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueConversion/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | fmt.Println(injectedMessage()) 21 | } 22 | 23 | type Foo string 24 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueConversion/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() Foo { 24 | wire.Build(wire.Value(Foo("Hello, World!"))) 25 | return "" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueConversion/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueConversion/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueConversion/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage() Foo { 12 | foo := _wireFooValue 13 | return foo 14 | } 15 | 16 | var ( 17 | _wireFooValue = Foo("Hello, World!") 18 | ) 19 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueFromFunctionScope/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | type foo struct { 22 | V int 23 | } 24 | 25 | type bar struct { 26 | V int 27 | } 28 | 29 | func newBar(v int) *bar { 30 | return &bar{V: v} 31 | } 32 | 33 | func main() { 34 | f := &foo{V: 42} 35 | b := injectBar(f) 36 | fmt.Printf("%d\n", b.V) 37 | } 38 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueFromFunctionScope/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectBar(f *foo) *bar { 24 | wire.Build( 25 | newBar, 26 | wire.Value(f.V), // fails because f.V is not from package scope 27 | ) 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueFromFunctionScope/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueFromFunctionScope/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: inject injectBar: value int can't be used: f is not declared in package scope -------------------------------------------------------------------------------- /internal/wire/testdata/ValueIsInterfaceValue/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "io/ioutil" 20 | "strings" 21 | ) 22 | 23 | func main() { 24 | r := injectedReader(strings.NewReader("hello world")) 25 | buf, _ := ioutil.ReadAll(r) 26 | fmt.Println(string(buf)) 27 | } 28 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueIsInterfaceValue/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "io" 21 | "strings" 22 | 23 | "github.com/google/wire" 24 | ) 25 | 26 | func injectedReader(r *strings.Reader) io.Reader { 27 | wire.Build(wire.Value(io.Reader(r))) 28 | return nil 29 | } 30 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueIsInterfaceValue/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueIsInterfaceValue/want/wire_errs.txt: -------------------------------------------------------------------------------- 1 | example.com/foo/wire.go:x:y: argument to Value may not be an interface value (found io.Reader); use InterfaceValue instead -------------------------------------------------------------------------------- /internal/wire/testdata/ValueIsStruct/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | func main() { 22 | f := injectFoo() 23 | fmt.Printf("%d\n", f.X) 24 | } 25 | 26 | type Foo struct { 27 | X int 28 | } 29 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueIsStruct/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectFoo() Foo { 24 | wire.Build(wire.Value(Foo{X: 42})) 25 | return Foo{} 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueIsStruct/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueIsStruct/want/program_out.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/ValueIsStruct/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectFoo() Foo { 12 | foo := _wireFooValue 13 | return foo 14 | } 15 | 16 | var ( 17 | _wireFooValue = Foo{X: 42} 18 | ) 19 | -------------------------------------------------------------------------------- /internal/wire/testdata/VarValue/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import "fmt" 18 | 19 | func main() { 20 | // Mutating value; value should have been stored at package initialization. 21 | msg = "Hello, World!" 22 | 23 | fmt.Println(injectedMessage()) 24 | } 25 | 26 | var msg string = "Package init" 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/VarValue/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage() string { 24 | wire.Build(wire.Value(msg)) 25 | return "" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/VarValue/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/VarValue/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Package init 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/VarValue/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage() string { 12 | string2 := _wireStringValue 13 | return string2 14 | } 15 | 16 | var ( 17 | _wireStringValue = msg 18 | ) 19 | -------------------------------------------------------------------------------- /internal/wire/testdata/Varargs/foo/foo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package main 16 | 17 | import ( 18 | "fmt" 19 | "strings" 20 | ) 21 | 22 | func main() { 23 | fmt.Println(injectedMessage("", "Hello,", "World!")) 24 | } 25 | 26 | type title string 27 | 28 | // provideMessage provides a friendly user greeting. 29 | func provideMessage(words ...string) string { 30 | return strings.Join(words, " ") 31 | } 32 | -------------------------------------------------------------------------------- /internal/wire/testdata/Varargs/foo/wire.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Wire Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | //+build wireinject 16 | 17 | package main 18 | 19 | import ( 20 | "github.com/google/wire" 21 | ) 22 | 23 | func injectedMessage(t title, lines ...string) string { 24 | wire.Build(provideMessage) 25 | return "" 26 | } 27 | -------------------------------------------------------------------------------- /internal/wire/testdata/Varargs/pkg: -------------------------------------------------------------------------------- 1 | example.com/foo 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/Varargs/want/program_out.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /internal/wire/testdata/Varargs/want/wire_gen.go: -------------------------------------------------------------------------------- 1 | // Code generated by Wire. DO NOT EDIT. 2 | 3 | //go:generate go run -mod=mod github.com/google/wire/cmd/wire 4 | //go:build !wireinject 5 | // +build !wireinject 6 | 7 | package main 8 | 9 | // Injectors from wire.go: 10 | 11 | func injectedMessage(t title, lines ...string) string { 12 | string2 := provideMessage(lines...) 13 | return string2 14 | } 15 | --------------------------------------------------------------------------------