Support variadic provider and injector functions (#91)

Fixes #61
This commit is contained in:
shantuo
2018-12-03 08:30:42 -08:00
committed by Ross Light
parent 65d810f60a
commit ef9bb67152
8 changed files with 100 additions and 4 deletions

View File

@@ -0,0 +1,31 @@
// Copyright 2018 The Wire Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(injectedMessage("", "Hello,", "World!"))
}
type title string
// provideMessage provides a friendly user greeting.
func provideMessage(words ...string) string {
return strings.Join(words, " ")
}

View File

@@ -0,0 +1,26 @@
// Copyright 2018 The Wire Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//+build wireinject
package main
import (
"github.com/google/wire"
)
func injectedMessage(t title, lines ...string) string {
wire.Build(provideMessage)
return ""
}

1
internal/wire/testdata/Varargs/pkg vendored Normal file
View File

@@ -0,0 +1 @@
example.com/foo

View File

@@ -0,0 +1 @@
Hello, World!

View File

@@ -0,0 +1,13 @@
// Code generated by Wire. DO NOT EDIT.
//go:generate wire
//+build !wireinject
package main
// Injectors from wire.go:
func injectedMessage(t title, lines ...string) string {
string2 := provideMessage(lines...)
return string2
}