Skip to content

Commit e123047

Browse files
committed
updating isEnvExist to return false if empty
1 parent 8c8f96c commit e123047

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/TibiaDataUtils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ func TibiaDataSanitize0026String(data string) string {
188188
return strings.ReplaceAll(data, "\u0026#39;", "'")
189189
}
190190

191-
// isEnvExist func - check if environment var is set
192-
func isEnvExist(key string) (ok bool) {
193-
_, ok = os.LookupEnv(key)
194-
return
191+
// isEnvExist func - check if environment var is set and not empty
192+
func isEnvExist(key string) bool {
193+
data, ok := os.LookupEnv(key)
194+
return ok && data != ""
195195
}
196196

197197
// getEnv func - read an environment or return a default value

src/main.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,24 +104,23 @@ func TibiaDataInitializer() {
104104
}
105105

106106
// Adding information of host
107-
TibiaDataHost = getEnv("TIBIADATA_HOST", "")
108-
if TibiaDataHost != "" {
109-
TibiaDataHost = "+https://" + TibiaDataHost
107+
if isEnvExist("TIBIADATA_HOST") {
108+
TibiaDataHost = "+https://" + getEnv("TIBIADATA_HOST", "")
110109
}
111110

112111
// Setting TibiaDataProxyDomain
113112
if isEnvExist("TIBIADATA_PROXY") {
114113

115-
TibiaDataProxyProtocol := "https"
116-
if isEnvExist("TIBIADATA_PROXY_PROTOCOL") {
117-
TibiaDataProxyProtocol = getEnv("TIBIADATA_PROXY_PROTOCOL", "https")
114+
TibiaDataProxyProtocol := getEnv("TIBIADATA_PROXY_PROTOCOL", "https")
115+
switch TibiaDataProxyProtocol {
116+
case "http":
117+
TibiaDataProxyProtocol = "http"
118118
}
119119

120120
TibiaDataProxyDomain = TibiaDataProxyProtocol + "://" + getEnv("TIBIADATA_PROXY", "www.tibia.com") + "/"
121+
log.Printf("[info] TibiaData API proxy: %s", TibiaDataProxyDomain)
121122
}
122123

123-
log.Printf("[info] TibiaData API proxy: %s", TibiaDataProxyDomain)
124-
125124
// Run some functions that are empty but required for documentation to be done
126125
_ = tibiaNewslistArchive()
127126
_ = tibiaNewslistArchiveDays()

src/webserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func runWebServer() {
102102
})
103103

104104
// Set proxy feature of gin
105-
trustedProxies := getEnv("GIN_TRUSTED_PROXIES", "")
106-
if len(trustedProxies) > 0 {
105+
if isEnvExist("GIN_TRUSTED_PROXIES") {
106+
trustedProxies := getEnv("GIN_TRUSTED_PROXIES", "")
107107
_ = router.SetTrustedProxies(strings.Split(trustedProxies, ","))
108108
log.Printf("[info] TibiaData API gin-trusted-proxies: %s", strings.Split(trustedProxies, ","))
109109
} else {

0 commit comments

Comments
 (0)