common.go 1.2 KB
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
}