Browse Source

Added all required dependencies

Thomas Boerger 3 years ago
parent
commit
1ebb35b988
100 changed files with 16822 additions and 0 deletions
  1. 191 0
      vendor/github.com/Unknwon/cae/LICENSE
  2. 37 0
      vendor/github.com/Unknwon/cae/README.md
  3. 29 0
      vendor/github.com/Unknwon/cae/README_ZH.md
  4. 108 0
      vendor/github.com/Unknwon/cae/cae.go
  5. 67 0
      vendor/github.com/Unknwon/cae/zip/read.go
  6. 77 0
      vendor/github.com/Unknwon/cae/zip/stream.go
  7. 364 0
      vendor/github.com/Unknwon/cae/zip/write.go
  8. 238 0
      vendor/github.com/Unknwon/cae/zip/zip.go
  9. 191 0
      vendor/github.com/Unknwon/com/LICENSE
  10. 20 0
      vendor/github.com/Unknwon/com/README.md
  11. 161 0
      vendor/github.com/Unknwon/com/cmd.go
  12. 157 0
      vendor/github.com/Unknwon/com/convert.go
  13. 173 0
      vendor/github.com/Unknwon/com/dir.go
  14. 145 0
      vendor/github.com/Unknwon/com/file.go
  15. 60 0
      vendor/github.com/Unknwon/com/html.go
  16. 201 0
      vendor/github.com/Unknwon/com/http.go
  17. 29 0
      vendor/github.com/Unknwon/com/math.go
  18. 80 0
      vendor/github.com/Unknwon/com/path.go
  19. 56 0
      vendor/github.com/Unknwon/com/regex.go
  20. 87 0
      vendor/github.com/Unknwon/com/slice.go
  21. 243 0
      vendor/github.com/Unknwon/com/string.go
  22. 115 0
      vendor/github.com/Unknwon/com/time.go
  23. 41 0
      vendor/github.com/Unknwon/com/url.go
  24. 191 0
      vendor/github.com/Unknwon/i18n/LICENSE
  25. 134 0
      vendor/github.com/Unknwon/i18n/README.md
  26. 225 0
      vendor/github.com/Unknwon/i18n/i18n.go
  27. 202 0
      vendor/github.com/Unknwon/paginater/LICENSE
  28. 65 0
      vendor/github.com/Unknwon/paginater/README.md
  29. 192 0
      vendor/github.com/Unknwon/paginater/paginater.go
  30. 202 0
      vendor/github.com/bradfitz/gomemcache/LICENSE
  31. 666 0
      vendor/github.com/bradfitz/gomemcache/memcache/memcache.go
  32. 114 0
      vendor/github.com/bradfitz/gomemcache/memcache/selector.go
  33. 191 0
      vendor/github.com/go-macaron/binding/LICENSE
  34. 20 0
      vendor/github.com/go-macaron/binding/README.md
  35. 669 0
      vendor/github.com/go-macaron/binding/binding.go
  36. 159 0
      vendor/github.com/go-macaron/binding/errors.go
  37. 191 0
      vendor/github.com/go-macaron/cache/LICENSE
  38. 20 0
      vendor/github.com/go-macaron/cache/README.md
  39. 122 0
      vendor/github.com/go-macaron/cache/cache.go
  40. 208 0
      vendor/github.com/go-macaron/cache/file.go
  41. 92 0
      vendor/github.com/go-macaron/cache/memcache/memcache.go
  42. 1 0
      vendor/github.com/go-macaron/cache/memcache/memcache.goconvey
  43. 179 0
      vendor/github.com/go-macaron/cache/memory.go
  44. 178 0
      vendor/github.com/go-macaron/cache/redis/redis.go
  45. 1 0
      vendor/github.com/go-macaron/cache/redis/redis.goconvey
  46. 84 0
      vendor/github.com/go-macaron/cache/utils.go
  47. 191 0
      vendor/github.com/go-macaron/captcha/LICENSE
  48. 16 0
      vendor/github.com/go-macaron/captcha/README.md
  49. 241 0
      vendor/github.com/go-macaron/captcha/captcha.go
  50. 498 0
      vendor/github.com/go-macaron/captcha/image.go
  51. 277 0
      vendor/github.com/go-macaron/captcha/siprng.go
  52. 191 0
      vendor/github.com/go-macaron/csrf/LICENSE
  53. 18 0
      vendor/github.com/go-macaron/csrf/README.md
  54. 251 0
      vendor/github.com/go-macaron/csrf/csrf.go
  55. 97 0
      vendor/github.com/go-macaron/csrf/xsrf.go
  56. 191 0
      vendor/github.com/go-macaron/gzip/LICENSE
  57. 20 0
      vendor/github.com/go-macaron/gzip/README.md
  58. 121 0
      vendor/github.com/go-macaron/gzip/gzip.go
  59. 191 0
      vendor/github.com/go-macaron/i18n/LICENSE
  60. 16 0
      vendor/github.com/go-macaron/i18n/README.md
  61. 225 0
      vendor/github.com/go-macaron/i18n/i18n.go
  62. 191 0
      vendor/github.com/go-macaron/inject/LICENSE
  63. 11 0
      vendor/github.com/go-macaron/inject/README.md
  64. 262 0
      vendor/github.com/go-macaron/inject/inject.go
  65. 191 0
      vendor/github.com/go-macaron/session/LICENSE
  66. 20 0
      vendor/github.com/go-macaron/session/README.md
  67. 261 0
      vendor/github.com/go-macaron/session/file.go
  68. 217 0
      vendor/github.com/go-macaron/session/memory.go
  69. 235 0
      vendor/github.com/go-macaron/session/redis/redis.go
  70. 1 0
      vendor/github.com/go-macaron/session/redis/redis.goconvey
  71. 399 0
      vendor/github.com/go-macaron/session/session.go
  72. 60 0
      vendor/github.com/go-macaron/session/utils.go
  73. 191 0
      vendor/github.com/go-macaron/toolbox/LICENSE
  74. 110 0
      vendor/github.com/go-macaron/toolbox/README.md
  75. 83 0
      vendor/github.com/go-macaron/toolbox/healthcheck.go
  76. 163 0
      vendor/github.com/go-macaron/toolbox/profile.go
  77. 138 0
      vendor/github.com/go-macaron/toolbox/statistic.go
  78. 154 0
      vendor/github.com/go-macaron/toolbox/toolbox.go
  79. 55 0
      vendor/github.com/go-sql-driver/mysql/AUTHORS
  80. 114 0
      vendor/github.com/go-sql-driver/mysql/CHANGELOG.md
  81. 23 0
      vendor/github.com/go-sql-driver/mysql/CONTRIBUTING.md
  82. 21 0
      vendor/github.com/go-sql-driver/mysql/ISSUE_TEMPLATE.md
  83. 373 0
      vendor/github.com/go-sql-driver/mysql/LICENSE
  84. 9 0
      vendor/github.com/go-sql-driver/mysql/PULL_REQUEST_TEMPLATE.md
  85. 439 0
      vendor/github.com/go-sql-driver/mysql/README.md
  86. 19 0
      vendor/github.com/go-sql-driver/mysql/appengine.go
  87. 147 0
      vendor/github.com/go-sql-driver/mysql/buffer.go
  88. 250 0
      vendor/github.com/go-sql-driver/mysql/collations.go
  89. 377 0
      vendor/github.com/go-sql-driver/mysql/connection.go
  90. 163 0
      vendor/github.com/go-sql-driver/mysql/const.go
  91. 176 0
      vendor/github.com/go-sql-driver/mysql/driver.go
  92. 548 0
      vendor/github.com/go-sql-driver/mysql/dsn.go
  93. 132 0
      vendor/github.com/go-sql-driver/mysql/errors.go
  94. 182 0
      vendor/github.com/go-sql-driver/mysql/infile.go
  95. 1272 0
      vendor/github.com/go-sql-driver/mysql/packets.go
  96. 22 0
      vendor/github.com/go-sql-driver/mysql/result.go
  97. 112 0
      vendor/github.com/go-sql-driver/mysql/rows.go
  98. 150 0
      vendor/github.com/go-sql-driver/mysql/statement.go
  99. 31 0
      vendor/github.com/go-sql-driver/mysql/transaction.go
  100. 0 0
      vendor/github.com/go-sql-driver/mysql/utils.go

+ 191 - 0
vendor/github.com/Unknwon/cae/LICENSE

