-
Notifications
You must be signed in to change notification settings - Fork 3
/
wire_gen.go
72 lines (62 loc) · 2.55 KB
/
wire_gen.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
// Code generated by Wire. DO NOT EDIT.
//go:generate go run -mod=mod github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject
package main
import (
"github.com/cloudflare/cloudflare-go"
"github.com/tjjh89017/stunmesh-go/internal/config"
"github.com/tjjh89017/stunmesh-go/internal/crypto"
"github.com/tjjh89017/stunmesh-go/internal/ctrl"
"github.com/tjjh89017/stunmesh-go/internal/daemon"
"github.com/tjjh89017/stunmesh-go/internal/entity"
"github.com/tjjh89017/stunmesh-go/internal/logger"
"github.com/tjjh89017/stunmesh-go/internal/queue"
"github.com/tjjh89017/stunmesh-go/internal/repo"
"github.com/tjjh89017/stunmesh-go/internal/store"
"github.com/tjjh89017/stunmesh-go/internal/stun"
"golang.zx2c4.com/wireguard/wgctrl"
)
// Injectors from wire.go:
func setup() (*daemon.Daemon, error) {
configConfig, err := config.Load()
if err != nil {
return nil, err
}
queue := provideRefreshQueue()
client, err := wgctrl.New()
if err != nil {
return nil, err
}
devices := repo.NewDevices()
peers := repo.NewPeers(client)
zerologLogger := logger.NewLogger(configConfig)
deviceConfig := config.NewDeviceConfig(configConfig)
filterPeerService := entity.NewFilterPeerService(peers, deviceConfig)
bootstrapController := ctrl.NewBootstrapController(client, configConfig, devices, peers, zerologLogger, filterPeerService)
api, err := provideCloudflareApi(configConfig)
if err != nil {
return nil, err
}
cloudflareStore := provideStore(api, configConfig)
resolver := stun.NewResolver(configConfig, zerologLogger)
endpoint := crypto.NewEndpoint()
publishController := ctrl.NewPublishController(devices, peers, cloudflareStore, resolver, endpoint, zerologLogger)
establishController := ctrl.NewEstablishController(client, devices, peers, cloudflareStore, endpoint, zerologLogger)
refreshController := ctrl.NewRefreshController(peers, queue, zerologLogger)
daemonDaemon := daemon.New(configConfig, queue, bootstrapController, publishController, establishController, refreshController, zerologLogger)
return daemonDaemon, nil
}
// wire.go:
func provideCloudflareApi(config2 *config.Config) (*cloudflare.API, error) {
if config2.Cloudflare.ApiToken != "" {
return cloudflare.NewWithAPIToken(config2.Cloudflare.ApiToken)
}
return cloudflare.New(config2.Cloudflare.ApiKey, config2.Cloudflare.ApiEmail)
}
func provideStore(cfApi *cloudflare.API, config2 *config.Config) *store.CloudflareStore {
return store.NewCloudflareStore(cfApi, config2.Cloudflare.ZoneName)
}
func provideRefreshQueue() *queue.Queue[entity.PeerId] {
return queue.New[entity.PeerId]()
}