-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
71 lines (54 loc) · 1.74 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
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"os"
"github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/ch11/acme/internal/config"
"github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/ch11/acme/internal/modules/exchange"
"github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/ch11/acme/internal/modules/get"
"github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/ch11/acme/internal/modules/list"
"github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/ch11/acme/internal/modules/register"
"github.com/PacktPublishing/Hands-On-Dependency-Injection-in-Go/ch11/acme/internal/rest"
"github.com/google/go-cloud/wire"
)
func main() {
// bind stop channel to context
ctx := context.Background()
// start REST server
server, err := initializeServer()
if err != nil {
os.Exit(-1)
}
server.Listen(ctx.Done())
}
// List of wire enabled objects
var wireSetWithoutConfig = wire.NewSet(
// *exchange.Converter
exchange.NewConverter,
// *get.Getter
get.NewGetter,
// *list.Lister
list.NewLister,
// *register.Registerer
wire.Bind(new(register.Exchanger), &exchange.Converter{}),
register.NewRegisterer,
// *rest.Server
wire.Bind(new(rest.GetModel), &get.Getter{}),
wire.Bind(new(rest.ListModel), &list.Lister{}),
wire.Bind(new(rest.RegisterModel), ®ister.Registerer{}),
rest.New,
)
var wireSet = wire.NewSet(
wireSetWithoutConfig,
// *config.Config
config.Load,
// *exchange.Converter
wire.Bind(new(exchange.Config), &config.Config{}),
// *get.Getter
wire.Bind(new(get.Config), &config.Config{}),
// *list.Lister
wire.Bind(new(list.Config), &config.Config{}),
// *register.Registerer
wire.Bind(new(register.Config), &config.Config{}),
// *rest.Server
wire.Bind(new(rest.Config), &config.Config{}),
)