-
Notifications
You must be signed in to change notification settings - Fork 469
/
fileutil.go
executable file
·156 lines (133 loc) · 4.34 KB
/
fileutil.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package fileutil
import (
"os"
"path/filepath"
"sync"
)
const (
//ChassisConfDir is constant of type string
ChassisConfDir = "CHASSIS_CONF_DIR"
//ChassisHome is constant of type string
ChassisHome = "CHASSIS_HOME"
//SchemaDirectory is constant of type string
SchemaDirectory = "schema"
)
const (
//Global is a constant of type string
Global = "chassis.yaml"
//LoadBalancing is constant of type string
LoadBalancing = "load_balancing.yaml"
//RateLimiting is constant of type string
RateLimiting = "rate_limiting.yaml"
//Definition is constant of type string
Definition = "microservice.yaml"
//Hystric is constant of type string
Hystric = "circuit_breaker.yaml"
//PaasLager is constant of type string
PaasLager = "lager.yaml"
//TLS is constant of type string
TLS = "tls.yaml"
//Monitoring is constant of type string
Monitoring = "monitoring.yaml"
//Auth is constant of type string
Auth = "auth.yaml"
//Tracing is constant of type string
Tracing = "tracing.yaml"
//Router is constant of type string
Router = "router.yaml"
)
var configDir string
var homeDir string
var once sync.Once
//GetWorkDir is a function used to get the working directory
func GetWorkDir() (string, error) {
wd, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return "", err
}
return wd, nil
}
func initDir() {
if h := os.Getenv(ChassisHome); h != "" {
homeDir = h
} else {
wd, err := GetWorkDir()
if err != nil {
panic(err)
}
homeDir = wd
}
// set conf dir, CHASSIS_CONF_DIR has highest priority
if confDir := os.Getenv(ChassisConfDir); confDir != "" {
configDir = confDir
} else {
// CHASSIS_HOME has second most high priority
configDir = filepath.Join(homeDir, "conf")
}
}
//ChassisHomeDir is function used to get the home directory of chassis
func ChassisHomeDir() string {
once.Do(initDir)
return homeDir
}
//GetConfDir is a function used to get the configuration directory
func GetConfDir() string {
once.Do(initDir)
return configDir
}
//HystrixDefinition is a function used to join .yaml file name with configuration path
func HystrixDefinition() string {
return filepath.Join(GetConfDir(), Hystric)
}
//GetDefinition is a function used to join .yaml file name with configuration path
func GetDefinition() string {
return filepath.Join(GetConfDir(), Definition)
}
//GetLoadBalancing is a function used to join .yaml file name with configuration directory
func GetLoadBalancing() string {
return filepath.Join(GetConfDir(), LoadBalancing)
}
//GetRateLimiting is a function used to join .yaml file name with configuration directory
func GetRateLimiting() string {
return filepath.Join(GetConfDir(), RateLimiting)
}
//GetTLS is a function used to join .yaml file name with configuration directory
func GetTLS() string {
return filepath.Join(GetConfDir(), TLS)
}
//GetMonitoring is a function used to join .yaml file name with configuration directory
func GetMonitoring() string {
return filepath.Join(GetConfDir(), Monitoring)
}
//MicroserviceDefinition is a function used to join .yaml file name with configuration directory
func MicroserviceDefinition(microserviceName string) string {
return filepath.Join(GetConfDir(), microserviceName, Definition)
}
//GetMicroserviceDesc is a function used to join .yaml file name with configuration directory
func GetMicroserviceDesc() string {
return filepath.Join(GetConfDir(), Definition)
}
//GlobalDefinition is a function used to join .yaml file name with configuration directory
func GlobalDefinition() string {
return filepath.Join(GetConfDir(), Global)
}
//PaasLagerDefinition is a function used to join .yaml file name with configuration directory
func PaasLagerDefinition() string {
return filepath.Join(GetConfDir(), PaasLager)
}
//RouterDefinition is a function used to join .yaml file name with configuration directory
func RouterDefinition() string {
return filepath.Join(GetConfDir(), Router)
}
//GetAuth is a function used to join .yaml file name with configuration directory
func GetAuth() string {
return filepath.Join(GetConfDir(), Auth)
}
//GetTracing is a function used to join .yaml file name with configuration directory
func GetTracing() string {
return filepath.Join(GetConfDir(), Tracing)
}
//SchemaDir is a function used to join .yaml file name with configuration path
func SchemaDir(microserviceName string) string {
return filepath.Join(GetConfDir(), microserviceName, SchemaDirectory)
}