diff options
author | Michael Muré <batolettre@gmail.com> | 2020-02-05 22:03:19 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-02-05 22:33:03 +0100 |
commit | 1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6 (patch) | |
tree | e088b0fa43058afde1db71541d8fcb4b94905d6e /vendor/github.com/99designs/gqlgen/internal/code/util.go | |
parent | f093be96e98284580d61664adecd0a2ff8b354e4 (diff) | |
download | git-bug-1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6.tar.gz |
migrate to go modules
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/internal/code/util.go')
-rw-r--r-- | vendor/github.com/99designs/gqlgen/internal/code/util.go | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/vendor/github.com/99designs/gqlgen/internal/code/util.go b/vendor/github.com/99designs/gqlgen/internal/code/util.go deleted file mode 100644 index 2be83a23..00000000 --- a/vendor/github.com/99designs/gqlgen/internal/code/util.go +++ /dev/null @@ -1,56 +0,0 @@ -package code - -import ( - "go/build" - "os" - "path/filepath" - "regexp" - "strings" -) - -// take a string in the form github.com/package/blah.Type and split it into package and type -func PkgAndType(name string) (string, string) { - parts := strings.Split(name, ".") - if len(parts) == 1 { - return "", name - } - - return strings.Join(parts[:len(parts)-1], "."), parts[len(parts)-1] -} - -var modsRegex = regexp.MustCompile(`^(\*|\[\])*`) - -// NormalizeVendor takes a qualified package path and turns it into normal one. -// eg . -// github.com/foo/vendor/github.com/99designs/gqlgen/graphql becomes -// github.com/99designs/gqlgen/graphql -func NormalizeVendor(pkg string) string { - modifiers := modsRegex.FindAllString(pkg, 1)[0] - pkg = strings.TrimPrefix(pkg, modifiers) - parts := strings.Split(pkg, "/vendor/") - return modifiers + parts[len(parts)-1] -} - -// QualifyPackagePath takes an import and fully qualifies it with a vendor dir, if one is required. -// eg . -// github.com/99designs/gqlgen/graphql becomes -// github.com/foo/vendor/github.com/99designs/gqlgen/graphql -// -// x/tools/packages only supports 'qualified package paths' so this will need to be done prior to calling it -// See https://github.com/golang/go/issues/30289 -func QualifyPackagePath(importPath string) string { - wd, _ := os.Getwd() - - pkg, err := build.Import(importPath, wd, 0) - if err != nil { - return importPath - } - - return pkg.ImportPath -} - -var invalidPackageNameChar = regexp.MustCompile(`[^\w]`) - -func SanitizePackageName(pkg string) string { - return invalidPackageNameChar.ReplaceAllLiteralString(filepath.Base(pkg), "_") -} |