-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (54 loc) · 1.13 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
package main
import (
"context"
"fmt"
"log"
"os"
"os/signal"
"sync"
"syscall"
"github.com/evsamsonov/jsonrpc-fsproxy/pkg/jsonrpc"
"go.uber.org/zap"
)
func main() {
if len(os.Args) < 4 {
fmt.Println("Usage: jsonrpc-fsproxy [INPUT_FILE_PATH] [OUTPUT_FILE_PATH] [RPC_URL]")
os.Exit(1)
}
inputFilePath, outputFilePath, rpcURL := os.Args[1], os.Args[2], os.Args[3]
logger, err := zap.NewDevelopment()
if err != nil {
log.Fatalf("Failed to create logger: %v", err)
}
proxy, err := jsonrpc.NewFSProxy(
rpcURL,
inputFilePath,
outputFilePath,
logger,
)
if err != nil {
logger.Fatal("Failed to create proxy", zap.Error(err))
}
defer func() {
if err := proxy.Close(); err != nil {
logger.Warn("Failed to close proxy", zap.Error(err))
}
}()
var wg sync.WaitGroup
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
wg.Add(1)
go func() {
defer wg.Done()
if err := proxy.Run(ctx); err != nil {
logger.Fatal("Failed to run proxy", zap.Error(err))
}
}()
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
go func() {
<-sig
cancel()
}()
wg.Wait()
}