123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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")
- }
- }
|