iris/iris/fs.go
Gerasimos (Makis) Maropoulos 8bbd9f8fc5 Happy new year! Update to 6.0.0 | HTTP/2 full support. https://github.com/kataras/iris/issues/565
full commit from development branch.

Examples, book, middleware, plugins are updated to the latest iris
version. Read HISTORY.md for more.

The 'old' v5 branch which relied on fasthttp exists for those who want
to use it navigate there: https://github.com/kataras/iris/tree/5.0.0
2017-01-02 21:20:17 +02:00

71 lines
1.6 KiB
Go

package main
import (
"os"
"path/filepath"
"strings"
"github.com/kataras/go-errors"
)
var goPath string
// returns the (last) gopath+"/src/"
func getGoPath() string {
if goPath == "" {
errGoPathMissing := errors.New(Name + `: $GOPATH environment is missing. Please configure your $GOPATH. Reference:
https://github.com/golang/go/wiki/GOPATH`)
// set the gopath
goPath = os.Getenv("GOPATH")
if goPath == "" {
// we should panic here
panic(errGoPathMissing)
}
if idxLSep := strings.LastIndexByte(goPath, os.PathListSeparator); idxLSep == len(goPath)-1 {
// remove the last ';' or ':' in order to be safe to take the last correct path(if more than one )
goPath = goPath[0 : len(goPath)-2]
}
if idxLSep := strings.IndexByte(goPath, os.PathListSeparator); idxLSep != -1 {
// we have more than one user-defined gopaths
goPath = goPath[idxLSep+1:] // take the last
}
}
return join(goPath, "src")
}
const pathsep = string(os.PathSeparator)
// it just replaces / or double slashes with os.PathSeparator
// if second parameter receiver is true then it removes any ending slashes too
func fromslash(s string) string {
if len(s) == 0 {
return ""
}
s = strings.Replace(s, "//", "/", -1)
s = strings.Replace(s, "/", pathsep, -1)
return s
}
func removeTrailingSlash(s string) string {
if s[len(s)-1] == os.PathSeparator {
s = s[0 : len(s)-2]
}
return s
}
func toslash(paths ...string) string {
s := join(paths...)
s = strings.Replace(s, pathsep, "/", -1)
return removeTrailingSlash(s)
}
// combine paths
func join(paths ...string) string {
return removeTrailingSlash(fromslash(filepath.Join(paths...)))
}