|
|
9e995a |
From 57e0d7d32a08e28ffb8e42704bbf2d6e7906e0b1 Mon Sep 17 00:00:00 2001
|
|
|
9e995a |
From: Jan Chaloupka <jchaloup@redhat.com>
|
|
|
9e995a |
Date: Thu, 14 Jan 2016 21:14:10 +0100
|
|
|
9e995a |
Subject: [PATCH] internal->inteernal
|
|
|
9e995a |
|
|
|
9e995a |
---
|
|
|
9e995a |
.../p/google-api-go-client/googleapi/googleapi.go | 2 +-
|
|
|
9e995a |
.../googleapi/inteernal/uritemplates/LICENSE | 18 ++
|
|
|
9e995a |
.../inteernal/uritemplates/uritemplates.go | 359 +++++++++++++++++++++
|
|
|
9e995a |
.../googleapi/inteernal/uritemplates/utils.go | 13 +
|
|
|
9e995a |
.../googleapi/internal/uritemplates/LICENSE | 18 --
|
|
|
9e995a |
.../internal/uritemplates/uritemplates.go | 359 ---------------------
|
|
|
9e995a |
.../googleapi/internal/uritemplates/utils.go | 13 -
|
|
|
9e995a |
7 files changed, 391 insertions(+), 391 deletions(-)
|
|
|
9e995a |
create mode 100644 Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/LICENSE
|
|
|
9e995a |
create mode 100644 Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/uritemplates.go
|
|
|
9e995a |
create mode 100644 Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/utils.go
|
|
|
9e995a |
delete mode 100644 Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/LICENSE
|
|
|
9e995a |
delete mode 100644 Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/uritemplates.go
|
|
|
9e995a |
delete mode 100644 Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/utils.go
|
|
|
9e995a |
|
|
|
9e995a |
diff --git a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/googleapi.go b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/googleapi.go
|
|
|
9e995a |
index 7a0df3d..6922de4 100644
|
|
|
9e995a |
--- a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/googleapi.go
|
|
|
9e995a |
+++ b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/googleapi.go
|
|
|
9e995a |
@@ -19,7 +19,7 @@ import (
|
|
|
9e995a |
"os"
|
|
|
9e995a |
"strings"
|
|
|
9e995a |
|
|
|
9e995a |
- "github.com/coreos/flannel/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates"
|
|
|
9e995a |
+ "github.com/coreos/flannel/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates"
|
|
|
9e995a |
)
|
|
|
9e995a |
|
|
|
9e995a |
// ContentTyper is an interface for Readers which know (or would like
|
|
|
9e995a |
diff --git a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/LICENSE b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/LICENSE
|
|
|
9e995a |
new file mode 100644
|
|
|
9e995a |
index 0000000..de9c88c
|
|
|
9e995a |
--- /dev/null
|
|
|
9e995a |
+++ b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/LICENSE
|
|
|
9e995a |
@@ -0,0 +1,18 @@
|
|
|
9e995a |
+Copyright (c) 2013 Joshua Tacoma
|
|
|
9e995a |
+
|
|
|
9e995a |
+Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
9e995a |
+this software and associated documentation files (the "Software"), to deal in
|
|
|
9e995a |
+the Software without restriction, including without limitation the rights to
|
|
|
9e995a |
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
9e995a |
+the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
9e995a |
+subject to the following conditions:
|
|
|
9e995a |
+
|
|
|
9e995a |
+The above copyright notice and this permission notice shall be included in all
|
|
|
9e995a |
+copies or substantial portions of the Software.
|
|
|
9e995a |
+
|
|
|
9e995a |
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
9e995a |
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
9e995a |
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
9e995a |
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
9e995a |
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
9e995a |
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
9e995a |
diff --git a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/uritemplates.go b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/uritemplates.go
|
|
|
9e995a |
new file mode 100644
|
|
|
9e995a |
index 0000000..8a84813
|
|
|
9e995a |
--- /dev/null
|
|
|
9e995a |
+++ b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/uritemplates.go
|
|
|
9e995a |
@@ -0,0 +1,359 @@
|
|
|
9e995a |
+// Copyright 2013 Joshua Tacoma. All rights reserved.
|
|
|
9e995a |
+// Use of this source code is governed by a BSD-style
|
|
|
9e995a |
+// license that can be found in the LICENSE file.
|
|
|
9e995a |
+
|
|
|
9e995a |
+// Package uritemplates is a level 4 implementation of RFC 6570 (URI
|
|
|
9e995a |
+// Template, http://tools.ietf.org/html/rfc6570).
|
|
|
9e995a |
+//
|
|
|
9e995a |
+// To use uritemplates, parse a template string and expand it with a value
|
|
|
9e995a |
+// map:
|
|
|
9e995a |
+//
|
|
|
9e995a |
+// template, _ := uritemplates.Parse("https://api.github.com/repos{/user,repo}")
|
|
|
9e995a |
+// values := make(map[string]interface{})
|
|
|
9e995a |
+// values["user"] = "jtacoma"
|
|
|
9e995a |
+// values["repo"] = "uritemplates"
|
|
|
9e995a |
+// expanded, _ := template.ExpandString(values)
|
|
|
9e995a |
+// fmt.Printf(expanded)
|
|
|
9e995a |
+//
|
|
|
9e995a |
+package uritemplates
|
|
|
9e995a |
+
|
|
|
9e995a |
+import (
|
|
|
9e995a |
+ "bytes"
|
|
|
9e995a |
+ "errors"
|
|
|
9e995a |
+ "fmt"
|
|
|
9e995a |
+ "reflect"
|
|
|
9e995a |
+ "regexp"
|
|
|
9e995a |
+ "strconv"
|
|
|
9e995a |
+ "strings"
|
|
|
9e995a |
+)
|
|
|
9e995a |
+
|
|
|
9e995a |
+var (
|
|
|
9e995a |
+ unreserved = regexp.MustCompile("[^A-Za-z0-9\\-._~]")
|
|
|
9e995a |
+ reserved = regexp.MustCompile("[^A-Za-z0-9\\-._~:/?#[\\]@!$&'()*+,;=]")
|
|
|
9e995a |
+ validname = regexp.MustCompile("^([A-Za-z0-9_\\.]|%[0-9A-Fa-f][0-9A-Fa-f])+$")
|
|
|
9e995a |
+ hex = []byte("0123456789ABCDEF")
|
|
|
9e995a |
+)
|
|
|
9e995a |
+
|
|
|
9e995a |
+func pctEncode(src []byte) []byte {
|
|
|
9e995a |
+ dst := make([]byte, len(src)*3)
|
|
|
9e995a |
+ for i, b := range src {
|
|
|
9e995a |
+ buf := dst[i*3 : i*3+3]
|
|
|
9e995a |
+ buf[0] = 0x25
|
|
|
9e995a |
+ buf[1] = hex[b/16]
|
|
|
9e995a |
+ buf[2] = hex[b%16]
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return dst
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+func escape(s string, allowReserved bool) (escaped string) {
|
|
|
9e995a |
+ if allowReserved {
|
|
|
9e995a |
+ escaped = string(reserved.ReplaceAllFunc([]byte(s), pctEncode))
|
|
|
9e995a |
+ } else {
|
|
|
9e995a |
+ escaped = string(unreserved.ReplaceAllFunc([]byte(s), pctEncode))
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return escaped
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+// A UriTemplate is a parsed representation of a URI template.
|
|
|
9e995a |
+type UriTemplate struct {
|
|
|
9e995a |
+ raw string
|
|
|
9e995a |
+ parts []templatePart
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+// Parse parses a URI template string into a UriTemplate object.
|
|
|
9e995a |
+func Parse(rawtemplate string) (template *UriTemplate, err error) {
|
|
|
9e995a |
+ template = new(UriTemplate)
|
|
|
9e995a |
+ template.raw = rawtemplate
|
|
|
9e995a |
+ split := strings.Split(rawtemplate, "{")
|
|
|
9e995a |
+ template.parts = make([]templatePart, len(split)*2-1)
|
|
|
9e995a |
+ for i, s := range split {
|
|
|
9e995a |
+ if i == 0 {
|
|
|
9e995a |
+ if strings.Contains(s, "}") {
|
|
|
9e995a |
+ err = errors.New("unexpected }")
|
|
|
9e995a |
+ break
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ template.parts[i].raw = s
|
|
|
9e995a |
+ } else {
|
|
|
9e995a |
+ subsplit := strings.Split(s, "}")
|
|
|
9e995a |
+ if len(subsplit) != 2 {
|
|
|
9e995a |
+ err = errors.New("malformed template")
|
|
|
9e995a |
+ break
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ expression := subsplit[0]
|
|
|
9e995a |
+ template.parts[i*2-1], err = parseExpression(expression)
|
|
|
9e995a |
+ if err != nil {
|
|
|
9e995a |
+ break
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ template.parts[i*2].raw = subsplit[1]
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if err != nil {
|
|
|
9e995a |
+ template = nil
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return template, err
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+type templatePart struct {
|
|
|
9e995a |
+ raw string
|
|
|
9e995a |
+ terms []templateTerm
|
|
|
9e995a |
+ first string
|
|
|
9e995a |
+ sep string
|
|
|
9e995a |
+ named bool
|
|
|
9e995a |
+ ifemp string
|
|
|
9e995a |
+ allowReserved bool
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+type templateTerm struct {
|
|
|
9e995a |
+ name string
|
|
|
9e995a |
+ explode bool
|
|
|
9e995a |
+ truncate int
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+func parseExpression(expression string) (result templatePart, err error) {
|
|
|
9e995a |
+ switch expression[0] {
|
|
|
9e995a |
+ case '+':
|
|
|
9e995a |
+ result.sep = ","
|
|
|
9e995a |
+ result.allowReserved = true
|
|
|
9e995a |
+ expression = expression[1:]
|
|
|
9e995a |
+ case '.':
|
|
|
9e995a |
+ result.first = "."
|
|
|
9e995a |
+ result.sep = "."
|
|
|
9e995a |
+ expression = expression[1:]
|
|
|
9e995a |
+ case '/':
|
|
|
9e995a |
+ result.first = "/"
|
|
|
9e995a |
+ result.sep = "/"
|
|
|
9e995a |
+ expression = expression[1:]
|
|
|
9e995a |
+ case ';':
|
|
|
9e995a |
+ result.first = ";"
|
|
|
9e995a |
+ result.sep = ";"
|
|
|
9e995a |
+ result.named = true
|
|
|
9e995a |
+ expression = expression[1:]
|
|
|
9e995a |
+ case '?':
|
|
|
9e995a |
+ result.first = "?"
|
|
|
9e995a |
+ result.sep = "&"
|
|
|
9e995a |
+ result.named = true
|
|
|
9e995a |
+ result.ifemp = "="
|
|
|
9e995a |
+ expression = expression[1:]
|
|
|
9e995a |
+ case '&':
|
|
|
9e995a |
+ result.first = "&"
|
|
|
9e995a |
+ result.sep = "&"
|
|
|
9e995a |
+ result.named = true
|
|
|
9e995a |
+ result.ifemp = "="
|
|
|
9e995a |
+ expression = expression[1:]
|
|
|
9e995a |
+ case '#':
|
|
|
9e995a |
+ result.first = "#"
|
|
|
9e995a |
+ result.sep = ","
|
|
|
9e995a |
+ result.allowReserved = true
|
|
|
9e995a |
+ expression = expression[1:]
|
|
|
9e995a |
+ default:
|
|
|
9e995a |
+ result.sep = ","
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ rawterms := strings.Split(expression, ",")
|
|
|
9e995a |
+ result.terms = make([]templateTerm, len(rawterms))
|
|
|
9e995a |
+ for i, raw := range rawterms {
|
|
|
9e995a |
+ result.terms[i], err = parseTerm(raw)
|
|
|
9e995a |
+ if err != nil {
|
|
|
9e995a |
+ break
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return result, err
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+func parseTerm(term string) (result templateTerm, err error) {
|
|
|
9e995a |
+ if strings.HasSuffix(term, "*") {
|
|
|
9e995a |
+ result.explode = true
|
|
|
9e995a |
+ term = term[:len(term)-1]
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ split := strings.Split(term, ":")
|
|
|
9e995a |
+ if len(split) == 1 {
|
|
|
9e995a |
+ result.name = term
|
|
|
9e995a |
+ } else if len(split) == 2 {
|
|
|
9e995a |
+ result.name = split[0]
|
|
|
9e995a |
+ var parsed int64
|
|
|
9e995a |
+ parsed, err = strconv.ParseInt(split[1], 10, 0)
|
|
|
9e995a |
+ result.truncate = int(parsed)
|
|
|
9e995a |
+ } else {
|
|
|
9e995a |
+ err = errors.New("multiple colons in same term")
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if !validname.MatchString(result.name) {
|
|
|
9e995a |
+ err = errors.New("not a valid name: " + result.name)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if result.explode && result.truncate > 0 {
|
|
|
9e995a |
+ err = errors.New("both explode and prefix modifers on same term")
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return result, err
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+// Expand expands a URI template with a set of values to produce a string.
|
|
|
9e995a |
+func (self *UriTemplate) Expand(value interface{}) (string, error) {
|
|
|
9e995a |
+ values, ismap := value.(map[string]interface{})
|
|
|
9e995a |
+ if !ismap {
|
|
|
9e995a |
+ if m, ismap := struct2map(value); !ismap {
|
|
|
9e995a |
+ return "", errors.New("expected map[string]interface{}, struct, or pointer to struct.")
|
|
|
9e995a |
+ } else {
|
|
|
9e995a |
+ return self.Expand(m)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ var buf bytes.Buffer
|
|
|
9e995a |
+ for _, p := range self.parts {
|
|
|
9e995a |
+ err := p.expand(&buf, values)
|
|
|
9e995a |
+ if err != nil {
|
|
|
9e995a |
+ return "", err
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return buf.String(), nil
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+func (self *templatePart) expand(buf *bytes.Buffer, values map[string]interface{}) error {
|
|
|
9e995a |
+ if len(self.raw) > 0 {
|
|
|
9e995a |
+ buf.WriteString(self.raw)
|
|
|
9e995a |
+ return nil
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ var zeroLen = buf.Len()
|
|
|
9e995a |
+ buf.WriteString(self.first)
|
|
|
9e995a |
+ var firstLen = buf.Len()
|
|
|
9e995a |
+ for _, term := range self.terms {
|
|
|
9e995a |
+ value, exists := values[term.name]
|
|
|
9e995a |
+ if !exists {
|
|
|
9e995a |
+ continue
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if buf.Len() != firstLen {
|
|
|
9e995a |
+ buf.WriteString(self.sep)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ switch v := value.(type) {
|
|
|
9e995a |
+ case string:
|
|
|
9e995a |
+ self.expandString(buf, term, v)
|
|
|
9e995a |
+ case []interface{}:
|
|
|
9e995a |
+ self.expandArray(buf, term, v)
|
|
|
9e995a |
+ case map[string]interface{}:
|
|
|
9e995a |
+ if term.truncate > 0 {
|
|
|
9e995a |
+ return errors.New("cannot truncate a map expansion")
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ self.expandMap(buf, term, v)
|
|
|
9e995a |
+ default:
|
|
|
9e995a |
+ if m, ismap := struct2map(value); ismap {
|
|
|
9e995a |
+ if term.truncate > 0 {
|
|
|
9e995a |
+ return errors.New("cannot truncate a map expansion")
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ self.expandMap(buf, term, m)
|
|
|
9e995a |
+ } else {
|
|
|
9e995a |
+ str := fmt.Sprintf("%v", value)
|
|
|
9e995a |
+ self.expandString(buf, term, str)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if buf.Len() == firstLen {
|
|
|
9e995a |
+ original := buf.Bytes()[:zeroLen]
|
|
|
9e995a |
+ buf.Reset()
|
|
|
9e995a |
+ buf.Write(original)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return nil
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+func (self *templatePart) expandName(buf *bytes.Buffer, name string, empty bool) {
|
|
|
9e995a |
+ if self.named {
|
|
|
9e995a |
+ buf.WriteString(name)
|
|
|
9e995a |
+ if empty {
|
|
|
9e995a |
+ buf.WriteString(self.ifemp)
|
|
|
9e995a |
+ } else {
|
|
|
9e995a |
+ buf.WriteString("=")
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+func (self *templatePart) expandString(buf *bytes.Buffer, t templateTerm, s string) {
|
|
|
9e995a |
+ if len(s) > t.truncate && t.truncate > 0 {
|
|
|
9e995a |
+ s = s[:t.truncate]
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ self.expandName(buf, t.name, len(s) == 0)
|
|
|
9e995a |
+ buf.WriteString(escape(s, self.allowReserved))
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+func (self *templatePart) expandArray(buf *bytes.Buffer, t templateTerm, a []interface{}) {
|
|
|
9e995a |
+ if len(a) == 0 {
|
|
|
9e995a |
+ return
|
|
|
9e995a |
+ } else if !t.explode {
|
|
|
9e995a |
+ self.expandName(buf, t.name, false)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ for i, value := range a {
|
|
|
9e995a |
+ if t.explode && i > 0 {
|
|
|
9e995a |
+ buf.WriteString(self.sep)
|
|
|
9e995a |
+ } else if i > 0 {
|
|
|
9e995a |
+ buf.WriteString(",")
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ var s string
|
|
|
9e995a |
+ switch v := value.(type) {
|
|
|
9e995a |
+ case string:
|
|
|
9e995a |
+ s = v
|
|
|
9e995a |
+ default:
|
|
|
9e995a |
+ s = fmt.Sprintf("%v", v)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if len(s) > t.truncate && t.truncate > 0 {
|
|
|
9e995a |
+ s = s[:t.truncate]
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if self.named && t.explode {
|
|
|
9e995a |
+ self.expandName(buf, t.name, len(s) == 0)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ buf.WriteString(escape(s, self.allowReserved))
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+func (self *templatePart) expandMap(buf *bytes.Buffer, t templateTerm, m map[string]interface{}) {
|
|
|
9e995a |
+ if len(m) == 0 {
|
|
|
9e995a |
+ return
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if !t.explode {
|
|
|
9e995a |
+ self.expandName(buf, t.name, len(m) == 0)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ var firstLen = buf.Len()
|
|
|
9e995a |
+ for k, value := range m {
|
|
|
9e995a |
+ if firstLen != buf.Len() {
|
|
|
9e995a |
+ if t.explode {
|
|
|
9e995a |
+ buf.WriteString(self.sep)
|
|
|
9e995a |
+ } else {
|
|
|
9e995a |
+ buf.WriteString(",")
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ var s string
|
|
|
9e995a |
+ switch v := value.(type) {
|
|
|
9e995a |
+ case string:
|
|
|
9e995a |
+ s = v
|
|
|
9e995a |
+ default:
|
|
|
9e995a |
+ s = fmt.Sprintf("%v", v)
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if t.explode {
|
|
|
9e995a |
+ buf.WriteString(escape(k, self.allowReserved))
|
|
|
9e995a |
+ buf.WriteRune('=')
|
|
|
9e995a |
+ buf.WriteString(escape(s, self.allowReserved))
|
|
|
9e995a |
+ } else {
|
|
|
9e995a |
+ buf.WriteString(escape(k, self.allowReserved))
|
|
|
9e995a |
+ buf.WriteRune(',')
|
|
|
9e995a |
+ buf.WriteString(escape(s, self.allowReserved))
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+}
|
|
|
9e995a |
+
|
|
|
9e995a |
+func struct2map(v interface{}) (map[string]interface{}, bool) {
|
|
|
9e995a |
+ value := reflect.ValueOf(v)
|
|
|
9e995a |
+ switch value.Type().Kind() {
|
|
|
9e995a |
+ case reflect.Ptr:
|
|
|
9e995a |
+ return struct2map(value.Elem().Interface())
|
|
|
9e995a |
+ case reflect.Struct:
|
|
|
9e995a |
+ m := make(map[string]interface{})
|
|
|
9e995a |
+ for i := 0; i < value.NumField(); i++ {
|
|
|
9e995a |
+ tag := value.Type().Field(i).Tag
|
|
|
9e995a |
+ var name string
|
|
|
9e995a |
+ if strings.Contains(string(tag), ":") {
|
|
|
9e995a |
+ name = tag.Get("uri")
|
|
|
9e995a |
+ } else {
|
|
|
9e995a |
+ name = strings.TrimSpace(string(tag))
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ if len(name) == 0 {
|
|
|
9e995a |
+ name = value.Type().Field(i).Name
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ m[name] = value.Field(i).Interface()
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return m, true
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return nil, false
|
|
|
9e995a |
+}
|
|
|
9e995a |
diff --git a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/utils.go b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/utils.go
|
|
|
9e995a |
new file mode 100644
|
|
|
9e995a |
index 0000000..399ef46
|
|
|
9e995a |
--- /dev/null
|
|
|
9e995a |
+++ b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/inteernal/uritemplates/utils.go
|
|
|
9e995a |
@@ -0,0 +1,13 @@
|
|
|
9e995a |
+package uritemplates
|
|
|
9e995a |
+
|
|
|
9e995a |
+func Expand(path string, expansions map[string]string) (string, error) {
|
|
|
9e995a |
+ template, err := Parse(path)
|
|
|
9e995a |
+ if err != nil {
|
|
|
9e995a |
+ return "", err
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ values := make(map[string]interface{})
|
|
|
9e995a |
+ for k, v := range expansions {
|
|
|
9e995a |
+ values[k] = v
|
|
|
9e995a |
+ }
|
|
|
9e995a |
+ return template.Expand(values)
|
|
|
9e995a |
+}
|
|
|
9e995a |
diff --git a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/LICENSE b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/LICENSE
|
|
|
9e995a |
deleted file mode 100644
|
|
|
9e995a |
index de9c88c..0000000
|
|
|
9e995a |
--- a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/LICENSE
|
|
|
9e995a |
+++ /dev/null
|
|
|
9e995a |
@@ -1,18 +0,0 @@
|
|
|
9e995a |
-Copyright (c) 2013 Joshua Tacoma
|
|
|
9e995a |
-
|
|
|
9e995a |
-Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
9e995a |
-this software and associated documentation files (the "Software"), to deal in
|
|
|
9e995a |
-the Software without restriction, including without limitation the rights to
|
|
|
9e995a |
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
9e995a |
-the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
9e995a |
-subject to the following conditions:
|
|
|
9e995a |
-
|
|
|
9e995a |
-The above copyright notice and this permission notice shall be included in all
|
|
|
9e995a |
-copies or substantial portions of the Software.
|
|
|
9e995a |
-
|
|
|
9e995a |
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
9e995a |
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
9e995a |
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
9e995a |
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
9e995a |
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
9e995a |
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
9e995a |
diff --git a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/uritemplates.go b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/uritemplates.go
|
|
|
9e995a |
deleted file mode 100644
|
|
|
9e995a |
index 8a84813..0000000
|
|
|
9e995a |
--- a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/uritemplates.go
|
|
|
9e995a |
+++ /dev/null
|
|
|
9e995a |
@@ -1,359 +0,0 @@
|
|
|
9e995a |
-// Copyright 2013 Joshua Tacoma. All rights reserved.
|
|
|
9e995a |
-// Use of this source code is governed by a BSD-style
|
|
|
9e995a |
-// license that can be found in the LICENSE file.
|
|
|
9e995a |
-
|
|
|
9e995a |
-// Package uritemplates is a level 4 implementation of RFC 6570 (URI
|
|
|
9e995a |
-// Template, http://tools.ietf.org/html/rfc6570).
|
|
|
9e995a |
-//
|
|
|
9e995a |
-// To use uritemplates, parse a template string and expand it with a value
|
|
|
9e995a |
-// map:
|
|
|
9e995a |
-//
|
|
|
9e995a |
-// template, _ := uritemplates.Parse("https://api.github.com/repos{/user,repo}")
|
|
|
9e995a |
-// values := make(map[string]interface{})
|
|
|
9e995a |
-// values["user"] = "jtacoma"
|
|
|
9e995a |
-// values["repo"] = "uritemplates"
|
|
|
9e995a |
-// expanded, _ := template.ExpandString(values)
|
|
|
9e995a |
-// fmt.Printf(expanded)
|
|
|
9e995a |
-//
|
|
|
9e995a |
-package uritemplates
|
|
|
9e995a |
-
|
|
|
9e995a |
-import (
|
|
|
9e995a |
- "bytes"
|
|
|
9e995a |
- "errors"
|
|
|
9e995a |
- "fmt"
|
|
|
9e995a |
- "reflect"
|
|
|
9e995a |
- "regexp"
|
|
|
9e995a |
- "strconv"
|
|
|
9e995a |
- "strings"
|
|
|
9e995a |
-)
|
|
|
9e995a |
-
|
|
|
9e995a |
-var (
|
|
|
9e995a |
- unreserved = regexp.MustCompile("[^A-Za-z0-9\\-._~]")
|
|
|
9e995a |
- reserved = regexp.MustCompile("[^A-Za-z0-9\\-._~:/?#[\\]@!$&'()*+,;=]")
|
|
|
9e995a |
- validname = regexp.MustCompile("^([A-Za-z0-9_\\.]|%[0-9A-Fa-f][0-9A-Fa-f])+$")
|
|
|
9e995a |
- hex = []byte("0123456789ABCDEF")
|
|
|
9e995a |
-)
|
|
|
9e995a |
-
|
|
|
9e995a |
-func pctEncode(src []byte) []byte {
|
|
|
9e995a |
- dst := make([]byte, len(src)*3)
|
|
|
9e995a |
- for i, b := range src {
|
|
|
9e995a |
- buf := dst[i*3 : i*3+3]
|
|
|
9e995a |
- buf[0] = 0x25
|
|
|
9e995a |
- buf[1] = hex[b/16]
|
|
|
9e995a |
- buf[2] = hex[b%16]
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return dst
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-func escape(s string, allowReserved bool) (escaped string) {
|
|
|
9e995a |
- if allowReserved {
|
|
|
9e995a |
- escaped = string(reserved.ReplaceAllFunc([]byte(s), pctEncode))
|
|
|
9e995a |
- } else {
|
|
|
9e995a |
- escaped = string(unreserved.ReplaceAllFunc([]byte(s), pctEncode))
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return escaped
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-// A UriTemplate is a parsed representation of a URI template.
|
|
|
9e995a |
-type UriTemplate struct {
|
|
|
9e995a |
- raw string
|
|
|
9e995a |
- parts []templatePart
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-// Parse parses a URI template string into a UriTemplate object.
|
|
|
9e995a |
-func Parse(rawtemplate string) (template *UriTemplate, err error) {
|
|
|
9e995a |
- template = new(UriTemplate)
|
|
|
9e995a |
- template.raw = rawtemplate
|
|
|
9e995a |
- split := strings.Split(rawtemplate, "{")
|
|
|
9e995a |
- template.parts = make([]templatePart, len(split)*2-1)
|
|
|
9e995a |
- for i, s := range split {
|
|
|
9e995a |
- if i == 0 {
|
|
|
9e995a |
- if strings.Contains(s, "}") {
|
|
|
9e995a |
- err = errors.New("unexpected }")
|
|
|
9e995a |
- break
|
|
|
9e995a |
- }
|
|
|
9e995a |
- template.parts[i].raw = s
|
|
|
9e995a |
- } else {
|
|
|
9e995a |
- subsplit := strings.Split(s, "}")
|
|
|
9e995a |
- if len(subsplit) != 2 {
|
|
|
9e995a |
- err = errors.New("malformed template")
|
|
|
9e995a |
- break
|
|
|
9e995a |
- }
|
|
|
9e995a |
- expression := subsplit[0]
|
|
|
9e995a |
- template.parts[i*2-1], err = parseExpression(expression)
|
|
|
9e995a |
- if err != nil {
|
|
|
9e995a |
- break
|
|
|
9e995a |
- }
|
|
|
9e995a |
- template.parts[i*2].raw = subsplit[1]
|
|
|
9e995a |
- }
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if err != nil {
|
|
|
9e995a |
- template = nil
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return template, err
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-type templatePart struct {
|
|
|
9e995a |
- raw string
|
|
|
9e995a |
- terms []templateTerm
|
|
|
9e995a |
- first string
|
|
|
9e995a |
- sep string
|
|
|
9e995a |
- named bool
|
|
|
9e995a |
- ifemp string
|
|
|
9e995a |
- allowReserved bool
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-type templateTerm struct {
|
|
|
9e995a |
- name string
|
|
|
9e995a |
- explode bool
|
|
|
9e995a |
- truncate int
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-func parseExpression(expression string) (result templatePart, err error) {
|
|
|
9e995a |
- switch expression[0] {
|
|
|
9e995a |
- case '+':
|
|
|
9e995a |
- result.sep = ","
|
|
|
9e995a |
- result.allowReserved = true
|
|
|
9e995a |
- expression = expression[1:]
|
|
|
9e995a |
- case '.':
|
|
|
9e995a |
- result.first = "."
|
|
|
9e995a |
- result.sep = "."
|
|
|
9e995a |
- expression = expression[1:]
|
|
|
9e995a |
- case '/':
|
|
|
9e995a |
- result.first = "/"
|
|
|
9e995a |
- result.sep = "/"
|
|
|
9e995a |
- expression = expression[1:]
|
|
|
9e995a |
- case ';':
|
|
|
9e995a |
- result.first = ";"
|
|
|
9e995a |
- result.sep = ";"
|
|
|
9e995a |
- result.named = true
|
|
|
9e995a |
- expression = expression[1:]
|
|
|
9e995a |
- case '?':
|
|
|
9e995a |
- result.first = "?"
|
|
|
9e995a |
- result.sep = "&"
|
|
|
9e995a |
- result.named = true
|
|
|
9e995a |
- result.ifemp = "="
|
|
|
9e995a |
- expression = expression[1:]
|
|
|
9e995a |
- case '&':
|
|
|
9e995a |
- result.first = "&"
|
|
|
9e995a |
- result.sep = "&"
|
|
|
9e995a |
- result.named = true
|
|
|
9e995a |
- result.ifemp = "="
|
|
|
9e995a |
- expression = expression[1:]
|
|
|
9e995a |
- case '#':
|
|
|
9e995a |
- result.first = "#"
|
|
|
9e995a |
- result.sep = ","
|
|
|
9e995a |
- result.allowReserved = true
|
|
|
9e995a |
- expression = expression[1:]
|
|
|
9e995a |
- default:
|
|
|
9e995a |
- result.sep = ","
|
|
|
9e995a |
- }
|
|
|
9e995a |
- rawterms := strings.Split(expression, ",")
|
|
|
9e995a |
- result.terms = make([]templateTerm, len(rawterms))
|
|
|
9e995a |
- for i, raw := range rawterms {
|
|
|
9e995a |
- result.terms[i], err = parseTerm(raw)
|
|
|
9e995a |
- if err != nil {
|
|
|
9e995a |
- break
|
|
|
9e995a |
- }
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return result, err
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-func parseTerm(term string) (result templateTerm, err error) {
|
|
|
9e995a |
- if strings.HasSuffix(term, "*") {
|
|
|
9e995a |
- result.explode = true
|
|
|
9e995a |
- term = term[:len(term)-1]
|
|
|
9e995a |
- }
|
|
|
9e995a |
- split := strings.Split(term, ":")
|
|
|
9e995a |
- if len(split) == 1 {
|
|
|
9e995a |
- result.name = term
|
|
|
9e995a |
- } else if len(split) == 2 {
|
|
|
9e995a |
- result.name = split[0]
|
|
|
9e995a |
- var parsed int64
|
|
|
9e995a |
- parsed, err = strconv.ParseInt(split[1], 10, 0)
|
|
|
9e995a |
- result.truncate = int(parsed)
|
|
|
9e995a |
- } else {
|
|
|
9e995a |
- err = errors.New("multiple colons in same term")
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if !validname.MatchString(result.name) {
|
|
|
9e995a |
- err = errors.New("not a valid name: " + result.name)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if result.explode && result.truncate > 0 {
|
|
|
9e995a |
- err = errors.New("both explode and prefix modifers on same term")
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return result, err
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-// Expand expands a URI template with a set of values to produce a string.
|
|
|
9e995a |
-func (self *UriTemplate) Expand(value interface{}) (string, error) {
|
|
|
9e995a |
- values, ismap := value.(map[string]interface{})
|
|
|
9e995a |
- if !ismap {
|
|
|
9e995a |
- if m, ismap := struct2map(value); !ismap {
|
|
|
9e995a |
- return "", errors.New("expected map[string]interface{}, struct, or pointer to struct.")
|
|
|
9e995a |
- } else {
|
|
|
9e995a |
- return self.Expand(m)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- }
|
|
|
9e995a |
- var buf bytes.Buffer
|
|
|
9e995a |
- for _, p := range self.parts {
|
|
|
9e995a |
- err := p.expand(&buf, values)
|
|
|
9e995a |
- if err != nil {
|
|
|
9e995a |
- return "", err
|
|
|
9e995a |
- }
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return buf.String(), nil
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-func (self *templatePart) expand(buf *bytes.Buffer, values map[string]interface{}) error {
|
|
|
9e995a |
- if len(self.raw) > 0 {
|
|
|
9e995a |
- buf.WriteString(self.raw)
|
|
|
9e995a |
- return nil
|
|
|
9e995a |
- }
|
|
|
9e995a |
- var zeroLen = buf.Len()
|
|
|
9e995a |
- buf.WriteString(self.first)
|
|
|
9e995a |
- var firstLen = buf.Len()
|
|
|
9e995a |
- for _, term := range self.terms {
|
|
|
9e995a |
- value, exists := values[term.name]
|
|
|
9e995a |
- if !exists {
|
|
|
9e995a |
- continue
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if buf.Len() != firstLen {
|
|
|
9e995a |
- buf.WriteString(self.sep)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- switch v := value.(type) {
|
|
|
9e995a |
- case string:
|
|
|
9e995a |
- self.expandString(buf, term, v)
|
|
|
9e995a |
- case []interface{}:
|
|
|
9e995a |
- self.expandArray(buf, term, v)
|
|
|
9e995a |
- case map[string]interface{}:
|
|
|
9e995a |
- if term.truncate > 0 {
|
|
|
9e995a |
- return errors.New("cannot truncate a map expansion")
|
|
|
9e995a |
- }
|
|
|
9e995a |
- self.expandMap(buf, term, v)
|
|
|
9e995a |
- default:
|
|
|
9e995a |
- if m, ismap := struct2map(value); ismap {
|
|
|
9e995a |
- if term.truncate > 0 {
|
|
|
9e995a |
- return errors.New("cannot truncate a map expansion")
|
|
|
9e995a |
- }
|
|
|
9e995a |
- self.expandMap(buf, term, m)
|
|
|
9e995a |
- } else {
|
|
|
9e995a |
- str := fmt.Sprintf("%v", value)
|
|
|
9e995a |
- self.expandString(buf, term, str)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- }
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if buf.Len() == firstLen {
|
|
|
9e995a |
- original := buf.Bytes()[:zeroLen]
|
|
|
9e995a |
- buf.Reset()
|
|
|
9e995a |
- buf.Write(original)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return nil
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-func (self *templatePart) expandName(buf *bytes.Buffer, name string, empty bool) {
|
|
|
9e995a |
- if self.named {
|
|
|
9e995a |
- buf.WriteString(name)
|
|
|
9e995a |
- if empty {
|
|
|
9e995a |
- buf.WriteString(self.ifemp)
|
|
|
9e995a |
- } else {
|
|
|
9e995a |
- buf.WriteString("=")
|
|
|
9e995a |
- }
|
|
|
9e995a |
- }
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-func (self *templatePart) expandString(buf *bytes.Buffer, t templateTerm, s string) {
|
|
|
9e995a |
- if len(s) > t.truncate && t.truncate > 0 {
|
|
|
9e995a |
- s = s[:t.truncate]
|
|
|
9e995a |
- }
|
|
|
9e995a |
- self.expandName(buf, t.name, len(s) == 0)
|
|
|
9e995a |
- buf.WriteString(escape(s, self.allowReserved))
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-func (self *templatePart) expandArray(buf *bytes.Buffer, t templateTerm, a []interface{}) {
|
|
|
9e995a |
- if len(a) == 0 {
|
|
|
9e995a |
- return
|
|
|
9e995a |
- } else if !t.explode {
|
|
|
9e995a |
- self.expandName(buf, t.name, false)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- for i, value := range a {
|
|
|
9e995a |
- if t.explode && i > 0 {
|
|
|
9e995a |
- buf.WriteString(self.sep)
|
|
|
9e995a |
- } else if i > 0 {
|
|
|
9e995a |
- buf.WriteString(",")
|
|
|
9e995a |
- }
|
|
|
9e995a |
- var s string
|
|
|
9e995a |
- switch v := value.(type) {
|
|
|
9e995a |
- case string:
|
|
|
9e995a |
- s = v
|
|
|
9e995a |
- default:
|
|
|
9e995a |
- s = fmt.Sprintf("%v", v)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if len(s) > t.truncate && t.truncate > 0 {
|
|
|
9e995a |
- s = s[:t.truncate]
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if self.named && t.explode {
|
|
|
9e995a |
- self.expandName(buf, t.name, len(s) == 0)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- buf.WriteString(escape(s, self.allowReserved))
|
|
|
9e995a |
- }
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-func (self *templatePart) expandMap(buf *bytes.Buffer, t templateTerm, m map[string]interface{}) {
|
|
|
9e995a |
- if len(m) == 0 {
|
|
|
9e995a |
- return
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if !t.explode {
|
|
|
9e995a |
- self.expandName(buf, t.name, len(m) == 0)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- var firstLen = buf.Len()
|
|
|
9e995a |
- for k, value := range m {
|
|
|
9e995a |
- if firstLen != buf.Len() {
|
|
|
9e995a |
- if t.explode {
|
|
|
9e995a |
- buf.WriteString(self.sep)
|
|
|
9e995a |
- } else {
|
|
|
9e995a |
- buf.WriteString(",")
|
|
|
9e995a |
- }
|
|
|
9e995a |
- }
|
|
|
9e995a |
- var s string
|
|
|
9e995a |
- switch v := value.(type) {
|
|
|
9e995a |
- case string:
|
|
|
9e995a |
- s = v
|
|
|
9e995a |
- default:
|
|
|
9e995a |
- s = fmt.Sprintf("%v", v)
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if t.explode {
|
|
|
9e995a |
- buf.WriteString(escape(k, self.allowReserved))
|
|
|
9e995a |
- buf.WriteRune('=')
|
|
|
9e995a |
- buf.WriteString(escape(s, self.allowReserved))
|
|
|
9e995a |
- } else {
|
|
|
9e995a |
- buf.WriteString(escape(k, self.allowReserved))
|
|
|
9e995a |
- buf.WriteRune(',')
|
|
|
9e995a |
- buf.WriteString(escape(s, self.allowReserved))
|
|
|
9e995a |
- }
|
|
|
9e995a |
- }
|
|
|
9e995a |
-}
|
|
|
9e995a |
-
|
|
|
9e995a |
-func struct2map(v interface{}) (map[string]interface{}, bool) {
|
|
|
9e995a |
- value := reflect.ValueOf(v)
|
|
|
9e995a |
- switch value.Type().Kind() {
|
|
|
9e995a |
- case reflect.Ptr:
|
|
|
9e995a |
- return struct2map(value.Elem().Interface())
|
|
|
9e995a |
- case reflect.Struct:
|
|
|
9e995a |
- m := make(map[string]interface{})
|
|
|
9e995a |
- for i := 0; i < value.NumField(); i++ {
|
|
|
9e995a |
- tag := value.Type().Field(i).Tag
|
|
|
9e995a |
- var name string
|
|
|
9e995a |
- if strings.Contains(string(tag), ":") {
|
|
|
9e995a |
- name = tag.Get("uri")
|
|
|
9e995a |
- } else {
|
|
|
9e995a |
- name = strings.TrimSpace(string(tag))
|
|
|
9e995a |
- }
|
|
|
9e995a |
- if len(name) == 0 {
|
|
|
9e995a |
- name = value.Type().Field(i).Name
|
|
|
9e995a |
- }
|
|
|
9e995a |
- m[name] = value.Field(i).Interface()
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return m, true
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return nil, false
|
|
|
9e995a |
-}
|
|
|
9e995a |
diff --git a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/utils.go b/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/utils.go
|
|
|
9e995a |
deleted file mode 100644
|
|
|
9e995a |
index 399ef46..0000000
|
|
|
9e995a |
--- a/Godeps/_workspace/src/code.google.com/p/google-api-go-client/googleapi/internal/uritemplates/utils.go
|
|
|
9e995a |
+++ /dev/null
|
|
|
9e995a |
@@ -1,13 +0,0 @@
|
|
|
9e995a |
-package uritemplates
|
|
|
9e995a |
-
|
|
|
9e995a |
-func Expand(path string, expansions map[string]string) (string, error) {
|
|
|
9e995a |
- template, err := Parse(path)
|
|
|
9e995a |
- if err != nil {
|
|
|
9e995a |
- return "", err
|
|
|
9e995a |
- }
|
|
|
9e995a |
- values := make(map[string]interface{})
|
|
|
9e995a |
- for k, v := range expansions {
|
|
|
9e995a |
- values[k] = v
|
|
|
9e995a |
- }
|
|
|
9e995a |
- return template.Expand(values)
|
|
|
9e995a |
-}
|
|
|
9e995a |
--
|
|
|
9e995a |
1.9.3
|
|
|
9e995a |
|