common.go
1.2 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
package constant
import (
"fmt"
"os"
"strconv"
"strings"
)
var SERVICE_NAME = "allied-creation-user"
var SERVICE_ENV = "dev"
var HTTP_PORT int = 8081
var CACHE_PREFIX = "allied-creation-user-dev"
var LOG_LEVEL = "debug"
var CUSTOMER_ACCOUNT = []int64{3129687560814592, 3129687690100739, 3492238958608384}
const CUSTOMER_ACCOUNT_DELIMITER = ","
/***** 1.数据传输 *****/
const HeaderCompanyId = "companyId"
const HeaderUserId = "userId"
const HeaderOrgId = "orgId"
func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
}
if os.Getenv("CUSTOMER_ACCOUNT") != "" {
account := os.Getenv("CUSTOMER_ACCOUNT")
accounts := strings.Split(account, CUSTOMER_ACCOUNT_DELIMITER)
var tmpAccounts []int64
for i := range accounts {
v, err := strconv.ParseInt(accounts[i], 10, 64)
if err != nil {
panic(err)
}
tmpAccounts = append(tmpAccounts, v)
}
if len(tmpAccounts) > 0 {
CUSTOMER_ACCOUNT = tmpAccounts
}
}
if os.Getenv("SERVICE_ENV") != "" {
SERVICE_ENV = os.Getenv("SERVICE_ENV")
}
if os.Getenv("HTTP_PORT") != "" {
HTTP_PORT, _ = strconv.Atoi(os.Getenv("HTTP_PORT"))
}
SERVICE_NAME = fmt.Sprintf("%v-%v", SERVICE_NAME, SERVICE_ENV)
CACHE_PREFIX = SERVICE_NAME
}