Vendor deps

Olivier Tremblay 2 years ago
parent
commit
6d83cd1f4e
58 changed files with 10383 additions and 3 deletions
  1. 4 0
      lib/dbcodegenerator.go
  2. 33 3
      lib/libautoapi.go
  3. 1 0
      lib/tableinfo.go
  4. 27 0
      vendor/github.com/gorilla/context/LICENSE
  5. 7 0
      vendor/github.com/gorilla/context/README.md
  6. 143 0
      vendor/github.com/gorilla/context/context.go
  7. 82 0
      vendor/github.com/gorilla/context/doc.go
  8. 27 0
      vendor/github.com/gorilla/mux/LICENSE
  9. 7 0
      vendor/github.com/gorilla/mux/README.md
  10. 199 0
      vendor/github.com/gorilla/mux/doc.go
  11. 353 0
      vendor/github.com/gorilla/mux/mux.go
  12. 276 0
      vendor/github.com/gorilla/mux/regexp.go
  13. 524 0
      vendor/github.com/gorilla/mux/route.go
  14. 13 0
      vendor/github.com/howeyc/gopass/LICENSE.txt
  15. 21 0
      vendor/github.com/howeyc/gopass/README.md
  16. 29 0
      vendor/github.com/howeyc/gopass/bsd.go
  17. 23 0
      vendor/github.com/howeyc/gopass/nix.go
  18. 44 0
      vendor/github.com/howeyc/gopass/pass.go
  19. 42 0
      vendor/github.com/howeyc/gopass/win.go
  20. 780 0
      vendor/github.com/stretchr/testify/assert/assertions.go
  21. 150 0
      vendor/github.com/stretchr/testify/assert/doc.go
  22. 10 0
      vendor/github.com/stretchr/testify/assert/errors.go
  23. 252 0
      vendor/github.com/stretchr/testify/assert/forward_assertions.go
  24. 157 0
      vendor/github.com/stretchr/testify/assert/http_assertions.go
  25. 24 0
      vendor/github.com/ziutek/mymysql/LICENSE
  26. 16 0
      vendor/github.com/ziutek/mymysql/godrv/appengine.go
  27. 420 0
      vendor/github.com/ziutek/mymysql/godrv/driver.go
  28. 533 0
      vendor/github.com/ziutek/mymysql/mysql/errors.go
  29. 15 0
      vendor/github.com/ziutek/mymysql/mysql/field.go
  30. 105 0
      vendor/github.com/ziutek/mymysql/mysql/interface.go
  31. 475 0
      vendor/github.com/ziutek/mymysql/mysql/row.go
  32. 225 0
      vendor/github.com/ziutek/mymysql/mysql/types.go
  33. 245 0
      vendor/github.com/ziutek/mymysql/mysql/utils.go
  34. 24 0
      vendor/github.com/ziutek/mymysql/native/LICENSE
  35. 17 0
      vendor/github.com/ziutek/mymysql/native/addons.go
  36. 150 0
      vendor/github.com/ziutek/mymysql/native/binding.go
  37. 507 0
      vendor/github.com/ziutek/mymysql/native/codecs.go
  38. 149 0
      vendor/github.com/ziutek/mymysql/native/command.go
  39. 25 0
      vendor/github.com/ziutek/mymysql/native/common.go
  40. 192 0
      vendor/github.com/ziutek/mymysql/native/consts.go
  41. 84 0
      vendor/github.com/ziutek/mymysql/native/init.go
  42. 833 0
      vendor/github.com/ziutek/mymysql/native/mysql.go
  43. 250 0
      vendor/github.com/ziutek/mymysql/native/packet.go
  44. 161 0
      vendor/github.com/ziutek/mymysql/native/paramvalue.go
  45. 108 0
      vendor/github.com/ziutek/mymysql/native/passwd.go
  46. 160 0
      vendor/github.com/ziutek/mymysql/native/prepared.go
  47. 406 0
      vendor/github.com/ziutek/mymysql/native/result.go
  48. 116 0
      vendor/github.com/ziutek/mymysql/native/unsafe.go-disabled
  49. 27 0
      vendor/golang.org/x/crypto/LICENSE
  50. 22 0
      vendor/golang.org/x/crypto/PATENTS
  51. 892 0
      vendor/golang.org/x/crypto/ssh/terminal/terminal.go
  52. 128 0
      vendor/golang.org/x/crypto/ssh/terminal/util.go
  53. 12 0
      vendor/golang.org/x/crypto/ssh/terminal/util_bsd.go
  54. 11 0
      vendor/golang.org/x/crypto/ssh/terminal/util_linux.go
  55. 174 0
      vendor/golang.org/x/crypto/ssh/terminal/util_windows.go
  56. 27 0
      vendor/golang.org/x/tools/LICENSE
  57. 22 0
      vendor/golang.org/x/tools/PATENTS
  58. 624 0
      vendor/golang.org/x/tools/go/ast/astutil/enclosing.go

+ 4 - 0
lib/dbcodegenerator.go

@@ -127,6 +127,10 @@ func Save(row *dbi.{{.Table.NormalizedTableName}}) error {
127 127
         {{end}}
128 128
     return nil
129 129
 }
