-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
78 lines (63 loc) · 1.47 KB
/
Copy pathmain.go
File metadata and controls
78 lines (63 loc) · 1.47 KB
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
73
74
75
76
77
78
/*
Copyright LLC Newity. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package main
import (
"flag"
"os"
"github.com/SmartBFT-Go/walreader/reader"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func main() {
pathForRead := flag.String("f", "", "path to WAL file")
pathForSave := flag.String("to", "", "path to the file for saving WAL file")
flag.Parse()
config := zap.NewDevelopmentConfig()
config.DisableCaller = true
config.Encoding = "console"
if *pathForSave != "" {
config.OutputPaths = []string{"stdout", *pathForSave}
} else {
config.OutputPaths = []string{"stdout"}
}
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
atom := zap.NewAtomicLevel()
atom.SetLevel(zap.DebugLevel)
log, err := config.Build()
if err != nil {
panic(err)
}
logger := log.Sugar()
defer logger.Sync()
if *pathForRead == "" {
logger.Fatal("Please provide path to WAL file of directory with WAL files with -f= flag")
}
isD, err := isDir(*pathForRead)
if err != nil {
logger.Fatal(err)
}
r := reader.NewReader(logger, *pathForRead)
if !isD {
if err = r.ReadFile(*pathForRead); err != nil {
logger.Warnf(err.Error())
}
} else {
if err = r.ReadDir(); err != nil {
logger.Warnf(err.Error())
}
}
}
func isDir(fsPath string) (bool, error) {
file, err := os.Open(fsPath)
if err != nil {
return false, err
}
defer file.Close()
fileInfo, err := file.Stat()
if err != nil {
return false, err
}
return fileInfo.IsDir(), nil
}