You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
855 B
42 lines
855 B
package blademaster |
|
|
|
import ( |
|
"os" |
|
"path" |
|
) |
|
|
|
func lastChar(str string) uint8 { |
|
if str == "" { |
|
panic("The length of the string can't be 0") |
|
} |
|
return str[len(str)-1] |
|
} |
|
|
|
func joinPaths(absolutePath, relativePath string) string { |
|
if relativePath == "" { |
|
return absolutePath |
|
} |
|
|
|
finalPath := path.Join(absolutePath, relativePath) |
|
appendSlash := lastChar(relativePath) == '/' && lastChar(finalPath) != '/' |
|
if appendSlash { |
|
return finalPath + "/" |
|
} |
|
return finalPath |
|
} |
|
|
|
func resolveAddress(addr []string) string { |
|
switch len(addr) { |
|
case 0: |
|
if port := os.Getenv("PORT"); port != "" { |
|
//debugPrint("Environment variable PORT=\"%s\"", port) |
|
return ":" + port |
|
} |
|
//debugPrint("Environment variable PORT is undefined. Using port :8080 by default") |
|
return ":8080" |
|
case 1: |
|
return addr[0] |
|
default: |
|
panic("too much parameters") |
|
} |
|
}
|
|
|