130
+
131
+{{range .Table.ForeignKeys}}
132
+//{{.ForeignTable}}, {{.ForeignField}}
133
+{{end}}
130 134
 `))
131 135
 	path, err := GetRootPath()
132 136
 	if err != nil {

+ 33 - 3
lib/libautoapi.go

@@ -5,6 +5,7 @@ import (
5 5
 	"database/sql"
6 6
 	"errors"
7 7
 	"fmt"
8
+	"log"
8 9
 	"os"
9 10
 	"sort"
10 11
 	"strings"
@@ -26,7 +27,7 @@ func Error(msg string) error {
26 27
 
27 28
 func getTableInfo(db *sql.DB, dbName string) (map[string]tableInfo, error) {
28 29
 
29
-	moreRows, err := db.Query("select table_name, column_name, data_type, column_key, is_nullable, extra, column_type from information_schema.columns where table_schema = ?", dbName)
30
+	moreRows, err := db.Query("select table_name, column_name, data_type, column_key, is_nullable, extra, column_type, column_default from information_schema.columns where table_schema = ?", dbName)
30 31
 
31 32
 	if err != nil {
32 33
 		return nil, err
@@ -34,7 +35,8 @@ func getTableInfo(db *sql.DB, dbName string) (map[string]tableInfo, error) {
34 35
 	tables := map[string]tableInfo{}
35 36
 	for moreRows.Next() {
36 37
 		var tn, cn, ct, ck, nullable, extra, cdt string
37
-		err := moreRows.Scan(&tn, &cn, &ct, &ck, &nullable, &extra, &cdt)
38
+		var cd sql.NullString
39
+		err := moreRows.Scan(&tn, &cn, &ct, &ck, &nullable, &extra, &cdt, &cd)
38 40
 		if err != nil {
39 41
 			return nil, err
40 42
 		}
@@ -46,6 +48,7 @@ func getTableInfo(db *sql.DB, dbName string) (map[string]tableInfo, error) {
46 48
 				TableColumns: map[string]tableColumn{},
47 49
 				ColOrder:     []tableColumn{},
48 50
 				Constraints:  []string{},
51
+				ForeignKeys:  []fk{},
49 52
 			}
50 53
 		}
51 54
 
@@ -55,16 +58,43 @@ func getTableInfo(db *sql.DB, dbName string) (map[string]tableInfo, error) {
55 58
 		col := tableColumn{ColumnName: cn, ColumnType: ct}
56 59
 
57 60
 		col.Primary = ck == "PRI"
58
-		if nullable == "NO" && extra != "auto_increment" && ct != "bit" {
61
+		if nullable == "NO" && extra != "auto_increment" && ct != "bit" && cd.Valid {
59 62
 			table.Constraints = append(table.Constraints, fmt.Sprintf(`if %s {return lib.Error("Preconditions failed, %s must be set.")}`, col.NullCheck(fmt.Sprintf("row.%s", col.CapitalizedColumnName())), col.CapitalizedColumnName()))
60 63
 		}
61 64
 		table.TableColumns[cn] = col
62 65
 		table.ColOrder = append(table.ColOrder, col)
63 66
 		tables[tn] = table
64 67
 	}
68
+
69
+	foreign_keys, err := db.Query("select k.table_name, k.column_name, k.referenced_table_name, k.referenced_column_name from information_schema.key_column_usage k inner join information_schema.table_constraints using(constraint_name) where k.table_schema = ? and constraint_type = 'FOREIGN KEY';", dbName)
70
+	if err == nil {
71
+		for foreign_keys.Next() {
72
+			var tn, cn, ftn, fcn string
73
+			err = foreign_keys.Scan(&tn, &cn, &ftn, &fcn)
74
+			if err != nil {
75
+				log.Println(err)
76
+				continue
77
+			}
78
+			if table, ok := tables[tn]; ok {
79
+				table.ForeignKeys = append(table.ForeignKeys, fk{TableName: tn, FieldName: cn, ForeignTable: ftn, ForeignField: fcn})
80
+				tables[tn] = table
81
+			} else {
82
+				log.Println("Foreign keys: Table not found")
83
+			}
84
+		}
85
+	} else {
86
+		log.Println(err)
87
+	}
65 88
 	return tables, nil
66 89
 }
67 90
 
91
+type fk struct {
92
+	TableName    string
93
+	FieldName    string
94
+	ForeignTable string
95
+	ForeignField string
96
+}
97
+
68 98
 //Generate grabs a sql connection, a database name, and generate all the required code to talk to the db.
69 99
 func Generate(db *sql.DB, dbName string) error {
70 100
 	tables, err := getTableInfo(db, dbName)

+ 1 - 0
lib/tableinfo.go

@@ -10,6 +10,7 @@ type tableInfo struct {
10 10
 	TableColumns map[string]tableColumn
11 11
 	ColOrder     []tableColumn
12 12
 	Constraints  []string
13
+	ForeignKeys  []fk
13 14
 }
14 15
 
15 16
 func (t tableInfo) QueryFieldNames() string {

+ 27 - 0
vendor/github.com/gorilla/context/LICENSE

@@ -0,0 +1,27 @@
1
+Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
2
+
3
+Redistribution and use in source and binary forms, with or without
4
+modification, are permitted provided that the following conditions are
5
+met:
6
+
7
+	 * Redistributions of source code must retain the above copyright
8
+notice, this list of conditions and the following disclaimer.
9
+	 * Redistributions in binary form must reproduce the above
10
+copyright notice, this list of conditions and the following disclaimer
11
+in the documentation and/or other materials provided with the
12
+distribution.
13
+	 * Neither the name of Google Inc. nor the names of its
14
+contributors may be used to endorse or promote products derived from
15
+this software without specific prior written permission.
16
+
17
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 7 - 0
vendor/github.com/gorilla/context/README.md

@@ -0,0 +1,7 @@
1
+context
2
+=======
3
+[![Build Status](https://travis-ci.org/gorilla/context.png?branch=master)](https://travis-ci.org/gorilla/context)
4
+
5
+gorilla/context is a general purpose registry for global request variables.
6
+
7
+Read the full documentation here: http://www.gorillatoolkit.org/pkg/context

+ 143 - 0
vendor/github.com/gorilla/context/context.go

@@ -0,0 +1,143 @@
1
+// Copyright 2012 The Gorilla Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package context
6
+
7
+import (
8
+	"net/http"
9
+	"sync"
10
+	"time"
11
+)
12
+
13
+var (
14
+	mutex sync.RWMutex
15
+	data  = make(map[*http.Request]map[interface{}]interface{})
16
+	datat = make(map[*http.Request]int64)
17
+)
18
+
19
+// Set stores a value for a given key in a given request.
20
+func Set(r *http.Request, key, val interface{}) {
21
+	mutex.Lock()
22
+	if data[r] == nil {
23
+		data[r] = make(map[interface{}]interface{})
24
+		datat[r] = time.Now().Unix()
25
+	}
26
+	data[r][key] = val
27
+	mutex.Unlock()
28
+}
29
+
30
+// Get returns a value stored for a given key in a given request.
31
+func Get(r *http.Request, key interface{}) interface{} {
32
+	mutex.RLock()
33
+	if ctx := data[r]; ctx != nil {
34
+		value := ctx[key]
35
+		mutex.RUnlock()
36
+		return value
37
+	}
38
+	mutex.RUnlock()
39
+	return nil
40
+}
41
+
42
+// GetOk returns stored value and presence state like multi-value return of map access.
43
+func GetOk(r *http.Request, key interface{}) (interface{}, bool) {
44
+	mutex.RLock()
45
+	if _, ok := data[r]; ok {
46
+		value, ok := data[r][key]
47
+		mutex.RUnlock()
48
+		return value, ok
49
+	}
50
+	mutex.RUnlock()
51
+	return nil, false
52
+}
53
+
54
+// GetAll returns all stored values for the request as a map. Nil is returned for invalid requests.
55
+func GetAll(r *http.Request) map[interface{}]interface{} {
56
+	mutex.RLock()
57
+	if context, ok := data[r]; ok {
58
+		result := make(map[interface{}]interface{}, len(context))
59
+		for k, v := range context {
60
+			result[k] = v
61
+		}
62
+		mutex.RUnlock()
63
+		return result
64
+	}
65
+	mutex.RUnlock()
66
+	return nil
67
+}
68
+
69
+// GetAllOk returns all stored values for the request as a map and a boolean value that indicates if
70
+// the request was registered.
71
+func GetAllOk(r *http.Request) (map[interface{}]interface{}, bool) {
72
+	mutex.RLock()
73
+	context, ok := data[r]
74
+	result := make(map[interface{}]interface{}, len(context))
75
+	for k, v := range context {
76
+		result[k] = v
77
+	}
78
+	mutex.RUnlock()
79
+	return result, ok
80
+}
81
+
82
+// Delete removes a value stored for a given key in a given request.
83
+func Delete(r *http.Request, key interface{}) {
84
+	mutex.Lock()
85
+	if data[r] != nil {
86
+		delete(data[r], key)
87
+	}
88
+	mutex.Unlock()
89
+}
90
+
91
+// Clear removes all values stored for a given request.
92
+//
93
+// This is usually called by a handler wrapper to clean up request
94
+// variables at the end of a request lifetime. See ClearHandler().
95
+func Clear(r *http.Request) {
96
+	mutex.Lock()
97
+	clear(r)
98
+	mutex.Unlock()
99
+}
100
+
101
+// clear is Clear without the lock.
102
+func clear(r *http.Request) {
103
+	delete(data, r)
104
+	delete(datat, r)
105
+}
106
+
107
+// Purge removes request data stored for longer than maxAge, in seconds.
108
+// It returns the amount of requests removed.
109
+//
110
+// If maxAge <= 0, all request data is removed.
111
+//
112
+// This is only used for sanity check: in case context cleaning was not
113
+// properly set some request data can be kept forever, consuming an increasing
114
+// amount of memory. In case this is detected, Purge() must be called
115
+// periodically until the problem is fixed.
116
+func Purge(maxAge int) int {
117
+	mutex.Lock()
118
+	count := 0
119
+	if maxAge <= 0 {
120
+		count = len(data)
121
+		data = make(map[*http.Request]map[interface{}]interface{})
122
+		datat = make(map[*http.Request]int64)
123
+	} else {
124
+		min := time.Now().Unix() - int64(maxAge)
125
+		for r := range data {
126
+			if datat[r] < min {
127
+				clear(r)
128
+				count++
129
+			}
130
+		}
131
+	}
132
+	mutex.Unlock()
133
+	return count
134
+}
135
+
136
+// ClearHandler wraps an http.Handler and clears request values at the end
137
+// of a request lifetime.
138
+func ClearHandler(h http.Handler) http.Handler {
139
+	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
140
+		defer Clear(r)
141
+		h.ServeHTTP(w, r)
142
+	})
143
+}

+ 82 - 0
vendor/github.com/gorilla/context/doc.go

@@ -0,0 +1,82 @@
1
+// Copyright 2012 The Gorilla Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+/*
6
+Package context stores values shared during a request lifetime.
7
+
8
+For example, a router can set variables extracted from the URL and later
9
+application handlers can access those values, or it can be used to store
10
+sessions values to be saved at the end of a request. There are several
11
+others common uses.
12
+
13
+The idea was posted by Brad Fitzpatrick to the go-nuts mailing list:
14
+
15
+	http://groups.google.com/group/golang-nuts/msg/e2d679d303aa5d53
16
+
17
+Here's the basic usage: first define the keys that you will need. The key
18
+type is interface{} so a key can be of any type that supports equality.
19
+Here we define a key using a custom int type to avoid name collisions:
20
+
21
+	package foo
22
+
23
+	import (
24
+		"github.com/gorilla/context"
25
+	)
26
+
27
+	type key int
28
+
29
+	const MyKey key = 0
30
+
31
+Then set a variable. Variables are bound to an http.Request object, so you
32
+need a request instance to set a value:
33
+
34
+	context.Set(r, MyKey, "bar")
35
+
36
+The application can later access the variable using the same key you provided:
37
+
38
+	func MyHandler(w http.ResponseWriter, r *http.Request) {
39
+		// val is "bar".
40
+		val := context.Get(r, foo.MyKey)
41
+
42
+		// returns ("bar", true)
43
+		val, ok := context.GetOk(r, foo.MyKey)
44
+		// ...
45
+	}
46
+
47
+And that's all about the basic usage. We discuss some other ideas below.
48
+
49
+Any type can be stored in the context. To enforce a given type, make the key
50
+private and wrap Get() and Set() to accept and return values of a specific
51
+type:
52
+
53
+	type key int
54
+
55
+	const mykey key = 0
56
+
57
+	// GetMyKey returns a value for this package from the request values.
58
+	func GetMyKey(r *http.Request) SomeType {
59
+		if rv := context.Get(r, mykey); rv != nil {
60
+			return rv.(SomeType)
61
+		}
62
+		return nil
63
+	}
64
+
65
+	// SetMyKey sets a value for this package in the request values.
66
+	func SetMyKey(r *http.Request, val SomeType) {
67
+		context.Set(r, mykey, val)
68
+	}
69
+
70
+Variables must be cleared at the end of a request, to remove all values
71
+that were stored. This can be done in an http.Handler, after a request was
72
+served. Just call Clear() passing the request:
73
+
74
+	context.Clear(r)
75
+
76
+...or use ClearHandler(), which conveniently wraps an http.Handler to clear
77
+variables at the end of a request lifetime.
78
+
79
+The Routers from the packages gorilla/mux and gorilla/pat call Clear()
80
+so if you are using either of them you don't need to clear the context manually.
81
+*/
82
+package context

+ 27 - 0
vendor/github.com/gorilla/mux/LICENSE

@@ -0,0 +1,27 @@
1
+Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
2
+
3
+Redistribution and use in source and binary forms, with or without
4
+modification, are permitted provided that the following conditions are
5
+met:
6
+
7
+	 * Redistributions of source code must retain the above copyright
8
+notice, this list of conditions and the following disclaimer.
9
+	 * Redistributions in binary form must reproduce the above
10
+copyright notice, this list of conditions and the following disclaimer
11
+in the documentation and/or other materials provided with the
12
+distribution.
13
+	 * Neither the name of Google Inc. nor the names of its
14
+contributors may be used to endorse or promote products derived from
15
+this software without specific prior written permission.
16
+
17
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 7 - 0
vendor/github.com/gorilla/mux/README.md

@@ -0,0 +1,7 @@
1
+mux
2
+===
3
+[![Build Status](https://travis-ci.org/gorilla/mux.png?branch=master)](https://travis-ci.org/gorilla/mux)
4
+
5
+gorilla/mux is a powerful URL router and dispatcher.
6
+
7
+Read the full documentation here: http://www.gorillatoolkit.org/pkg/mux

+ 199 - 0
vendor/github.com/gorilla/mux/doc.go

@@ -0,0 +1,199 @@
1
+// Copyright 2012 The Gorilla Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+/*
6
+Package gorilla/mux implements a request router and dispatcher.
7
+
8
+The name mux stands for "HTTP request multiplexer". Like the standard
9
+http.ServeMux, mux.Router matches incoming requests against a list of
10
+registered routes and calls a handler for the route that matches the URL
11
+or other conditions. The main features are:
12
+
13
+	* Requests can be matched based on URL host, path, path prefix, schemes,
14
+	  header and query values, HTTP methods or using custom matchers.
15
+	* URL hosts and paths can have variables with an optional regular
16
+	  expression.
17
+	* Registered URLs can be built, or "reversed", which helps maintaining
18
+	  references to resources.
19
+	* Routes can be used as subrouters: nested routes are only tested if the
20
+	  parent route matches. This is useful to define groups of routes that
21
+	  share common conditions like a host, a path prefix or other repeated
22
+	  attributes. As a bonus, this optimizes request matching.
23
+	* It implements the http.Handler interface so it is compatible with the
24
+	  standard http.ServeMux.
25
+
26
+Let's start registering a couple of URL paths and handlers:
27
+
28
+	func main() {
29
+		r := mux.NewRouter()
30
+		r.HandleFunc("/", HomeHandler)
31
+		r.HandleFunc("/products", ProductsHandler)
32
+		r.HandleFunc("/articles", ArticlesHandler)
33
+		http.Handle("/", r)
34
+	}
35
+
36
+Here we register three routes mapping URL paths to handlers. This is
37
+equivalent to how http.HandleFunc() works: if an incoming request URL matches
38
+one of the paths, the corresponding handler is called passing
39
+(http.ResponseWriter, *http.Request) as parameters.
40
+
41
+Paths can have variables. They are defined using the format {name} or
42
+{name:pattern}. If a regular expression pattern is not defined, the matched
43
+variable will be anything until the next slash. For example:
44
+
45
+	r := mux.NewRouter()
46
+	r.HandleFunc("/products/{key}", ProductHandler)
47
+	r.HandleFunc("/articles/{category}/", ArticlesCategoryHandler)
48
+	r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler)
49
+
50
+The names are used to create a map of route variables which can be retrieved
51
+calling mux.Vars():
52
+
53
+	vars := mux.Vars(request)
54
+	category := vars["category"]
55
+
56
+And this is all you need to know about the basic usage. More advanced options
57
+are explained below.
58
+
59
+Routes can also be restricted to a domain or subdomain. Just define a host
60
+pattern to be matched. They can also have variables:
61
+
62
+	r := mux.NewRouter()
63
+	// Only matches if domain is "www.domain.com".
64
+	r.Host("www.domain.com")
65
+	// Matches a dynamic subdomain.
66
+	r.Host("{subdomain:[a-z]+}.domain.com")
67
+
68
+There are several other matchers that can be added. To match path prefixes:
69
+
70
+	r.PathPrefix("/products/")
71
+
72
+...or HTTP methods:
73
+
74
+	r.Methods("GET", "POST")
75
+
76
+...or URL schemes:
77
+
78
+	r.Schemes("https")
79
+
80
+...or header values:
81
+
82
+	r.Headers("X-Requested-With", "XMLHttpRequest")
83
+
84
+...or query values:
85
+
86
+	r.Queries("key", "value")
87
+
88
+...or to use a custom matcher function:
89
+
90
+	r.MatcherFunc(func(r *http.Request, rm *RouteMatch) bool {
91
+		return r.ProtoMajor == 0
92
+    })
93
+
94
+...and finally, it is possible to combine several matchers in a single route:
95
+
96
+	r.HandleFunc("/products", ProductsHandler).
97
+	  Host("www.domain.com").
98
+	  Methods("GET").
99
+	  Schemes("http")
100
+
101
+Setting the same matching conditions again and again can be boring, so we have
102
+a way to group several routes that share the same requirements.
103
+We call it "subrouting".
104
+
105
+For example, let's say we have several URLs that should only match when the
106
+host is "www.domain.com". Create a route for that host and get a "subrouter"
107
+from it:
108
+
109
+	r := mux.NewRouter()
110
+	s := r.Host("www.domain.com").Subrouter()
111
+
112
+Then register routes in the subrouter:
113
+
114
+	s.HandleFunc("/products/", ProductsHandler)
115
+	s.HandleFunc("/products/{key}", ProductHandler)
116
+	s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
117
+
118
+The three URL paths we registered above will only be tested if the domain is
119
+"www.domain.com", because the subrouter is tested first. This is not
120
+only convenient, but also optimizes request matching. You can create
121
+subrouters combining any attribute matchers accepted by a route.
122
+
123
+Subrouters can be used to create domain or path "namespaces": you define
124
+subrouters in a central place and then parts of the app can register its
125
+paths relatively to a given subrouter.
126
+
127
+There's one more thing about subroutes. When a subrouter has a path prefix,
128
+the inner routes use it as base for their paths:
129
+
130
+	r := mux.NewRouter()
131
+	s := r.PathPrefix("/products").Subrouter()
132
+	// "/products/"
133
+	s.HandleFunc("/", ProductsHandler)
134
+	// "/products/{key}/"
135
+	s.HandleFunc("/{key}/", ProductHandler)
136
+	// "/products/{key}/details"
137
+	s.HandleFunc("/{key}/details", ProductDetailsHandler)
138
+
139
+Now let's see how to build registered URLs.
140
+
141
+Routes can be named. All routes that define a name can have their URLs built,
142
+or "reversed". We define a name calling Name() on a route. For example:
143
+
144
+	r := mux.NewRouter()
145
+	r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
146
+	  Name("article")
147
+
148
+To build a URL, get the route and call the URL() method, passing a sequence of
149
+key/value pairs for the route variables. For the previous route, we would do:
150
+
151
+	url, err := r.Get("article").URL("category", "technology", "id", "42")
152
+
153
+...and the result will be a url.URL with the following path:
154
+
155
+	"/articles/technology/42"
156
+
157
+This also works for host variables:
158
+
159
+	r := mux.NewRouter()
160
+	r.Host("{subdomain}.domain.com").
161
+	  Path("/articles/{category}/{id:[0-9]+}").
162
+	  HandlerFunc(ArticleHandler).
163
+	  Name("article")
164
+
165
+	// url.String() will be "http://news.domain.com/articles/technology/42"
166
+	url, err := r.Get("article").URL("subdomain", "news",
167
+									 "category", "technology",
168
+									 "id", "42")
169
+
170
+All variables defined in the route are required, and their values must
171
+conform to the corresponding patterns. These requirements guarantee that a
172
+generated URL will always match a registered route -- the only exception is
173
+for explicitly defined "build-only" routes which never match.
174
+
175
+There's also a way to build only the URL host or path for a route:
176
+use the methods URLHost() or URLPath() instead. For the previous route,
177
+we would do:
178
+
179
+	// "http://news.domain.com/"
180
+	host, err := r.Get("article").URLHost("subdomain", "news")
181
+
182
+	// "/articles/technology/42"
183
+	path, err := r.Get("article").URLPath("category", "technology", "id", "42")
184
+
185
+And if you use subrouters, host and path defined separately can be built
186
+as well:
187
+
188
+	r := mux.NewRouter()
189
+	s := r.Host("{subdomain}.domain.com").Subrouter()
190
+	s.Path("/articles/{category}/{id:[0-9]+}").
191
+	  HandlerFunc(ArticleHandler).
192
+	  Name("article")
193
+
194
+	// "http://news.domain.com/articles/technology/42"
195
+	url, err := r.Get("article").URL("subdomain", "news",
196
+									 "category", "technology",
197
+									 "id", "42")
198
+*/
199
+package mux

+ 353 - 0
vendor/github.com/gorilla/mux/mux.go

@@ -0,0 +1,353 @@
1
+// Copyright 2012 The Gorilla Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package mux
6
+
7
+import (
8
+	"fmt"
9
+	"net/http"
10
+	"path"
11
+
12
+	"github.com/gorilla/context"
13
+)
14
+
15
+// NewRouter returns a new router instance.
16
+func NewRouter() *Router {
17
+	return &Router{namedRoutes: make(map[string]*Route), KeepContext: false}
18
+}
19
+
20
+// Router registers routes to be matched and dispatches a handler.
21
+//
22
+// It implements the http.Handler interface, so it can be registered to serve
23
+// requests:
24
+//
25
+//     var router = mux.NewRouter()
26
+//
27
+//     func main() {
28
+//         http.Handle("/", router)
29
+//     }
30
+//
31
+// Or, for Google App Engine, register it in a init() function:
32
+//
33
+//     func init() {
34
+//         http.Handle("/", router)
35
+//     }
36
+//
37
+// This will send all incoming requests to the router.
38
+type Router struct {
39
+	// Configurable Handler to be used when no route matches.
40
+	NotFoundHandler http.Handler
41
+	// Parent route, if this is a subrouter.
42
+	parent parentRoute
43
+	// Routes to be matched, in order.
44
+	routes []*Route
45
+	// Routes by name for URL building.
46
+	namedRoutes map[string]*Route
47
+	// See Router.StrictSlash(). This defines the flag for new routes.
48
+	strictSlash bool
49
+	// If true, do not clear the request context after handling the request
50
+	KeepContext bool
51
+}
52
+
53
+// Match matches registered routes against the request.
54
+func (r *Router) Match(req *http.Request, match *RouteMatch) bool {
55
+	for _, route := range r.routes {
56
+		if route.Match(req, match) {
57
+			return true
58
+		}
59
+	}
60
+	return false
61
+}
62
+
63
+// ServeHTTP dispatches the handler registered in the matched route.
64
+//
65
+// When there is a match, the route variables can be retrieved calling
66
+// mux.Vars(request).
67
+func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
68
+	// Clean path to canonical form and redirect.
69
+	if p := cleanPath(req.URL.Path); p != req.URL.Path {
70
+
71
+		// Added 3 lines (Philip Schlump) - It was droping the query string and #whatever from query.
72
+		// This matches with fix in go 1.2 r.c. 4 for same problem.  Go Issue:
73
+		// http://code.google.com/p/go/issues/detail?id=5252
74
+		url := *req.URL
75
+		url.Path = p
76
+		p = url.String()
77
+
78
+		w.Header().Set("Location", p)
79
+		w.WriteHeader(http.StatusMovedPermanently)
80
+		return
81
+	}
82
+	var match RouteMatch
83
+	var handler http.Handler
84
+	if r.Match(req, &match) {
85
+		handler = match.Handler
86
+		setVars(req, match.Vars)
87
+		setCurrentRoute(req, match.Route)
88
+	}
89
+	if handler == nil {
90
+		handler = r.NotFoundHandler
91
+		if handler == nil {
92
+			handler = http.NotFoundHandler()
93
+		}
94
+	}
95
+	if !r.KeepContext {
96
+		defer context.Clear(req)
97
+	}
98
+	handler.ServeHTTP(w, req)
99
+}
100
+
101
+// Get returns a route registered with the given name.
102
+func (r *Router) Get(name string) *Route {
103
+	return r.getNamedRoutes()[name]
104
+}
105
+
106
+// GetRoute returns a route registered with the given name. This method
107
+// was renamed to Get() and remains here for backwards compatibility.
108
+func (r *Router) GetRoute(name string) *Route {
109
+	return r.getNamedRoutes()[name]
110
+}
111
+
112
+// StrictSlash defines the trailing slash behavior for new routes. The initial
113
+// value is false.
114
+//
115
+// When true, if the route path is "/path/", accessing "/path" will redirect
116
+// to the former and vice versa. In other words, your application will always
117
+// see the path as specified in the route.
118
+//
119
+// When false, if the route path is "/path", accessing "/path/" will not match
120
+// this route and vice versa.
121
+//
122
+// Special case: when a route sets a path prefix using the PathPrefix() method,
123
+// strict slash is ignored for that route because the redirect behavior can't
124
+// be determined from a prefix alone. However, any subrouters created from that
125
+// route inherit the original StrictSlash setting.
126
+func (r *Router) StrictSlash(value bool) *Router {
127
+	r.strictSlash = value
128
+	return r
129
+}
130
+
131
+// ----------------------------------------------------------------------------
132
+// parentRoute
133
+// ----------------------------------------------------------------------------
134
+
135
+// getNamedRoutes returns the map where named routes are registered.
136
+func (r *Router) getNamedRoutes() map[string]*Route {
137
+	if r.namedRoutes == nil {
138
+		if r.parent != nil {
139
+			r.namedRoutes = r.parent.getNamedRoutes()
140
+		} else {
141
+			r.namedRoutes = make(map[string]*Route)
142
+		}
143
+	}
144
+	return r.namedRoutes
145
+}
146
+
147
+// getRegexpGroup returns regexp definitions from the parent route, if any.
148
+func (r *Router) getRegexpGroup() *routeRegexpGroup {
149
+	if r.parent != nil {
150
+		return r.parent.getRegexpGroup()
151
+	}
152
+	return nil
153
+}
154
+
155
+// ----------------------------------------------------------------------------
156
+// Route factories
157
+// ----------------------------------------------------------------------------
158
+
159
+// NewRoute registers an empty route.
160
+func (r *Router) NewRoute() *Route {
161
+	route := &Route{parent: r, strictSlash: r.strictSlash}
162
+	r.routes = append(r.routes, route)
163
+	return route
164
+}
165
+
166
+// Handle registers a new route with a matcher for the URL path.
167
+// See Route.Path() and Route.Handler().
168
+func (r *Router) Handle(path string, handler http.Handler) *Route {
169
+	return r.NewRoute().Path(path).Handler(handler)
170
+}
171
+
172
+// HandleFunc registers a new route with a matcher for the URL path.
173
+// See Route.Path() and Route.HandlerFunc().
174
+func (r *Router) HandleFunc(path string, f func(http.ResponseWriter,
175
+	*http.Request)) *Route {
176
+	return r.NewRoute().Path(path).HandlerFunc(f)
177
+}
178
+
179
+// Headers registers a new route with a matcher for request header values.
180
+// See Route.Headers().
181
+func (r *Router) Headers(pairs ...string) *Route {
182
+	return r.NewRoute().Headers(pairs...)
183
+}
184
+
185
+// Host registers a new route with a matcher for the URL host.
186
+// See Route.Host().
187
+func (r *Router) Host(tpl string) *Route {
188
+	return r.NewRoute().Host(tpl)
189
+}
190
+
191
+// MatcherFunc registers a new route with a custom matcher function.
192
+// See Route.MatcherFunc().
193
+func (r *Router) MatcherFunc(f MatcherFunc) *Route {
194
+	return r.NewRoute().MatcherFunc(f)
195
+}
196
+
197
+// Methods registers a new route with a matcher for HTTP methods.
198
+// See Route.Methods().
199
+func (r *Router) Methods(methods ...string) *Route {
200
+	return r.NewRoute().Methods(methods...)
201
+}
202
+
203
+// Path registers a new route with a matcher for the URL path.
204
+// See Route.Path().
205
+func (r *Router) Path(tpl string) *Route {
206
+	return r.NewRoute().Path(tpl)
207
+}
208
+
209
+// PathPrefix registers a new route with a matcher for the URL path prefix.
210
+// See Route.PathPrefix().
211
+func (r *Router) PathPrefix(tpl string) *Route {
212
+	return r.NewRoute().PathPrefix(tpl)
213
+}
214
+
215
+// Queries registers a new route with a matcher for URL query values.
216
+// See Route.Queries().
217
+func (r *Router) Queries(pairs ...string) *Route {
218
+	return r.NewRoute().Queries(pairs...)
219
+}
220
+
221
+// Schemes registers a new route with a matcher for URL schemes.
222
+// See Route.Schemes().
223
+func (r *Router) Schemes(schemes ...string) *Route {
224
+	return r.NewRoute().Schemes(schemes...)
225
+}
226
+
227
+// ----------------------------------------------------------------------------
228
+// Context
229
+// ----------------------------------------------------------------------------
230
+
231
+// RouteMatch stores information about a matched route.
232
+type RouteMatch struct {
233
+	Route   *Route
234
+	Handler http.Handler
235
+	Vars    map[string]string
236
+}
237
+
238
+type contextKey int
239
+
240
+const (
241
+	varsKey contextKey = iota
242
+	routeKey
243
+)
244
+
245
+// Vars returns the route variables for the current request, if any.
246
+func Vars(r *http.Request) map[string]string {
247
+	if rv := context.Get(r, varsKey); rv != nil {
248
+		return rv.(map[string]string)
249
+	}
250
+	return nil
251
+}
252
+
253
+// CurrentRoute returns the matched route for the current request, if any.
254
+func CurrentRoute(r *http.Request) *Route {
255
+	if rv := context.Get(r, routeKey); rv != nil {
256
+		return rv.(*Route)
257
+	}
258
+	return nil
259
+}
260
+
261
+func setVars(r *http.Request, val interface{}) {
262
+	context.Set(r, varsKey, val)
263
+}
264
+
265
+func setCurrentRoute(r *http.Request, val interface{}) {
266
+	context.Set(r, routeKey, val)
267
+}
268
+
269
+// ----------------------------------------------------------------------------
270
+// Helpers
271
+// ----------------------------------------------------------------------------
272
+
273
+// cleanPath returns the canonical path for p, eliminating . and .. elements.
274
+// Borrowed from the net/http package.
275
+func cleanPath(p string) string {
276
+	if p == "" {
277
+		return "/"
278
+	}
279
+	if p[0] != '/' {
280
+		p = "/" + p
281
+	}
282
+	np := path.Clean(p)
283
+	// path.Clean removes trailing slash except for root;
284
+	// put the trailing slash back if necessary.
285
+	if p[len(p)-1] == '/' && np != "/" {
286
+		np += "/"
287
+	}
288
+	return np
289
+}
290
+
291
+// uniqueVars returns an error if two slices contain duplicated strings.
292
+func uniqueVars(s1, s2 []string) error {
293
+	for _, v1 := range s1 {
294
+		for _, v2 := range s2 {
295
+			if v1 == v2 {
296
+				return fmt.Errorf("mux: duplicated route variable %q", v2)
297
+			}
298
+		}
299
+	}
300
+	return nil
301
+}
302
+
303
+// mapFromPairs converts variadic string parameters to a string map.
304
+func mapFromPairs(pairs ...string) (map[string]string, error) {
305
+	length := len(pairs)
306
+	if length%2 != 0 {
307
+		return nil, fmt.Errorf(
308
+			"mux: number of parameters must be multiple of 2, got %v", pairs)
309
+	}
310
+	m := make(map[string]string, length/2)
311
+	for i := 0; i < length; i += 2 {
312
+		m[pairs[i]] = pairs[i+1]
313
+	}
314
+	return m, nil
315
+}
316
+
317
+// matchInArray returns true if the given string value is in the array.
318
+func matchInArray(arr []string, value string) bool {
319
+	for _, v := range arr {
320
+		if v == value {
321
+			return true
322
+		}
323
+	}
324
+	return false
325
+}
326
+
327
+// matchMap returns true if the given key/value pairs exist in a given map.
328
+func matchMap(toCheck map[string]string, toMatch map[string][]string,
329
+	canonicalKey bool) bool {
330
+	for k, v := range toCheck {
331
+		// Check if key exists.
332
+		if canonicalKey {
333
+			k = http.CanonicalHeaderKey(k)
334
+		}
335
+		if values := toMatch[k]; values == nil {
336
+			return false
337
+		} else if v != "" {
338
+			// If value was defined as an empty string we only check that the
339
+			// key exists. Otherwise we also check for equality.
340
+			valueExists := false
341
+			for _, value := range values {
342
+				if v == value {
343
+					valueExists = true
344
+					break
345
+				}
346
+			}
347
+			if !valueExists {
348
+				return false
349
+			}
350
+		}
351
+	}
352
+	return true
353
+}

+ 276 - 0
vendor/github.com/gorilla/mux/regexp.go

@@ -0,0 +1,276 @@
1
+// Copyright 2012 The Gorilla Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package mux
6
+
7
+import (
8
+	"bytes"
9
+	"fmt"
10
+	"net/http"
11
+	"net/url"
12
+	"regexp"
13
+	"strings"
14
+)
15
+
16
+// newRouteRegexp parses a route template and returns a routeRegexp,
17
+// used to match a host, a path or a query string.
18
+//
19
+// It will extract named variables, assemble a regexp to be matched, create
20
+// a "reverse" template to build URLs and compile regexps to validate variable
21
+// values used in URL building.
22
+//
23
+// Previously we accepted only Python-like identifiers for variable
24
+// names ([a-zA-Z_][a-zA-Z0-9_]*), but currently the only restriction is that
25
+// name and pattern can't be empty, and names can't contain a colon.
26
+func newRouteRegexp(tpl string, matchHost, matchPrefix, matchQuery, strictSlash bool) (*routeRegexp, error) {
27
+	// Check if it is well-formed.
28
+	idxs, errBraces := braceIndices(tpl)
29
+	if errBraces != nil {
30
+		return nil, errBraces
31
+	}
32
+	// Backup the original.
33
+	template := tpl
34
+	// Now let's parse it.
35
+	defaultPattern := "[^/]+"
36
+	if matchQuery {
37
+		defaultPattern = "[^?&]+"
38
+		matchPrefix = true
39
+	} else if matchHost {
40
+		defaultPattern = "[^.]+"
41
+		matchPrefix = false
42
+	}
43
+	// Only match strict slash if not matching
44
+	if matchPrefix || matchHost || matchQuery {
45
+		strictSlash = false
46
+	}
47
+	// Set a flag for strictSlash.
48
+	endSlash := false
49
+	if strictSlash && strings.HasSuffix(tpl, "/") {
50
+		tpl = tpl[:len(tpl)-1]
51
+		endSlash = true
52
+	}
53
+	varsN := make([]string, len(idxs)/2)
54
+	varsR := make([]*regexp.Regexp, len(idxs)/2)
55
+	pattern := bytes.NewBufferString("")
56
+	if !matchQuery {
57
+		pattern.WriteByte('^')
58
+	}
59
+	reverse := bytes.NewBufferString("")
60
+	var end int
61
+	var err error
62
+	for i := 0; i < len(idxs); i += 2 {
63
+		// Set all values we are interested in.
64
+		raw := tpl[end:idxs[i]]
65
+		end = idxs[i+1]
66
+		parts := strings.SplitN(tpl[idxs[i]+1:end-1], ":", 2)
67
+		name := parts[0]
68
+		patt := defaultPattern
69
+		if len(parts) == 2 {
70
+			patt = parts[1]
71
+		}
72
+		// Name or pattern can't be empty.
73
+		if name == "" || patt == "" {
74
+			return nil, fmt.Errorf("mux: missing name or pattern in %q",
75
+				tpl[idxs[i]:end])
76
+		}
77
+		// Build the regexp pattern.
78
+		fmt.Fprintf(pattern, "%s(%s)", regexp.QuoteMeta(raw), patt)
79
+		// Build the reverse template.
80
+		fmt.Fprintf(reverse, "%s%%s", raw)
81
+		// Append variable name and compiled pattern.
82
+		varsN[i/2] = name
83
+		varsR[i/2], err = regexp.Compile(fmt.Sprintf("^%s$", patt))
84
+		if err != nil {
85
+			return nil, err
86
+		}
87
+	}
88
+	// Add the remaining.
89
+	raw := tpl[end:]
90
+	pattern.WriteString(regexp.QuoteMeta(raw))
91
+	if strictSlash {
92
+		pattern.WriteString("[/]?")
93
+	}
94
+	if !matchPrefix {
95
+		pattern.WriteByte('$')
96
+	}
97
+	reverse.WriteString(raw)
98
+	if endSlash {
99
+		reverse.WriteByte('/')
100
+	}
101
+	// Compile full regexp.
102
+	reg, errCompile := regexp.Compile(pattern.String())
103
+	if errCompile != nil {
104
+		return nil, errCompile
105
+	}
106
+	// Done!
107
+	return &routeRegexp{
108
+		template:    template,
109
+		matchHost:   matchHost,
110
+		matchQuery:  matchQuery,
111
+		strictSlash: strictSlash,
112
+		regexp:      reg,
113
+		reverse:     reverse.String(),
114
+		varsN:       varsN,
115
+		varsR:       varsR,
116
+	}, nil
117
+}
118
+
119
+// routeRegexp stores a regexp to match a host or path and information to
120
+// collect and validate route variables.
121
+type routeRegexp struct {
122
+	// The unmodified template.
123
+	template string
124
+	// True for host match, false for path or query string match.
125
+	matchHost bool
126
+	// True for query string match, false for path and host match.
127
+	matchQuery bool
128
+	// The strictSlash value defined on the route, but disabled if PathPrefix was used.
129
+	strictSlash bool
130
+	// Expanded regexp.
131
+	regexp *regexp.Regexp
132
+	// Reverse template.
133
+	reverse string
134
+	// Variable names.
135
+	varsN []string
136
+	// Variable regexps (validators).
137
+	varsR []*regexp.Regexp
138
+}
139
+
140
+// Match matches the regexp against the URL host or path.
141
+func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
142
+	if !r.matchHost {
143
+		if r.matchQuery {
144
+			return r.regexp.MatchString(req.URL.RawQuery)
145
+		} else {
146
+			return r.regexp.MatchString(req.URL.Path)
147
+		}
148
+	}
149
+	return r.regexp.MatchString(getHost(req))
150
+}
151
+
152
+// url builds a URL part using the given values.
153
+func (r *routeRegexp) url(pairs ...string) (string, error) {
154
+	values, err := mapFromPairs(pairs...)
155
+	if err != nil {
156
+		return "", err
157
+	}
158
+	urlValues := make([]interface{}, len(r.varsN))
159
+	for k, v := range r.varsN {
160
+		value, ok := values[v]
161
+		if !ok {
162
+			return "", fmt.Errorf("mux: missing route variable %q", v)
163
+		}
164
+		urlValues[k] = value
165
+	}
166
+	rv := fmt.Sprintf(r.reverse, urlValues...)
167
+	if !r.regexp.MatchString(rv) {
168
+		// The URL is checked against the full regexp, instead of checking
169
+		// individual variables. This is faster but to provide a good error
170
+		// message, we check individual regexps if the URL doesn't match.
171
+		for k, v := range r.varsN {
172
+			if !r.varsR[k].MatchString(values[v]) {
173
+				return "", fmt.Errorf(
174
+					"mux: variable %q doesn't match, expected %q", values[v],
175
+					r.varsR[k].String())
176
+			}
177
+		}
178
+	}
179
+	return rv, nil
180
+}
181
+
182
+// braceIndices returns the first level curly brace indices from a string.
183
+// It returns an error in case of unbalanced braces.
184
+func braceIndices(s string) ([]int, error) {
185
+	var level, idx int
186
+	idxs := make([]int, 0)
187
+	for i := 0; i < len(s); i++ {
188
+		switch s[i] {
189
+		case '{':
190
+			if level++; level == 1 {
191
+				idx = i
192
+			}
193
+		case '}':
194
+			if level--; level == 0 {
195
+				idxs = append(idxs, idx, i+1)
196
+			} else if level < 0 {
197
+				return nil, fmt.Errorf("mux: unbalanced braces in %q", s)
198
+			}
199
+		}
200
+	}
201
+	if level != 0 {
202
+		return nil, fmt.Errorf("mux: unbalanced braces in %q", s)
203
+	}
204
+	return idxs, nil
205
+}
206
+
207
+// ----------------------------------------------------------------------------
208
+// routeRegexpGroup
209
+// ----------------------------------------------------------------------------
210
+
211
+// routeRegexpGroup groups the route matchers that carry variables.
212
+type routeRegexpGroup struct {
213
+	host    *routeRegexp
214
+	path    *routeRegexp
215
+	queries []*routeRegexp
216
+}
217
+
218
+// setMatch extracts the variables from the URL once a route matches.
219
+func (v *routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) {
220
+	// Store host variables.
221
+	if v.host != nil {
222
+		hostVars := v.host.regexp.FindStringSubmatch(getHost(req))
223
+		if hostVars != nil {
224
+			for k, v := range v.host.varsN {
225
+				m.Vars[v] = hostVars[k+1]
226
+			}
227
+		}
228
+	}
229
+	// Store path variables.
230
+	if v.path != nil {
231
+		pathVars := v.path.regexp.FindStringSubmatch(req.URL.Path)
232
+		if pathVars != nil {
233
+			for k, v := range v.path.varsN {
234
+				m.Vars[v] = pathVars[k+1]
235
+			}
236
+			// Check if we should redirect.
237
+			if v.path.strictSlash {
238
+				p1 := strings.HasSuffix(req.URL.Path, "/")
239
+				p2 := strings.HasSuffix(v.path.template, "/")
240
+				if p1 != p2 {
241
+					u, _ := url.Parse(req.URL.String())
242
+					if p1 {
243
+						u.Path = u.Path[:len(u.Path)-1]
244
+					} else {
245
+						u.Path += "/"
246
+					}
247
+					m.Handler = http.RedirectHandler(u.String(), 301)
248
+				}
249
+			}
250
+		}
251
+	}
252
+	// Store query string variables.
253
+	rawQuery := req.URL.RawQuery
254
+	for _, q := range v.queries {
255
+		queryVars := q.regexp.FindStringSubmatch(rawQuery)
256
+		if queryVars != nil {
257
+			for k, v := range q.varsN {
258
+				m.Vars[v] = queryVars[k+1]
259
+			}
260
+		}
261
+	}
262
+}
263
+
264
+// getHost tries its best to return the request host.
265
+func getHost(r *http.Request) string {
266
+	if r.URL.IsAbs() {
267
+		return r.URL.Host
268
+	}
269
+	host := r.Host
270
+	// Slice off any port information.
271
+	if i := strings.Index(host, ":"); i != -1 {
272
+		host = host[:i]
273
+	}
274
+	return host
275
+
276
+}

+ 524 - 0
vendor/github.com/gorilla/mux/route.go

@@ -0,0 +1,524 @@
1
+// Copyright 2012 The Gorilla Authors. All rights reserved.
2
+// Use of this source code is governed by a BSD-style
3
+// license that can be found in the LICENSE file.
4
+
5
+package mux
6
+
7
+import (
8
+	"errors"
9
+	"fmt"
10
+	"net/http"
11
+	"net/url"
12
+	"strings"
13
+)
14
+
15
+// Route stores information to match a request and build URLs.
16
+type Route struct {
17
+	// Parent where the route was registered (a Router).
18
+	parent parentRoute
19
+	// Request handler for the route.
20
+	handler http.Handler
21
+	// List of matchers.
22
+	matchers []matcher
23
+	// Manager for the variables from host and path.
24
+	regexp *routeRegexpGroup
25
+	// If true, when the path pattern is "/path/", accessing "/path" will
26
+	// redirect to the former and vice versa.
27
+	strictSlash bool
28
+	// If true, this route never matches: it is only used to build URLs.
29
+	buildOnly bool
30
+	// The name used to build URLs.
31
+	name string
32
+	// Error resulted from building a route.
33
+	err error
34
+}
35
+
36
+// Match matches the route against the request.
37
+func (r *Route) Match(req *http.Request, match *RouteMatch) bool {
38
+	if r.buildOnly || r.err != nil {
39
+		return false
40
+	}
41
+	// Match everything.
42
+	for _, m := range r.matchers {
43
+		if matched := m.Match(req, match); !matched {
44
+			return false
45
+		}
46
+	}
47
+	// Yay, we have a match. Let's collect some info about it.
48
+	if match.Route == nil {
49
+		match.Route = r
50
+	}
51
+	if match.Handler == nil {
52
+		match.Handler = r.handler
53
+	}
54
+	if match.Vars == nil {
55
+		match.Vars = make(map[string]string)
56
+	}
57
+	// Set variables.
58
+	if r.regexp != nil {
59
+		r.regexp.setMatch(req, match, r)
60
+	}
61
+	return true
62
+}
63
+
64
+// ----------------------------------------------------------------------------
65
+// Route attributes
66
+// ----------------------------------------------------------------------------
67
+
68
+// GetError returns an error resulted from building the route, if any.
69
+func (r *Route) GetError() error {
70
+	return r.err
71
+}
72
+
73
+// BuildOnly sets the route to never match: it is only used to build URLs.
74
+func (r *Route) BuildOnly() *Route {
75
+	r.buildOnly = true
76
+	return r
77
+}
78
+
79
+// Handler --------------------------------------------------------------------
80
+
81
+// Handler sets a handler for the route.
82
+func (r *Route) Handler(handler http.Handler) *Route {
83
+	if r.err == nil {
84
+		r.handler = handler
85
+	}
86
+	return r
87
+}
88
+
89
+// HandlerFunc sets a handler function for the route.
90
+func (r *Route) HandlerFunc(f func(http.ResponseWriter, *http.Request)) *Route {
91
+	return r.Handler(http.HandlerFunc(f))
92
+}
93
+
94
+// GetHandler returns the handler for the route, if any.
95
+func (r *Route) GetHandler() http.Handler {
96
+	return r.handler
97
+}
98
+
99
+// Name -----------------------------------------------------------------------
100
+
101
+// Name sets the name for the route, used to build URLs.
102
+// If the name was registered already it will be overwritten.
103
+func (r *Route) Name(name string) *Route {
104
+	if r.name != "" {
105
+		r.err = fmt.Errorf("mux: route already has name %q, can't set %q",
106
+			r.name, name)
107
+	}
108
+	if r.err == nil {
109
+		r.name = name
110
+		r.getNamedRoutes()[name] = r
111
+	}
112
+	return r
113
+}
114
+
115
+// GetName returns the name for the route, if any.
116
+func (r *Route) GetName() string {
117
+	return r.name
118
+}
119
+
120
+// ----------------------------------------------------------------------------
121
+// Matchers
122
+// ----------------------------------------------------------------------------
123
+
124
+// matcher types try to match a request.
125
+type matcher interface {
126
+	Match(*http.Request, *RouteMatch) bool
127
+}
128
+
129
+// addMatcher adds a matcher to the route.
130
+func (r *Route) addMatcher(m matcher) *Route {
131
+	if r.err == nil {
132
+		r.matchers = append(r.matchers, m)
133
+	}
134
+	return r
135
+}
136
+
137
+// addRegexpMatcher adds a host or path matcher and builder to a route.
138
+func (r *Route) addRegexpMatcher(tpl string, matchHost, matchPrefix, matchQuery bool) error {
139
+	if r.err != nil {
140
+		return r.err
141
+	}
142
+	r.regexp = r.getRegexpGroup()
143
+	if !matchHost && !matchQuery {
144
+		if len(tpl) == 0 || tpl[0] != '/' {
145
+			return fmt.Errorf("mux: path must start with a slash, got %q", tpl)
146
+		}
147
+		if r.regexp.path != nil {
148
+			tpl = strings.TrimRight(r.regexp.path.template, "/") + tpl
149
+		}
150
+	}
151
+	rr, err := newRouteRegexp(tpl, matchHost, matchPrefix, matchQuery, r.strictSlash)
152
+	if err != nil {
153
+		return err
154
+	}
155
+	for _, q := range r.regexp.queries {
156
+		if err = uniqueVars(rr.varsN, q.varsN); err != nil {
157
+			return err
158
+		}
159
+	}
160
+	if matchHost {
161
+		if r.regexp.path != nil {
162
+			if err = uniqueVars(rr.varsN, r.regexp.path.varsN); err != nil {
163
+				return err
164
+			}
165
+		}
166
+		r.regexp.host = rr
167
+	} else {
168
+		if r.regexp.host != nil {
169
+			if err = uniqueVars(rr.varsN, r.regexp.host.varsN); err != nil {
170
+				return err
171
+			}
172
+		}
173
+		if matchQuery {
174
+			r.regexp.queries = append(r.regexp.queries, rr)
175
+		} else {
176
+			r.regexp.path = rr
177
+		}
178
+	}
179
+	r.addMatcher(rr)
180
+	return nil
181
+}
182
+
183
+// Headers --------------------------------------------------------------------
184
+
185
+// headerMatcher matches the request against header values.
186
+type headerMatcher map[string]string
187
+
188
+func (m headerMatcher) Match(r *http.Request, match *RouteMatch) bool {
189
+	return matchMap(m, r.Header, true)
190
+}
191
+
192
+// Headers adds a matcher for request header values.
193
+// It accepts a sequence of key/value pairs to be matched. For example:
194
+//
195
+//     r := mux.NewRouter()
196
+//     r.Headers("Content-Type", "application/json",
197
+//               "X-Requested-With", "XMLHttpRequest")
198
+//
199
+// The above route will only match if both request header values match.
200
+//
201
+// It the value is an empty string, it will match any value if the key is set.
202
+func (r *Route) Headers(pairs ...string) *Route {
203
+	if r.err == nil {
204
+		var headers map[string]string
205
+		headers, r.err = mapFromPairs(pairs...)
206
+		return r.addMatcher(headerMatcher(headers))
207
+	}
208
+	return r
209
+}
210
+
211
+// Host -----------------------------------------------------------------------
212
+
213
+// Host adds a matcher for the URL host.
214
+// It accepts a template with zero or more URL variables enclosed by {}.
215
+// Variables can define an optional regexp pattern to me matched:
216
+//
217
+// - {name} matches anything until the next dot.
218
+//
219
+// - {name:pattern} matches the given regexp pattern.
220
+//
221
+// For example:
222
+//
223
+//     r := mux.NewRouter()
224
+//     r.Host("www.domain.com")
225
+//     r.Host("{subdomain}.domain.com")
226
+//     r.Host("{subdomain:[a-z]+}.domain.com")
227
+//
228
+// Variable names must be unique in a given route. They can be retrieved
229
+// calling mux.Vars(request).
230
+func (r *Route) Host(tpl string) *Route {
231
+	r.err = r.addRegexpMatcher(tpl, true, false, false)
232
+	return r
233
+}
234
+
235
+// MatcherFunc ----------------------------------------------------------------
236
+
237
+// MatcherFunc is the function signature used by custom matchers.
238
+type MatcherFunc func(*http.Request, *RouteMatch) bool
239
+
240
+func (m MatcherFunc) Match(r *http.Request, match *RouteMatch) bool {
241
+	return m(r, match)
242
+}
243
+
244
+// MatcherFunc adds a custom function to be used as request matcher.
245
+func (r *Route) MatcherFunc(f MatcherFunc) *Route {
246
+	return r.addMatcher(f)
247
+}
248
+
249
+// Methods --------------------------------------------------------------------
250
+
251
+// methodMatcher matches the request against HTTP methods.
252
+type methodMatcher []string
253
+
254
+func (m methodMatcher) Match(r *http.Request, match *RouteMatch) bool {
255
+	return matchInArray(m, r.Method)
256
+}
257
+
258
+// Methods adds a matcher for HTTP methods.
259
+// It accepts a sequence of one or more methods to be matched, e.g.:
260
+// "GET", "POST", "PUT".
261
+func (r *Route) Methods(methods ...string) *Route {
262
+	for k, v := range methods {
263
+		methods[k] = strings.ToUpper(v)
264
+	}
265
+	return r.addMatcher(methodMatcher(methods))
266
+}
267
+
268
+// Path -----------------------------------------------------------------------
269
+
270
+// Path adds a matcher for the URL path.
271
+// It accepts a template with zero or more URL variables enclosed by {}. The
272
+// template must start with a "/".
273
+// Variables can define an optional regexp pattern to me matched:
274
+//
275
+// - {name} matches anything until the next slash.
276
+//
277
+// - {name:pattern} matches the given regexp pattern.
278
+//
279
+// For example:
280
+//
281
+//     r := mux.NewRouter()
282
+//     r.Path("/products/").Handler(ProductsHandler)
283
+//     r.Path("/products/{key}").Handler(ProductsHandler)
284
+//     r.Path("/articles/{category}/{id:[0-9]+}").
285
+//       Handler(ArticleHandler)
286
+//
287
+// Variable names must be unique in a given route. They can be retrieved
288
+// calling mux.Vars(request).
289
+func (r *Route) Path(tpl string) *Route {
290
+	r.err = r.addRegexpMatcher(tpl, false, false, false)
291
+	return r
292
+}
293
+
294
+// PathPrefix -----------------------------------------------------------------
295
+
296
+// PathPrefix adds a matcher for the URL path prefix. This matches if the given
297
+// template is a prefix of the full URL path. See Route.Path() for details on
298
+// the tpl argument.
299
+//
300
+// Note that it does not treat slashes specially ("/foobar/" will be matched by
301
+// the prefix "/foo") so you may want to use a trailing slash here.
302
+//
303
+// Also note that the setting of Router.StrictSlash() has no effect on routes
304
+// with a PathPrefix matcher.
305
+func (r *Route) PathPrefix(tpl string) *Route {
306
+	r.err = r.addRegexpMatcher(tpl, false, true, false)
307
+	return r
308
+}
309
+
310
+// Query ----------------------------------------------------------------------
311
+
312
+// Queries adds a matcher for URL query values.
313
+// It accepts a sequence of key/value pairs. Values may define variables.
314
+// For example:
315
+//
316
+//     r := mux.NewRouter()
317
+//     r.Queries("foo", "bar", "id", "{id:[0-9]+}")
318
+//
319
+// The above route will only match if the URL contains the defined queries
320
+// values, e.g.: ?foo=bar&id=42.
321
+//
322
+// It the value is an empty string, it will match any value if the key is set.
323
+//
324
+// Variables can define an optional regexp pattern to me matched:
325
+//
326
+// - {name} matches anything until the next slash.
327
+//
328
+// - {name:pattern} matches the given regexp pattern.
329
+func (r *Route) Queries(pairs ...string) *Route {
330
+	length := len(pairs)
331
+	if length%2 != 0 {
332
+		r.err = fmt.Errorf(
333
+			"mux: number of parameters must be multiple of 2, got %v", pairs)
334
+		return nil
335
+	}
336
+	for i := 0; i < length; i += 2 {
337
+		if r.err = r.addRegexpMatcher(pairs[i]+"="+pairs[i+1], false, true, true); r.err != nil {
338
+			return r
339
+		}
340
+	}
341
+
342
+	return r
343
+}
344
+
345
+// Schemes --------------------------------------------------------------------
346
+
347
+// schemeMatcher matches the request against URL schemes.
348
+type schemeMatcher []string
349
+
350
+func (m schemeMatcher) Match(r *http.Request, match *RouteMatch) bool {
351
+	return matchInArray(m, r.URL.Scheme)
352
+}
353
+
354
+// Schemes adds a matcher for URL schemes.
355
+// It accepts a sequence of schemes to be matched, e.g.: "http", "https".
356
+func (r *Route) Schemes(schemes ...string) *Route {
357
+	for k, v := range schemes {
358
+		schemes[k] = strings.ToLower(v)
359
+	}
360
+	return r.addMatcher(schemeMatcher(schemes))
361
+}
362
+
363
+// Subrouter ------------------------------------------------------------------
364
+
365
+// Subrouter creates a subrouter for the route.
366
+//
367
+// It will test the inner routes only if the parent route matched. For example:
368
+//
369
+//     r := mux.NewRouter()
370
+//     s := r.Host("www.domain.com").Subrouter()
371
+//     s.HandleFunc("/products/", ProductsHandler)
372
+//     s.HandleFunc("/products/{key}", ProductHandler)
373
+//     s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
374
+//
375
+// Here, the routes registered in the subrouter won't be tested if the host
376
+// doesn't match.
377
+func (r *Route) Subrouter() *Router {
378
+	router := &Router{parent: r, strictSlash: r.strictSlash}
379
+	r.addMatcher(router)
380
+	return router
381
+}
382
+
383
+// ----------------------------------------------------------------------------
384
+// URL building
385
+// ----------------------------------------------------------------------------
386
+
387
+// URL builds a URL for the route.
388
+//
389
+// It accepts a sequence of key/value pairs for the route variables. For
390
+// example, given this route:
391
+//
392
+//     r := mux.NewRouter()
393
+//     r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
394
+//       Name("article")
395
+//
396
+// ...a URL for it can be built using:
397
+//
398
+//     url, err := r.Get("article").URL("category", "technology", "id", "42")
399
+//
400
+// ...which will return an url.URL with the following path:
401
+//
402
+//     "/articles/technology/42"
403
+//
404
+// This also works for host variables:
405
+//
406
+//     r := mux.NewRouter()
407
+//     r.Host("{subdomain}.domain.com").
408
+//       HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
409
+//       Name("article")
410
+//
411
+//     // url.String() will be "http://news.domain.com/articles/technology/42"
412
+//     url, err := r.Get("article").URL("subdomain", "news",
413
+//                                      "category", "technology",
414
+//                                      "id", "42")
415
+//
416
+// All variables defined in the route are required, and their values must
417
+// conform to the corresponding patterns.
418
+func (r *Route) URL(pairs ...string) (*url.URL, error) {
419
+	if r.err != nil {
420
+		return nil, r.err
421
+	}
422
+	if r.regexp == nil {
423
+		return nil, errors.New("mux: route doesn't have a host or path")
424
+	}
425
+	var scheme, host, path string
426
+	var err error
427
+	if r.regexp.host != nil {
428
+		// Set a default scheme.
429
+		scheme = "http"
430
+		if host, err = r.regexp.host.url(pairs...); err != nil {
431
+			return nil, err
432
+		}
433
+	}
434
+	if r.regexp.path != nil {
435
+		if path, err = r.regexp.path.url(pairs...); err != nil {
436
+			return nil, err
437
+		}
438
+	}
439
+	return &url.URL{
440
+		Scheme: scheme,
441
+		Host:   host,
442
+		Path:   path,
443
+	}, nil
444
+}
445
+
446
+// URLHost builds the host part of the URL for a route. See Route.URL().
447
+//
448
+// The route must have a host defined.
449
+func (r *Route) URLHost(pairs ...string) (*url.URL, error) {
450
+	if r.err != nil {
451
+		return nil, r.err
452
+	}
453
+	if r.regexp == nil || r.regexp.host == nil {
454
+		return nil, errors.New("mux: route doesn't have a host")
455
+	}
456
+	host, err := r.regexp.host.url(pairs...)
457
+	if err != nil {
458
+		return nil, err
459
+	}
460
+	return &url.URL{
461
+		Scheme: "http",
462
+		Host:   host,
463
+	}, nil
464
+}
465
+
466
+// URLPath builds the path part of the URL for a route. See Route.URL().
467
+//
468
+// The route must have a path defined.
469
+func (r *Route) URLPath(pairs ...string) (*url.URL, error) {
470
+	if r.err != nil {
471
+		return nil, r.err
472
+	}
473
+	if r.regexp == nil || r.regexp.path == nil {
474
+		return nil, errors.New("mux: route doesn't have a path")
475
+	}
476
+	path, err := r.regexp.path.url(pairs...)
477
+	if err != nil {
478
+		return nil, err
479
+	}
480
+	return &url.URL{
481
+		Path: path,
482
+	}, nil
483
+}
484
+
485
+// ----------------------------------------------------------------------------
486
+// parentRoute
487
+// ----------------------------------------------------------------------------
488
+
489
+// parentRoute allows routes to know about parent host and path definitions.
490
+type parentRoute interface {
491
+	getNamedRoutes() map[string]*Route
492
+	getRegexpGroup() *routeRegexpGroup
493
+}
494
+
495
+// getNamedRoutes returns the map where named routes are registered.
496
+func (r *Route) getNamedRoutes() map[string]*Route {
497
+	if r.parent == nil {
498
+		// During tests router is not always set.
499
+		r.parent = NewRouter()
500
+	}
501
+	return r.parent.getNamedRoutes()
502
+}
503
+
504
+// getRegexpGroup returns regexp definitions from this route.
505
+func (r *Route) getRegexpGroup() *routeRegexpGroup {
506
+	if r.regexp == nil {
507
+		if r.parent == nil {
508
+			// During tests router is not always set.
509
+			r.parent = NewRouter()
510
+		}
511
+		regexp := r.parent.getRegexpGroup()
512
+		if regexp == nil {
513
+			r.regexp = new(routeRegexpGroup)
514
+		} else {
515
+			// Copy.
516
+			r.regexp = &routeRegexpGroup{
517
+				host:    regexp.host,
518
+				path:    regexp.path,
519
+				queries: regexp.queries,
520
+			}
521
+		}
522
+	}
523
+	return r.regexp
524
+}

+ 13 - 0
vendor/github.com/howeyc/gopass/LICENSE.txt

@@ -0,0 +1,13 @@
1
+Copyright (c) 2012 Chris Howey
2
+
3
+Permission to use, copy, modify, and distribute this software for any
4
+purpose with or without fee is hereby granted, provided that the above
5
+copyright notice and this permission notice appear in all copies.
6
+
7
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

+ 21 - 0
vendor/github.com/howeyc/gopass/README.md

@@ -0,0 +1,21 @@
1
+# getpasswd in Go
2
+
3
+Retrieve password from user terminal input without echo
4
+
5
+Verified on BSD, Linux, and Windows.
6
+
7
+Example:
8
+```go
9
+package main
10
+
11
+import "fmt"
12
+import "github.com/howeyc/gopass"
13
+
14
+func main() {
15
+	fmt.Printf("Password: ")
16
+	pass := gopass.GetPasswd() // Silent, for *'s use gopass.GetPasswdMasked()
17
+    // Do something with pass
18
+}
19
+```
20
+
21
+Caution: Multi-byte characters not supported!

+ 29 - 0
vendor/github.com/howeyc/gopass/bsd.go

@@ -0,0 +1,29 @@
1
+// +build freebsd openbsd netbsd
2
+
3
+package gopass
4
+
5
+/*
6
+#include <termios.h>
7
+#include <unistd.h>
8
+#include <stdio.h>
9
+
10
+int getch() {
11
+        int ch;
12
+        struct termios t_old, t_new;
13
+
14
+        tcgetattr(STDIN_FILENO, &t_old);
15
+        t_new = t_old;
16
+        t_new.c_lflag &= ~(ICANON | ECHO);
17
+        tcsetattr(STDIN_FILENO, TCSANOW, &t_new);
18
+
19
+        ch = getchar();
20
+
21
+        tcsetattr(STDIN_FILENO, TCSANOW, &t_old);
22
+        return ch;
23
+}
24
+*/
25
+import "C"
26
+
27
+func getch() byte {
28
+	return byte(C.getch())
29
+}

+ 23 - 0
vendor/github.com/howeyc/gopass/nix.go

@@ -0,0 +1,23 @@
1
+// +build linux darwin
2
+
3
+package gopass
4
+
5
+import (
6
+	"syscall"
7
+
8
+	"golang.org/x/crypto/ssh/terminal"
9
+)
10
+
11
+func getch() byte {
12
+	if oldState, err := terminal.MakeRaw(0); err != nil {
13
+		panic(err)
14
+	} else {
15
+		defer terminal.Restore(0, oldState)
16
+	}
17
+
18
+	var buf [1]byte
19
+	if n, err := syscall.Read(0, buf[:]); n == 0 || err != nil {
20
+		panic(err)
21
+	}
22
+	return buf[0]
23
+}

+ 44 - 0
vendor/github.com/howeyc/gopass/pass.go

@@ -0,0 +1,44 @@
1
+package gopass
2
+
3
+import (
4
+	"os"
5
+)
6
+
7
+// getPasswd returns the input read from terminal.
8
+// If masked is true, typing will be matched by asterisks on the screen.
9
+// Otherwise, typing will echo nothing.
10
+func getPasswd(masked bool) []byte {
11
+	var pass, bs, mask []byte
12
+	if masked {
13
+		bs = []byte("\b \b")
14
+		mask = []byte("*")
15
+	}
16
+
17
+	for {
18
+		if v := getch(); v == 127 || v == 8 {
19
+			if l := len(pass); l > 0 {
20
+				pass = pass[:l-1]
21
+				os.Stdout.Write(bs)
22
+			}
23
+		} else if v == 13 || v == 10 {
24
+			break
25
+		} else if v != 0 {
26
+			pass = append(pass, v)
27
+			os.Stdout.Write(mask)
28
+		}
29
+	}
30
+	println()
31
+	return pass
32
+}
33
+
34
+// GetPasswd returns the password read from the terminal without echoing input.
35
+// The returned byte array does not include end-of-line characters.
36
+func GetPasswd() []byte {
37
+	return getPasswd(false)
38
+}
39
+
40
+// GetPasswdMasked returns the password read from the terminal, echoing asterisks.
41
+// The returned byte array does not include end-of-line characters.
42
+func GetPasswdMasked() []byte {
43
+	return getPasswd(true)
44
+}

+ 42 - 0
vendor/github.com/howeyc/gopass/win.go

@@ -0,0 +1,42 @@
1
+// +build windows
2
+
3
+package gopass
4
+
5
+import "syscall"
6
+import "unsafe"
7
+import "unicode/utf16"
8
+
9
+func getch() byte {
10
+	modkernel32 := syscall.NewLazyDLL("kernel32.dll")
11
+	procReadConsole := modkernel32.NewProc("ReadConsoleW")
12
+	procGetConsoleMode := modkernel32.NewProc("GetConsoleMode")
13
+	procSetConsoleMode := modkernel32.NewProc("SetConsoleMode")
14
+
15
+	var mode uint32
16
+	pMode := &mode
17
+	procGetConsoleMode.Call(uintptr(syscall.Stdin), uintptr(unsafe.Pointer(pMode)))
18
+
19
+	var echoMode, lineMode uint32
20
+	echoMode = 4
21
+	lineMode = 2
22
+	var newMode uint32
23
+	newMode = mode ^ (echoMode | lineMode)
24
+
25
+	procSetConsoleMode.Call(uintptr(syscall.Stdin), uintptr(newMode))
26
+
27
+	line := make([]uint16, 1)
28
+	pLine := &line[0]
29
+	var n uint16
30
+	procReadConsole.Call(uintptr(syscall.Stdin), uintptr(unsafe.Pointer(pLine)), uintptr(len(line)), uintptr(unsafe.Pointer(&n)))
31
+
32
+	b := []byte(string(utf16.Decode(line)))
33
+
34
+	procSetConsoleMode.Call(uintptr(syscall.Stdin), uintptr(mode))
35
+
36
+	// Not sure how this could happen, but it did for someone
37
+	if len(b) > 0 {
38
+		return b[0]
39
+	} else {
40
+		return 13
41
+	}
42
+}

+ 780 - 0
vendor/github.com/stretchr/testify/assert/assertions.go

@@ -0,0 +1,780 @@
1
+package assert
2
+
3
+import (
4
+	"bufio"
5
+	"bytes"
6
+	"fmt"
7
+	"reflect"
8
+	"regexp"
9
+	"runtime"
10
+	"strings"
11
+	"time"
12
+)
13
+
14
+// TestingT is an interface wrapper around *testing.T
15
+type TestingT interface {
16
+	Errorf(format string, args ...interface{})
17
+}
18
+
19
+// Comparison a custom function that returns true on success and false on failure
20
+type Comparison func() (success bool)
21
+
22
+/*
23
+	Helper functions
24
+*/
25
+
26
+// ObjectsAreEqual determines if two objects are considered equal.
27
+//
28
+// This function does no assertion of any kind.
29
+func ObjectsAreEqual(expected, actual interface{}) bool {
30
+
31
+	if expected == nil || actual == nil {
32
+		return expected == actual
33
+	}
34
+
35
+	if reflect.DeepEqual(expected, actual) {
36
+		return true
37
+	}
38
+
39
+	actualType := reflect.TypeOf(actual)
40
+	if actualType.ConvertibleTo(reflect.TypeOf(expected)) {
41
+		expectedValue := reflect.ValueOf(expected)
42
+		// Attempt comparison after type conversion
43
+		if reflect.DeepEqual(actual, expectedValue.Convert(actualType).Interface()) {
44
+			return true
45
+		}
46
+	}
47
+
48
+	// Last ditch effort
49
+	if fmt.Sprintf("%#v", expected) == fmt.Sprintf("%#v", actual) {
50
+		return true
51
+	}
52
+
53
+	return false
54
+
55
+}
56
+
57
+/* CallerInfo is necessary because the assert functions use the testing object
58
+internally, causing it to print the file:line of the assert method, rather than where
59
+the problem actually occured in calling code.*/
60
+
61
+// CallerInfo returns a string containing the file and line number of the assert call
62
+// that failed.
63
+func CallerInfo() string {
64
+
65
+	file := ""
66
+	line := 0
67
+	ok := false
68
+
69
+	for i := 0; ; i++ {
70
+		_, file, line, ok = runtime.Caller(i)
71
+		if !ok {
72
+			return ""
73
+		}
74
+		parts := strings.Split(file, "/")
75
+		dir := parts[len(parts)-2]
76
+		file = parts[len(parts)-1]
77
+		if (dir != "assert" && dir != "mock" && dir != "require") || file == "mock_test.go" {
78
+			break
79
+		}
80
+	}
81
+
82
+	return fmt.Sprintf("%s:%d", file, line)
83
+}
84
+
85
+// getWhitespaceString returns a string that is long enough to overwrite the default
86
+// output from the go testing framework.
87
+func getWhitespaceString() string {
88
+
89
+	_, file, line, ok := runtime.Caller(1)
90
+	if !ok {
91
+		return ""
92
+	}
93
+	parts := strings.Split(file, "/")
94
+	file = parts[len(parts)-1]
95
+
96
+	return strings.Repeat(" ", len(fmt.Sprintf("%s:%d:      ", file, line)))
97
+
98
+}
99
+
100
+func messageFromMsgAndArgs(msgAndArgs ...interface{}) string {
101
+	if len(msgAndArgs) == 0 || msgAndArgs == nil {
102
+		return ""
103
+	}
104
+	if len(msgAndArgs) == 1 {
105
+		return msgAndArgs[0].(string)
106
+	}
107
+	if len(msgAndArgs) > 1 {
108
+		return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...)
109
+	}
110
+	return ""
111
+}
112
+
113
+// Indents all lines of the message by appending a number of tabs to each line, in an output format compatible with Go's
114
+// test printing (see inner comment for specifics)
115
+func indentMessageLines(message string, tabs int) string {
116
+	outBuf := new(bytes.Buffer)
117
+
118
+	for i, scanner := 0, bufio.NewScanner(strings.NewReader(message)); scanner.Scan(); i++ {
119
+		if i != 0 {
120
+			outBuf.WriteRune('\n')
121
+		}
122
+		for ii := 0; ii < tabs; ii++ {
123
+			outBuf.WriteRune('\t')
124
+			// Bizarrely, all lines except the first need one fewer tabs prepended, so deliberately advance the counter
125
+			// by 1 prematurely.
126
+			if ii == 0 && i > 0 {
127
+				ii++
128
+			}
129
+		}
130
+		outBuf.WriteString(scanner.Text())
131
+	}
132
+
133
+	return outBuf.String()
134
+}
135
+
136
+// Fail reports a failure through
137
+func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool {
138
+
139
+	message := messageFromMsgAndArgs(msgAndArgs...)
140
+
141
+	if len(message) > 0 {
142
+		t.Errorf("\r%s\r\tLocation:\t%s\n"+
143
+			"\r\tError:%s\n"+
144
+			"\r\tMessages:\t%s\n\r",
145
+			getWhitespaceString(),
146
+			CallerInfo(),
147
+			indentMessageLines(failureMessage, 2),
148
+			message)
149
+	} else {
150
+		t.Errorf("\r%s\r\tLocation:\t%s\n"+
151
+			"\r\tError:%s\n\r",
152
+			getWhitespaceString(),
153
+			CallerInfo(),
154
+			indentMessageLines(failureMessage, 2))
155
+	}
156
+
157
+	return false
158
+}
159
+
160
+// Implements asserts that an object is implemented by the specified interface.
161
+//
162
+//    assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject")
163
+func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool {
164
+
165
+	interfaceType := reflect.TypeOf(interfaceObject).Elem()
166
+
167
+	if !reflect.TypeOf(object).Implements(interfaceType) {
168
+		return Fail(t, fmt.Sprintf("Object must implement %v", interfaceType), msgAndArgs...)
169
+	}
170
+
171
+	return true
172
+
173
+}
174
+
175
+// IsType asserts that the specified objects are of the same type.
176
+func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
177
+
178
+	if !ObjectsAreEqual(reflect.TypeOf(object), reflect.TypeOf(expectedType)) {
179
+		return Fail(t, fmt.Sprintf("Object expected to be of type %v, but was %v", reflect.TypeOf(expectedType), reflect.TypeOf(object)), msgAndArgs...)
180
+	}
181
+
182
+	return true
183
+}
184
+
185
+// Equal asserts that two objects are equal.
186
+//
187
+//    assert.Equal(t, 123, 123, "123 and 123 should be equal")
188
+//
189
+// Returns whether the assertion was successful (true) or not (false).
190
+func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
191
+
192
+	if !ObjectsAreEqual(expected, actual) {
193
+		return Fail(t, fmt.Sprintf("Not equal: %#v (expected)\n"+
194
+			"        != %#v (actual)", expected, actual), msgAndArgs...)
195
+	}
196
+
197
+	return true
198
+
199
+}
200
+
201
+// Exactly asserts that two objects are equal is value and type.
202
+//
203
+//    assert.Exactly(t, int32(123), int64(123), "123 and 123 should NOT be equal")
204
+//
205
+// Returns whether the assertion was successful (true) or not (false).
206
+func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool {
207
+
208
+	aType := reflect.TypeOf(expected)
209
+	bType := reflect.TypeOf(actual)
210
+
211
+	if aType != bType {
212
+		return Fail(t, "Types expected to match exactly", "%v != %v", aType, bType)
213
+	}
214
+
215
+	return Equal(t, expected, actual, msgAndArgs...)
216
+
217
+}
218
+
219
+// NotNil asserts that the specified object is not nil.
220
+//
221
+//    assert.NotNil(t, err, "err should be something")
222
+//
223
+// Returns whether the assertion was successful (true) or not (false).
224
+func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
225
+
226
+	success := true
227
+
228
+	if object == nil {
229
+		success = false
230
+	} else {
231
+		value := reflect.ValueOf(object)
232
+		kind := value.Kind()
233
+		if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
234
+			success = false
235
+		}
236
+	}
237
+
238
+	if !success {
239
+		Fail(t, "Expected not to be nil.", msgAndArgs...)
240
+	}
241
+
242
+	return success
243
+}
244
+
245
+// isNil checks if a specified object is nil or not, without Failing.
246
+func isNil(object interface{}) bool {
247
+	if object == nil {
248
+		return true
249
+	}
250
+
251
+	value := reflect.ValueOf(object)
252
+	kind := value.Kind()
253
+	if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
254
+		return true
255
+	}
256
+
257
+	return false
258
+}
259
+
260
+// Nil asserts that the specified object is nil.
261
+//
262
+//    assert.Nil(t, err, "err should be nothing")
263
+//
264
+// Returns whether the assertion was successful (true) or not (false).
265
+func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
266
+	if isNil(object) {
267
+		return true
268
+	}
269
+	return Fail(t, fmt.Sprintf("Expected nil, but got: %#v", object), msgAndArgs...)
270
+}
271
+
272
+var zeros = []interface{}{
273
+	int(0),
274
+	int8(0),
275
+	int16(0),
276
+	int32(0),
277
+	int64(0),
278
+	uint(0),
279
+	uint8(0),
280
+	uint16(0),
281
+	uint32(0),
282
+	uint64(0),
283
+	float32(0),
284
+	float64(0),
285
+}
286
+
287
+// isEmpty gets whether the specified object is considered empty or not.
288
+func isEmpty(object interface{}) bool {
289
+
290
+	if object == nil {
291
+		return true
292
+	} else if object == "" {
293
+		return true
294
+	} else if object == false {
295
+		return true
296
+	}
297
+
298
+	for _, v := range zeros {
299
+		if object == v {
300
+			return true
301
+		}
302
+	}
303
+
304
+	objValue := reflect.ValueOf(object)
305
+
306
+	switch objValue.Kind() {
307
+	case reflect.Map:
308
+		fallthrough
309
+	case reflect.Slice, reflect.Chan:
310
+		{
311
+			return (objValue.Len() == 0)
312
+		}
313
+	case reflect.Ptr: