-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
44 lines (36 loc) · 796 Bytes
/
app.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
package main
import (
"context"
"fmt"
"log/slog"
"alluvial/ethereum"
"alluvial/json"
)
type App struct {
address string
ethereum *ethereum.LoadBalancer
log *slog.Logger
json json.Writer
}
func newApp(ctx context.Context, opts Options) (*App, func(), error) {
lbOpts := ethereum.Options{
Gateways: opts.Config.Gateways,
HTTPClient: opts.httpClient,
Log: opts.Log,
MinClients: opts.Config.GatewaysMinimumClients,
}
lb, err := ethereum.NewLoadBalancer(ctx, lbOpts)
if err != nil {
return &App{}, func() {}, fmt.Errorf("loadbalancer setup error: %w", err)
}
app := &App{
address: opts.Config.Address,
json: json.NewWriter(opts.Log),
ethereum: lb,
log: opts.Log,
}
cleanup := func() {
lb.Close()
}
return app, cleanup, nil
}