-
Notifications
You must be signed in to change notification settings - Fork 95
/
default_params.go
70 lines (60 loc) · 1.42 KB
/
default_params.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
package common
import (
"os"
"os/user"
"path/filepath"
"runtime"
"gopkg.in/natefinch/lumberjack.v2"
)
const (
DefaultHTTPHost = "localhost" // Default host interface for the HTTP RPC server
DefaultHTTPPort = 48132 // Default TCP port for the HTTP RPC server
DefaultWSHost = "localhost" // Default host interface for the websocket RPC server
DefaultWSPort = 31420 // Default TCP port for the websocket RPC server
DefaultP2PPort = 8483
)
// DefaultDataDir is $HOME/viteisbest/
func DefaultDataDir() string {
home := HomeDir()
if home != "" {
return filepath.Join(home, "viteisbest")
}
return ""
}
//it is the dir in go-vite/testdata
func GoViteTestDataDir() string {
_, filename, _, _ := runtime.Caller(0)
return filepath.Join(filepath.Dir(filepath.Dir(filename)), "testdata")
}
func HomeDir() string {
if home := os.Getenv("HOME"); home != "" {
return home
}
if usr, err := user.Current(); err == nil {
return usr.HomeDir
}
return ""
}
func DefaultHttpEndpoint() string {
return ":48132"
}
func DefaultWSEndpoint() string {
return ":31420"
}
func DefaultIpcFile() string {
endpoint := "vite.ipc"
if runtime.GOOS == "windows" {
endpoint = `\\.\pipe\vite.ipc`
}
return endpoint
}
func MakeDefaultLogger(absFilePath string) *lumberjack.Logger {
return &lumberjack.Logger{
Filename: absFilePath,
MaxSize: 100,
MaxBackups: 14,
MaxAge: 14,
Compress: true,
LocalTime: true,
}
}