goshorly/utils/env.go

62 lines
862 B
Go
Raw Normal View History

2021-12-07 19:23:27 +00:00
package utils
import (
"log"
"os"
)
2021-12-08 13:11:35 +00:00
var (
HOST string
PORT string
HTTPS string
PROXY bool
URL string
REDIS_URI string
)
2021-12-07 19:23:27 +00:00
2021-12-08 10:04:28 +00:00
func Init_env_vars() {
2021-12-08 13:11:35 +00:00
2021-12-07 19:23:27 +00:00
UHOST, err := os.LookupEnv("HOST")
if !err {
log.Fatal("HOST enviroment variable not found, please set it!")
}
HOST = UHOST
UHTTPS, _ := os.LookupEnv("HTTPS")
if UHTTPS != "true" {
HTTPS = "http"
} else {
HTTPS = "https"
}
UPROXY, _ := os.LookupEnv("PROXY")
if UPROXY != "true" {
PROXY = false
} else {
PROXY = true
}
UPORT, err := os.LookupEnv("PORT")
if !err {
PORT = "3000"
} else {
PORT = UPORT
}
UREDIS_URI, _ := os.LookupEnv("REDIS_URI")
if UREDIS_URI != "" {
2021-12-08 13:11:35 +00:00
REDIS_URI = "redis"
}
2021-12-07 19:23:27 +00:00
create_string()
}
func create_string() {
if !PROXY {
URL = HTTPS + "://" + HOST + ":" + PORT + "/"
} else {
URL = HTTPS + "://" + HOST + "/"
}
}