This repository has been archived by the owner on Oct 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
const.go
115 lines (96 loc) · 1.84 KB
/
const.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package gutowire
import (
"go/ast"
"sync"
"text/template"
"golang.org/x/sync/errgroup"
)
const (
filePrefix = "autowire"
wireTag = "@autowire"
setTemplate = `// Code generated by go-autowire. DO NOT EDIT.
//go:build wireinject
// +build wireinject
package {{ .Package }}
import (
"github.com/google/wire"
)
var {{ .SetName }} = wire.NewSet({{ range $Item := .Items}}
{{ $Item }},
{{ end }}
)
`
initTemplateHead = `// Code generated by go-autowire. DO NOT EDIT.
//go:build wireinject
// +build wireinject
package %s
`
initItemTemplate = `
func Initialize%s(%s) (%s, func(), error) {
panic(wire.Build(Sets))
}
`
)
var setTemp = template.Must(template.New("").Parse(setTemplate))
type (
wireSet struct {
Package string
Items []string
SetName string
}
opt struct {
searchPath string
pkg string
genPath string
initWire []string
}
Option func(*opt)
autoWireSearcher struct {
sets []string
genPath string
pkg string
elementMap map[string]map[string]element
options []Option
modBase string
initElements []element
configElements []element
initWire []string
wg errgroup.Group
sync.Mutex
}
element struct {
name string
constructor string
fields []string
implements []string
pkg string
pkgPath string
typ uint
initWire bool
configWire bool
}
tmpDecl struct {
docs string
name string
isFunc bool
typeSpec *ast.TypeSpec
}
)
func WithPkg(pkg string) Option {
return func(o *opt) {
o.pkg = pkg
}
}
func InitStruct(initStruct ...string) Option {
return func(o *opt) {
if len(initStruct) == 0 {
initStruct = []string{"*"}
}
o.initWire = initStruct
}
}
func WithSearchPath(path string) Option {
return func(o *opt) {
o.searchPath = path
}
}