|
|
@@ -11,43 +11,33 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// build variables
|
|
|
|
// build variables
|
|
|
|
var Version string
|
|
|
|
var (
|
|
|
|
|
|
|
|
Version string
|
|
|
|
// ParseArgs -> to parse the cli flag and get db url. This is useful with heroku button
|
|
|
|
ARG_DB_URL *string
|
|
|
|
func ParseArgs() {
|
|
|
|
ARG_DB_TYPE *string
|
|
|
|
dbURL := flag.String("database_url", "", "Database connection string")
|
|
|
|
ARG_AUTHORIZER_URL *string
|
|
|
|
dbType := flag.String("databse_type", "", "Database type, possible values are postgres,mysql,sqlite")
|
|
|
|
ARG_ENV_FILE *string
|
|
|
|
authorizerURL := flag.String("authorizer_url", "", "URL for authorizer instance, eg: https://xyz.herokuapp.com")
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *dbURL != "" {
|
|
|
|
|
|
|
|
constants.DATABASE_URL = *dbURL
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if *dbType != "" {
|
|
|
|
|
|
|
|
constants.DATABASE_TYPE = *dbType
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if *authorizerURL != "" {
|
|
|
|
|
|
|
|
constants.AUTHORIZER_URL = *authorizerURL
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// InitEnv -> to initialize env and through error if required env are not present
|
|
|
|
// InitEnv -> to initialize env and through error if required env are not present
|
|
|
|
func InitEnv() {
|
|
|
|
func InitEnv() {
|
|
|
|
envPath := `.env`
|
|
|
|
envPath := `.env`
|
|
|
|
envFile := flag.String("env_file", "", "Env file path")
|
|
|
|
ARG_DB_URL = flag.String("database_url", "", "Database connection string")
|
|
|
|
|
|
|
|
ARG_DB_TYPE = flag.String("database_type", "", "Database type, possible values are postgres,mysql,sqlite")
|
|
|
|
|
|
|
|
ARG_AUTHORIZER_URL = flag.String("authorizer_url", "", "URL for authorizer instance, eg: https://xyz.herokuapp.com")
|
|
|
|
|
|
|
|
ARG_ENV_FILE = flag.String("env_file", "", "Env file path")
|
|
|
|
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
flag.Parse()
|
|
|
|
if *envFile != "" {
|
|
|
|
if *ARG_ENV_FILE != "" {
|
|
|
|
envPath = *envFile
|
|
|
|
envPath = *ARG_ENV_FILE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
err := godotenv.Load(envPath)
|
|
|
|
err := godotenv.Load(envPath)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Error loading .env file")
|
|
|
|
log.Println("Error loading .env file")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
constants.VERSION = Version
|
|
|
|
constants.VERSION = Version
|
|
|
|
|
|
|
|
|
|
|
|
constants.ADMIN_SECRET = os.Getenv("ADMIN_SECRET")
|
|
|
|
constants.ADMIN_SECRET = os.Getenv("ADMIN_SECRET")
|
|
|
|
constants.ENV = os.Getenv("ENV")
|
|
|
|
constants.ENV = os.Getenv("ENV")
|
|
|
|
constants.DATABASE_TYPE = os.Getenv("DATABASE_TYPE")
|
|
|
|
constants.DATABASE_TYPE = os.Getenv("DATABASE_TYPE")
|
|
|
@@ -104,20 +94,18 @@ func InitEnv() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
constants.ALLOWED_ORIGINS = allowedOrigins
|
|
|
|
constants.ALLOWED_ORIGINS = allowedOrigins
|
|
|
|
|
|
|
|
|
|
|
|
allowedCallbackSplit := strings.Split(os.Getenv("ALLOWED_CALLBACK_URLS"), ",")
|
|
|
|
if *ARG_AUTHORIZER_URL != "" {
|
|
|
|
allowedCallbacks := []string{}
|
|
|
|
constants.AUTHORIZER_URL = *ARG_AUTHORIZER_URL
|
|
|
|
for _, val := range allowedCallbackSplit {
|
|
|
|
}
|
|
|
|
trimVal := strings.TrimSpace(val)
|
|
|
|
|
|
|
|
if trimVal != "" {
|
|
|
|
if *ARG_DB_URL != "" {
|
|
|
|
allowedCallbacks = append(allowedCallbacks, trimVal)
|
|
|
|
constants.DATABASE_URL = *ARG_DB_URL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if *ARG_DB_TYPE != "" {
|
|
|
|
|
|
|
|
constants.DATABASE_TYPE = *ARG_DB_TYPE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(allowedCallbackSplit) == 0 {
|
|
|
|
|
|
|
|
allowedCallbackSplit = []string{"*"}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
constants.ALLOWED_CALLBACK_URLS = allowedCallbackSplit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ParseArgs()
|
|
|
|
|
|
|
|
if constants.DATABASE_URL == "" {
|
|
|
|
if constants.DATABASE_URL == "" {
|
|
|
|
panic("Database url is required")
|
|
|
|
panic("Database url is required")
|
|
|
|
}
|
|
|
|
}
|
|
|
|