planetscale 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (378) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ci.yml +24 -0
  3. data/.github/workflows/gem-push.yml +38 -0
  4. data/.github/workflows/licensed.yml +43 -0
  5. data/.gitignore +10 -0
  6. data/.licensed.yml +9 -0
  7. data/.licenses/go/github.com/armon/circbuf.dep.yml +31 -0
  8. data/.licenses/go/github.com/gorilla/mux.dep.yml +41 -0
  9. data/.licenses/go/github.com/hashicorp/go-cleanhttp.dep.yml +375 -0
  10. data/.licenses/go/github.com/mitchellh/go-homedir.dep.yml +32 -0
  11. data/.licenses/go/github.com/pkg/errors.dep.yml +36 -0
  12. data/.licenses/go/github.com/planetscale/planetscale-go/planetscale.dep.yml +160 -0
  13. data/.licenses/go/github.com/planetscale/sql-proxy/proxy.dep.yml +180 -0
  14. data/.licenses/go/go.uber.org/atomic.dep.yml +31 -0
  15. data/.licenses/go/go.uber.org/multierr.dep.yml +30 -0
  16. data/.licenses/go/go.uber.org/zap.dep.yml +30 -0
  17. data/.licenses/go/go.uber.org/zap/buffer.dep.yml +30 -0
  18. data/.licenses/go/go.uber.org/zap/internal/bufferpool.dep.yml +30 -0
  19. data/.licenses/go/go.uber.org/zap/internal/color.dep.yml +30 -0
  20. data/.licenses/go/go.uber.org/zap/internal/exit.dep.yml +31 -0
  21. data/.licenses/go/go.uber.org/zap/zapcore.dep.yml +31 -0
  22. data/.licenses/go/golang.org/x/net/context/ctxhttp.dep.yml +63 -0
  23. data/.licenses/go/golang.org/x/oauth2.dep.yml +44 -0
  24. data/.licenses/go/golang.org/x/oauth2/internal.dep.yml +38 -0
  25. data/.ruby_version +1 -0
  26. data/Gemfile +8 -0
  27. data/LICENSE +201 -0
  28. data/README.md +88 -0
  29. data/Rakefile +10 -0
  30. data/bin/console +15 -0
  31. data/bin/setup +17 -0
  32. data/controller.go +255 -0
  33. data/go.mod +16 -0
  34. data/go.sum +428 -0
  35. data/lib/generators/planetscale/install_generator.rb +58 -0
  36. data/lib/planetscale.rb +137 -0
  37. data/lib/planetscale/version.rb +5 -0
  38. data/planetscale.gemspec +44 -0
  39. data/proxy.go +128 -0
  40. data/vendor/github.com/armon/circbuf/.gitignore +22 -0
  41. data/vendor/github.com/armon/circbuf/LICENSE +20 -0
  42. data/vendor/github.com/armon/circbuf/README.md +28 -0
  43. data/vendor/github.com/armon/circbuf/circbuf.go +92 -0
  44. data/vendor/github.com/armon/circbuf/go.mod +1 -0
  45. data/vendor/github.com/golang/protobuf/AUTHORS +3 -0
  46. data/vendor/github.com/golang/protobuf/CONTRIBUTORS +3 -0
  47. data/vendor/github.com/golang/protobuf/LICENSE +28 -0
  48. data/vendor/github.com/golang/protobuf/proto/buffer.go +324 -0
  49. data/vendor/github.com/golang/protobuf/proto/defaults.go +63 -0
  50. data/vendor/github.com/golang/protobuf/proto/deprecated.go +113 -0
  51. data/vendor/github.com/golang/protobuf/proto/discard.go +58 -0
  52. data/vendor/github.com/golang/protobuf/proto/extensions.go +356 -0
  53. data/vendor/github.com/golang/protobuf/proto/properties.go +306 -0
  54. data/vendor/github.com/golang/protobuf/proto/proto.go +167 -0
  55. data/vendor/github.com/golang/protobuf/proto/registry.go +317 -0
  56. data/vendor/github.com/golang/protobuf/proto/text_decode.go +801 -0
  57. data/vendor/github.com/golang/protobuf/proto/text_encode.go +560 -0
  58. data/vendor/github.com/golang/protobuf/proto/wire.go +78 -0
  59. data/vendor/github.com/golang/protobuf/proto/wrappers.go +34 -0
  60. data/vendor/github.com/gorilla/mux/AUTHORS +8 -0
  61. data/vendor/github.com/gorilla/mux/LICENSE +27 -0
  62. data/vendor/github.com/gorilla/mux/README.md +805 -0
  63. data/vendor/github.com/gorilla/mux/doc.go +306 -0
  64. data/vendor/github.com/gorilla/mux/go.mod +3 -0
  65. data/vendor/github.com/gorilla/mux/middleware.go +74 -0
  66. data/vendor/github.com/gorilla/mux/mux.go +606 -0
  67. data/vendor/github.com/gorilla/mux/regexp.go +388 -0
  68. data/vendor/github.com/gorilla/mux/route.go +736 -0
  69. data/vendor/github.com/gorilla/mux/test_helpers.go +19 -0
  70. data/vendor/github.com/hashicorp/go-cleanhttp/LICENSE +363 -0
  71. data/vendor/github.com/hashicorp/go-cleanhttp/README.md +30 -0
  72. data/vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go +58 -0
  73. data/vendor/github.com/hashicorp/go-cleanhttp/doc.go +20 -0
  74. data/vendor/github.com/hashicorp/go-cleanhttp/go.mod +3 -0
  75. data/vendor/github.com/hashicorp/go-cleanhttp/handlers.go +48 -0
  76. data/vendor/github.com/mitchellh/go-homedir/LICENSE +21 -0
  77. data/vendor/github.com/mitchellh/go-homedir/README.md +14 -0
  78. data/vendor/github.com/mitchellh/go-homedir/go.mod +1 -0
  79. data/vendor/github.com/mitchellh/go-homedir/homedir.go +167 -0
  80. data/vendor/github.com/pkg/errors/.gitignore +24 -0
  81. data/vendor/github.com/pkg/errors/.travis.yml +10 -0
  82. data/vendor/github.com/pkg/errors/LICENSE +23 -0
  83. data/vendor/github.com/pkg/errors/Makefile +44 -0
  84. data/vendor/github.com/pkg/errors/README.md +59 -0
  85. data/vendor/github.com/pkg/errors/appveyor.yml +32 -0
  86. data/vendor/github.com/pkg/errors/errors.go +288 -0
  87. data/vendor/github.com/pkg/errors/go113.go +38 -0
  88. data/vendor/github.com/pkg/errors/stack.go +177 -0
  89. data/vendor/github.com/planetscale/planetscale-go/planetscale/backups.go +139 -0
  90. data/vendor/github.com/planetscale/planetscale-go/planetscale/branches.go +258 -0
  91. data/vendor/github.com/planetscale/planetscale-go/planetscale/certs.go +142 -0
  92. data/vendor/github.com/planetscale/planetscale-go/planetscale/client.go +305 -0
  93. data/vendor/github.com/planetscale/planetscale-go/planetscale/databases.go +131 -0
  94. data/vendor/github.com/planetscale/planetscale-go/planetscale/deploy_requests.go +368 -0
  95. data/vendor/github.com/planetscale/planetscale-go/planetscale/organizations.go +78 -0
  96. data/vendor/github.com/planetscale/planetscale-go/planetscale/service_tokens.go +163 -0
  97. data/vendor/github.com/planetscale/sql-proxy/proxy/client.go +467 -0
  98. data/vendor/github.com/planetscale/sql-proxy/proxy/tls_cache.go +73 -0
  99. data/vendor/go.uber.org/atomic/.codecov.yml +19 -0
  100. data/vendor/go.uber.org/atomic/.gitignore +12 -0
  101. data/vendor/go.uber.org/atomic/.travis.yml +27 -0
  102. data/vendor/go.uber.org/atomic/CHANGELOG.md +76 -0
  103. data/vendor/go.uber.org/atomic/LICENSE.txt +19 -0
  104. data/vendor/go.uber.org/atomic/Makefile +78 -0
  105. data/vendor/go.uber.org/atomic/README.md +63 -0
  106. data/vendor/go.uber.org/atomic/bool.go +81 -0
  107. data/vendor/go.uber.org/atomic/bool_ext.go +53 -0
  108. data/vendor/go.uber.org/atomic/doc.go +23 -0
  109. data/vendor/go.uber.org/atomic/duration.go +82 -0
  110. data/vendor/go.uber.org/atomic/duration_ext.go +40 -0
  111. data/vendor/go.uber.org/atomic/error.go +51 -0
  112. data/vendor/go.uber.org/atomic/error_ext.go +39 -0
  113. data/vendor/go.uber.org/atomic/float64.go +76 -0
  114. data/vendor/go.uber.org/atomic/float64_ext.go +47 -0
  115. data/vendor/go.uber.org/atomic/gen.go +26 -0
  116. data/vendor/go.uber.org/atomic/go.mod +8 -0
  117. data/vendor/go.uber.org/atomic/go.sum +9 -0
  118. data/vendor/go.uber.org/atomic/int32.go +102 -0
  119. data/vendor/go.uber.org/atomic/int64.go +102 -0
  120. data/vendor/go.uber.org/atomic/nocmp.go +35 -0
  121. data/vendor/go.uber.org/atomic/string.go +54 -0
  122. data/vendor/go.uber.org/atomic/string_ext.go +43 -0
  123. data/vendor/go.uber.org/atomic/uint32.go +102 -0
  124. data/vendor/go.uber.org/atomic/uint64.go +102 -0
  125. data/vendor/go.uber.org/atomic/value.go +31 -0
  126. data/vendor/go.uber.org/multierr/.codecov.yml +15 -0
  127. data/vendor/go.uber.org/multierr/.gitignore +4 -0
  128. data/vendor/go.uber.org/multierr/.travis.yml +23 -0
  129. data/vendor/go.uber.org/multierr/CHANGELOG.md +60 -0
  130. data/vendor/go.uber.org/multierr/LICENSE.txt +19 -0
  131. data/vendor/go.uber.org/multierr/Makefile +42 -0
  132. data/vendor/go.uber.org/multierr/README.md +23 -0
  133. data/vendor/go.uber.org/multierr/error.go +449 -0
  134. data/vendor/go.uber.org/multierr/glide.yaml +8 -0
  135. data/vendor/go.uber.org/multierr/go.mod +8 -0
  136. data/vendor/go.uber.org/multierr/go.sum +11 -0
  137. data/vendor/go.uber.org/multierr/go113.go +52 -0
  138. data/vendor/go.uber.org/zap/.codecov.yml +17 -0
  139. data/vendor/go.uber.org/zap/.gitignore +32 -0
  140. data/vendor/go.uber.org/zap/.readme.tmpl +109 -0
  141. data/vendor/go.uber.org/zap/.travis.yml +23 -0
  142. data/vendor/go.uber.org/zap/CHANGELOG.md +432 -0
  143. data/vendor/go.uber.org/zap/CODE_OF_CONDUCT.md +75 -0
  144. data/vendor/go.uber.org/zap/CONTRIBUTING.md +81 -0
  145. data/vendor/go.uber.org/zap/FAQ.md +156 -0
  146. data/vendor/go.uber.org/zap/LICENSE.txt +19 -0
  147. data/vendor/go.uber.org/zap/Makefile +63 -0
  148. data/vendor/go.uber.org/zap/README.md +134 -0
  149. data/vendor/go.uber.org/zap/array.go +320 -0
  150. data/vendor/go.uber.org/zap/buffer/buffer.go +123 -0
  151. data/vendor/go.uber.org/zap/buffer/pool.go +49 -0
  152. data/vendor/go.uber.org/zap/checklicense.sh +17 -0
  153. data/vendor/go.uber.org/zap/config.go +264 -0
  154. data/vendor/go.uber.org/zap/doc.go +113 -0
  155. data/vendor/go.uber.org/zap/encoder.go +79 -0
  156. data/vendor/go.uber.org/zap/error.go +80 -0
  157. data/vendor/go.uber.org/zap/field.go +539 -0
  158. data/vendor/go.uber.org/zap/flag.go +39 -0
  159. data/vendor/go.uber.org/zap/glide.yaml +34 -0
  160. data/vendor/go.uber.org/zap/global.go +168 -0
  161. data/vendor/go.uber.org/zap/global_go112.go +26 -0
  162. data/vendor/go.uber.org/zap/global_prego112.go +26 -0
  163. data/vendor/go.uber.org/zap/go.mod +13 -0
  164. data/vendor/go.uber.org/zap/go.sum +56 -0
  165. data/vendor/go.uber.org/zap/http_handler.go +81 -0
  166. data/vendor/go.uber.org/zap/internal/bufferpool/bufferpool.go +31 -0
  167. data/vendor/go.uber.org/zap/internal/color/color.go +44 -0
  168. data/vendor/go.uber.org/zap/internal/exit/exit.go +64 -0
  169. data/vendor/go.uber.org/zap/level.go +132 -0
  170. data/vendor/go.uber.org/zap/logger.go +344 -0
  171. data/vendor/go.uber.org/zap/options.go +140 -0
  172. data/vendor/go.uber.org/zap/sink.go +161 -0
  173. data/vendor/go.uber.org/zap/stacktrace.go +85 -0
  174. data/vendor/go.uber.org/zap/sugar.go +304 -0
  175. data/vendor/go.uber.org/zap/time.go +27 -0
  176. data/vendor/go.uber.org/zap/writer.go +99 -0
  177. data/vendor/go.uber.org/zap/zapcore/console_encoder.go +161 -0
  178. data/vendor/go.uber.org/zap/zapcore/core.go +113 -0
  179. data/vendor/go.uber.org/zap/zapcore/doc.go +24 -0
  180. data/vendor/go.uber.org/zap/zapcore/encoder.go +443 -0
  181. data/vendor/go.uber.org/zap/zapcore/entry.go +264 -0
  182. data/vendor/go.uber.org/zap/zapcore/error.go +115 -0
  183. data/vendor/go.uber.org/zap/zapcore/field.go +227 -0
  184. data/vendor/go.uber.org/zap/zapcore/hook.go +68 -0
  185. data/vendor/go.uber.org/zap/zapcore/increase_level.go +66 -0
  186. data/vendor/go.uber.org/zap/zapcore/json_encoder.go +534 -0
  187. data/vendor/go.uber.org/zap/zapcore/level.go +175 -0
  188. data/vendor/go.uber.org/zap/zapcore/level_strings.go +46 -0
  189. data/vendor/go.uber.org/zap/zapcore/marshaler.go +61 -0
  190. data/vendor/go.uber.org/zap/zapcore/memory_encoder.go +179 -0
  191. data/vendor/go.uber.org/zap/zapcore/sampler.go +208 -0
  192. data/vendor/go.uber.org/zap/zapcore/tee.go +81 -0
  193. data/vendor/go.uber.org/zap/zapcore/write_syncer.go +123 -0
  194. data/vendor/golang.org/x/net/AUTHORS +3 -0
  195. data/vendor/golang.org/x/net/CONTRIBUTORS +3 -0
  196. data/vendor/golang.org/x/net/LICENSE +27 -0
  197. data/vendor/golang.org/x/net/PATENTS +22 -0
  198. data/vendor/golang.org/x/net/context/context.go +56 -0
  199. data/vendor/golang.org/x/net/context/ctxhttp/ctxhttp.go +71 -0
  200. data/vendor/golang.org/x/net/context/go17.go +73 -0
  201. data/vendor/golang.org/x/net/context/go19.go +21 -0
  202. data/vendor/golang.org/x/net/context/pre_go17.go +301 -0
  203. data/vendor/golang.org/x/net/context/pre_go19.go +110 -0
  204. data/vendor/golang.org/x/oauth2/.travis.yml +13 -0
  205. data/vendor/golang.org/x/oauth2/AUTHORS +3 -0
  206. data/vendor/golang.org/x/oauth2/CONTRIBUTING.md +26 -0
  207. data/vendor/golang.org/x/oauth2/CONTRIBUTORS +3 -0
  208. data/vendor/golang.org/x/oauth2/LICENSE +27 -0
  209. data/vendor/golang.org/x/oauth2/README.md +36 -0
  210. data/vendor/golang.org/x/oauth2/go.mod +9 -0
  211. data/vendor/golang.org/x/oauth2/go.sum +361 -0
  212. data/vendor/golang.org/x/oauth2/internal/client_appengine.go +14 -0
  213. data/vendor/golang.org/x/oauth2/internal/doc.go +6 -0
  214. data/vendor/golang.org/x/oauth2/internal/oauth2.go +37 -0
  215. data/vendor/golang.org/x/oauth2/internal/token.go +294 -0
  216. data/vendor/golang.org/x/oauth2/internal/transport.go +33 -0
  217. data/vendor/golang.org/x/oauth2/oauth2.go +381 -0
  218. data/vendor/golang.org/x/oauth2/token.go +178 -0
  219. data/vendor/golang.org/x/oauth2/transport.go +89 -0
  220. data/vendor/google.golang.org/appengine/LICENSE +202 -0
  221. data/vendor/google.golang.org/appengine/internal/api.go +678 -0
  222. data/vendor/google.golang.org/appengine/internal/api_classic.go +169 -0
  223. data/vendor/google.golang.org/appengine/internal/api_common.go +123 -0
  224. data/vendor/google.golang.org/appengine/internal/app_id.go +28 -0
  225. data/vendor/google.golang.org/appengine/internal/base/api_base.pb.go +308 -0
  226. data/vendor/google.golang.org/appengine/internal/base/api_base.proto +33 -0
  227. data/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.pb.go +4367 -0
  228. data/vendor/google.golang.org/appengine/internal/datastore/datastore_v3.proto +551 -0
  229. data/vendor/google.golang.org/appengine/internal/identity.go +55 -0
  230. data/vendor/google.golang.org/appengine/internal/identity_classic.go +61 -0
  231. data/vendor/google.golang.org/appengine/internal/identity_flex.go +11 -0
  232. data/vendor/google.golang.org/appengine/internal/identity_vm.go +134 -0
  233. data/vendor/google.golang.org/appengine/internal/internal.go +110 -0
  234. data/vendor/google.golang.org/appengine/internal/log/log_service.pb.go +1313 -0
  235. data/vendor/google.golang.org/appengine/internal/log/log_service.proto +150 -0
  236. data/vendor/google.golang.org/appengine/internal/main.go +16 -0
  237. data/vendor/google.golang.org/appengine/internal/main_common.go +7 -0
  238. data/vendor/google.golang.org/appengine/internal/main_vm.go +69 -0
  239. data/vendor/google.golang.org/appengine/internal/metadata.go +60 -0
  240. data/vendor/google.golang.org/appengine/internal/net.go +56 -0
  241. data/vendor/google.golang.org/appengine/internal/regen.sh +40 -0
  242. data/vendor/google.golang.org/appengine/internal/remote_api/remote_api.pb.go +361 -0
  243. data/vendor/google.golang.org/appengine/internal/remote_api/remote_api.proto +44 -0
  244. data/vendor/google.golang.org/appengine/internal/transaction.go +115 -0
  245. data/vendor/google.golang.org/appengine/internal/urlfetch/urlfetch_service.pb.go +527 -0
  246. data/vendor/google.golang.org/appengine/internal/urlfetch/urlfetch_service.proto +64 -0
  247. data/vendor/google.golang.org/appengine/urlfetch/urlfetch.go +210 -0
  248. data/vendor/google.golang.org/protobuf/AUTHORS +3 -0
  249. data/vendor/google.golang.org/protobuf/CONTRIBUTORS +3 -0
  250. data/vendor/google.golang.org/protobuf/LICENSE +27 -0
  251. data/vendor/google.golang.org/protobuf/PATENTS +22 -0
  252. data/vendor/google.golang.org/protobuf/encoding/prototext/decode.go +773 -0
  253. data/vendor/google.golang.org/protobuf/encoding/prototext/doc.go +7 -0
  254. data/vendor/google.golang.org/protobuf/encoding/prototext/encode.go +371 -0
  255. data/vendor/google.golang.org/protobuf/encoding/protowire/wire.go +538 -0
  256. data/vendor/google.golang.org/protobuf/internal/descfmt/stringer.go +318 -0
  257. data/vendor/google.golang.org/protobuf/internal/descopts/options.go +29 -0
  258. data/vendor/google.golang.org/protobuf/internal/detrand/rand.go +69 -0
  259. data/vendor/google.golang.org/protobuf/internal/encoding/defval/default.go +213 -0
  260. data/vendor/google.golang.org/protobuf/internal/encoding/messageset/messageset.go +241 -0
  261. data/vendor/google.golang.org/protobuf/internal/encoding/tag/tag.go +207 -0
  262. data/vendor/google.golang.org/protobuf/internal/encoding/text/decode.go +665 -0
  263. data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_number.go +190 -0
  264. data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_string.go +161 -0
  265. data/vendor/google.golang.org/protobuf/internal/encoding/text/decode_token.go +373 -0
  266. data/vendor/google.golang.org/protobuf/internal/encoding/text/doc.go +29 -0
  267. data/vendor/google.golang.org/protobuf/internal/encoding/text/encode.go +265 -0
  268. data/vendor/google.golang.org/protobuf/internal/errors/errors.go +89 -0
  269. data/vendor/google.golang.org/protobuf/internal/errors/is_go112.go +39 -0
  270. data/vendor/google.golang.org/protobuf/internal/errors/is_go113.go +12 -0
  271. data/vendor/google.golang.org/protobuf/internal/filedesc/build.go +158 -0
  272. data/vendor/google.golang.org/protobuf/internal/filedesc/desc.go +631 -0
  273. data/vendor/google.golang.org/protobuf/internal/filedesc/desc_init.go +471 -0
  274. data/vendor/google.golang.org/protobuf/internal/filedesc/desc_lazy.go +704 -0
  275. data/vendor/google.golang.org/protobuf/internal/filedesc/desc_list.go +450 -0
  276. data/vendor/google.golang.org/protobuf/internal/filedesc/desc_list_gen.go +356 -0
  277. data/vendor/google.golang.org/protobuf/internal/filedesc/placeholder.go +107 -0
  278. data/vendor/google.golang.org/protobuf/internal/filetype/build.go +297 -0
  279. data/vendor/google.golang.org/protobuf/internal/flags/flags.go +24 -0
  280. data/vendor/google.golang.org/protobuf/internal/flags/proto_legacy_disable.go +9 -0
  281. data/vendor/google.golang.org/protobuf/internal/flags/proto_legacy_enable.go +9 -0
  282. data/vendor/google.golang.org/protobuf/internal/genid/any_gen.go +34 -0
  283. data/vendor/google.golang.org/protobuf/internal/genid/api_gen.go +106 -0
  284. data/vendor/google.golang.org/protobuf/internal/genid/descriptor_gen.go +829 -0
  285. data/vendor/google.golang.org/protobuf/internal/genid/doc.go +11 -0
  286. data/vendor/google.golang.org/protobuf/internal/genid/duration_gen.go +34 -0
  287. data/vendor/google.golang.org/protobuf/internal/genid/empty_gen.go +19 -0
  288. data/vendor/google.golang.org/protobuf/internal/genid/field_mask_gen.go +31 -0
  289. data/vendor/google.golang.org/protobuf/internal/genid/goname.go +25 -0
  290. data/vendor/google.golang.org/protobuf/internal/genid/map_entry.go +16 -0
  291. data/vendor/google.golang.org/protobuf/internal/genid/source_context_gen.go +31 -0
  292. data/vendor/google.golang.org/protobuf/internal/genid/struct_gen.go +116 -0
  293. data/vendor/google.golang.org/protobuf/internal/genid/timestamp_gen.go +34 -0
  294. data/vendor/google.golang.org/protobuf/internal/genid/type_gen.go +184 -0
  295. data/vendor/google.golang.org/protobuf/internal/genid/wrappers.go +13 -0
  296. data/vendor/google.golang.org/protobuf/internal/genid/wrappers_gen.go +175 -0
  297. data/vendor/google.golang.org/protobuf/internal/impl/api_export.go +177 -0
  298. data/vendor/google.golang.org/protobuf/internal/impl/checkinit.go +141 -0
  299. data/vendor/google.golang.org/protobuf/internal/impl/codec_extension.go +223 -0
  300. data/vendor/google.golang.org/protobuf/internal/impl/codec_field.go +830 -0
  301. data/vendor/google.golang.org/protobuf/internal/impl/codec_gen.go +5637 -0
  302. data/vendor/google.golang.org/protobuf/internal/impl/codec_map.go +388 -0
  303. data/vendor/google.golang.org/protobuf/internal/impl/codec_map_go111.go +37 -0
  304. data/vendor/google.golang.org/protobuf/internal/impl/codec_map_go112.go +11 -0
  305. data/vendor/google.golang.org/protobuf/internal/impl/codec_message.go +217 -0
  306. data/vendor/google.golang.org/protobuf/internal/impl/codec_messageset.go +123 -0
  307. data/vendor/google.golang.org/protobuf/internal/impl/codec_reflect.go +209 -0
  308. data/vendor/google.golang.org/protobuf/internal/impl/codec_tables.go +557 -0
  309. data/vendor/google.golang.org/protobuf/internal/impl/codec_unsafe.go +17 -0
  310. data/vendor/google.golang.org/protobuf/internal/impl/convert.go +496 -0
  311. data/vendor/google.golang.org/protobuf/internal/impl/convert_list.go +141 -0
  312. data/vendor/google.golang.org/protobuf/internal/impl/convert_map.go +121 -0
  313. data/vendor/google.golang.org/protobuf/internal/impl/decode.go +276 -0
  314. data/vendor/google.golang.org/protobuf/internal/impl/encode.go +201 -0
  315. data/vendor/google.golang.org/protobuf/internal/impl/enum.go +21 -0
  316. data/vendor/google.golang.org/protobuf/internal/impl/extension.go +156 -0
  317. data/vendor/google.golang.org/protobuf/internal/impl/legacy_enum.go +219 -0
  318. data/vendor/google.golang.org/protobuf/internal/impl/legacy_export.go +92 -0
  319. data/vendor/google.golang.org/protobuf/internal/impl/legacy_extension.go +176 -0
  320. data/vendor/google.golang.org/protobuf/internal/impl/legacy_file.go +81 -0
  321. data/vendor/google.golang.org/protobuf/internal/impl/legacy_message.go +558 -0
  322. data/vendor/google.golang.org/protobuf/internal/impl/merge.go +176 -0
  323. data/vendor/google.golang.org/protobuf/internal/impl/merge_gen.go +209 -0
  324. data/vendor/google.golang.org/protobuf/internal/impl/message.go +276 -0
  325. data/vendor/google.golang.org/protobuf/internal/impl/message_reflect.go +465 -0
  326. data/vendor/google.golang.org/protobuf/internal/impl/message_reflect_field.go +543 -0
  327. data/vendor/google.golang.org/protobuf/internal/impl/message_reflect_gen.go +249 -0
  328. data/vendor/google.golang.org/protobuf/internal/impl/pointer_reflect.go +178 -0
  329. data/vendor/google.golang.org/protobuf/internal/impl/pointer_unsafe.go +174 -0
  330. data/vendor/google.golang.org/protobuf/internal/impl/validate.go +576 -0
  331. data/vendor/google.golang.org/protobuf/internal/impl/weak.go +74 -0
  332. data/vendor/google.golang.org/protobuf/internal/order/order.go +89 -0
  333. data/vendor/google.golang.org/protobuf/internal/order/range.go +115 -0
  334. data/vendor/google.golang.org/protobuf/internal/pragma/pragma.go +29 -0
  335. data/vendor/google.golang.org/protobuf/internal/set/ints.go +58 -0
  336. data/vendor/google.golang.org/protobuf/internal/strs/strings.go +196 -0
  337. data/vendor/google.golang.org/protobuf/internal/strs/strings_pure.go +27 -0
  338. data/vendor/google.golang.org/protobuf/internal/strs/strings_unsafe.go +94 -0
  339. data/vendor/google.golang.org/protobuf/internal/version/version.go +79 -0
  340. data/vendor/google.golang.org/protobuf/proto/checkinit.go +71 -0
  341. data/vendor/google.golang.org/protobuf/proto/decode.go +278 -0
  342. data/vendor/google.golang.org/protobuf/proto/decode_gen.go +603 -0
  343. data/vendor/google.golang.org/protobuf/proto/doc.go +94 -0
  344. data/vendor/google.golang.org/protobuf/proto/encode.go +319 -0
  345. data/vendor/google.golang.org/protobuf/proto/encode_gen.go +97 -0
  346. data/vendor/google.golang.org/protobuf/proto/equal.go +167 -0
  347. data/vendor/google.golang.org/protobuf/proto/extension.go +92 -0
  348. data/vendor/google.golang.org/protobuf/proto/merge.go +139 -0
  349. data/vendor/google.golang.org/protobuf/proto/messageset.go +93 -0
  350. data/vendor/google.golang.org/protobuf/proto/proto.go +43 -0
  351. data/vendor/google.golang.org/protobuf/proto/proto_methods.go +19 -0
  352. data/vendor/google.golang.org/protobuf/proto/proto_reflect.go +19 -0
  353. data/vendor/google.golang.org/protobuf/proto/reset.go +43 -0
  354. data/vendor/google.golang.org/protobuf/proto/size.go +97 -0
  355. data/vendor/google.golang.org/protobuf/proto/size_gen.go +55 -0
  356. data/vendor/google.golang.org/protobuf/proto/wrappers.go +29 -0
  357. data/vendor/google.golang.org/protobuf/reflect/protodesc/desc.go +276 -0
  358. data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go +248 -0
  359. data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_resolve.go +286 -0
  360. data/vendor/google.golang.org/protobuf/reflect/protodesc/desc_validate.go +374 -0
  361. data/vendor/google.golang.org/protobuf/reflect/protodesc/proto.go +252 -0
  362. data/vendor/google.golang.org/protobuf/reflect/protoreflect/methods.go +77 -0
  363. data/vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go +504 -0
  364. data/vendor/google.golang.org/protobuf/reflect/protoreflect/source.go +128 -0
  365. data/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go +461 -0
  366. data/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go +665 -0
  367. data/vendor/google.golang.org/protobuf/reflect/protoreflect/value.go +285 -0
  368. data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_pure.go +59 -0
  369. data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go +411 -0
  370. data/vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe.go +98 -0
  371. data/vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go +869 -0
  372. data/vendor/google.golang.org/protobuf/runtime/protoiface/legacy.go +15 -0
  373. data/vendor/google.golang.org/protobuf/runtime/protoiface/methods.go +167 -0
  374. data/vendor/google.golang.org/protobuf/runtime/protoimpl/impl.go +44 -0
  375. data/vendor/google.golang.org/protobuf/runtime/protoimpl/version.go +56 -0
  376. data/vendor/google.golang.org/protobuf/types/descriptorpb/descriptor.pb.go +4039 -0
  377. data/vendor/modules.txt +79 -0
  378. metadata +495 -0
