diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-14 12:40:31 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-14 12:41:59 +0200 |
commit | b478cd1bcb4756b20f7f4b15fcf81f23e1a60a02 (patch) | |
tree | 8ce232dcab3dd00708f8ba66c334472457e5980d /vendor/github.com/99designs/gqlgen/internal | |
parent | a3fc9abb921f5ce7084d6ab7473442d0b72b1d78 (diff) | |
download | git-bug-b478cd1bcb4756b20f7f4b15fcf81f23e1a60a02.tar.gz |
graphql: update gqlgen to 0.5.1
fix #6
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/internal')
-rw-r--r-- | vendor/github.com/99designs/gqlgen/internal/gopath/gopath.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/github.com/99designs/gqlgen/internal/gopath/gopath.go b/vendor/github.com/99designs/gqlgen/internal/gopath/gopath.go new file mode 100644 index 00000000..c9b66167 --- /dev/null +++ b/vendor/github.com/99designs/gqlgen/internal/gopath/gopath.go @@ -0,0 +1,37 @@ +package gopath + +import ( + "fmt" + "go/build" + "path/filepath" + "strings" +) + +var NotFound = fmt.Errorf("not on GOPATH") + +// Contains returns true if the given directory is in the GOPATH +func Contains(dir string) bool { + _, err := Dir2Import(dir) + return err == nil +} + +// Dir2Import takes an *absolute* path and returns a golang import path for the package, and returns an error if it isn't on the gopath +func Dir2Import(dir string) (string, error) { + dir = filepath.ToSlash(dir) + for _, gopath := range filepath.SplitList(build.Default.GOPATH) { + gopath = filepath.ToSlash(filepath.Join(gopath, "src")) + if len(gopath) < len(dir) && strings.EqualFold(gopath, dir[0:len(gopath)]) { + return dir[len(gopath)+1:], nil + } + } + return "", NotFound +} + +// MustDir2Import takes an *absolute* path and returns a golang import path for the package, and panics if it isn't on the gopath +func MustDir2Import(dir string) string { + pkg, err := Dir2Import(dir) + if err != nil { + panic(err) + } + return pkg +} |