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/vektah/gqlgen/codegen/templates/templates.go | |
parent | a3fc9abb921f5ce7084d6ab7473442d0b72b1d78 (diff) | |
download | git-bug-b478cd1bcb4756b20f7f4b15fcf81f23e1a60a02.tar.gz |
graphql: update gqlgen to 0.5.1
fix #6
Diffstat (limited to 'vendor/github.com/vektah/gqlgen/codegen/templates/templates.go')
-rw-r--r-- | vendor/github.com/vektah/gqlgen/codegen/templates/templates.go | 139 |
1 files changed, 0 insertions, 139 deletions
diff --git a/vendor/github.com/vektah/gqlgen/codegen/templates/templates.go b/vendor/github.com/vektah/gqlgen/codegen/templates/templates.go deleted file mode 100644 index 3d29b403..00000000 --- a/vendor/github.com/vektah/gqlgen/codegen/templates/templates.go +++ /dev/null @@ -1,139 +0,0 @@ -//go:generate go run ./inliner/inliner.go - -package templates - -import ( - "bytes" - "fmt" - "sort" - "strconv" - "strings" - "text/template" - "unicode" -) - -func Run(name string, tpldata interface{}) (*bytes.Buffer, error) { - t := template.New("").Funcs(template.FuncMap{ - "ucFirst": ucFirst, - "lcFirst": lcFirst, - "quote": strconv.Quote, - "rawQuote": rawQuote, - "toCamel": ToCamel, - "dump": dump, - "prefixLines": prefixLines, - }) - - for filename, data := range data { - _, err := t.New(filename).Parse(data) - if err != nil { - panic(err) - } - } - - buf := &bytes.Buffer{} - err := t.Lookup(name).Execute(buf, tpldata) - if err != nil { - return nil, err - } - - return buf, nil -} - -func ucFirst(s string) string { - if s == "" { - return "" - } - r := []rune(s) - r[0] = unicode.ToUpper(r[0]) - return string(r) -} - -func lcFirst(s string) string { - if s == "" { - return "" - } - - r := []rune(s) - r[0] = unicode.ToLower(r[0]) - return string(r) -} - -func isDelimiter(c rune) bool { - return c == '-' || c == '_' || unicode.IsSpace(c) -} - -func ToCamel(s string) string { - buffer := make([]rune, 0, len(s)) - upper := true - lastWasUpper := false - - for _, c := range s { - if isDelimiter(c) { - upper = true - continue - } - if !lastWasUpper && unicode.IsUpper(c) { - upper = true - } - - if upper { - buffer = append(buffer, unicode.ToUpper(c)) - } else { - buffer = append(buffer, unicode.ToLower(c)) - } - upper = false - lastWasUpper = unicode.IsUpper(c) - } - - return string(buffer) -} - -func rawQuote(s string) string { - return "`" + strings.Replace(s, "`", "`+\"`\"+`", -1) + "`" -} - -func dump(val interface{}) string { - switch val := val.(type) { - case int: - return strconv.Itoa(val) - case float64: - return fmt.Sprintf("%f", val) - case string: - return strconv.Quote(val) - case bool: - return strconv.FormatBool(val) - case nil: - return "nil" - case []interface{}: - var parts []string - for _, part := range val { - parts = append(parts, dump(part)) - } - return "[]interface{}{" + strings.Join(parts, ",") + "}" - case map[string]interface{}: - buf := bytes.Buffer{} - buf.WriteString("map[string]interface{}{") - var keys []string - for key := range val { - keys = append(keys, key) - } - sort.Strings(keys) - - for _, key := range keys { - data := val[key] - - buf.WriteString(strconv.Quote(key)) - buf.WriteString(":") - buf.WriteString(dump(data)) - buf.WriteString(",") - } - buf.WriteString("}") - return buf.String() - default: - panic(fmt.Errorf("unsupported type %T", val)) - } -} - -func prefixLines(prefix, s string) string { - return prefix + strings.Replace(s, "\n", "\n"+prefix, -1) -} |