@@ -0,0 +1,388 @@
1
+ // Copyright 2012 The Gorilla Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package mux
6
+
7
+ import (
8
+ "bytes"
9
+ "fmt"
10
+ "net/http"
11
+ "net/url"
12
+ "regexp"
13
+ "strconv"
14
+ "strings"
15
+ )
16
+
17
+ type routeRegexpOptions struct {
18
+ strictSlash bool
19
+ useEncodedPath bool
20
+ }
21
+
22
+ type regexpType int
23
+
24
+ const (
25
+ regexpTypePath regexpType = 0
26
+ regexpTypeHost regexpType = 1
27
+ regexpTypePrefix regexpType = 2
28
+ regexpTypeQuery regexpType = 3
29
+ )
30
+
31
+ // newRouteRegexp parses a route template and returns a routeRegexp,
32
+ // used to match a host, a path or a query string.
33
+ //
34
+ // It will extract named variables, assemble a regexp to be matched, create
35
+ // a "reverse" template to build URLs and compile regexps to validate variable
36
+ // values used in URL building.
37
+ //
38
+ // Previously we accepted only Python-like identifiers for variable
39
+ // names ([a-zA-Z_][a-zA-Z0-9_]*), but currently the only restriction is that
40
+ // name and pattern can't be empty, and names can't contain a colon.
41
+ func newRouteRegexp(tpl string, typ regexpType, options routeRegexpOptions) (*routeRegexp, error) {
42
+ // Check if it is well-formed.
43
+ idxs, errBraces := braceIndices(tpl)
44
+ if errBraces != nil {
45
+ return nil, errBraces
46
+ }
47
+ // Backup the original.
48
+ template := tpl
49
+ // Now let's parse it.
50
+ defaultPattern := "[^/]+"
51
+ if typ == regexpTypeQuery {
52
+ defaultPattern = ".*"
53
+ } else if typ == regexpTypeHost {
54
+ defaultPattern = "[^.]+"
55
+ }
56
+ // Only match strict slash if not matching
57
+ if typ != regexpTypePath {
58
+ options.strictSlash = false
59
+ }
60
+ // Set a flag for strictSlash.
61
+ endSlash := false
62
+ if options.strictSlash && strings.HasSuffix(tpl, "/") {
63
+ tpl = tpl[:len(tpl)-1]
64
+ endSlash = true
65
+ }
66
+ varsN := make([]string, len(idxs)/2)
67
+ varsR := make([]*regexp.Regexp, len(idxs)/2)
68
+ pattern := bytes.NewBufferString("")
69
+ pattern.WriteByte('^')
70
+ reverse := bytes.NewBufferString("")
71
+ var end int
72
+ var err error
73
+ for i := 0; i < len(idxs); i += 2 {
74
+ // Set all values we are interested in.
75
+ raw := tpl[end:idxs[i]]
76
+ end = idxs[i+1]
77
+ parts := strings.SplitN(tpl[idxs[i]+1:end-1], ":", 2)
78
+ name := parts[0]
79
+ patt := defaultPattern
80
+ if len(parts) == 2 {
81
+ patt = parts[1]
82
+ }
83
+ // Name or pattern can't be empty.
84
+ if name == "" || patt == "" {
85
+ return nil, fmt.Errorf("mux: missing name or pattern in %q",
86
+ tpl[idxs[i]:end])
87
+ }
88
+ // Build the regexp pattern.
89
+ fmt.Fprintf(pattern, "%s(?P<%s>%s)", regexp.QuoteMeta(raw), varGroupName(i/2), patt)
90
+
91
+ // Build the reverse template.
92
+ fmt.Fprintf(reverse, "%s%%s", raw)
93
+
94
+ // Append variable name and compiled pattern.
95
+ varsN[i/2] = name
96
+ varsR[i/2], err = regexp.Compile(fmt.Sprintf("^%s$", patt))
97
+ if err != nil {
98
+ return nil, err
99
+ }
100
+ }
101
+ // Add the remaining.
102
+ raw := tpl[end:]
103
+ pattern.WriteString(regexp.QuoteMeta(raw))
104
+ if options.strictSlash {
105
+ pattern.WriteString("[/]?")
106
+ }
107
+ if typ == regexpTypeQuery {
108
+ // Add the default pattern if the query value is empty
109
+ if queryVal := strings.SplitN(template, "=", 2)[1]; queryVal == "" {
110
+ pattern.WriteString(defaultPattern)
111
+ }
112
+ }
113
+ if typ != regexpTypePrefix {
114
+ pattern.WriteByte('$')
115
+ }
116
+
117
+ var wildcardHostPort bool
118
+ if typ == regexpTypeHost {
119
+ if !strings.Contains(pattern.String(), ":") {
120
+ wildcardHostPort = true
121
+ }
122
+ }
123
+ reverse.WriteString(raw)
124
+ if endSlash {
125
+ reverse.WriteByte('/')
126
+ }
127
+ // Compile full regexp.
128
+ reg, errCompile := regexp.Compile(pattern.String())
129
+ if errCompile != nil {
130
+ return nil, errCompile
131
+ }
132
+
133
+ // Check for capturing groups which used to work in older versions
134
+ if reg.NumSubexp() != len(idxs)/2 {
135
+ panic(fmt.Sprintf("route %s contains capture groups in its regexp. ", template) +
136
+ "Only non-capturing groups are accepted: e.g. (?:pattern) instead of (pattern)")
137
+ }
138
+
139
+ // Done!
140
+ return &routeRegexp{
141
+ template: template,
142
+ regexpType: typ,
143
+ options: options,
144
+ regexp: reg,
145
+ reverse: reverse.String(),
146
+ varsN: varsN,
147
+ varsR: varsR,
148
+ wildcardHostPort: wildcardHostPort,
149
+ }, nil
150
+ }
151
+
152
+ // routeRegexp stores a regexp to match a host or path and information to
153
+ // collect and validate route variables.
154
+ type routeRegexp struct {
155
+ // The unmodified template.
156
+ template string
157
+ // The type of match
158
+ regexpType regexpType
159
+ // Options for matching
160
+ options routeRegexpOptions
161
+ // Expanded regexp.
162
+ regexp *regexp.Regexp
163
+ // Reverse template.
164
+ reverse string
165
+ // Variable names.
166
+ varsN []string
167
+ // Variable regexps (validators).
168
+ varsR []*regexp.Regexp
169
+ // Wildcard host-port (no strict port match in hostname)
170
+ wildcardHostPort bool
171
+ }
172
+
173
+ // Match matches the regexp against the URL host or path.
174
+ func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
175
+ if r.regexpType == regexpTypeHost {
176
+ host := getHost(req)
177
+ if r.wildcardHostPort {
178
+ // Don't be strict on the port match
179
+ if i := strings.Index(host, ":"); i != -1 {
180
+ host = host[:i]
181
+ }
182
+ }
183
+ return r.regexp.MatchString(host)
184
+ }
185
+
186
+ if r.regexpType == regexpTypeQuery {
187
+ return r.matchQueryString(req)
188
+ }
189
+ path := req.URL.Path
190
+ if r.options.useEncodedPath {
191
+ path = req.URL.EscapedPath()
192
+ }
193
+ return r.regexp.MatchString(path)
194
+ }
195
+
196
+ // url builds a URL part using the given values.
197
+ func (r *routeRegexp) url(values map[string]string) (string, error) {
198
+ urlValues := make([]interface{}, len(r.varsN), len(r.varsN))
199
+ for k, v := range r.varsN {
200
+ value, ok := values[v]
201
+ if !ok {
202
+ return "", fmt.Errorf("mux: missing route variable %q", v)
203
+ }
204
+ if r.regexpType == regexpTypeQuery {
205
+ value = url.QueryEscape(value)
206
+ }
207
+ urlValues[k] = value
208
+ }
209
+ rv := fmt.Sprintf(r.reverse, urlValues...)
210
+ if !r.regexp.MatchString(rv) {
211
+ // The URL is checked against the full regexp, instead of checking
212
+ // individual variables. This is faster but to provide a good error
213
+ // message, we check individual regexps if the URL doesn't match.
214
+ for k, v := range r.varsN {
215
+ if !r.varsR[k].MatchString(values[v]) {
216
+ return "", fmt.Errorf(
217
+ "mux: variable %q doesn't match, expected %q", values[v],
218
+ r.varsR[k].String())
219
+ }
220
+ }
221
+ }
222
+ return rv, nil
223
+ }
224
+
225
+ // getURLQuery returns a single query parameter from a request URL.
226
+ // For a URL with foo=bar&baz=ding, we return only the relevant key
227
+ // value pair for the routeRegexp.
228
+ func (r *routeRegexp) getURLQuery(req *http.Request) string {
229
+ if r.regexpType != regexpTypeQuery {
230
+ return ""
231
+ }
232
+ templateKey := strings.SplitN(r.template, "=", 2)[0]
233
+ val, ok := findFirstQueryKey(req.URL.RawQuery, templateKey)
234
+ if ok {
235
+ return templateKey + "=" + val
236
+ }
237
+ return ""
238
+ }
239
+
240
+ // findFirstQueryKey returns the same result as (*url.URL).Query()[key][0].
241
+ // If key was not found, empty string and false is returned.
242
+ func findFirstQueryKey(rawQuery, key string) (value string, ok bool) {
243
+ query := []byte(rawQuery)
244
+ for len(query) > 0 {
245
+ foundKey := query
246
+ if i := bytes.IndexAny(foundKey, "&;"); i >= 0 {
247
+ foundKey, query = foundKey[:i], foundKey[i+1:]
248
+ } else {
249
+ query = query[:0]
250
+ }
251
+ if len(foundKey) == 0 {
252
+ continue
253
+ }
254
+ var value []byte
255
+ if i := bytes.IndexByte(foundKey, '='); i >= 0 {
256
+ foundKey, value = foundKey[:i], foundKey[i+1:]
257
+ }
258
+ if len(foundKey) < len(key) {
259
+ // Cannot possibly be key.
260
+ continue
261
+ }
262
+ keyString, err := url.QueryUnescape(string(foundKey))
263
+ if err != nil {
264
+ continue
265
+ }
266
+ if keyString != key {
267
+ continue
268
+ }
269
+ valueString, err := url.QueryUnescape(string(value))
270
+ if err != nil {
271
+ continue
272
+ }
273
+ return valueString, true
274
+ }
275
+ return "", false
276
+ }
277
+
278
+ func (r *routeRegexp) matchQueryString(req *http.Request) bool {
279
+ return r.regexp.MatchString(r.getURLQuery(req))
280
+ }
281
+
282
+ // braceIndices returns the first level curly brace indices from a string.
283
+ // It returns an error in case of unbalanced braces.
284
+ func braceIndices(s string) ([]int, error) {
285
+ var level, idx int
286
+ var idxs []int
287
+ for i := 0; i < len(s); i++ {
288
+ switch s[i] {
289
+ case '{':
290
+ if level++; level == 1 {
291
+ idx = i
292
+ }
293
+ case '}':
294
+ if level--; level == 0 {
295
+ idxs = append(idxs, idx, i+1)
296
+ } else if level < 0 {
297
+ return nil, fmt.Errorf("mux: unbalanced braces in %q", s)
298
+ }
299
+ }
300
+ }
301
+ if level != 0 {
302
+ return nil, fmt.Errorf("mux: unbalanced braces in %q", s)
303
+ }
304
+ return idxs, nil
305
+ }
306
+
307
+ // varGroupName builds a capturing group name for the indexed variable.
308
+ func varGroupName(idx int) string {
309
+ return "v" + strconv.Itoa(idx)
310
+ }
311
+
312
+ // ----------------------------------------------------------------------------
313
+ // routeRegexpGroup
314
+ // ----------------------------------------------------------------------------
315
+
316
+ // routeRegexpGroup groups the route matchers that carry variables.
317
+ type routeRegexpGroup struct {
318
+ host *routeRegexp
319
+ path *routeRegexp
320
+ queries []*routeRegexp
321
+ }
322
+
323
+ // setMatch extracts the variables from the URL once a route matches.
324
+ func (v routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route) {
325
+ // Store host variables.
326
+ if v.host != nil {
327
+ host := getHost(req)
328
+ if v.host.wildcardHostPort {
329
+ // Don't be strict on the port match
330
+ if i := strings.Index(host, ":"); i != -1 {
331
+ host = host[:i]
332
+ }
333
+ }
334
+ matches := v.host.regexp.FindStringSubmatchIndex(host)
335
+ if len(matches) > 0 {
336
+ extractVars(host, matches, v.host.varsN, m.Vars)
337
+ }
338
+ }
339
+ path := req.URL.Path
340
+ if r.useEncodedPath {
341
+ path = req.URL.EscapedPath()
342
+ }
343
+ // Store path variables.
344
+ if v.path != nil {
345
+ matches := v.path.regexp.FindStringSubmatchIndex(path)
346
+ if len(matches) > 0 {
347
+ extractVars(path, matches, v.path.varsN, m.Vars)
348
+ // Check if we should redirect.
349
+ if v.path.options.strictSlash {
350
+ p1 := strings.HasSuffix(path, "/")
351
+ p2 := strings.HasSuffix(v.path.template, "/")
352
+ if p1 != p2 {
353
+ u, _ := url.Parse(req.URL.String())
354
+ if p1 {
355
+ u.Path = u.Path[:len(u.Path)-1]
356
+ } else {
357
+ u.Path += "/"
358
+ }
359
+ m.Handler = http.RedirectHandler(u.String(), http.StatusMovedPermanently)
360
+ }
361
+ }
362
+ }
363
+ }
364
+ // Store query string variables.
365
+ for _, q := range v.queries {
366
+ queryURL := q.getURLQuery(req)
367
+ matches := q.regexp.FindStringSubmatchIndex(queryURL)
368
+ if len(matches) > 0 {
369
+ extractVars(queryURL, matches, q.varsN, m.Vars)
370
+ }
371
+ }
372
+ }
373
+
374
+ // getHost tries its best to return the request host.
375
+ // According to section 14.23 of RFC 2616 the Host header
376
+ // can include the port number if the default value of 80 is not used.
377
+ func getHost(r *http.Request) string {
378
+ if r.URL.IsAbs() {
379
+ return r.URL.Host
380
+ }
381
+ return r.Host
382
+ }
383
+
384
+ func extractVars(input string, matches []int, names []string, output map[string]string) {
385
+ for i, name := range names {
386
+ output[name] = input[matches[2*i+2]:matches[2*i+3]]
387
+ }
388
+ }
@@ -0,0 +1,736 @@
1
+ // Copyright 2012 The Gorilla Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package mux
6
+
7
+ import (
8
+ "errors"
9
+ "fmt"
10
+ "net/http"
11
+ "net/url"
12
+ "regexp"
13
+ "strings"
14
+ )
15
+
16
+ // Route stores information to match a request and build URLs.
17
+ type Route struct {
18
+ // Request handler for the route.
19
+ handler http.Handler
20
+ // If true, this route never matches: it is only used to build URLs.
21
+ buildOnly bool
22
+ // The name used to build URLs.
23
+ name string
24
+ // Error resulted from building a route.
25
+ err error
26
+
27
+ // "global" reference to all named routes
28
+ namedRoutes map[string]*Route
29
+
30
+ // config possibly passed in from `Router`
31
+ routeConf
32
+ }
33
+
34
+ // SkipClean reports whether path cleaning is enabled for this route via
35
+ // Router.SkipClean.
36
+ func (r *Route) SkipClean() bool {
37
+ return r.skipClean
38
+ }
39
+
40
+ // Match matches the route against the request.
41
+ func (r *Route) Match(req *http.Request, match *RouteMatch) bool {
42
+ if r.buildOnly || r.err != nil {
43
+ return false
44
+ }
45
+
46
+ var matchErr error
47
+
48
+ // Match everything.
49
+ for _, m := range r.matchers {
50
+ if matched := m.Match(req, match); !matched {
51
+ if _, ok := m.(methodMatcher); ok {
52
+ matchErr = ErrMethodMismatch
53
+ continue
54
+ }
55
+
56
+ // Ignore ErrNotFound errors. These errors arise from match call
57
+ // to Subrouters.
58
+ //
59
+ // This prevents subsequent matching subrouters from failing to
60
+ // run middleware. If not ignored, the middleware would see a
61
+ // non-nil MatchErr and be skipped, even when there was a
62
+ // matching route.
63
+ if match.MatchErr == ErrNotFound {
64
+ match.MatchErr = nil
65
+ }
66
+
67
+ matchErr = nil
68
+ return false
69
+ }
70
+ }
71
+
72
+ if matchErr != nil {
73
+ match.MatchErr = matchErr
74
+ return false
75
+ }
76
+
77
+ if match.MatchErr == ErrMethodMismatch && r.handler != nil {
78
+ // We found a route which matches request method, clear MatchErr
79
+ match.MatchErr = nil
80
+ // Then override the mis-matched handler
81
+ match.Handler = r.handler
82
+ }
83
+
84
+ // Yay, we have a match. Let's collect some info about it.
85
+ if match.Route == nil {
86
+ match.Route = r
87
+ }
88
+ if match.Handler == nil {
89
+ match.Handler = r.handler
90
+ }
91
+ if match.Vars == nil {
92
+ match.Vars = make(map[string]string)
93
+ }
94
+
95
+ // Set variables.
96
+ r.regexp.setMatch(req, match, r)
97
+ return true
98
+ }
99
+
100
+ // ----------------------------------------------------------------------------
101
+ // Route attributes
102
+ // ----------------------------------------------------------------------------
103
+
104
+ // GetError returns an error resulted from building the route, if any.
105
+ func (r *Route) GetError() error {
106
+ return r.err
107
+ }
108
+
109
+ // BuildOnly sets the route to never match: it is only used to build URLs.
110
+ func (r *Route) BuildOnly() *Route {
111
+ r.buildOnly = true
112
+ return r
113
+ }
114
+
115
+ // Handler --------------------------------------------------------------------
116
+
117
+ // Handler sets a handler for the route.
118
+ func (r *Route) Handler(handler http.Handler) *Route {
119
+ if r.err == nil {
120
+ r.handler = handler
121
+ }
122
+ return r
123
+ }
124
+
125
+ // HandlerFunc sets a handler function for the route.
126
+ func (r *Route) HandlerFunc(f func(http.ResponseWriter, *http.Request)) *Route {
127
+ return r.Handler(http.HandlerFunc(f))
128
+ }
129
+
130
+ // GetHandler returns the handler for the route, if any.
131
+ func (r *Route) GetHandler() http.Handler {
132
+ return r.handler
133
+ }
134
+
135
+ // Name -----------------------------------------------------------------------
136
+
137
+ // Name sets the name for the route, used to build URLs.
138
+ // It is an error to call Name more than once on a route.
139
+ func (r *Route) Name(name string) *Route {
140
+ if r.name != "" {
141
+ r.err = fmt.Errorf("mux: route already has name %q, can't set %q",
142
+ r.name, name)
143
+ }
144
+ if r.err == nil {
145
+ r.name = name
146
+ r.namedRoutes[name] = r
147
+ }
148
+ return r
149
+ }
150
+
151
+ // GetName returns the name for the route, if any.
152
+ func (r *Route) GetName() string {
153
+ return r.name
154
+ }
155
+
156
+ // ----------------------------------------------------------------------------
157
+ // Matchers
158
+ // ----------------------------------------------------------------------------
159
+
160
+ // matcher types try to match a request.
161
+ type matcher interface {
162
+ Match(*http.Request, *RouteMatch) bool
163
+ }
164
+
165
+ // addMatcher adds a matcher to the route.
166
+ func (r *Route) addMatcher(m matcher) *Route {
167
+ if r.err == nil {
168
+ r.matchers = append(r.matchers, m)
169
+ }
170
+ return r
171
+ }
172
+
173
+ // addRegexpMatcher adds a host or path matcher and builder to a route.
174
+ func (r *Route) addRegexpMatcher(tpl string, typ regexpType) error {
175
+ if r.err != nil {
176
+ return r.err
177
+ }
178
+ if typ == regexpTypePath || typ == regexpTypePrefix {
179
+ if len(tpl) > 0 && tpl[0] != '/' {
180
+ return fmt.Errorf("mux: path must start with a slash, got %q", tpl)
181
+ }
182
+ if r.regexp.path != nil {
183
+ tpl = strings.TrimRight(r.regexp.path.template, "/") + tpl
184
+ }
185
+ }
186
+ rr, err := newRouteRegexp(tpl, typ, routeRegexpOptions{
187
+ strictSlash: r.strictSlash,
188
+ useEncodedPath: r.useEncodedPath,
189
+ })
190
+ if err != nil {
191
+ return err
192
+ }
193
+ for _, q := range r.regexp.queries {
194
+ if err = uniqueVars(rr.varsN, q.varsN); err != nil {
195
+ return err
196
+ }
197
+ }
198
+ if typ == regexpTypeHost {
199
+ if r.regexp.path != nil {
200
+ if err = uniqueVars(rr.varsN, r.regexp.path.varsN); err != nil {
201
+ return err
202
+ }
203
+ }
204
+ r.regexp.host = rr
205
+ } else {
206
+ if r.regexp.host != nil {
207
+ if err = uniqueVars(rr.varsN, r.regexp.host.varsN); err != nil {
208
+ return err
209
+ }
210
+ }
211
+ if typ == regexpTypeQuery {
212
+ r.regexp.queries = append(r.regexp.queries, rr)
213
+ } else {
214
+ r.regexp.path = rr
215
+ }
216
+ }
217
+ r.addMatcher(rr)
218
+ return nil
219
+ }
220
+
221
+ // Headers --------------------------------------------------------------------
222
+
223
+ // headerMatcher matches the request against header values.
224
+ type headerMatcher map[string]string
225
+
226
+ func (m headerMatcher) Match(r *http.Request, match *RouteMatch) bool {
227
+ return matchMapWithString(m, r.Header, true)
228
+ }
229
+
230
+ // Headers adds a matcher for request header values.
231
+ // It accepts a sequence of key/value pairs to be matched. For example:
232
+ //
233
+ // r := mux.NewRouter()
234
+ // r.Headers("Content-Type", "application/json",
235
+ // "X-Requested-With", "XMLHttpRequest")
236
+ //
237
+ // The above route will only match if both request header values match.
238
+ // If the value is an empty string, it will match any value if the key is set.
239
+ func (r *Route) Headers(pairs ...string) *Route {
240
+ if r.err == nil {
241
+ var headers map[string]string
242
+ headers, r.err = mapFromPairsToString(pairs...)
243
+ return r.addMatcher(headerMatcher(headers))
244
+ }
245
+ return r
246
+ }
247
+
248
+ // headerRegexMatcher matches the request against the route given a regex for the header
249
+ type headerRegexMatcher map[string]*regexp.Regexp
250
+
251
+ func (m headerRegexMatcher) Match(r *http.Request, match *RouteMatch) bool {
252
+ return matchMapWithRegex(m, r.Header, true)
253
+ }
254
+
255
+ // HeadersRegexp accepts a sequence of key/value pairs, where the value has regex
256
+ // support. For example:
257
+ //
258
+ // r := mux.NewRouter()
259
+ // r.HeadersRegexp("Content-Type", "application/(text|json)",
260
+ // "X-Requested-With", "XMLHttpRequest")
261
+ //
262
+ // The above route will only match if both the request header matches both regular expressions.
263
+ // If the value is an empty string, it will match any value if the key is set.
264
+ // Use the start and end of string anchors (^ and $) to match an exact value.
265
+ func (r *Route) HeadersRegexp(pairs ...string) *Route {
266
+ if r.err == nil {
267
+ var headers map[string]*regexp.Regexp
268
+ headers, r.err = mapFromPairsToRegex(pairs...)
269
+ return r.addMatcher(headerRegexMatcher(headers))
270
+ }
271
+ return r
272
+ }
273
+
274
+ // Host -----------------------------------------------------------------------
275
+
276
+ // Host adds a matcher for the URL host.
277
+ // It accepts a template with zero or more URL variables enclosed by {}.
278
+ // Variables can define an optional regexp pattern to be matched:
279
+ //
280
+ // - {name} matches anything until the next dot.
281
+ //
282
+ // - {name:pattern} matches the given regexp pattern.
283
+ //
284
+ // For example:
285
+ //
286
+ // r := mux.NewRouter()
287
+ // r.Host("www.example.com")
288
+ // r.Host("{subdomain}.domain.com")
289
+ // r.Host("{subdomain:[a-z]+}.domain.com")
290
+ //
291
+ // Variable names must be unique in a given route. They can be retrieved
292
+ // calling mux.Vars(request).
293
+ func (r *Route) Host(tpl string) *Route {
294
+ r.err = r.addRegexpMatcher(tpl, regexpTypeHost)
295
+ return r
296
+ }
297
+
298
+ // MatcherFunc ----------------------------------------------------------------
299
+
300
+ // MatcherFunc is the function signature used by custom matchers.
301
+ type MatcherFunc func(*http.Request, *RouteMatch) bool
302
+
303
+ // Match returns the match for a given request.
304
+ func (m MatcherFunc) Match(r *http.Request, match *RouteMatch) bool {
305
+ return m(r, match)
306
+ }
307
+
308
+ // MatcherFunc adds a custom function to be used as request matcher.
309
+ func (r *Route) MatcherFunc(f MatcherFunc) *Route {
310
+ return r.addMatcher(f)
311
+ }
312
+
313
+ // Methods --------------------------------------------------------------------
314
+
315
+ // methodMatcher matches the request against HTTP methods.
316
+ type methodMatcher []string
317
+
318
+ func (m methodMatcher) Match(r *http.Request, match *RouteMatch) bool {
319
+ return matchInArray(m, r.Method)
320
+ }
321
+
322
+ // Methods adds a matcher for HTTP methods.
323
+ // It accepts a sequence of one or more methods to be matched, e.g.:
324
+ // "GET", "POST", "PUT".
325
+ func (r *Route) Methods(methods ...string) *Route {
326
+ for k, v := range methods {
327
+ methods[k] = strings.ToUpper(v)
328
+ }
329
+ return r.addMatcher(methodMatcher(methods))
330
+ }
331
+
332
+ // Path -----------------------------------------------------------------------
333
+
334
+ // Path adds a matcher for the URL path.
335
+ // It accepts a template with zero or more URL variables enclosed by {}. The
336
+ // template must start with a "/".
337
+ // Variables can define an optional regexp pattern to be matched:
338
+ //
339
+ // - {name} matches anything until the next slash.
340
+ //
341
+ // - {name:pattern} matches the given regexp pattern.
342
+ //
343
+ // For example:
344
+ //
345
+ // r := mux.NewRouter()
346
+ // r.Path("/products/").Handler(ProductsHandler)
347
+ // r.Path("/products/{key}").Handler(ProductsHandler)
348
+ // r.Path("/articles/{category}/{id:[0-9]+}").
349
+ // Handler(ArticleHandler)
350
+ //
351
+ // Variable names must be unique in a given route. They can be retrieved
352
+ // calling mux.Vars(request).
353
+ func (r *Route) Path(tpl string) *Route {
354
+ r.err = r.addRegexpMatcher(tpl, regexpTypePath)
355
+ return r
356
+ }
357
+
358
+ // PathPrefix -----------------------------------------------------------------
359
+
360
+ // PathPrefix adds a matcher for the URL path prefix. This matches if the given
361
+ // template is a prefix of the full URL path. See Route.Path() for details on
362
+ // the tpl argument.
363
+ //
364
+ // Note that it does not treat slashes specially ("/foobar/" will be matched by
365
+ // the prefix "/foo") so you may want to use a trailing slash here.
366
+ //
367
+ // Also note that the setting of Router.StrictSlash() has no effect on routes
368
+ // with a PathPrefix matcher.
369
+ func (r *Route) PathPrefix(tpl string) *Route {
370
+ r.err = r.addRegexpMatcher(tpl, regexpTypePrefix)
371
+ return r
372
+ }
373
+
374
+ // Query ----------------------------------------------------------------------
375
+
376
+ // Queries adds a matcher for URL query values.
377
+ // It accepts a sequence of key/value pairs. Values may define variables.
378
+ // For example:
379
+ //
380
+ // r := mux.NewRouter()
381
+ // r.Queries("foo", "bar", "id", "{id:[0-9]+}")
382
+ //
383
+ // The above route will only match if the URL contains the defined queries
384
+ // values, e.g.: ?foo=bar&id=42.
385
+ //
386
+ // If the value is an empty string, it will match any value if the key is set.
387
+ //
388
+ // Variables can define an optional regexp pattern to be matched:
389
+ //
390
+ // - {name} matches anything until the next slash.
391
+ //
392
+ // - {name:pattern} matches the given regexp pattern.
393
+ func (r *Route) Queries(pairs ...string) *Route {
394
+ length := len(pairs)
395
+ if length%2 != 0 {
396
+ r.err = fmt.Errorf(
397
+ "mux: number of parameters must be multiple of 2, got %v", pairs)
398
+ return nil
399
+ }
400
+ for i := 0; i < length; i += 2 {
401
+ if r.err = r.addRegexpMatcher(pairs[i]+"="+pairs[i+1], regexpTypeQuery); r.err != nil {
402
+ return r
403
+ }
404
+ }
405
+
406
+ return r
407
+ }
408
+
409
+ // Schemes --------------------------------------------------------------------
410
+
411
+ // schemeMatcher matches the request against URL schemes.
412
+ type schemeMatcher []string
413
+
414
+ func (m schemeMatcher) Match(r *http.Request, match *RouteMatch) bool {
415
+ scheme := r.URL.Scheme
416
+ // https://golang.org/pkg/net/http/#Request
417
+ // "For [most] server requests, fields other than Path and RawQuery will be
418
+ // empty."
419
+ // Since we're an http muxer, the scheme is either going to be http or https
420
+ // though, so we can just set it based on the tls termination state.
421
+ if scheme == "" {
422
+ if r.TLS == nil {
423
+ scheme = "http"
424
+ } else {
425
+ scheme = "https"
426
+ }
427
+ }
428
+ return matchInArray(m, scheme)
429
+ }
430
+
431
+ // Schemes adds a matcher for URL schemes.
432
+ // It accepts a sequence of schemes to be matched, e.g.: "http", "https".
433
+ // If the request's URL has a scheme set, it will be matched against.
434
+ // Generally, the URL scheme will only be set if a previous handler set it,
435
+ // such as the ProxyHeaders handler from gorilla/handlers.
436
+ // If unset, the scheme will be determined based on the request's TLS
437
+ // termination state.
438
+ // The first argument to Schemes will be used when constructing a route URL.
439
+ func (r *Route) Schemes(schemes ...string) *Route {
440
+ for k, v := range schemes {
441
+ schemes[k] = strings.ToLower(v)
442
+ }
443
+ if len(schemes) > 0 {
444
+ r.buildScheme = schemes[0]
445
+ }
446
+ return r.addMatcher(schemeMatcher(schemes))
447
+ }
448
+
449
+ // BuildVarsFunc --------------------------------------------------------------
450
+
451
+ // BuildVarsFunc is the function signature used by custom build variable
452
+ // functions (which can modify route variables before a route's URL is built).
453
+ type BuildVarsFunc func(map[string]string) map[string]string
454
+
455
+ // BuildVarsFunc adds a custom function to be used to modify build variables
456
+ // before a route's URL is built.
457
+ func (r *Route) BuildVarsFunc(f BuildVarsFunc) *Route {
458
+ if r.buildVarsFunc != nil {
459
+ // compose the old and new functions
460
+ old := r.buildVarsFunc
461
+ r.buildVarsFunc = func(m map[string]string) map[string]string {
462
+ return f(old(m))
463
+ }
464
+ } else {
465
+ r.buildVarsFunc = f
466
+ }
467
+ return r
468
+ }
469
+
470
+ // Subrouter ------------------------------------------------------------------
471
+
472
+ // Subrouter creates a subrouter for the route.
473
+ //
474
+ // It will test the inner routes only if the parent route matched. For example:
475
+ //
476
+ // r := mux.NewRouter()
477
+ // s := r.Host("www.example.com").Subrouter()
478
+ // s.HandleFunc("/products/", ProductsHandler)
479
+ // s.HandleFunc("/products/{key}", ProductHandler)
480
+ // s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
481
+ //
482
+ // Here, the routes registered in the subrouter won't be tested if the host
483
+ // doesn't match.
484
+ func (r *Route) Subrouter() *Router {
485
+ // initialize a subrouter with a copy of the parent route's configuration
486
+ router := &Router{routeConf: copyRouteConf(r.routeConf), namedRoutes: r.namedRoutes}
487
+ r.addMatcher(router)
488
+ return router
489
+ }
490
+
491
+ // ----------------------------------------------------------------------------
492
+ // URL building
493
+ // ----------------------------------------------------------------------------
494
+
495
+ // URL builds a URL for the route.
496
+ //
497
+ // It accepts a sequence of key/value pairs for the route variables. For
498
+ // example, given this route:
499
+ //
500
+ // r := mux.NewRouter()
501
+ // r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
502
+ // Name("article")
503
+ //
504
+ // ...a URL for it can be built using:
505
+ //
506
+ // url, err := r.Get("article").URL("category", "technology", "id", "42")
507
+ //
508
+ // ...which will return an url.URL with the following path:
509
+ //
510
+ // "/articles/technology/42"
511
+ //
512
+ // This also works for host variables:
513
+ //
514
+ // r := mux.NewRouter()
515
+ // r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
516
+ // Host("{subdomain}.domain.com").
517
+ // Name("article")
518
+ //
519
+ // // url.String() will be "http://news.domain.com/articles/technology/42"
520
+ // url, err := r.Get("article").URL("subdomain", "news",
521
+ // "category", "technology",
522
+ // "id", "42")
523
+ //
524
+ // The scheme of the resulting url will be the first argument that was passed to Schemes:
525
+ //
526
+ // // url.String() will be "https://example.com"
527
+ // r := mux.NewRouter()
528
+ // url, err := r.Host("example.com")
529
+ // .Schemes("https", "http").URL()
530
+ //
531
+ // All variables defined in the route are required, and their values must
532
+ // conform to the corresponding patterns.
533
+ func (r *Route) URL(pairs ...string) (*url.URL, error) {
534
+ if r.err != nil {
535
+ return nil, r.err
536
+ }
537
+ values, err := r.prepareVars(pairs...)
538
+ if err != nil {
539
+ return nil, err
540
+ }
541
+ var scheme, host, path string
542
+ queries := make([]string, 0, len(r.regexp.queries))
543
+ if r.regexp.host != nil {
544
+ if host, err = r.regexp.host.url(values); err != nil {
545
+ return nil, err
546
+ }
547
+ scheme = "http"
548
+ if r.buildScheme != "" {
549
+ scheme = r.buildScheme
550
+ }
551
+ }
552
+ if r.regexp.path != nil {
553
+ if path, err = r.regexp.path.url(values); err != nil {
554
+ return nil, err
555
+ }
556
+ }
557
+ for _, q := range r.regexp.queries {
558
+ var query string
559
+ if query, err = q.url(values); err != nil {
560
+ return nil, err
561
+ }
562
+ queries = append(queries, query)
563
+ }
564
+ return &url.URL{
565
+ Scheme: scheme,
566
+ Host: host,
567
+ Path: path,
568
+ RawQuery: strings.Join(queries, "&"),
569
+ }, nil
570
+ }
571
+
572
+ // URLHost builds the host part of the URL for a route. See Route.URL().
573
+ //
574
+ // The route must have a host defined.
575
+ func (r *Route) URLHost(pairs ...string) (*url.URL, error) {
576
+ if r.err != nil {
577
+ return nil, r.err
578
+ }
579
+ if r.regexp.host == nil {
580
+ return nil, errors.New("mux: route doesn't have a host")
581
+ }
582
+ values, err := r.prepareVars(pairs...)
583
+ if err != nil {
584
+ return nil, err
585
+ }
586
+ host, err := r.regexp.host.url(values)
587
+ if err != nil {
588
+ return nil, err
589
+ }
590
+ u := &url.URL{
591
+ Scheme: "http",
592
+ Host: host,
593
+ }
594
+ if r.buildScheme != "" {
595
+ u.Scheme = r.buildScheme
596
+ }
597
+ return u, nil
598
+ }
599
+
600
+ // URLPath builds the path part of the URL for a route. See Route.URL().
601
+ //
602
+ // The route must have a path defined.
603
+ func (r *Route) URLPath(pairs ...string) (*url.URL, error) {
604
+ if r.err != nil {
605
+ return nil, r.err
606
+ }
607
+ if r.regexp.path == nil {
608
+ return nil, errors.New("mux: route doesn't have a path")
609
+ }
610
+ values, err := r.prepareVars(pairs...)
611
+ if err != nil {
612
+ return nil, err
613
+ }
614
+ path, err := r.regexp.path.url(values)
615
+ if err != nil {
616
+ return nil, err
617
+ }
618
+ return &url.URL{
619
+ Path: path,
620
+ }, nil
621
+ }
622
+
623
+ // GetPathTemplate returns the template used to build the
624
+ // route match.
625
+ // This is useful for building simple REST API documentation and for instrumentation
626
+ // against third-party services.
627
+ // An error will be returned if the route does not define a path.
628
+ func (r *Route) GetPathTemplate() (string, error) {
629
+ if r.err != nil {
630
+ return "", r.err
631
+ }
632
+ if r.regexp.path == nil {
633
+ return "", errors.New("mux: route doesn't have a path")
634
+ }
635
+ return r.regexp.path.template, nil
636
+ }
637
+
638
+ // GetPathRegexp returns the expanded regular expression used to match route path.
639
+ // This is useful for building simple REST API documentation and for instrumentation
640
+ // against third-party services.
641
+ // An error will be returned if the route does not define a path.
642
+ func (r *Route) GetPathRegexp() (string, error) {
643
+ if r.err != nil {
644
+ return "", r.err
645
+ }
646
+ if r.regexp.path == nil {
647
+ return "", errors.New("mux: route does not have a path")
648
+ }
649
+ return r.regexp.path.regexp.String(), nil
650
+ }
651
+
652
+ // GetQueriesRegexp returns the expanded regular expressions used to match the
653
+ // route queries.
654
+ // This is useful for building simple REST API documentation and for instrumentation
655
+ // against third-party services.
656
+ // An error will be returned if the route does not have queries.
657
+ func (r *Route) GetQueriesRegexp() ([]string, error) {
658
+ if r.err != nil {
659
+ return nil, r.err
660
+ }
661
+ if r.regexp.queries == nil {
662
+ return nil, errors.New("mux: route doesn't have queries")
663
+ }
664
+ queries := make([]string, 0, len(r.regexp.queries))
665
+ for _, query := range r.regexp.queries {
666
+ queries = append(queries, query.regexp.String())
667
+ }
668
+ return queries, nil
669
+ }
670
+
671
+ // GetQueriesTemplates returns the templates used to build the
672
+ // query matching.
673
+ // This is useful for building simple REST API documentation and for instrumentation
674
+ // against third-party services.
675
+ // An error will be returned if the route does not define queries.
676
+ func (r *Route) GetQueriesTemplates() ([]string, error) {
677
+ if r.err != nil {
678
+ return nil, r.err
679
+ }
680
+ if r.regexp.queries == nil {
681
+ return nil, errors.New("mux: route doesn't have queries")
682
+ }
683
+ queries := make([]string, 0, len(r.regexp.queries))
684
+ for _, query := range r.regexp.queries {
685
+ queries = append(queries, query.template)
686
+ }
687
+ return queries, nil
688
+ }
689
+
690
+ // GetMethods returns the methods the route matches against
691
+ // This is useful for building simple REST API documentation and for instrumentation
692
+ // against third-party services.
693
+ // An error will be returned if route does not have methods.
694
+ func (r *Route) GetMethods() ([]string, error) {
695
+ if r.err != nil {
696
+ return nil, r.err
697
+ }
698
+ for _, m := range r.matchers {
699
+ if methods, ok := m.(methodMatcher); ok {
700
+ return []string(methods), nil
701
+ }
702
+ }
703
+ return nil, errors.New("mux: route doesn't have methods")
704
+ }
705
+
706
+ // GetHostTemplate returns the template used to build the
707
+ // route match.
708
+ // This is useful for building simple REST API documentation and for instrumentation
709
+ // against third-party services.
710
+ // An error will be returned if the route does not define a host.
711
+ func (r *Route) GetHostTemplate() (string, error) {
712
+ if r.err != nil {
713
+ return "", r.err
714
+ }
715
+ if r.regexp.host == nil {
716
+ return "", errors.New("mux: route doesn't have a host")
717
+ }
718
+ return r.regexp.host.template, nil
719
+ }
720
+
721
+ // prepareVars converts the route variable pairs into a map. If the route has a
722
+ // BuildVarsFunc, it is invoked.
723
+ func (r *Route) prepareVars(pairs ...string) (map[string]string, error) {
724
+ m, err := mapFromPairsToString(pairs...)
725
+ if err != nil {
726
+ return nil, err
727
+ }
728
+ return r.buildVars(m), nil
729
+ }
730
+
731
+ func (r *Route) buildVars(m map[string]string) map[string]string {
732
+ if r.buildVarsFunc != nil {
733
+ m = r.buildVarsFunc(m)
734
+ }
735
+ return m
736
+ }