@@ -0,0 +1,191 @@
1
+Apache License
2
+Version 2.0, January 2004
3
+http://www.apache.org/licenses/
4
+
5
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+1. Definitions.
8
+
9
+"License" shall mean the terms and conditions for use, reproduction, and
10
+distribution as defined by Sections 1 through 9 of this document.
11
+
12
+"Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+owner that is granting the License.
14
+
15
+"Legal Entity" shall mean the union of the acting entity and all other entities
16
+that control, are controlled by, or are under common control with that entity.
17
+For the purposes of this definition, "control" means (i) the power, direct or
18
+indirect, to cause the direction or management of such entity, whether by
19
+contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+"You" (or "Your") shall mean an individual or Legal Entity exercising
23
+permissions granted by this License.
24
+
25
+"Source" form shall mean the preferred form for making modifications, including
26
+but not limited to software source code, documentation source, and configuration
27
+files.
28
+
29
+"Object" form shall mean any form resulting from mechanical transformation or
30
+translation of a Source form, including but not limited to compiled object code,
31
+generated documentation, and conversions to other media types.
32
+
33
+"Work" shall mean the work of authorship, whether in Source or Object form, made
34
+available under the License, as indicated by a copyright notice that is included
35
+in or attached to the work (an example is provided in the Appendix below).
36
+
37
+"Derivative Works" shall mean any work, whether in Source or Object form, that
38
+is based on (or derived from) the Work and for which the editorial revisions,
39
+annotations, elaborations, or other modifications represent, as a whole, an
40
+original work of authorship. For the purposes of this License, Derivative Works
41
+shall not include works that remain separable from, or merely link (or bind by
42
+name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+"Contribution" shall mean any work of authorship, including the original version
45
+of the Work and any modifications or additions to that Work or Derivative Works
46
+thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+by the copyright owner or by an individual or Legal Entity authorized to submit
48
+on behalf of the copyright owner. For the purposes of this definition,
49
+"submitted" means any form of electronic, verbal, or written communication sent
50
+to the Licensor or its representatives, including but not limited to
51
+communication on electronic mailing lists, source code control systems, and
52
+issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+the purpose of discussing and improving the Work, but excluding communication
54
+that is conspicuously marked or otherwise designated in writing by the copyright
55
+owner as "Not a Contribution."
56
+
57
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+of whom a Contribution has been received by Licensor and subsequently
59
+incorporated within the Work.
60
+
61
+2. Grant of Copyright License.
62
+
63
+Subject to the terms and conditions of this License, each Contributor hereby
64
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65
+irrevocable copyright license to reproduce, prepare Derivative Works of,
66
+publicly display, publicly perform, sublicense, and distribute the Work and such
67
+Derivative Works in Source or Object form.
68
+
69
+3. Grant of Patent License.
70
+
71
+Subject to the terms and conditions of this License, each Contributor hereby
72
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73
+irrevocable (except as stated in this section) patent license to make, have
74
+made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75
+such license applies only to those patent claims licensable by such Contributor
76
+that are necessarily infringed by their Contribution(s) alone or by combination
77
+of their Contribution(s) with the Work to which such Contribution(s) was
78
+submitted. If You institute patent litigation against any entity (including a
79
+cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80
+Contribution incorporated within the Work constitutes direct or contributory
81
+patent infringement, then any patent licenses granted to You under this License
82
+for that Work shall terminate as of the date such litigation is filed.
83
+
84
+4. Redistribution.
85
+
86
+You may reproduce and distribute copies of the Work or Derivative Works thereof
87
+in any medium, with or without modifications, and in Source or Object form,
88
+provided that You meet the following conditions:
89
+
90
+You must give any other recipients of the Work or Derivative Works a copy of
91
+this License; and
92
+You must cause any modified files to carry prominent notices stating that You
93
+changed the files; and
94
+You must retain, in the Source form of any Derivative Works that You distribute,
95
+all copyright, patent, trademark, and attribution notices from the Source form
96
+of the Work, excluding those notices that do not pertain to any part of the
97
+Derivative Works; and
98
+If the Work includes a "NOTICE" text file as part of its distribution, then any
99
+Derivative Works that You distribute must include a readable copy of the
100
+attribution notices contained within such NOTICE file, excluding those notices
101
+that do not pertain to any part of the Derivative Works, in at least one of the
102
+following places: within a NOTICE text file distributed as part of the
103
+Derivative Works; within the Source form or documentation, if provided along
104
+with the Derivative Works; or, within a display generated by the Derivative
105
+Works, if and wherever such third-party notices normally appear. The contents of
106
+the NOTICE file are for informational purposes only and do not modify the
107
+License. You may add Your own attribution notices within Derivative Works that
108
+You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+provided that such additional attribution notices cannot be construed as
110
+modifying the License.
111
+You may add Your own copyright statement to Your modifications and may provide
112
+additional or different license terms and conditions for use, reproduction, or
113
+distribution of Your modifications, or for any such Derivative Works as a whole,
114
+provided Your use, reproduction, and distribution of the Work otherwise complies
115
+with the conditions stated in this License.
116
+
117
+5. Submission of Contributions.
118
+
119
+Unless You explicitly state otherwise, any Contribution intentionally submitted
120
+for inclusion in the Work by You to the Licensor shall be under the terms and
121
+conditions of this License, without any additional terms or conditions.
122
+Notwithstanding the above, nothing herein shall supersede or modify the terms of
123
+any separate license agreement you may have executed with Licensor regarding
124
+such Contributions.
125
+
126
+6. Trademarks.
127
+
128
+This License does not grant permission to use the trade names, trademarks,
129
+service marks, or product names of the Licensor, except as required for
130
+reasonable and customary use in describing the origin of the Work and
131
+reproducing the content of the NOTICE file.
132
+
133
+7. Disclaimer of Warranty.
134
+
135
+Unless required by applicable law or agreed to in writing, Licensor provides the
136
+Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138
+including, without limitation, any warranties or conditions of TITLE,
139
+NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140
+solely responsible for determining the appropriateness of using or
141
+redistributing the Work and assume any risks associated with Your exercise of
142
+permissions under this License.
143
+
144
+8. Limitation of Liability.
145
+
146
+In no event and under no legal theory, whether in tort (including negligence),
147
+contract, or otherwise, unless required by applicable law (such as deliberate
148
+and grossly negligent acts) or agreed to in writing, shall any Contributor be
149
+liable to You for damages, including any direct, indirect, special, incidental,
150
+or consequential damages of any character arising as a result of this License or
151
+out of the use or inability to use the Work (including but not limited to
152
+damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153
+any and all other commercial damages or losses), even if such Contributor has
154
+been advised of the possibility of such damages.
155
+
156
+9. Accepting Warranty or Additional Liability.
157
+
158
+While redistributing the Work or Derivative Works thereof, You may choose to
159
+offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160
+other liability obligations and/or rights consistent with this License. However,
161
+in accepting such obligations, You may act only on Your own behalf and on Your
162
+sole responsibility, not on behalf of any other Contributor, and only if You
163
+agree to indemnify, defend, and hold each Contributor harmless for any liability
164
+incurred by, or claims asserted against, such Contributor by reason of your
165
+accepting any such warranty or additional liability.
166
+
167
+END OF TERMS AND CONDITIONS
168
+
169
+APPENDIX: How to apply the Apache License to your work
170
+
171
+To apply the Apache License to your work, attach the following boilerplate
172
+notice, with the fields enclosed by brackets "[]" replaced with your own
173
+identifying information. (Don't include the brackets!) The text should be
174
+enclosed in the appropriate comment syntax for the file format. We also
175
+recommend that a file or class name and description of purpose be included on
176
+the same "printed page" as the copyright notice for easier identification within
177
+third-party archives.
178
+
179
+   Copyright [yyyy] [name of copyright owner]
180
+
181
+   Licensed under the Apache License, Version 2.0 (the "License");
182
+   you may not use this file except in compliance with the License.
183
+   You may obtain a copy of the License at
184
+
185
+     http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+   Unless required by applicable law or agreed to in writing, software
188
+   distributed under the License is distributed on an "AS IS" BASIS,
189
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+   See the License for the specific language governing permissions and
191
+   limitations under the License.

+ 37 - 0
vendor/github.com/Unknwon/cae/README.md

@@ -0,0 +1,37 @@
1
+Compression and Archive Extensions
2
+==================================
3
+
4
+[![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/Unknwon/cae)
5
+
6
+[中文文档](README_ZH.md)
7
+
8
+Package cae implements PHP-like Compression and Archive Extensions.
9
+
10
+But this package has some modifications depends on Go-style.
11
+
12
+Reference: [PHP:Compression and Archive Extensions](http://www.php.net/manual/en/refs.compression.php).
13
+
14
+Code Convention: based on [Go Code Convention](https://github.com/Unknwon/go-code-convention).
15
+
16
+### Implementations
17
+
18
+Package `zip`([Go Walker](http://gowalker.org/github.com/Unknwon/cae/zip)) and `tz`([Go Walker](http://gowalker.org/github.com/Unknwon/cae/tz)) both enable you to transparently read or write ZIP/TAR.GZ compressed archives and the files inside them.
19
+
20
+- Features:
21
+	- Add file or directory from everywhere to archive, no one-to-one limitation.
22
+	- Extract part of entries, not all at once. 
23
+	- Stream data directly into `io.Writer` without any file system storage.
24
+
25
+### Test cases and Coverage
26
+
27
+All subpackages use [GoConvey](http://goconvey.co/) to write test cases, and coverage is more than 80 percent.
28
+
29
+### Use cases
30
+
31
+- [Gogs](https://github.com/gogits/gogs): self hosted Git service in the Go Programming Language.
32
+- [GoBlog](https://github.com/fuxiaohei/GoBlog): personal blogging application.
33
+- [GoBuild](https://github.com/shxsun/gobuild/): online Go cross-platform compilation and download service.
34
+
35
+## License
36
+
37
+This project is under Apache v2 License. See the [LICENSE](LICENSE) file for the full license text.

+ 29 - 0
vendor/github.com/Unknwon/cae/README_ZH.md

@@ -0,0 +1,29 @@
1
+压缩与打包扩展
2
+=============
3
+
4
+[![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/Unknwon/cae)
5
+
6
+包 cae 实现了 PHP 风格的压缩与打包扩展。
7
+
8
+但本包依据 Go 语言的风格进行了一些修改。
9
+
10
+引用:[PHP:Compression and Archive Extensions](http://www.php.net/manual/en/refs.compression.php)
11
+
12
+编码规范:基于 [Go 编码规范](https://github.com/Unknwon/go-code-convention)
13
+
14
+### 实现
15
+
16
+包 `zip`([Go Walker](http://gowalker.org/github.com/Unknwon/cae/zip)) 和 `tz`([Go Walker](http://gowalker.org/github.com/Unknwon/cae/tz)) 都允许你轻易的读取或写入 ZIP/TAR.GZ 压缩档案和其内部文件。
17
+
18
+- 特性:
19
+	- 将任意位置的文件或目录加入档案,没有一对一的操作限制。
20
+	- 只解压部分文件,而非一次性解压全部。 
21
+	- 将数据以流的形式直接写入 `io.Writer` 而不需经过文件系统的存储。
22
+
23
+### 测试用例与覆盖率
24
+
25
+所有子包均采用 [GoConvey](http://goconvey.co/) 来书写测试用例,覆盖率均超过 80%。
26
+
27
+## 授权许可
28
+
29
+本项目采用 Apache v2 开源授权许可证,完整的授权说明已放置在 [LICENSE](LICENSE) 文件中。

+ 108 - 0
vendor/github.com/Unknwon/cae/cae.go

@@ -0,0 +1,108 @@
1
+// Copyright 2013 Unknown
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+// Package cae implements PHP-like Compression and Archive Extensions.
16
+package cae
17
+
18
+import (
19
+	"io"
20
+	"os"
21
+	"strings"
22
+)
23
+
24
+// A Streamer describes an streamable archive object.
25
+type Streamer interface {
26
+	StreamFile(string, os.FileInfo, []byte) error
27
+	StreamReader(string, os.FileInfo, io.Reader) error
28
+	Close() error
29
+}
30
+
31
+// A HookFunc represents a middleware for packing and extracting archive.
32
+type HookFunc func(string, os.FileInfo) error
33
+
34
+// HasPrefix returns true if name has any string in given slice as prefix.
35
+func HasPrefix(name string, prefixes []string) bool {
36
+	for _, prefix := range prefixes {
37
+		if strings.HasPrefix(name, prefix) {
38
+			return true
39
+		}
40
+	}
41
+	return false
42
+}
43
+
44
+// IsEntry returns true if name equals to any string in given slice.
45
+func IsEntry(name string, entries []string) bool {
46
+	for _, e := range entries {
47
+		if e == name {
48
+			return true
49
+		}
50
+	}
51
+	return false
52
+}
53
+
54
+// IsFilter returns true if given name matches any of global filter rule.
55
+func IsFilter(name string) bool {
56
+	if strings.Contains(name, ".DS_Store") {
57
+		return true
58
+	}
59
+	return false
60
+}
61
+
62
+// IsExist returns true if given path is a file or directory.
63
+func IsExist(path string) bool {
64
+	_, err := os.Stat(path)
65
+	return err == nil || os.IsExist(err)
66
+}
67
+
68
+// Copy copies file from source to target path.
69
+func Copy(dest, src string) error {
70
+	// Gather file information to set back later.
71
+	si, err := os.Lstat(src)
72
+	if err != nil {
73
+		return err
74
+	}
75
+
76
+	// Handle symbolic link.
77
+	if si.Mode()&os.ModeSymlink != 0 {
78
+		target, err := os.Readlink(src)
79
+		if err != nil {
80
+			return err
81
+		}
82
+		// NOTE: os.Chmod and os.Chtimes don't recoganize symbolic link,
83
+		// which will lead "no such file or directory" error.
84
+		return os.Symlink(target, dest)
85
+	}
86
+
87
+	sr, err := os.Open(src)
88
+	if err != nil {
89
+		return err
90
+	}
91
+	defer sr.Close()
92
+
93
+	dw, err := os.Create(dest)
94
+	if err != nil {
95
+		return err
96
+	}
97
+	defer dw.Close()
98
+
99
+	if _, err = io.Copy(dw, sr); err != nil {
100
+		return err
101
+	}
102
+
103
+	// Set back file information.
104
+	if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil {
105
+		return err
106
+	}
107
+	return os.Chmod(dest, si.Mode())
108
+}

+ 67 - 0
vendor/github.com/Unknwon/cae/zip/read.go

@@ -0,0 +1,67 @@
1
+// Copyright 2013 Unknown
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package zip
16
+
17
+import (
18
+	"archive/zip"
19
+	"os"
20
+	"strings"
21
+)
22
+
23
+// OpenFile is the generalized open call; most users will use Open
24
+// instead. It opens the named zip file with specified flag
25
+// (O_RDONLY etc.) if applicable. If successful,
26
+// methods on the returned ZipArchive can be used for I/O.
27
+// If there is an error, it will be of type *PathError.
28
+func (z *ZipArchive) Open(name string, flag int, perm os.FileMode) error {
29
+	// Create a new archive if it's specified and not exist.
30
+	if flag&os.O_CREATE != 0 {
31
+		f, err := os.Create(name)
32
+		if err != nil {
33
+			return err
34
+		}
35
+		zw := zip.NewWriter(f)
36
+		if err = zw.Close(); err != nil {
37
+			return err
38
+		}
39
+	}
40
+
41
+	rc, err := zip.OpenReader(name)
42
+	if err != nil {
43
+		return err
44
+	}
45
+
46
+	z.ReadCloser = rc
47
+	z.FileName = name
48
+	z.Comment = rc.Comment
49
+	z.NumFiles = len(rc.File)
50
+	z.Flag = flag
51
+	z.Permission = perm
52
+	z.isHasChanged = false
53
+
54
+	z.files = make([]*File, z.NumFiles)
55
+	for i, f := range rc.File {
56
+		z.files[i] = &File{}
57
+		z.files[i].FileHeader, err = zip.FileInfoHeader(f.FileInfo())
58
+		if err != nil {
59
+			return err
60
+		}
61
+		z.files[i].Name = strings.Replace(f.Name, "\\", "/", -1)
62
+		if f.FileInfo().IsDir() && !strings.HasSuffix(z.files[i].Name, "/") {
63
+			z.files[i].Name += "/"
64
+		}
65
+	}
66
+	return nil
67
+}

+ 77 - 0
vendor/github.com/Unknwon/cae/zip/stream.go

@@ -0,0 +1,77 @@
1
+// Copyright 2014 Unknown
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package zip
16
+
17
+import (
18
+	"archive/zip"
19
+	"io"
20
+	"os"
21
+	"path/filepath"
22
+)
23
+
24
+// A StreamArchive represents a streamable archive.
25
+type StreamArchive struct {
26
+	*zip.Writer
27
+}
28
+
29
+// NewStreamArachive returns a new streamable archive with given io.Writer.
30
+// It's caller's responsibility to close io.Writer and streamer after operation.
31
+func NewStreamArachive(w io.Writer) *StreamArchive {
32
+	return &StreamArchive{zip.NewWriter(w)}
33
+}
34
+
35
+// StreamFile streams a file or directory entry into StreamArchive.
36
+func (s *StreamArchive) StreamFile(relPath string, fi os.FileInfo, data []byte) error {
37
+	if fi.IsDir() {
38
+		fh, err := zip.FileInfoHeader(fi)
39
+		if err != nil {
40
+			return err
41
+		}
42
+		fh.Name = relPath + "/"
43
+		if _, err = s.Writer.CreateHeader(fh); err != nil {
44
+			return err
45
+		}
46
+	} else {
47
+		fh, err := zip.FileInfoHeader(fi)
48
+		if err != nil {
49
+			return err
50
+		}
51
+		fh.Name = filepath.Join(relPath, fi.Name())
52
+		fh.Method = zip.Deflate
53
+		fw, err := s.Writer.CreateHeader(fh)
54
+		if err != nil {
55
+			return err
56
+		} else if _, err = fw.Write(data); err != nil {
57
+			return err
58
+		}
59
+	}
60
+	return nil
61
+}
62
+
63
+// StreamReader streams data from io.Reader to StreamArchive.
64
+func (s *StreamArchive) StreamReader(relPath string, fi os.FileInfo, r io.Reader) (err error) {
65
+	fh, err := zip.FileInfoHeader(fi)
66
+	if err != nil {
67
+		return err
68
+	}
69
+	fh.Name = filepath.Join(relPath, fi.Name())
70
+
71
+	fw, err := s.Writer.CreateHeader(fh)
72
+	if err != nil {
73
+		return err
74
+	}
75
+	_, err = io.Copy(fw, r)
76
+	return err
77
+}

+ 364 - 0
vendor/github.com/Unknwon/cae/zip/write.go

@@ -0,0 +1,364 @@
1
+// Copyright 2013 Unknown
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package zip
16
+
17
+import (
18
+	"archive/zip"
19
+	"fmt"
20
+	"io"
21
+	"os"
22
+	"path"
23
+	"path/filepath"
24
+	"strings"
25
+
26
+	"github.com/Unknwon/cae"
27
+)
28
+
29
+// Switcher of printing trace information when pack and extract.
30
+var Verbose = true
31
+
32
+// extractFile extracts zip.File to file system.
33
+func extractFile(f *zip.File, destPath string) error {
34
+	filePath := path.Join(destPath, f.Name)
35
+	os.MkdirAll(path.Dir(filePath), os.ModePerm)
36
+
37
+	rc, err := f.Open()
38
+	if err != nil {
39
+		return err
40
+	}
41
+	defer rc.Close()
42
+
43
+	fw, err := os.Create(filePath)
44
+	if err != nil {
45
+		return err
46
+	}
47
+	defer fw.Close()
48
+
49
+	if _, err = io.Copy(fw, rc); err != nil {
50
+		return err
51
+	}
52
+
53
+	// Skip symbolic links.
54
+	if f.FileInfo().Mode()&os.ModeSymlink != 0 {
55
+		return nil
56
+	}
57
+	// Set back file information.
58
+	if err = os.Chtimes(filePath, f.ModTime(), f.ModTime()); err != nil {
59
+		return err
60
+	}
61
+	return os.Chmod(filePath, f.FileInfo().Mode())
62
+}
63
+
64
+var defaultExtractFunc = func(fullName string, fi os.FileInfo) error {
65
+	if !Verbose {
66
+		return nil
67
+	}
68
+
69
+	fmt.Println("Extracting file..." + fullName)
70
+	return nil
71
+}
72
+
73
+// ExtractToFunc extracts the whole archive or the given files to the
74
+// specified destination.
75
+// It accepts a function as a middleware for custom operations.
76
+func (z *ZipArchive) ExtractToFunc(destPath string, fn cae.HookFunc, entries ...string) (err error) {
77
+	destPath = strings.Replace(destPath, "\\", "/", -1)
78
+	isHasEntry := len(entries) > 0
79
+	if Verbose {
80
+		fmt.Println("Unzipping " + z.FileName + "...")
81
+	}
82
+	os.MkdirAll(destPath, os.ModePerm)
83
+	for _, f := range z.File {
84
+		f.Name = strings.Replace(f.Name, "\\", "/", -1)
85
+
86
+		// Directory.
87
+		if strings.HasSuffix(f.Name, "/") {
88
+			if isHasEntry {
89
+				if cae.IsEntry(f.Name, entries) {
90
+					if err = fn(f.Name, f.FileInfo()); err != nil {
91
+						continue
92
+					}
93
+					os.MkdirAll(path.Join(destPath, f.Name), os.ModePerm)
94
+				}
95
+				continue
96
+			}
97
+			if err = fn(f.Name, f.FileInfo()); err != nil {
98
+				continue
99
+			}
100
+			os.MkdirAll(path.Join(destPath, f.Name), os.ModePerm)
101
+			continue
102
+		}
103
+
104
+		// File.
105
+		if isHasEntry {
106
+			if cae.IsEntry(f.Name, entries) {
107
+				if err = fn(f.Name, f.FileInfo()); err != nil {
108
+					continue
109
+				}
110
+				err = extractFile(f, destPath)
111
+			}
112
+		} else {
113
+			if err = fn(f.Name, f.FileInfo()); err != nil {
114
+				continue
115
+			}
116
+			err = extractFile(f, destPath)
117
+		}
118
+		if err != nil {
119
+			return err
120
+		}
121
+	}
122
+	return nil
123
+}
124
+
125
+// ExtractToFunc extracts the whole archive or the given files to the
126
+// specified destination.
127
+// It accepts a function as a middleware for custom operations.
128
+func ExtractToFunc(srcPath, destPath string, fn cae.HookFunc, entries ...string) (err error) {
129
+	z, err := Open(srcPath)
130
+	if err != nil {
131
+		return err
132
+	}
133
+	defer z.Close()
134
+	return z.ExtractToFunc(destPath, fn, entries...)
135
+}
136
+
137
+// ExtractTo extracts the whole archive or the given files to the
138
+// specified destination.
139
+// Call Flush() to apply changes before this.
140
+func (z *ZipArchive) ExtractTo(destPath string, entries ...string) (err error) {
141
+	return z.ExtractToFunc(destPath, defaultExtractFunc, entries...)
142
+}
143
+
144
+// ExtractTo extracts given archive or the given files to the
145
+// specified destination.
146
+func ExtractTo(srcPath, destPath string, entries ...string) (err error) {
147
+	return ExtractToFunc(srcPath, destPath, defaultExtractFunc, entries...)
148
+}
149
+
150
+// extractFile extracts file from ZipArchive to file system.
151
+func (z *ZipArchive) extractFile(f *File) error {
152
+	if !z.isHasWriter {
153
+		for _, zf := range z.ReadCloser.File {
154
+			if f.Name == zf.Name {
155
+				return extractFile(zf, path.Dir(f.tmpPath))
156
+			}
157
+		}
158
+	}
159
+	return cae.Copy(f.tmpPath, f.absPath)
160
+}
161
+
162
+// Flush saves changes to original zip file if any.
163
+func (z *ZipArchive) Flush() error {
164
+	if !z.isHasChanged || (z.ReadCloser == nil && !z.isHasWriter) {
165
+		return nil
166
+	}
167
+
168
+	// Extract to tmp path and pack back.
169
+	tmpPath := path.Join(os.TempDir(), "cae", path.Base(z.FileName))
170
+	os.RemoveAll(tmpPath)
171
+	defer os.RemoveAll(tmpPath)
172
+
173
+	for _, f := range z.files {
174
+		if strings.HasSuffix(f.Name, "/") {
175
+			os.MkdirAll(path.Join(tmpPath, f.Name), os.ModePerm)
176
+			continue
177
+		}
178
+
179
+		// Relative path inside zip temporary changed.
180
+		f.tmpPath = path.Join(tmpPath, f.Name)
181
+		if err := z.extractFile(f); err != nil {
182
+			return err
183
+		}
184
+	}
185
+
186
+	if z.isHasWriter {
187
+		return packToWriter(tmpPath, z.writer, defaultPackFunc, true)
188
+	}
189
+
190
+	if err := PackTo(tmpPath, z.FileName); err != nil {
191
+		return err
192
+	}
193
+	return z.Open(z.FileName, os.O_RDWR|os.O_TRUNC, z.Permission)
194
+}
195
+
196
+// packFile packs a file or directory to zip.Writer.
197
+func packFile(srcFile string, recPath string, zw *zip.Writer, fi os.FileInfo) error {
198
+	if fi.IsDir() {
199
+		fh, err := zip.FileInfoHeader(fi)
200
+		if err != nil {
201
+			return err
202
+		}
203
+		fh.Name = recPath + "/"
204
+		if _, err = zw.CreateHeader(fh); err != nil {
205
+			return err
206
+		}
207
+	} else {
208
+		fh, err := zip.FileInfoHeader(fi)
209
+		if err != nil {
210
+			return err
211
+		}
212
+		fh.Name = recPath
213
+		fh.Method = zip.Deflate
214
+
215
+		fw, err := zw.CreateHeader(fh)
216
+		if err != nil {
217
+			return err
218
+		}
219
+
220
+		if fi.Mode()&os.ModeSymlink != 0 {
221
+			target, err := os.Readlink(srcFile)
222
+			if err != nil {
223
+				return err
224
+			}
225
+			if _, err = fw.Write([]byte(target)); err != nil {
226
+				return err
227
+			}
228
+		} else {
229
+			f, err := os.Open(srcFile)
230
+			if err != nil {
231
+				return err
232
+			}
233
+			defer f.Close()
234
+			
235
+			if _, err = io.Copy(fw, f); err != nil {
236
+				return err
237
+			}
238
+		}
239
+	}
240
+	return nil
241
+}
242
+
243
+// packDir packs a directory and its subdirectories and files
244
+// recursively to zip.Writer.
245
+func packDir(srcPath string, recPath string, zw *zip.Writer, fn cae.HookFunc) error {
246
+	dir, err := os.Open(srcPath)
247
+	if err != nil {
248
+		return err
249
+	}
250
+	defer dir.Close()
251
+
252
+	fis, err := dir.Readdir(0)
253
+	if err != nil {
254
+		return err
255
+	}
256
+	for _, fi := range fis {
257
+		if cae.IsFilter(fi.Name()) {
258
+			continue
259
+		}
260
+		curPath := srcPath + "/" + fi.Name()
261
+		tmpRecPath := filepath.Join(recPath, fi.Name())
262
+		if err = fn(curPath, fi); err != nil {
263
+			continue
264
+		}
265
+
266
+		if fi.IsDir() {
267
+			if err = packFile(srcPath, tmpRecPath, zw, fi); err != nil {
268
+				return err
269
+			}
270
+			err = packDir(curPath, tmpRecPath, zw, fn)
271
+		} else {
272
+			err = packFile(curPath, tmpRecPath, zw, fi)
273
+		}
274
+		if err != nil {
275
+			return err
276
+		}
277
+	}
278
+	return nil
279
+}
280
+
281
+// packToWriter packs given path object to io.Writer.
282
+func packToWriter(srcPath string, w io.Writer, fn func(fullName string, fi os.FileInfo) error, includeDir bool) error {
283
+	zw := zip.NewWriter(w)
284
+	defer zw.Close()
285
+
286
+	f, err := os.Open(srcPath)
287
+	if err != nil {
288
+		return err
289
+	}
290
+	defer f.Close()
291
+
292
+	fi, err := f.Stat()
293
+	if err != nil {
294
+		return err
295
+	}
296
+
297
+	basePath := path.Base(srcPath)
298
+	if fi.IsDir() {
299
+		if includeDir {
300
+			if err = packFile(srcPath, basePath, zw, fi); err != nil {
301
+				return err
302
+			}
303
+		} else {
304
+			basePath = ""
305
+		}
306
+		return packDir(srcPath, basePath, zw, fn)
307
+	}
308
+	return packFile(srcPath, basePath, zw, fi)
309
+}
310
+
311
+// packTo packs given source path object to target path.
312
+func packTo(srcPath, destPath string, fn cae.HookFunc, includeDir bool) error {
313
+	fw, err := os.Create(destPath)
314
+	if err != nil {
315
+		return err
316
+	}
317
+	defer fw.Close()
318
+
319
+	return packToWriter(srcPath, fw, fn, includeDir)
320
+}
321
+
322
+// PackToFunc packs the complete archive to the specified destination.
323
+// It accepts a function as a middleware for custom operations.
324
+func PackToFunc(srcPath, destPath string, fn func(fullName string, fi os.FileInfo) error, includeDir ...bool) error {
325
+	isIncludeDir := false
326
+	if len(includeDir) > 0 && includeDir[0] {
327
+		isIncludeDir = true
328
+	}
329
+	return packTo(srcPath, destPath, fn, isIncludeDir)
330
+}
331
+
332
+var defaultPackFunc = func(fullName string, fi os.FileInfo) error {
333
+	if !Verbose {
334
+		return nil
335
+	}
336
+
337
+	if fi.IsDir() {
338
+		fmt.Printf("Adding dir...%s\n", fullName)
339
+	} else {
340
+		fmt.Printf("Adding file...%s\n", fullName)
341
+	}
342
+	return nil
343
+}
344
+
345
+// PackTo packs the whole archive to the specified destination.
346
+// Call Flush() will automatically call this in the end.
347
+func PackTo(srcPath, destPath string, includeDir ...bool) error {
348
+	return PackToFunc(srcPath, destPath, defaultPackFunc, includeDir...)
349
+}
350
+
351
+// Close opens or creates archive and save changes.
352
+func (z *ZipArchive) Close() (err error) {
353
+	if err = z.Flush(); err != nil {
354
+		return err
355
+	}
356
+
357
+	if z.ReadCloser != nil {
358
+		if err = z.ReadCloser.Close(); err != nil {
359
+			return err
360
+		}
361
+		z.ReadCloser = nil
362
+	}
363
+	return nil
364
+}

+ 238 - 0
vendor/github.com/Unknwon/cae/zip/zip.go

@@ -0,0 +1,238 @@
1
+// Copyright 2013 Unknown
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+// Package zip enables you to transparently read or write ZIP compressed archives and the files inside them.
16
+package zip
17
+
18
+import (
19
+	"archive/zip"
20
+	"errors"
21
+	"io"
22
+	"os"
23
+	"path"
24
+	"strings"
25
+
26
+	"github.com/Unknwon/cae"
27
+)
28
+
29
+// A File represents a file or directory entry in archive.
30
+type File struct {
31
+	*zip.FileHeader
32
+	oldName    string // NOTE: unused, for future change name feature.
33
+	oldComment string // NOTE: unused, for future change comment feature.
34
+	absPath    string // Absolute path of local file system.
35
+	tmpPath    string
36
+}
37
+
38
+// A ZipArchive represents a file archive, compressed with Zip.
39
+type ZipArchive struct {
40
+	*zip.ReadCloser
41
+	FileName   string
42
+	Comment    string
43
+	NumFiles   int
44
+	Flag       int
45
+	Permission os.FileMode
46
+
47
+	files        []*File
48
+	isHasChanged bool
49
+
50
+	// For supporting flushing to io.Writer.
51
+	writer      io.Writer
52
+	isHasWriter bool
53
+}
54
+
55
+// OpenFile is the generalized open call; most users will use Open
56
+// instead. It opens the named zip file with specified flag
57
+// (O_RDONLY etc.) if applicable. If successful,
58
+// methods on the returned ZipArchive can be used for I/O.
59
+// If there is an error, it will be of type *PathError.
60
+func OpenFile(name string, flag int, perm os.FileMode) (*ZipArchive, error) {
61
+	z := new(ZipArchive)
62
+	err := z.Open(name, flag, perm)
63
+	return z, err
64
+}
65
+
66
+// Create creates the named zip file, truncating
67
+// it if it already exists. If successful, methods on the returned
68
+// ZipArchive can be used for I/O; the associated file descriptor has mode
69
+// O_RDWR.
70
+// If there is an error, it will be of type *PathError.
71
+func Create(name string) (*ZipArchive, error) {
72
+	os.MkdirAll(path.Dir(name), os.ModePerm)
73
+	return OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
74
+}
75
+
76
+// Open opens the named zip file for reading. If successful, methods on
77
+// the returned ZipArchive can be used for reading; the associated file
78
+// descriptor has mode O_RDONLY.
79
+// If there is an error, it will be of type *PathError.
80
+func Open(name string) (*ZipArchive, error) {
81
+	return OpenFile(name, os.O_RDONLY, 0)
82
+}
83
+
84
+// New accepts a variable that implemented interface io.Writer
85
+// for write-only purpose operations.
86
+func New(w io.Writer) *ZipArchive {
87
+	return &ZipArchive{
88
+		writer:      w,
89
+		isHasWriter: true,
90
+	}
91
+}
92
+
93
+// List returns a string slice of files' name in ZipArchive.
94
+// Specify prefixes will be used as filters.
95
+func (z *ZipArchive) List(prefixes ...string) []string {
96
+	isHasPrefix := len(prefixes) > 0
97
+	names := make([]string, 0, z.NumFiles)
98
+	for _, f := range z.files {
99
+		if isHasPrefix && !cae.HasPrefix(f.Name, prefixes) {
100
+			continue
101
+		}
102
+		names = append(names, f.Name)
103
+	}
104
+	return names
105
+}
106
+
107
+// AddEmptyDir adds a raw directory entry to ZipArchive,
108
+// it returns false if same directory enry already existed.
109
+func (z *ZipArchive) AddEmptyDir(dirPath string) bool {
110
+	dirPath = strings.Replace(dirPath, "\\", "/", -1)
111
+
112
+	if !strings.HasSuffix(dirPath, "/") {
113
+		dirPath += "/"
114
+	}
115
+
116
+	for _, f := range z.files {
117
+		if dirPath == f.Name {
118
+			return false
119
+		}
120
+	}
121
+
122
+	dirPath = strings.TrimSuffix(dirPath, "/")
123
+	if strings.Contains(dirPath, "/") {
124
+		// Auto add all upper level directories.
125
+		z.AddEmptyDir(path.Dir(dirPath))
126
+	}
127
+	z.files = append(z.files, &File{
128
+		FileHeader: &zip.FileHeader{
129
+			Name:             dirPath + "/",
130
+			UncompressedSize: 0,
131
+		},
132
+	})
133
+	z.updateStat()
134
+	return true
135
+}
136
+
137
+// AddDir adds a directory and subdirectories entries to ZipArchive.
138
+func (z *ZipArchive) AddDir(dirPath, absPath string) error {
139
+	dir, err := os.Open(absPath)
140
+	if err != nil {
141
+		return err
142
+	}
143
+	defer dir.Close()
144
+
145
+	// Make sure we have all upper level directories.
146
+	z.AddEmptyDir(dirPath)
147
+
148
+	fis, err := dir.Readdir(0)
149
+	if err != nil {
150
+		return err
151
+	}
152
+	for _, fi := range fis {
153
+		curPath := absPath + "/" + fi.Name()
154
+		tmpRecPath := path.Join(dirPath, fi.Name())
155
+		if fi.IsDir() {
156
+			if err = z.AddDir(tmpRecPath, curPath); err != nil {
157
+				return err
158
+			}
159
+		} else {
160
+			if err = z.AddFile(tmpRecPath, curPath); err != nil {
161
+				return err
162
+			}
163
+		}
164
+	}
165
+	return nil
166
+}
167
+
168
+// updateStat should be called after every change for rebuilding statistic.
169
+func (z *ZipArchive) updateStat() {
170
+	z.NumFiles = len(z.files)
171
+	z.isHasChanged = true
172
+}
173
+
174
+// AddFile adds a file entry to ZipArchive.
175
+func (z *ZipArchive) AddFile(fileName, absPath string) error {
176
+	fileName = strings.Replace(fileName, "\\", "/", -1)
177
+	absPath = strings.Replace(absPath, "\\", "/", -1)
178
+
179
+	if cae.IsFilter(absPath) {
180
+		return nil
181
+	}
182
+
183
+	f, err := os.Open(absPath)
184
+	if err != nil {
185
+		return err
186
+	}
187
+	defer f.Close()
188
+
189
+	fi, err := f.Stat()
190
+	if err != nil {
191
+		return err
192
+	}
193
+
194
+	file := new(File)
195
+	file.FileHeader, err = zip.FileInfoHeader(fi)
196
+	if err != nil {
197
+		return err
198
+	}
199
+	file.Name = fileName
200
+	file.absPath = absPath
201
+
202
+	z.AddEmptyDir(path.Dir(fileName))
203
+
204
+	isExist := false
205
+	for _, f := range z.files {
206
+		if fileName == f.Name {
207
+			f = file
208
+			isExist = true
209
+			break
210
+		}
211
+	}
212
+	if !isExist {
213
+		z.files = append(z.files, file)
214
+	}
215
+
216
+	z.updateStat()
217
+	return nil
218
+}
219
+
220
+// DeleteIndex deletes an entry in the archive by its index.
221
+func (z *ZipArchive) DeleteIndex(idx int) error {
222
+	if idx >= z.NumFiles {
223
+		return errors.New("index out of range of number of files")
224
+	}
225
+
226
+	z.files = append(z.files[:idx], z.files[idx+1:]...)
227
+	return nil
228
+}
229
+
230
+// DeleteName deletes an entry in the archive by its name.
231
+func (z *ZipArchive) DeleteName(name string) error {
232
+	for i, f := range z.files {
233
+		if f.Name == name {
234
+			return z.DeleteIndex(i)
235
+		}
236
+	}
237
+	return errors.New("entry with given name not found")
238
+}

+ 191 - 0
vendor/github.com/Unknwon/com/LICENSE

@@ -0,0 +1,191 @@
1
+Apache License
2
+Version 2.0, January 2004
3
+http://www.apache.org/licenses/
4
+
5
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+1. Definitions.
8
+
9
+"License" shall mean the terms and conditions for use, reproduction, and
10
+distribution as defined by Sections 1 through 9 of this document.
11
+
12
+"Licensor" shall mean the copyright owner or entity authorized by the copyright
13
+owner that is granting the License.
14
+
15
+"Legal Entity" shall mean the union of the acting entity and all other entities
16
+that control, are controlled by, or are under common control with that entity.
17
+For the purposes of this definition, "control" means (i) the power, direct or
18
+indirect, to cause the direction or management of such entity, whether by
19
+contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20
+outstanding shares, or (iii) beneficial ownership of such entity.
21
+
22
+"You" (or "Your") shall mean an individual or Legal Entity exercising
23
+permissions granted by this License.
24
+
25
+"Source" form shall mean the preferred form for making modifications, including
26
+but not limited to software source code, documentation source, and configuration
27
+files.
28
+
29
+"Object" form shall mean any form resulting from mechanical transformation or
30
+translation of a Source form, including but not limited to compiled object code,
31
+generated documentation, and conversions to other media types.
32
+
33
+"Work" shall mean the work of authorship, whether in Source or Object form, made
34
+available under the License, as indicated by a copyright notice that is included
35
+in or attached to the work (an example is provided in the Appendix below).
36
+
37
+"Derivative Works" shall mean any work, whether in Source or Object form, that
38
+is based on (or derived from) the Work and for which the editorial revisions,
39
+annotations, elaborations, or other modifications represent, as a whole, an
40
+original work of authorship. For the purposes of this License, Derivative Works
41
+shall not include works that remain separable from, or merely link (or bind by
42
+name) to the interfaces of, the Work and Derivative Works thereof.
43
+
44
+"Contribution" shall mean any work of authorship, including the original version
45
+of the Work and any modifications or additions to that Work or Derivative Works
46
+thereof, that is intentionally submitted to Licensor for inclusion in the Work
47
+by the copyright owner or by an individual or Legal Entity authorized to submit
48
+on behalf of the copyright owner. For the purposes of this definition,
49
+"submitted" means any form of electronic, verbal, or written communication sent
50
+to the Licensor or its representatives, including but not limited to
51
+communication on electronic mailing lists, source code control systems, and
52
+issue tracking systems that are managed by, or on behalf of, the Licensor for
53
+the purpose of discussing and improving the Work, but excluding communication
54
+that is conspicuously marked or otherwise designated in writing by the copyright
55
+owner as "Not a Contribution."
56
+
57
+"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58
+of whom a Contribution has been received by Licensor and subsequently
59
+incorporated within the Work.
60
+
61
+2. Grant of Copyright License.
62
+
63
+Subject to the terms and conditions of this License, each Contributor hereby
64
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65
+irrevocable copyright license to reproduce, prepare Derivative Works of,
66
+publicly display, publicly perform, sublicense, and distribute the Work and such
67
+Derivative Works in Source or Object form.
68
+
69
+3. Grant of Patent License.
70
+
71
+Subject to the terms and conditions of this License, each Contributor hereby
72
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73
+irrevocable (except as stated in this section) patent license to make, have
74
+made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75
+such license applies only to those patent claims licensable by such Contributor
76
+that are necessarily infringed by their Contribution(s) alone or by combination
77
+of their Contribution(s) with the Work to which such Contribution(s) was
78
+submitted. If You institute patent litigation against any entity (including a
79
+cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80
+Contribution incorporated within the Work constitutes direct or contributory
81
+patent infringement, then any patent licenses granted to You under this License
82
+for that Work shall terminate as of the date such litigation is filed.
83
+
84
+4. Redistribution.
85
+
86
+You may reproduce and distribute copies of the Work or Derivative Works thereof
87
+in any medium, with or without modifications, and in Source or Object form,
88
+provided that You meet the following conditions:
89
+
90
+You must give any other recipients of the Work or Derivative Works a copy of
91
+this License; and
92
+You must cause any modified files to carry prominent notices stating that You
93
+changed the files; and
94
+You must retain, in the Source form of any Derivative Works that You distribute,
95
+all copyright, patent, trademark, and attribution notices from the Source form
96
+of the Work, excluding those notices that do not pertain to any part of the
97
+Derivative Works; and
98
+If the Work includes a "NOTICE" text file as part of its distribution, then any
99
+Derivative Works that You distribute must include a readable copy of the
100
+attribution notices contained within such NOTICE file, excluding those notices
101
+that do not pertain to any part of the Derivative Works, in at least one of the
102
+following places: within a NOTICE text file distributed as part of the
103
+Derivative Works; within the Source form or documentation, if provided along
104
+with the Derivative Works; or, within a display generated by the Derivative
105
+Works, if and wherever such third-party notices normally appear. The contents of
106
+the NOTICE file are for informational purposes only and do not modify the
107
+License. You may add Your own attribution notices within Derivative Works that
108
+You distribute, alongside or as an addendum to the NOTICE text from the Work,
109
+provided that such additional attribution notices cannot be construed as
110
+modifying the License.
111
+You may add Your own copyright statement to Your modifications and may provide
112
+additional or different license terms and conditions for use, reproduction, or
113
+distribution of Your modifications, or for any such Derivative Works as a whole,
114
+provided Your use, reproduction, and distribution of the Work otherwise complies
115
+with the conditions stated in this License.
116
+
117
+5. Submission of Contributions.
118
+
119
+Unless You explicitly state otherwise, any Contribution intentionally submitted
120
+for inclusion in the Work by You to the Licensor shall be under the terms and
121
+conditions of this License, without any additional terms or conditions.
122
+Notwithstanding the above, nothing herein shall supersede or modify the terms of
123
+any separate license agreement you may have executed with Licensor regarding
124
+such Contributions.
125
+
126
+6. Trademarks.
127
+
128
+This License does not grant permission to use the trade names, trademarks,
129
+service marks, or product names of the Licensor, except as required for
130
+reasonable and customary use in describing the origin of the Work and
131
+reproducing the content of the NOTICE file.
132
+
133
+7. Disclaimer of Warranty.
134
+
135
+Unless required by applicable law or agreed to in writing, Licensor provides the
136
+Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138
+including, without limitation, any warranties or conditions of TITLE,
139
+NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140
+solely responsible for determining the appropriateness of using or
141
+redistributing the Work and assume any risks associated with Your exercise of
142
+permissions under this License.
143
+
144
+8. Limitation of Liability.
145
+
146
+In no event and under no legal theory, whether in tort (including negligence),
147
+contract, or otherwise, unless required by applicable law (such as deliberate
148
+and grossly negligent acts) or agreed to in writing, shall any Contributor be
149
+liable to You for damages, including any direct, indirect, special, incidental,
150
+or consequential damages of any character arising as a result of this License or
151
+out of the use or inability to use the Work (including but not limited to
152
+damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153
+any and all other commercial damages or losses), even if such Contributor has
154
+been advised of the possibility of such damages.
155
+
156
+9. Accepting Warranty or Additional Liability.
157
+
158
+While redistributing the Work or Derivative Works thereof, You may choose to
159
+offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160
+other liability obligations and/or rights consistent with this License. However,
161
+in accepting such obligations, You may act only on Your own behalf and on Your
162
+sole responsibility, not on behalf of any other Contributor, and only if You
163
+agree to indemnify, defend, and hold each Contributor harmless for any liability
164
+incurred by, or claims asserted against, such Contributor by reason of your
165
+accepting any such warranty or additional liability.
166
+
167
+END OF TERMS AND CONDITIONS
168
+
169
+APPENDIX: How to apply the Apache License to your work
170
+
171
+To apply the Apache License to your work, attach the following boilerplate
172
+notice, with the fields enclosed by brackets "[]" replaced with your own
173
+identifying information. (Don't include the brackets!) The text should be
174
+enclosed in the appropriate comment syntax for the file format. We also
175
+recommend that a file or class name and description of purpose be included on
176
+the same "printed page" as the copyright notice for easier identification within
177
+third-party archives.
178
+
179
+   Copyright [yyyy] [name of copyright owner]
180
+
181
+   Licensed under the Apache License, Version 2.0 (the "License");
182
+   you may not use this file except in compliance with the License.
183
+   You may obtain a copy of the License at
184
+
185
+     http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+   Unless required by applicable law or agreed to in writing, software
188
+   distributed under the License is distributed on an "AS IS" BASIS,
189
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+   See the License for the specific language governing permissions and
191
+   limitations under the License.

+ 20 - 0
vendor/github.com/Unknwon/com/README.md

@@ -0,0 +1,20 @@
1
+Common Functions
2
+================
3
+
4
+[![Build Status](https://travis-ci.org/Unknwon/com.svg)](https://travis-ci.org/Unknwon/com) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/Unknwon/com)
5
+
6
+This is an open source project for commonly used functions for the Go programming language.
7
+
8
+This package need >= **go 1.2**
9
+
10
+Code Convention: based on [Go Code Convention](https://github.com/Unknwon/go-code-convention).
11
+
12
+## Contribute
13
+
14
+Your contribute is welcome, but you have to check following steps after you added some functions and commit them:
15
+
16
+1. Make sure you wrote user-friendly comments for **all functions** .
17
+2. Make sure you wrote test cases with any possible condition for **all functions** in file `*_test.go`.
18
+3. Make sure you wrote benchmarks for **all functions** in file `*_test.go`.
19
+4. Make sure you wrote useful examples for **all functions** in file `example_test.go`.
20
+5. Make sure you ran `go test` and got **PASS** .

+ 161 - 0
vendor/github.com/Unknwon/com/cmd.go

@@ -0,0 +1,161 @@
1
+// +build go1.2
2
+
3
+// Copyright 2013 com authors
4
+//
5
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
6
+// not use this file except in compliance with the License. You may obtain
7
+// a copy of the License at
8
+//
9
+//     http://www.apache.org/licenses/LICENSE-2.0
10
+//
11
+// Unless required by applicable law or agreed to in writing, software
12
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+// License for the specific language governing permissions and limitations
15
+// under the License.
16
+
17
+// Package com is an open source project for commonly used functions for the Go programming language.
18
+package com
19
+
20
+import (
21
+	"bytes"
22
+	"fmt"
23
+	"os/exec"
24
+	"runtime"
25
+	"strings"
26
+)
27
+
28
+// ExecCmdDirBytes executes system command in given directory
29
+// and return stdout, stderr in bytes type, along with possible error.
30
+func ExecCmdDirBytes(dir, cmdName string, args ...string) ([]byte, []byte, error) {
31
+	bufOut := new(bytes.Buffer)
32
+	bufErr := new(bytes.Buffer)
33
+
34
+	cmd := exec.Command(cmdName, args...)
35
+	cmd.Dir = dir
36
+	cmd.Stdout = bufOut
37
+	cmd.Stderr = bufErr
38
+
39
+	err := cmd.Run()
40
+	return bufOut.Bytes(), bufErr.Bytes(), err
41
+}
42
+
43
+// ExecCmdBytes executes system command
44
+// and return stdout, stderr in bytes type, along with possible error.
45
+func ExecCmdBytes(cmdName string, args ...string) ([]byte, []byte, error) {
46
+	return ExecCmdDirBytes("", cmdName, args...)
47
+}
48
+
49
+// ExecCmdDir executes system command in given directory
50
+// and return stdout, stderr in string type, along with possible error.
51
+func ExecCmdDir(dir, cmdName string, args ...string) (string, string, error) {
52
+	bufOut, bufErr, err := ExecCmdDirBytes(dir, cmdName, args...)
53
+	return string(bufOut), string(bufErr), err
54
+}
55
+
56
+// ExecCmd executes system command
57
+// and return stdout, stderr in string type, along with possible error.
58
+func ExecCmd(cmdName string, args ...string) (string, string, error) {
59
+	return ExecCmdDir("", cmdName, args...)
60
+}
61
+
62
+// _________        .__                 .____
63
+// \_   ___ \  ____ |  |   ___________  |    |    ____   ____
64
+// /    \  \/ /  _ \|  |  /  _ \_  __ \ |    |   /  _ \ / ___\
65
+// \     \___(  <_> )  |_(  <_> )  | \/ |    |__(  <_> ) /_/  >
66
+//  \______  /\____/|____/\____/|__|    |_______ \____/\___  /
67
+//         \/                                   \/    /_____/
68
+
69
+// Color number constants.
70
+const (
71
+	Gray = uint8(iota + 90)
72
+	Red
73
+	Green
74
+	Yellow
75
+	Blue
76
+	Magenta
77
+	//NRed      = uint8(31) // Normal
78
+	EndColor = "\033[0m"
79
+)
80
+
81
+// getColorLevel returns colored level string by given level.
82
+func getColorLevel(level string) string {
83
+	level = strings.ToUpper(level)
84
+	switch level {
85
+	case "TRAC":
86
+		return fmt.Sprintf("\033[%dm%s\033[0m", Blue, level)
87
+	case "ERRO":
88
+		return fmt.Sprintf("\033[%dm%s\033[0m", Red, level)
89
+	case "WARN":
90
+		return fmt.Sprintf("\033[%dm%s\033[0m", Magenta, level)
91
+	case "SUCC":
92
+		return fmt.Sprintf("\033[%dm%s\033[0m", Green, level)
93
+	default:
94
+		return level
95
+	}
96
+}
97
+
98
+// ColorLogS colors log and return colored content.
99
+// Log format: <level> <content [highlight][path]> [ error ].
100
+// Level: TRAC -> blue; ERRO -> red; WARN -> Magenta; SUCC -> green; others -> default.
101
+// Content: default; path: yellow; error -> red.
102
+// Level has to be surrounded by "[" and "]".
103
+// Highlights have to be surrounded by "# " and " #"(space), "#" will be deleted.
104
+// Paths have to be surrounded by "( " and " )"(space).
105
+// Errors have to be surrounded by "[ " and " ]"(space).
106
+// Note: it hasn't support windows yet, contribute is welcome.
107
+func ColorLogS(format string, a ...interface{}) string {
108
+	log := fmt.Sprintf(format, a...)
109
+
110
+	var clog string
111
+
112
+	if runtime.GOOS != "windows" {
113
+		// Level.
114
+		i := strings.Index(log, "]")
115
+		if log[0] == '[' && i > -1 {
116
+			clog += "[" + getColorLevel(log[1:i]) + "]"
117
+		}
118
+
119
+		log = log[i+1:]
120
+
121
+		// Error.
122
+		log = strings.Replace(log, "[ ", fmt.Sprintf("[\033[%dm", Red), -1)
123
+		log = strings.Replace(log, " ]", EndColor+"]", -1)
124
+
125
+		// Path.
126
+		log = strings.Replace(log, "( ", fmt.Sprintf("(\033[%dm", Yellow), -1)
127
+		log = strings.Replace(log, " )", EndColor+")", -1)
128
+
129
+		// Highlights.
130
+		log = strings.Replace(log, "# ", fmt.Sprintf("\033[%dm", Gray), -1)
131
+		log = strings.Replace(log, " #", EndColor, -1)
132
+
133
+	} else {
134
+		// Level.
135
+		i := strings.Index(log, "]")
136
+		if log[0] == '[' && i > -1 {
137
+			clog += "[" + log[1:i] + "]"
138
+		}
139
+
140
+		log = log[i+1:]
141
+
142
+		// Error.
143
+		log = strings.Replace(log, "[ ", "[", -1)
144
+		log = strings.Replace(log, " ]", "]", -1)
145
+
146
+		// Path.
147
+		log = strings.Replace(log, "( ", "(", -1)
148
+		log = strings.Replace(log, " )", ")", -1)
149
+
150
+		// Highlights.
151
+		log = strings.Replace(log, "# ", "", -1)
152
+		log = strings.Replace(log, " #", "", -1)
153
+	}
154
+	return clog + log
155
+}
156
+
157
+// ColorLog prints colored log to stdout.
158
+// See color rules in function 'ColorLogS'.
159
+func ColorLog(format string, a ...interface{}) {
160
+	fmt.Print(ColorLogS(format, a...))
161
+}

+ 157 - 0
vendor/github.com/Unknwon/com/convert.go

@@ -0,0 +1,157 @@
1
+// Copyright 2014 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+import (
18
+	"fmt"
19
+	"strconv"
20
+)
21
+
22
+// Convert string to specify type.
23
+type StrTo string
24
+
25
+func (f StrTo) Exist() bool {
26
+	return string(f) != string(0x1E)
27
+}
28
+
29
+func (f StrTo) Uint8() (uint8, error) {
30
+	v, err := strconv.ParseUint(f.String(), 10, 8)
31
+	return uint8(v), err
32
+}
33
+
34
+func (f StrTo) Int() (int, error) {
35
+	v, err := strconv.ParseInt(f.String(), 10, 0)
36
+	return int(v), err
37
+}
38
+
39
+func (f StrTo) Int64() (int64, error) {
40
+	v, err := strconv.ParseInt(f.String(), 10, 64)
41
+	return int64(v), err
42
+}
43
+
44
+func (f StrTo) MustUint8() uint8 {
45
+	v, _ := f.Uint8()
46
+	return v
47
+}
48
+
49
+func (f StrTo) MustInt() int {
50
+	v, _ := f.Int()
51
+	return v
52
+}
53
+
54
+func (f StrTo) MustInt64() int64 {
55
+	v, _ := f.Int64()
56
+	return v
57
+}
58
+
59
+func (f StrTo) String() string {
60
+	if f.Exist() {
61
+		return string(f)
62
+	}
63
+	return ""
64
+}
65
+
66
+// Convert any type to string.
67
+func ToStr(value interface{}, args ...int) (s string) {
68
+	switch v := value.(type) {
69
+	case bool:
70
+		s = strconv.FormatBool(v)
71
+	case float32:
72
+		s = strconv.FormatFloat(float64(v), 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 32))
73
+	case float64:
74
+		s = strconv.FormatFloat(v, 'f', argInt(args).Get(0, -1), argInt(args).Get(1, 64))
75
+	case int:
76
+		s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10))
77
+	case int8:
78
+		s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10))
79
+	case int16:
80
+		s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10))
81
+	case int32:
82
+		s = strconv.FormatInt(int64(v), argInt(args).Get(0, 10))
83
+	case int64:
84
+		s = strconv.FormatInt(v, argInt(args).Get(0, 10))
85
+	case uint:
86
+		s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10))
87
+	case uint8:
88
+		s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10))
89
+	case uint16:
90
+		s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10))
91
+	case uint32:
92
+		s = strconv.FormatUint(uint64(v), argInt(args).Get(0, 10))
93
+	case uint64:
94
+		s = strconv.FormatUint(v, argInt(args).Get(0, 10))
95
+	case string:
96
+		s = v
97
+	case []byte:
98
+		s = string(v)
99
+	default:
100
+		s = fmt.Sprintf("%v", v)
101
+	}
102
+	return s
103
+}
104
+
105
+type argInt []int
106
+
107
+func (a argInt) Get(i int, args ...int) (r int) {
108
+	if i >= 0 && i < len(a) {
109
+		r = a[i]
110
+	} else if len(args) > 0 {
111
+		r = args[0]
112
+	}
113
+	return
114
+}
115
+
116
+// HexStr2int converts hex format string to decimal number.
117
+func HexStr2int(hexStr string) (int, error) {
118
+	num := 0
119
+	length := len(hexStr)
120
+	for i := 0; i < length; i++ {
121
+		char := hexStr[length-i-1]
122
+		factor := -1
123
+
124
+		switch {
125
+		case char >= '0' && char <= '9':
126
+			factor = int(char) - '0'
127
+		case char >= 'a' && char <= 'f':
128
+			factor = int(char) - 'a' + 10
129
+		default:
130
+			return -1, fmt.Errorf("invalid hex: %s", string(char))
131
+		}
132
+
133
+		num += factor * PowInt(16, i)
134
+	}
135
+	return num, nil
136
+}
137
+
138
+// Int2HexStr converts decimal number to hex format string.
139
+func Int2HexStr(num int) (hex string) {
140
+	if num == 0 {
141
+		return "0"
142
+	}
143
+
144
+	for num > 0 {
145
+		r := num % 16
146
+
147
+		c := "?"
148
+		if r >= 0 && r <= 9 {
149
+			c = string(r + '0')
150
+		} else {
151
+			c = string(r + 'a' - 10)
152
+		}
153
+		hex = c + hex
154
+		num = num / 16
155
+	}
156
+	return hex
157
+}

+ 173 - 0
vendor/github.com/Unknwon/com/dir.go

@@ -0,0 +1,173 @@
1
+// Copyright 2013 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+import (
18
+	"errors"
19
+	"fmt"
20
+	"os"
21
+	"path"
22
+	"strings"
23
+)
24
+
25
+// IsDir returns true if given path is a directory,
26
+// or returns false when it's a file or does not exist.
27
+func IsDir(dir string) bool {
28
+	f, e := os.Stat(dir)
29
+	if e != nil {
30
+		return false
31
+	}
32
+	return f.IsDir()
33
+}
34
+
35
+func statDir(dirPath, recPath string, includeDir, isDirOnly bool) ([]string, error) {
36
+	dir, err := os.Open(dirPath)
37
+	if err != nil {
38
+		return nil, err
39
+	}
40
+	defer dir.Close()
41
+
42
+	fis, err := dir.Readdir(0)
43
+	if err != nil {
44
+		return nil, err
45
+	}
46
+
47
+	statList := make([]string, 0)
48
+	for _, fi := range fis {
49
+		if strings.Contains(fi.Name(), ".DS_Store") {
50
+			continue
51
+		}
52
+
53
+		relPath := path.Join(recPath, fi.Name())
54
+		curPath := path.Join(dirPath, fi.Name())
55
+		if fi.IsDir() {
56
+			if includeDir {
57
+				statList = append(statList, relPath+"/")
58
+			}
59
+			s, err := statDir(curPath, relPath, includeDir, isDirOnly)
60
+			if err != nil {
61
+				return nil, err
62
+			}
63
+			statList = append(statList, s...)
64
+		} else if !isDirOnly {
65
+			statList = append(statList, relPath)
66
+		}
67
+	}
68
+	return statList, nil
69
+}
70
+
71
+// StatDir gathers information of given directory by depth-first.
72
+// It returns slice of file list and includes subdirectories if enabled;
73
+// it returns error and nil slice when error occurs in underlying functions,
74
+// or given path is not a directory or does not exist.
75
+//
76
+// Slice does not include given path itself.
77
+// If subdirectories is enabled, they will have suffix '/'.
78
+func StatDir(rootPath string, includeDir ...bool) ([]string, error) {
79
+	if !IsDir(rootPath) {
80
+		return nil, errors.New("not a directory or does not exist: " + rootPath)
81
+	}
82
+
83
+	isIncludeDir := false
84
+	if len(includeDir) >= 1 {
85
+		isIncludeDir = includeDir[0]
86
+	}
87
+	return statDir(rootPath, "", isIncludeDir, false)
88
+}
89
+
90
+// GetAllSubDirs returns all subdirectories of given root path.
91
+// Slice does not include given path itself.
92
+func GetAllSubDirs(rootPath string) ([]string, error) {
93
+	if !IsDir(rootPath) {
94
+		return nil, errors.New("not a directory or does not exist: " + rootPath)
95
+	}
96
+	return statDir(rootPath, "", true, true)
97
+}
98
+
99
+// GetFileListBySuffix returns an ordered list of file paths.
100
+// It recognize if given path is a file, and don't do recursive find.
101
+func GetFileListBySuffix(dirPath, suffix string) ([]string, error) {
102
+	if !IsExist(dirPath) {
103
+		return nil, fmt.Errorf("given path does not exist: %s", dirPath)
104
+	} else if IsFile(dirPath) {
105
+		return []string{dirPath}, nil
106
+	}
107
+
108
+	// Given path is a directory.
109
+	dir, err := os.Open(dirPath)
110
+	if err != nil {
111
+		return nil, err
112
+	}
113
+
114
+	fis, err := dir.Readdir(0)
115
+	if err != nil {
116
+		return nil, err
117
+	}
118
+
119
+	files := make([]string, 0, len(fis))
120
+	for _, fi := range fis {
121
+		if strings.HasSuffix(fi.Name(), suffix) {
122
+			files = append(files, path.Join(dirPath, fi.Name()))
123
+		}
124
+	}
125
+
126
+	return files, nil
127
+}
128
+
129
+// CopyDir copy files recursively from source to target directory.
130
+//
131
+// The filter accepts a function that process the path info.
132
+// and should return true for need to filter.
133
+//
134
+// It returns error when error occurs in underlying functions.
135
+func CopyDir(srcPath, destPath string, filters ...func(filePath string) bool) error {
136
+	// Check if target directory exists.
137
+	if IsExist(destPath) {
138
+		return errors.New("file or directory alreay exists: " + destPath)
139
+	}
140
+
141
+	err := os.MkdirAll(destPath, os.ModePerm)
142
+	if err != nil {
143
+		return err
144
+	}
145
+
146
+	// Gather directory info.
147
+	infos, err := StatDir(srcPath, true)
148
+	if err != nil {
149
+		return err
150
+	}
151
+
152
+	var filter func(filePath string) bool
153
+	if len(filters) > 0 {
154
+		filter = filters[0]
155
+	}
156
+
157
+	for _, info := range infos {
158
+		if filter != nil && filter(info) {
159
+			continue
160
+		}
161
+
162
+		curPath := path.Join(destPath, info)
163
+		if strings.HasSuffix(info, "/") {
164
+			err = os.MkdirAll(curPath, os.ModePerm)
165
+		} else {
166
+			err = Copy(path.Join(srcPath, info), curPath)
167
+		}
168
+		if err != nil {
169
+			return err
170
+		}
171
+	}
172
+	return nil
173
+}

+ 145 - 0
vendor/github.com/Unknwon/com/file.go

@@ -0,0 +1,145 @@
1
+// Copyright 2013 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+import (
18
+	"fmt"
19
+	"io"
20
+	"io/ioutil"
21
+	"math"
22
+	"os"
23
+	"path"
24
+)
25
+
26
+// Storage unit constants.
27
+const (
28
+	Byte  = 1
29
+	KByte = Byte * 1024
30
+	MByte = KByte * 1024
31
+	GByte = MByte * 1024
32
+	TByte = GByte * 1024
33
+	PByte = TByte * 1024
34
+	EByte = PByte * 1024
35
+)
36
+
37
+func logn(n, b float64) float64 {
38
+	return math.Log(n) / math.Log(b)
39
+}
40
+
41
+func humanateBytes(s uint64, base float64, sizes []string) string {
42
+	if s < 10 {
43
+		return fmt.Sprintf("%dB", s)
44
+	}
45
+	e := math.Floor(logn(float64(s), base))
46
+	suffix := sizes[int(e)]
47
+	val := float64(s) / math.Pow(base, math.Floor(e))
48
+	f := "%.0f"
49
+	if val < 10 {
50
+		f = "%.1f"
51
+	}
52
+
53
+	return fmt.Sprintf(f+"%s", val, suffix)
54
+}
55
+
56
+// HumaneFileSize calculates the file size and generate user-friendly string.
57
+func HumaneFileSize(s uint64) string {
58
+	sizes := []string{"B", "KB", "MB", "GB", "TB", "PB", "EB"}
59
+	return humanateBytes(s, 1024, sizes)
60
+}
61
+
62
+// FileMTime returns file modified time and possible error.
63
+func FileMTime(file string) (int64, error) {
64
+	f, err := os.Stat(file)
65
+	if err != nil {
66
+		return 0, err
67
+	}
68
+	return f.ModTime().Unix(), nil
69
+}
70
+
71
+// FileSize returns file size in bytes and possible error.
72
+func FileSize(file string) (int64, error) {
73
+	f, err := os.Stat(file)
74
+	if err != nil {
75
+		return 0, err
76
+	}
77
+	return f.Size(), nil
78
+}
79
+
80
+// Copy copies file from source to target path.
81
+func Copy(src, dest string) error {
82
+	// Gather file information to set back later.
83
+	si, err := os.Lstat(src)
84
+	if err != nil {
85
+		return err
86
+	}
87
+
88
+	// Handle symbolic link.
89
+	if si.Mode()&os.ModeSymlink != 0 {
90
+		target, err := os.Readlink(src)
91
+		if err != nil {
92
+			return err
93
+		}
94
+		// NOTE: os.Chmod and os.Chtimes don't recoganize symbolic link,
95
+		// which will lead "no such file or directory" error.
96
+		return os.Symlink(target, dest)
97
+	}
98
+
99
+	sr, err := os.Open(src)
100
+	if err != nil {
101
+		return err
102
+	}
103
+	defer sr.Close()
104
+
105
+	dw, err := os.Create(dest)
106
+	if err != nil {
107
+		return err
108
+	}
109
+	defer dw.Close()
110
+
111
+	if _, err = io.Copy(dw, sr); err != nil {
112
+		return err
113
+	}
114
+
115
+	// Set back file information.
116
+	if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil {
117
+		return err
118
+	}
119
+	return os.Chmod(dest, si.Mode())
120
+}
121
+
122
+// WriteFile writes data to a file named by filename.
123
+// If the file does not exist, WriteFile creates it
124
+// and its upper level paths.
125
+func WriteFile(filename string, data []byte) error {
126
+	os.MkdirAll(path.Dir(filename), os.ModePerm)
127
+	return ioutil.WriteFile(filename, data, 0655)
128
+}
129
+
130
+// IsFile returns true if given path is a file,
131
+// or returns false when it's a directory or does not exist.
132
+func IsFile(filePath string) bool {
133
+	f, e := os.Stat(filePath)
134
+	if e != nil {
135
+		return false
136
+	}
137
+	return !f.IsDir()
138
+}
139
+
140
+// IsExist checks whether a file or directory exists.
141
+// It returns false when the file or directory does not exist.
142
+func IsExist(path string) bool {
143
+	_, err := os.Stat(path)
144
+	return err == nil || os.IsExist(err)
145
+}

+ 60 - 0
vendor/github.com/Unknwon/com/html.go

@@ -0,0 +1,60 @@
1
+// Copyright 2013 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+import (
18
+	"html"
19
+	"regexp"
20
+	"strings"
21
+)
22
+
23
+// Html2JS converts []byte type of HTML content into JS format.
24
+func Html2JS(data []byte) []byte {
25
+	s := string(data)
26
+	s = strings.Replace(s, `\`, `\\`, -1)
27
+	s = strings.Replace(s, "\n", `\n`, -1)
28
+	s = strings.Replace(s, "\r", "", -1)
29
+	s = strings.Replace(s, "\"", `\"`, -1)
30
+	s = strings.Replace(s, "<table>", "&lt;table>", -1)
31
+	return []byte(s)
32
+}
33
+
34
+// encode html chars to string
35
+func HtmlEncode(str string) string {
36
+	return html.EscapeString(str)
37
+}
38
+
39
+// decode string to html chars
40
+func HtmlDecode(str string) string {
41
+	return html.UnescapeString(str)
42
+}
43
+
44
+// strip tags in html string
45
+func StripTags(src string) string {
46
+	//去除style,script,html tag
47
+	re := regexp.MustCompile(`(?s)<(?:style|script)[^<>]*>.*?</(?:style|script)>|</?[a-z][a-z0-9]*[^<>]*>|<!--.*?-->`)
48
+	src = re.ReplaceAllString(src, "")
49
+
50
+	//trim all spaces(2+) into \n
51
+	re = regexp.MustCompile(`\s{2,}`)
52
+	src = re.ReplaceAllString(src, "\n")
53
+
54
+	return strings.TrimSpace(src)
55
+}
56
+
57
+// change \n to <br/>
58
+func Nl2br(str string) string {
59
+	return strings.Replace(str, "\n", "<br/>", -1)
60
+}

+ 201 - 0
vendor/github.com/Unknwon/com/http.go

@@ -0,0 +1,201 @@
1
+// Copyright 2013 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+import (
18
+	"bytes"
19
+	"encoding/json"
20
+	"fmt"
21
+	"io"
22
+	"io/ioutil"
23
+	"net/http"
24
+	"os"
25
+	"path"
26
+)
27
+
28
+type NotFoundError struct {
29
+	Message string
30
+}
31
+
32
+func (e NotFoundError) Error() string {
33
+	return e.Message
34
+}
35
+
36
+type RemoteError struct {
37
+	Host string
38
+	Err  error
39
+}
40
+
41
+func (e *RemoteError) Error() string {
42
+	return e.Err.Error()
43
+}
44
+
45
+var UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1541.0 Safari/537.36"
46
+
47
+// HttpCall makes HTTP method call.
48
+func HttpCall(client *http.Client, method, url string, header http.Header, body io.Reader) (io.ReadCloser, error) {
49
+	req, err := http.NewRequest(method, url, body)
50
+	if err != nil {
51
+		return nil, err
52
+	}
53
+	req.Header.Set("User-Agent", UserAgent)
54
+	for k, vs := range header {
55
+		req.Header[k] = vs
56
+	}
57
+	resp, err := client.Do(req)
58
+	if err != nil {
59
+		return nil, err
60
+	}
61
+	if resp.StatusCode == 200 {
62
+		return resp.Body, nil
63
+	}
64
+	resp.Body.Close()
65
+	if resp.StatusCode == 404 { // 403 can be rate limit error.  || resp.StatusCode == 403 {
66
+		err = fmt.Errorf("resource not found: %s", url)
67
+	} else {
68
+		err = fmt.Errorf("%s %s -> %d", method, url, resp.StatusCode)
69
+	}
70
+	return nil, err
71
+}
72
+
73
+// HttpGet gets the specified resource.
74
+// ErrNotFound is returned if the server responds with status 404.
75
+func HttpGet(client *http.Client, url string, header http.Header) (io.ReadCloser, error) {
76
+	return HttpCall(client, "GET", url, header, nil)
77
+}
78
+
79
+// HttpPost posts the specified resource.
80
+// ErrNotFound is returned if the server responds with status 404.
81
+func HttpPost(client *http.Client, url string, header http.Header, body []byte) (io.ReadCloser, error) {
82
+	return HttpCall(client, "POST", url, header, bytes.NewBuffer(body))
83
+}
84
+
85
+// HttpGetToFile gets the specified resource and writes to file.
86
+// ErrNotFound is returned if the server responds with status 404.
87
+func HttpGetToFile(client *http.Client, url string, header http.Header, fileName string) error {
88
+	rc, err := HttpGet(client, url, header)
89
+	if err != nil {
90
+		return err
91
+	}
92
+	defer rc.Close()
93
+
94
+	os.MkdirAll(path.Dir(fileName), os.ModePerm)
95
+	f, err := os.Create(fileName)
96
+	if err != nil {
97
+		return err
98
+	}
99
+	defer f.Close()
100
+	_, err = io.Copy(f, rc)
101
+	return err
102
+}
103
+
104
+// HttpGetBytes gets the specified resource. ErrNotFound is returned if the server
105
+// responds with status 404.
106
+func HttpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error) {
107
+	rc, err := HttpGet(client, url, header)
108
+	if err != nil {
109
+		return nil, err
110
+	}
111
+	defer rc.Close()
112
+	return ioutil.ReadAll(rc)
113
+}
114
+
115
+// HttpGetJSON gets the specified resource and mapping to struct.
116
+// ErrNotFound is returned if the server responds with status 404.
117
+func HttpGetJSON(client *http.Client, url string, v interface{}) error {
118
+	rc, err := HttpGet(client, url, nil)
119
+	if err != nil {
120
+		return err
121
+	}
122
+	defer rc.Close()
123
+	err = json.NewDecoder(rc).Decode(v)
124
+	if _, ok := err.(*json.SyntaxError); ok {
125
+		return fmt.Errorf("JSON syntax error at %s", url)
126
+	}
127
+	return nil
128
+}
129
+
130
+// HttpPostJSON posts the specified resource with struct values,
131
+// and maps results to struct.
132
+// ErrNotFound is returned if the server responds with status 404.
133
+func HttpPostJSON(client *http.Client, url string, body, v interface{}) error {
134
+	data, err := json.Marshal(body)
135
+	if err != nil {
136
+		return err
137
+	}
138
+	rc, err := HttpPost(client, url, http.Header{"content-type": []string{"application/json"}}, data)
139
+	if err != nil {
140
+		return err
141
+	}
142
+	defer rc.Close()
143
+	err = json.NewDecoder(rc).Decode(v)
144
+	if _, ok := err.(*json.SyntaxError); ok {
145
+		return fmt.Errorf("JSON syntax error at %s", url)
146
+	}
147
+	return nil
148
+}
149
+
150
+// A RawFile describes a file that can be downloaded.
151
+type RawFile interface {
152
+	Name() string
153
+	RawUrl() string
154
+	Data() []byte
155
+	SetData([]byte)
156
+}
157
+
158
+// FetchFiles fetches files specified by the rawURL field in parallel.
159
+func FetchFiles(client *http.Client, files []RawFile, header http.Header) error {
160
+	ch := make(chan error, len(files))
161
+	for i := range files {
162
+		go func(i int) {
163
+			p, err := HttpGetBytes(client, files[i].RawUrl(), nil)
164
+			if err != nil {
165
+				ch <- err
166
+				return
167
+			}
168
+			files[i].SetData(p)
169
+			ch <- nil
170
+		}(i)
171
+	}
172
+	for _ = range files {
173
+		if err := <-ch; err != nil {
174
+			return err
175
+		}
176
+	}
177
+	return nil
178
+}
179
+
180
+// FetchFiles uses command `curl` to fetch files specified by the rawURL field in parallel.
181
+func FetchFilesCurl(files []RawFile, curlOptions ...string) error {
182
+	ch := make(chan error, len(files))
183
+	for i := range files {
184
+		go func(i int) {
185
+			stdout, _, err := ExecCmd("curl", append(curlOptions, files[i].RawUrl())...)
186
+			if err != nil {
187
+				ch <- err
188
+				return
189
+			}
190
+
191
+			files[i].SetData([]byte(stdout))
192
+			ch <- nil
193
+		}(i)
194
+	}
195
+	for _ = range files {
196
+		if err := <-ch; err != nil {
197
+			return err
198
+		}
199
+	}
200
+	return nil
201
+}

+ 29 - 0
vendor/github.com/Unknwon/com/math.go

@@ -0,0 +1,29 @@
1
+// Copyright 2014 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+// PowInt is int type of math.Pow function. 
18
+func PowInt(x int, y int) int {
19
+	if y <= 0 {
20
+		return 1
21
+	} else {
22
+		if y % 2 == 0 {
23
+			sqrt := PowInt(x, y/2)
24
+			return sqrt * sqrt
25
+		} else {
26
+			return PowInt(x, y-1) * x
27
+		}
28
+	}
29
+}

+ 80 - 0
vendor/github.com/Unknwon/com/path.go

@@ -0,0 +1,80 @@
1
+// Copyright 2013 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+import (
18
+	"errors"
19
+	"os"
20
+	"path/filepath"
21
+	"runtime"
22
+	"strings"
23
+)
24
+
25
+// GetGOPATHs returns all paths in GOPATH variable.
26
+func GetGOPATHs() []string {
27
+	gopath := os.Getenv("GOPATH")
28
+	var paths []string
29
+	if runtime.GOOS == "windows" {
30
+		gopath = strings.Replace(gopath, "\\", "/", -1)
31
+		paths = strings.Split(gopath, ";")
32
+	} else {
33
+		paths = strings.Split(gopath, ":")
34
+	}
35
+	return paths
36
+}
37
+
38
+// GetSrcPath returns app. source code path.
39
+// It only works when you have src. folder in GOPATH,
40
+// it returns error not able to locate source folder path.
41
+func GetSrcPath(importPath string) (appPath string, err error) {
42
+	paths := GetGOPATHs()
43
+	for _, p := range paths {
44
+		if IsExist(p + "/src/" + importPath + "/") {
45
+			appPath = p + "/src/" + importPath + "/"
46
+			break
47
+		}
48
+	}
49
+
50
+	if len(appPath) == 0 {
51
+		return "", errors.New("Unable to locate source folder path")
52
+	}
53
+
54
+	appPath = filepath.Dir(appPath) + "/"
55
+	if runtime.GOOS == "windows" {
56
+		// Replace all '\' to '/'.
57
+		appPath = strings.Replace(appPath, "\\", "/", -1)
58
+	}
59
+
60
+	return appPath, nil
61
+}
62
+
63
+// HomeDir returns path of '~'(in Linux) on Windows,
64
+// it returns error when the variable does not exist.
65
+func HomeDir() (home string, err error) {
66
+	if runtime.GOOS == "windows" {
67
+		home = os.Getenv("USERPROFILE")
68
+		if len(home) == 0 {
69
+			home = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
70
+		}
71
+	} else {
72
+		home = os.Getenv("HOME")
73
+	}
74
+
75
+	if len(home) == 0 {
76
+		return "", errors.New("Cannot specify home directory because it's empty")
77
+	}
78
+
79
+	return home, nil
80
+}

+ 56 - 0
vendor/github.com/Unknwon/com/regex.go

@@ -0,0 +1,56 @@
1
+// Copyright 2013 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+import "regexp"
18
+
19
+const (
20
+	regex_email_pattern        = `(?i)[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,6}`
21
+	regex_strict_email_pattern = `(?i)[A-Z0-9!#$%&'*+/=?^_{|}~-]+` +
22
+		`(?:\.[A-Z0-9!#$%&'*+/=?^_{|}~-]+)*` +
23
+		`@(?:[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?\.)+` +
24
+		`[A-Z0-9](?:[A-Z0-9-]*[A-Z0-9])?`
25
+	regex_url_pattern = `(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?`
26
+)
27
+
28
+var (
29
+	regex_email        *regexp.Regexp
30
+	regex_strict_email *regexp.Regexp
31
+	regex_url          *regexp.Regexp
32
+)
33
+
34
+func init() {
35
+	regex_email = regexp.MustCompile(regex_email_pattern)
36
+	regex_strict_email = regexp.MustCompile(regex_strict_email_pattern)
37
+	regex_url = regexp.MustCompile(regex_url_pattern)
38
+}
39
+
40
+// validate string is an email address, if not return false
41
+// basically validation can match 99% cases
42
+func IsEmail(email string) bool {
43
+	return regex_email.MatchString(email)
44
+}
45
+
46
+// validate string is an email address, if not return false
47
+// this validation omits RFC 2822
48
+func IsEmailRFC(email string) bool {
49
+	return regex_strict_email.MatchString(email)
50
+}
51
+
52
+// validate string is a url link, if not return false
53
+// simple validation can match 99% cases
54
+func IsUrl(url string) bool {
55
+	return regex_url.MatchString(url)
56
+}

+ 87 - 0
vendor/github.com/Unknwon/com/slice.go

@@ -0,0 +1,87 @@
1
+// Copyright 2013 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+import (
18
+	"strings"
19
+)
20
+
21
+// AppendStr appends string to slice with no duplicates.
22
+func AppendStr(strs []string, str string) []string {
23
+	for _, s := range strs {
24
+		if s == str {
25
+			return strs
26
+		}
27
+	}
28
+	return append(strs, str)
29
+}
30
+
31
+// CompareSliceStr compares two 'string' type slices.
32
+// It returns true if elements and order are both the same.
33
+func CompareSliceStr(s1, s2 []string) bool {
34
+	if len(s1) != len(s2) {
35
+		return false
36
+	}
37
+
38
+	for i := range s1 {
39
+		if s1[i] != s2[i] {
40
+			return false
41
+		}
42
+	}
43
+
44
+	return true
45
+}
46
+
47
+// CompareSliceStr compares two 'string' type slices.
48
+// It returns true if elements are the same, and ignores the order.
49
+func CompareSliceStrU(s1, s2 []string) bool {
50
+	if len(s1) != len(s2) {
51
+		return false
52
+	}
53
+
54
+	for i := range s1 {
55
+		for j := len(s2) - 1; j >= 0; j-- {
56
+			if s1[i] == s2[j] {
57
+				s2 = append(s2[:j], s2[j+1:]...)
58
+				break
59
+			}
60
+		}
61
+	}
62
+	if len(s2) > 0 {
63
+		return false
64
+	}
65
+	return true
66
+}
67
+
68
+// IsSliceContainsStr returns true if the string exists in given slice, ignore case.
69
+func IsSliceContainsStr(sl []string, str string) bool {
70
+	str = strings.ToLower(str)
71
+	for _, s := range sl {
72
+		if strings.ToLower(s) == str {
73
+			return true
74
+		}
75
+	}
76
+	return false
77
+}
78
+
79
+// IsSliceContainsInt64 returns true if the int64 exists in given slice.
80
+func IsSliceContainsInt64(sl []int64, i int64) bool {
81
+	for _, s := range sl {
82
+		if s == i {
83
+			return true
84
+		}
85
+	}
86
+	return false
87
+}

+ 243 - 0
vendor/github.com/Unknwon/com/string.go

@@ -0,0 +1,243 @@
1
+// Copyright 2013 com authors
2
+//
3
+// Licensed under the Apache License, Version 2.0 (the "License"): you may
4
+// not use this file except in compliance with the License. You may obtain
5
+// a copy of the License at
6
+//
7
+//     http://www.apache.org/licenses/LICENSE-2.0
8
+//
9
+// Unless required by applicable law or agreed to in writing, software
10
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+// License for the specific language governing permissions and limitations
13
+// under the License.
14
+
15
+package com
16
+
17
+import (
18
+	"bytes"
19
+	"crypto/aes"
20
+	"crypto/cipher"
21
+	"crypto/rand"
22
+	"encoding/base64"
23
+	"errors"
24
+	"io"
25
+	r "math/rand"
26
+	"strconv"
27
+	"strings"
28
+	"time"
29
+	"unicode"
30
+	"unicode/utf8"
31
+)
32
+
33
+// AESEncrypt encrypts text and given key with AES.
34
+func AESEncrypt(key, text []byte) ([]byte, error) {
35
+	block, err := aes.NewCipher(key)
36
+	if err != nil {
37
+		return nil, err
38
+	}
39
+	b := base64.StdEncoding.EncodeToString(text)
40
+	ciphertext := make([]byte, aes.BlockSize+len(b))
41
+	iv := ciphertext[:aes.BlockSize]
42
+	if _, err := io.ReadFull(rand.Reader, iv); err != nil {
43
+		return nil, err
44
+	}
45
+	cfb := cipher.NewCFBEncrypter(block, iv)
46
+	cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b))
47
+	return ciphertext, nil
48
+}
49
+
50
+// AESDecrypt decrypts text and given key with AES.
51
+func AESDecrypt(key, text []byte) ([]byte, error) {
52
+	block, err := aes.NewCipher(key)
53
+	if err != nil {
54
+		return nil, err
55
+	}
56
+	if len(text) < aes.BlockSize {
57
+		return nil, errors.New("ciphertext too short")
58
+	}
59
+	iv := text[:aes.BlockSize]
60
+	text = text[aes.BlockSize:]
61
+	cfb := cipher.NewCFBDecrypter(block, iv)
62
+	cfb.XORKeyStream(text, text)
63
+	data, err := base64.StdEncoding.DecodeString(string(text))
64
+	if err != nil {
65
+		return nil, err
66
+	}
67
+	return data, nil
68
+}
69
+
70
+// IsLetter returns true if the 'l' is an English letter.
71
+func IsLetter(l uint8) bool {
72
+	n := (l | 0x20) - 'a'
73
+	if n >= 0 && n < 26 {
74
+		return true
75
+	}
76
+	return false
77
+}
78
+
79
+// Expand replaces {k} in template with match[k] or subs[atoi(k)] if k is not in match.
80
+func Expand(template string, match map[string]string, subs ...string) string {
81
+	var p []byte
82
+	var i int
83
+	for {
84
+		i = strings.Index(template, "{")
85
+		if i < 0 {
86
+			break
87
+		}
88
+		p = append(p, template[:i]...)
89
+		template = template[i+1:]
90
+		i = strings.Index(template, "}")
91
+		if s, ok := match[template[:i]]; ok {
92
+			p = append(p, s...)
93
+		} else {
94
+			j, _ := strconv.Atoi(template[:i])
95
+			if j >= len(subs) {
96
+				p = append(p, []byte("Missing")...)
97
+			} else {
98
+				p = append(p, subs[j]...)
99
+			}
100
+		}
101
+		template = template[i+1:]
102
+	}
103
+	p = append(p, template...)
104
+	return string(p)
105
+}
106
+
107
+// Reverse s string, support unicode
108
+func Reverse(s string) string {
109
+	n := len(s)
110
+	runes := make([]rune, n)
111
+	for _, rune := range s {
112
+		n--
113
+		runes[n] = rune
114
+	}
115
+	return string(runes[n:])
116
+}
117
+
118
+// RandomCreateBytes generate random []byte by specify chars.
119
+func RandomCreateBytes(n int, alphabets ...byte) []byte {
120
+	const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
121
+	var bytes = make([]byte, n)
122
+	var randby bool
123
+	if num, err := rand.Read(bytes); num != n || err != nil {
124
+		r.Seed(time.Now().UnixNano())
125
+		randby = true
126
+	}
127
+	for i, b := range bytes {