-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (49 loc) · 1.27 KB
/
main.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
package main
import (
"io/ioutil"
"log"
"github.com/ffjlabo/auto-wire/config"
"github.com/ffjlabo/auto-wire/pkg/ast"
"github.com/ffjlabo/auto-wire/pkg/wire"
)
func main() {
// wire.go
importPath := config.ModuleName + "/" + config.UsecaseDir
content, err := wire.GenerateWireContent(config.DiDir, importPath)
if err != nil {
log.Fatal(err)
}
filePath := config.DiDir + "/wire.go"
err = ioutil.WriteFile(filePath, content, 0644)
if err != nil {
log.Fatal(err)
}
// provider.go作成例 1
providerName := "NewUserRepository"
bindMap := map[string]*ast.InterfaceSpec{
"User": &ast.InterfaceSpec{
Name: "UserRepository",
ImportPath: config.ModuleName + "/" + config.DomainRepo,
},
}
content, err = wire.GenerateProviderContent(config.InfraRepo, providerName, bindMap)
if err != nil {
log.Fatal(err)
}
filePath = config.InfraRepo + "/provider.go"
err = ioutil.WriteFile(filePath, content, 0644)
if err != nil {
log.Fatal(err)
}
// provider.go作成例 2
providerName = "NewSpotifyRepository"
content, err = wire.GenerateProviderContent(config.UsecaseDir, providerName, nil)
if err != nil {
log.Fatal(err)
}
filePath = config.UsecaseDir + "/provider.go"
err = ioutil.WriteFile(filePath, content, 0644)
if err != nil {
log.Fatal(err)
}
}