aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/codegen/templates/import.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-05 22:03:19 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-05 22:33:03 +0100
commit1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6 (patch)
treee088b0fa43058afde1db71541d8fcb4b94905d6e /vendor/github.com/99designs/gqlgen/codegen/templates/import.go
parentf093be96e98284580d61664adecd0a2ff8b354e4 (diff)
downloadgit-bug-1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6.tar.gz
migrate to go modules
Diffstat (limited to 'vendor/github.com/99designs/gqlgen/codegen/templates/import.go')
-rw-r--r--vendor/github.com/99designs/gqlgen/codegen/templates/import.go138
1 files changed, 0 insertions, 138 deletions
diff --git a/vendor/github.com/99designs/gqlgen/codegen/templates/import.go b/vendor/github.com/99designs/gqlgen/codegen/templates/import.go
deleted file mode 100644
index d5bd16a6..00000000
--- a/vendor/github.com/99designs/gqlgen/codegen/templates/import.go
+++ /dev/null
@@ -1,138 +0,0 @@
-package templates
-
-import (
- "fmt"
- "go/types"
- "strconv"
- "strings"
-
- "github.com/99designs/gqlgen/internal/code"
-)
-
-type Import struct {
- Name string
- Path string
- Alias string
-}
-
-type Imports struct {
- imports []*Import
- destDir string
-}
-
-func (i *Import) String() string {
- if strings.HasSuffix(i.Path, i.Alias) {
- return strconv.Quote(i.Path)
- }
-
- return i.Alias + " " + strconv.Quote(i.Path)
-}
-
-func (s *Imports) String() string {
- res := ""
- for i, imp := range s.imports {
- if i != 0 {
- res += "\n"
- }
- res += imp.String()
- }
- return res
-}
-
-func (s *Imports) Reserve(path string, aliases ...string) (string, error) {
- if path == "" {
- panic("empty ambient import")
- }
-
- // if we are referencing our own package we dont need an import
- if code.ImportPathForDir(s.destDir) == path {
- return "", nil
- }
-
- name := code.NameForPackage(path)
- var alias string
- if len(aliases) != 1 {
- alias = name
- } else {
- alias = aliases[0]
- }
-
- if existing := s.findByPath(path); existing != nil {
- if existing.Alias == alias {
- return "", nil
- }
- return "", fmt.Errorf("ambient import already exists")
- }
-
- if alias := s.findByAlias(alias); alias != nil {
- return "", fmt.Errorf("ambient import collides on an alias")
- }
-
- s.imports = append(s.imports, &Import{
- Name: name,
- Path: path,
- Alias: alias,
- })
-
- return "", nil
-}
-
-func (s *Imports) Lookup(path string) string {
- if path == "" {
- return ""
- }
-
- path = code.NormalizeVendor(path)
-
- // if we are referencing our own package we dont need an import
- if code.ImportPathForDir(s.destDir) == path {
- return ""
- }
-
- if existing := s.findByPath(path); existing != nil {
- return existing.Alias
- }
-
- imp := &Import{
- Name: code.NameForPackage(path),
- Path: path,
- }
- s.imports = append(s.imports, imp)
-
- alias := imp.Name
- i := 1
- for s.findByAlias(alias) != nil {
- alias = imp.Name + strconv.Itoa(i)
- i++
- if i > 10 {
- panic(fmt.Errorf("too many collisions, last attempt was %s", alias))
- }
- }
- imp.Alias = alias
-
- return imp.Alias
-}
-
-func (s *Imports) LookupType(t types.Type) string {
- return types.TypeString(t, func(i *types.Package) string {
- return s.Lookup(i.Path())
- })
-}
-
-func (s Imports) findByPath(importPath string) *Import {
- for _, imp := range s.imports {
- if imp.Path == importPath {
- return imp
- }
- }
- return nil
-}
-
-func (s Imports) findByAlias(alias string) *Import {
- for _, imp := range s.imports {
- if imp.Alias == alias {
- return imp
- }
- }
- return nil
-}