diff --git a/go.mod b/go.mod
index 35d8e27..20f610f 100644
--- a/go.mod
+++ b/go.mod
@@ -4,33 +4,33 @@ require (
github.com/DeanThompson/ginpprof v0.0.0-20170218162546-8c0e31bfeaa8
github.com/PuerkitoBio/goquery v1.5.0
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
- github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fortytw2/leaktest v1.3.0 // indirect
- github.com/gin-contrib/cors v0.0.0-20181008113111-488de3ec974f
- github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 // indirect
- github.com/gin-gonic/contrib v0.0.0-20181101072842-54170a7b0b4b
+ github.com/gin-contrib/cors v0.0.0-20190301062745-f9e10995c85a
+ github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect
+ github.com/gin-gonic/contrib v0.0.0-20190302003538-54ff787f7c73
github.com/gin-gonic/gin v1.3.0
github.com/go-irc/irc v2.1.0+incompatible
+ github.com/go-sql-driver/mysql v1.4.1 // indirect
+ github.com/golang/protobuf v1.3.1 // indirect
+ github.com/google/go-cmp v0.2.0 // indirect
github.com/gorilla/sessions v1.1.3 // indirect
github.com/jmoiron/sqlx v1.2.0
github.com/json-iterator/go v1.1.6
+ github.com/kr/pretty v0.1.0 // indirect
github.com/lib/pq v1.0.0
- github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 // indirect
- github.com/mattn/go-isatty v0.0.4 // indirect
- github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
- github.com/modern-go/reflect2 v1.0.1 // indirect
+ github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe // indirect
+ github.com/mattn/go-isatty v0.0.7 // indirect
+ github.com/mattn/go-sqlite3 v1.10.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
- github.com/olivere/elastic v6.2.12+incompatible
- github.com/pkg/errors v0.8.0 // indirect
- github.com/pmezard/go-difflib v1.0.0 // indirect
+ github.com/olivere/elastic v6.2.16+incompatible
+ github.com/pkg/errors v0.8.1 // indirect
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967
- github.com/stretchr/testify v1.2.2 // indirect
- github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f // indirect
- golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869
- golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
- golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8 // indirect
- google.golang.org/appengine v1.3.0 // indirect
- gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
- gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
- gopkg.in/yaml.v2 v2.2.1
+ github.com/stretchr/testify v1.3.0 // indirect
+ github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780 // indirect
+ golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c
+ golang.org/x/net v0.0.0-20190328230028-74de082e2cca // indirect
+ golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 // indirect
+ google.golang.org/appengine v1.5.0 // indirect
+ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
+ gopkg.in/yaml.v2 v2.2.2
)
diff --git a/go.sum b/go.sum
index 61a644d..89d3d58 100644
--- a/go.sum
+++ b/go.sum
@@ -6,26 +6,35 @@ github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRy
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff h1:RmdPFa+slIr4SCBg4st/l/vZWVe9QJKMXGO60Bxbe04=
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff/go.mod h1:+RTT1BOk5P97fT2CiHkbFQwkK3mjsFAP6zCYV2aXtjw=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
-github.com/gin-contrib/cors v0.0.0-20181008113111-488de3ec974f h1:7kBk9VE4vAlHGsHqIXuhkrFuL5xTimW4ElJ9tkrnlXk=
-github.com/gin-contrib/cors v0.0.0-20181008113111-488de3ec974f/go.mod h1:cw+u9IsAkC16e42NtYYVCLsHYXE98nB3M7Dr9mLSeH4=
+github.com/gin-contrib/cors v0.0.0-20190301062745-f9e10995c85a h1:zBycVvXa03SIX+jdMv8wGu9TMDMWdN8EhaR1FoeKHNo=
+github.com/gin-contrib/cors v0.0.0-20190301062745-f9e10995c85a/go.mod h1:pL2kNE+DgDU+eQ+dary5bX0Z6LPP8nR6Mqs1iejILw4=
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7 h1:AzN37oI0cOS+cougNAV9szl6CVoj2RYwzS3DpUQNtlY=
github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
-github.com/gin-gonic/contrib v0.0.0-20181101072842-54170a7b0b4b h1:uJjmSEX74D3EyhBeht+spHAvS+aFRinOZOXjVXqb2cY=
-github.com/gin-gonic/contrib v0.0.0-20181101072842-54170a7b0b4b/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg=
+github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g=
+github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
+github.com/gin-gonic/contrib v0.0.0-20190302003538-54ff787f7c73 h1:dC6mPFx+I6Kkj/NJhI/ZVGVapv0u9tIEo6vp4ogXEjQ=
+github.com/gin-gonic/contrib v0.0.0-20190302003538-54ff787f7c73/go.mod h1:iqneQ2Df3omzIVTkIfn7c1acsVnMGiSLn4XF5Blh3Yg=
github.com/gin-gonic/gin v1.3.0 h1:kCmZyPklC0gVdL728E6Aj20uYBJV93nj/TkwBTKhFbs=
github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y=
github.com/go-irc/irc v2.1.0+incompatible h1:pg7pMVq5OYQbqTxceByD/EN8VIsba7DtKn49rsCnG8Y=
github.com/go-irc/irc v2.1.0+incompatible/go.mod h1:jJILTRy8s/qOvusiKifAEfhQMVwft1ZwQaVJnnzmyX4=
github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
+github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
+github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
+github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
+github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
+github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
+github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
@@ -39,50 +48,73 @@ github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswD
github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
+github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
+github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
-github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic=
-github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
+github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe h1:W/GaMY0y69G4cFlmsC6B9sbuo2fP8OFP1ABjt4kPz+w=
+github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
+github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc=
+github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4=
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
+github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
+github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
-github.com/olivere/elastic v6.2.12+incompatible h1:JJ9FxBH/CkfeAXQbyUI8FqzC2vPivNiAXseD2ClQv5Y=
-github.com/olivere/elastic v6.2.12+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8=
-github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
-github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/olivere/elastic v6.2.16+incompatible h1:+mQIHbkADkOgq9tFqnbyg7uNFVV6swGU07EoK1u0nEQ=
+github.com/olivere/elastic v6.2.16+incompatible/go.mod h1:J+q1zQJTgAz9woqsbVRqGeB5G1iqDKVBWLNSYW8yfJ8=
+github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
+github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 h1:x7xEyJDP7Hv3LVgvWhzioQqbC/KtuUhTigKlH/8ehhE=
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
-github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f h1:y3Vj7GoDdcBkxFa2RUUFKM25TrBbWVDnjRDI0u975zQ=
-github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
-golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869 h1:kkXA53yGe04D0adEYJwEVQjeBppL01Exg+fnMjfUraU=
-golang.org/x/crypto v0.0.0-20181112202954-3d3f9f413869/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
+github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/ugorji/go v1.1.2 h1:JON3E2/GPW2iDNGoSAusl1KDf5TRQ8k8q7Tp097pZGs=
+github.com/ugorji/go v1.1.2/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
+github.com/ugorji/go/codec v0.0.0-20181209151446-772ced7fd4c2/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
+github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780 h1:vG/gY/PxA3v3l04qxe3tDjXyu3bozii8ulSlIPOYKhI=
+github.com/ugorji/go/codec v0.0.0-20190320090025-2dc34c0b8780/go.mod h1:iT03XoTwV7xq/+UGwKO3UbC1nNNlopQiY61beSdrtOA=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI=
+golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
-golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8 h1:YoY1wS6JYVRpIfFngRf2HHo9R9dAne3xbkGOQ5rJXjU=
-golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190328230028-74de082e2cca h1:hyA6yiAgbUwuWqtscNvWAI7U1CtlaD1KilQ6iudt1aI=
+golang.org/x/net v0.0.0-20190328230028-74de082e2cca/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sys v0.0.0-20181228144115-9a3f9b0469bb/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65 h1:hOY+O8MxdkPV10pNf7/XEHaySCiPKxixMKUshfHsGn0=
+golang.org/x/sys v0.0.0-20190329044733-9eb1bfa1ce65/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-google.golang.org/appengine v1.3.0 h1:FBSsiFRMz3LBeXIomRnVzrQwSDj4ibvcRexLG0LZGQk=
-google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
+google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c=
+google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ=
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
-gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
-gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/vendor/github.com/DeanThompson/ginpprof/.gitignore b/vendor/github.com/DeanThompson/ginpprof/.gitignore
deleted file mode 100644
index daf913b..0000000
--- a/vendor/github.com/DeanThompson/ginpprof/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-# Compiled Object files, Static and Dynamic libs (Shared Objects)
-*.o
-*.a
-*.so
-
-# Folders
-_obj
-_test
-
-# Architecture specific extensions/prefixes
-*.[568vq]
-[568vq].out
-
-*.cgo1.go
-*.cgo2.c
-_cgo_defun.c
-_cgo_gotypes.go
-_cgo_export.*
-
-_testmain.go
-
-*.exe
-*.test
-*.prof
diff --git a/vendor/github.com/DeanThompson/ginpprof/.travis.yml b/vendor/github.com/DeanThompson/ginpprof/.travis.yml
deleted file mode 100644
index 4be76b9..0000000
--- a/vendor/github.com/DeanThompson/ginpprof/.travis.yml
+++ /dev/null
@@ -1,11 +0,0 @@
-language: go
-
-go:
- - 1.5
- - 1.6
- - 1.7
- - 1.8
- - tip
-
-script:
- - go test
diff --git a/vendor/github.com/DeanThompson/ginpprof/LICENSE b/vendor/github.com/DeanThompson/ginpprof/LICENSE
deleted file mode 100644
index a25bc61..0000000
--- a/vendor/github.com/DeanThompson/ginpprof/LICENSE
+++ /dev/null
@@ -1,22 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2015 Yangliang Li
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
diff --git a/vendor/github.com/DeanThompson/ginpprof/README.md b/vendor/github.com/DeanThompson/ginpprof/README.md
deleted file mode 100644
index f5d658b..0000000
--- a/vendor/github.com/DeanThompson/ginpprof/README.md
+++ /dev/null
@@ -1,68 +0,0 @@
-ginpprof
-========
-
-[![GoDoc](https://godoc.org/github.com/DeanThompson/ginpprof?status.svg)](https://godoc.org/github.com/DeanThompson/ginpprof)
-[![Build
-Status](https://travis-ci.org/DeanThompson/ginpprof.svg?branch=master)](https://travis-ci.org/DeanThompson/ginpprof)
-
-A wrapper for [golang web framework gin](https://github.com/gin-gonic/gin) to use `net/http/pprof` easily.
-
-## Install
-
-First install ginpprof to your GOPATH using `go get`:
-
-```sh
-go get github.com/DeanThompson/ginpprof
-```
-
-## Usage
-
-```go
-package main
-
-import (
- "github.com/gin-gonic/gin"
-
- "github.com/DeanThompson/ginpprof"
-)
-
-func main() {
- router := gin.Default()
-
- router.GET("/ping", func(c *gin.Context) {
- c.String(200, "pong")
- })
-
- // automatically add routers for net/http/pprof
- // e.g. /debug/pprof, /debug/pprof/heap, etc.
- ginpprof.Wrap(router)
-
- // ginpprof also plays well with *gin.RouterGroup
- // group := router.Group("/debug/pprof")
- // ginpprof.WrapGroup(group)
-
- router.Run(":8080")
-}
-```
-
-Start this server, and you will see such outputs:
-
-```text
-[GIN-debug] GET /ping --> main.main.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/ --> github.com/DeanThompson/ginpprof.IndexHandler.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/heap --> github.com/DeanThompson/ginpprof.HeapHandler.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/goroutine --> github.com/DeanThompson/ginpprof.GoroutineHandler.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/block --> github.com/DeanThompson/ginpprof.BlockHandler.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/threadcreate --> github.com/DeanThompson/ginpprof.ThreadCreateHandler.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/cmdline --> github.com/DeanThompson/ginpprof.CmdlineHandler.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/profile --> github.com/DeanThompson/ginpprof.ProfileHandler.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/symbol --> github.com/DeanThompson/ginpprof.SymbolHandler.func1 (3 handlers)
-[GIN-debug] POST /debug/pprof/symbol --> github.com/DeanThompson/ginpprof.SymbolHandler.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/trace --> github.com/DeanThompson/ginpprof.TraceHandler.func1 (3 handlers)
-[GIN-debug] GET /debug/pprof/mutex --> github.com/DeanThompson/ginpprof.MutexHandler.func1 (3 handlers)
-[GIN-debug] Listening and serving HTTP on :8080
-```
-
-Now visit [http://127.0.0.1:8080/debug/pprof/](http://127.0.0.1:8080/debug/pprof/) and you'll see what you want.
-
-Have Fun.
diff --git a/vendor/github.com/DeanThompson/ginpprof/pprof.go b/vendor/github.com/DeanThompson/ginpprof/pprof.go
deleted file mode 100644
index a76da61..0000000
--- a/vendor/github.com/DeanThompson/ginpprof/pprof.go
+++ /dev/null
@@ -1,123 +0,0 @@
-package ginpprof
-
-import (
- "net/http/pprof"
- "strings"
-
- "github.com/gin-gonic/gin"
-)
-
-// Wrap adds several routes from package `net/http/pprof` to *gin.Engine object
-func Wrap(router *gin.Engine) {
- WrapGroup(&router.RouterGroup)
-}
-
-// Wrapper make sure we are backward compatible
-var Wrapper = Wrap
-
-// WrapGroup adds several routes from package `net/http/pprof` to *gin.RouterGroup object
-func WrapGroup(router *gin.RouterGroup) {
- routers := []struct {
- Method string
- Path string
- Handler gin.HandlerFunc
- }{
- {"GET", "/debug/pprof/", IndexHandler()},
- {"GET", "/debug/pprof/heap", HeapHandler()},
- {"GET", "/debug/pprof/goroutine", GoroutineHandler()},
- {"GET", "/debug/pprof/block", BlockHandler()},
- {"GET", "/debug/pprof/threadcreate", ThreadCreateHandler()},
- {"GET", "/debug/pprof/cmdline", CmdlineHandler()},
- {"GET", "/debug/pprof/profile", ProfileHandler()},
- {"GET", "/debug/pprof/symbol", SymbolHandler()},
- {"POST", "/debug/pprof/symbol", SymbolHandler()},
- {"GET", "/debug/pprof/trace", TraceHandler()},
- {"GET", "/debug/pprof/mutex", MutexHandler()},
- }
-
- basePath := strings.TrimSuffix(router.BasePath(), "/")
- var prefix string
-
- switch {
- case basePath == "":
- prefix = ""
- case strings.HasSuffix(basePath, "/debug"):
- prefix = "/debug"
- case strings.HasSuffix(basePath, "/debug/pprof"):
- prefix = "/debug/pprof"
- }
-
- for _, r := range routers {
- router.Handle(r.Method, strings.TrimPrefix(r.Path, prefix), r.Handler)
- }
-}
-
-// IndexHandler will pass the call from /debug/pprof to pprof
-func IndexHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Index(ctx.Writer, ctx.Request)
- }
-}
-
-// HeapHandler will pass the call from /debug/pprof/heap to pprof
-func HeapHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Handler("heap").ServeHTTP(ctx.Writer, ctx.Request)
- }
-}
-
-// GoroutineHandler will pass the call from /debug/pprof/goroutine to pprof
-func GoroutineHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Handler("goroutine").ServeHTTP(ctx.Writer, ctx.Request)
- }
-}
-
-// BlockHandler will pass the call from /debug/pprof/block to pprof
-func BlockHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Handler("block").ServeHTTP(ctx.Writer, ctx.Request)
- }
-}
-
-// ThreadCreateHandler will pass the call from /debug/pprof/threadcreate to pprof
-func ThreadCreateHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Handler("threadcreate").ServeHTTP(ctx.Writer, ctx.Request)
- }
-}
-
-// CmdlineHandler will pass the call from /debug/pprof/cmdline to pprof
-func CmdlineHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Cmdline(ctx.Writer, ctx.Request)
- }
-}
-
-// ProfileHandler will pass the call from /debug/pprof/profile to pprof
-func ProfileHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Profile(ctx.Writer, ctx.Request)
- }
-}
-
-// SymbolHandler will pass the call from /debug/pprof/symbol to pprof
-func SymbolHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Symbol(ctx.Writer, ctx.Request)
- }
-}
-
-// TraceHandler will pass the call from /debug/pprof/trace to pprof
-func TraceHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Trace(ctx.Writer, ctx.Request)
- }
-}
-
-// MutexHandler will pass the call from /debug/pprof/mutex to pprof
-func MutexHandler() gin.HandlerFunc {
- return func(ctx *gin.Context) {
- pprof.Handler("mutex").ServeHTTP(ctx.Writer, ctx.Request)
- }
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/.gitattributes b/vendor/github.com/PuerkitoBio/goquery/.gitattributes
deleted file mode 100644
index 0cc26ec..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/.gitattributes
+++ /dev/null
@@ -1 +0,0 @@
-testdata/* linguist-vendored
diff --git a/vendor/github.com/PuerkitoBio/goquery/.gitignore b/vendor/github.com/PuerkitoBio/goquery/.gitignore
deleted file mode 100644
index 970381c..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/.gitignore
+++ /dev/null
@@ -1,16 +0,0 @@
-# editor temporary files
-*.sublime-*
-.DS_Store
-*.swp
-#*.*#
-tags
-
-# direnv config
-.env*
-
-# test binaries
-*.test
-
-# coverage and profilte outputs
-*.out
-
diff --git a/vendor/github.com/PuerkitoBio/goquery/.travis.yml b/vendor/github.com/PuerkitoBio/goquery/.travis.yml
deleted file mode 100644
index cc1402d..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/.travis.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-language: go
-
-go:
- - 1.1
- - 1.2.x
- - 1.3.x
- - 1.4.x
- - 1.5.x
- - 1.6.x
- - 1.7.x
- - 1.8.x
- - 1.9.x
- - "1.10.x"
- - 1.11.x
- - tip
-
diff --git a/vendor/github.com/PuerkitoBio/goquery/LICENSE b/vendor/github.com/PuerkitoBio/goquery/LICENSE
deleted file mode 100644
index f743d37..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/LICENSE
+++ /dev/null
@@ -1,12 +0,0 @@
-Copyright (c) 2012-2016, Martin Angers & Contributors
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
-* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-
-* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/PuerkitoBio/goquery/README.md b/vendor/github.com/PuerkitoBio/goquery/README.md
deleted file mode 100644
index 84f9af3..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/README.md
+++ /dev/null
@@ -1,179 +0,0 @@
-# goquery - a little like that j-thing, only in Go
-[![build status](https://secure.travis-ci.org/PuerkitoBio/goquery.svg?branch=master)](http://travis-ci.org/PuerkitoBio/goquery) [![GoDoc](https://godoc.org/github.com/PuerkitoBio/goquery?status.png)](http://godoc.org/github.com/PuerkitoBio/goquery) [![Sourcegraph Badge](https://sourcegraph.com/github.com/PuerkitoBio/goquery/-/badge.svg)](https://sourcegraph.com/github.com/PuerkitoBio/goquery?badge)
-
-goquery brings a syntax and a set of features similar to [jQuery][] to the [Go language][go]. It is based on Go's [net/html package][html] and the CSS Selector library [cascadia][]. Since the net/html parser returns nodes, and not a full-featured DOM tree, jQuery's stateful manipulation functions (like height(), css(), detach()) have been left off.
-
-Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML. See the [wiki][] for various options to do this.
-
-Syntax-wise, it is as close as possible to jQuery, with the same function names when possible, and that warm and fuzzy chainable interface. jQuery being the ultra-popular library that it is, I felt that writing a similar HTML-manipulating library was better to follow its API than to start anew (in the same spirit as Go's `fmt` package), even though some of its methods are less than intuitive (looking at you, [index()][index]...).
-
-## Table of Contents
-
-* [Installation](#installation)
-* [Changelog](#changelog)
-* [API](#api)
-* [Examples](#examples)
-* [Related Projects](#related-projects)
-* [Support](#support)
-* [License](#license)
-
-## Installation
-
-Please note that because of the net/html dependency, goquery requires Go1.1+.
-
- $ go get github.com/PuerkitoBio/goquery
-
-(optional) To run unit tests:
-
- $ cd $GOPATH/src/github.com/PuerkitoBio/goquery
- $ go test
-
-(optional) To run benchmarks (warning: it runs for a few minutes):
-
- $ cd $GOPATH/src/github.com/PuerkitoBio/goquery
- $ go test -bench=".*"
-
-## Changelog
-
-**Note that goquery's API is now stable, and will not break.**
-
-* **2018-11-15 (v1.5.0)** : Go module support (thanks @Zaba505).
-* **2018-06-07 (v1.4.1)** : Add `NewDocumentFromReader` examples.
-* **2018-03-24 (v1.4.0)** : Deprecate `NewDocument(url)` and `NewDocumentFromResponse(response)`.
-* **2018-01-28 (v1.3.0)** : Add `ToEnd` constant to `Slice` until the end of the selection (thanks to @davidjwilkins for raising the issue).
-* **2018-01-11 (v1.2.0)** : Add `AddBack*` and deprecate `AndSelf` (thanks to @davidjwilkins).
-* **2017-02-12 (v1.1.0)** : Add `SetHtml` and `SetText` (thanks to @glebtv).
-* **2016-12-29 (v1.0.2)** : Optimize allocations for `Selection.Text` (thanks to @radovskyb).
-* **2016-08-28 (v1.0.1)** : Optimize performance for large documents.
-* **2016-07-27 (v1.0.0)** : Tag version 1.0.0.
-* **2016-06-15** : Invalid selector strings internally compile to a `Matcher` implementation that never matches any node (instead of a panic). So for example, `doc.Find("~")` returns an empty `*Selection` object.
-* **2016-02-02** : Add `NodeName` utility function similar to the DOM's `nodeName` property. It returns the tag name of the first element in a selection, and other relevant values of non-element nodes (see godoc for details). Add `OuterHtml` utility function similar to the DOM's `outerHTML` property (named `OuterHtml` in small caps for consistency with the existing `Html` method on the `Selection`).
-* **2015-04-20** : Add `AttrOr` helper method to return the attribute's value or a default value if absent. Thanks to [piotrkowalczuk][piotr].
-* **2015-02-04** : Add more manipulation functions - Prepend* - thanks again to [Andrew Stone][thatguystone].
-* **2014-11-28** : Add more manipulation functions - ReplaceWith*, Wrap* and Unwrap - thanks again to [Andrew Stone][thatguystone].
-* **2014-11-07** : Add manipulation functions (thanks to [Andrew Stone][thatguystone]) and `*Matcher` functions, that receive compiled cascadia selectors instead of selector strings, thus avoiding potential panics thrown by goquery via `cascadia.MustCompile` calls. This results in better performance (selectors can be compiled once and reused) and more idiomatic error handling (you can handle cascadia's compilation errors, instead of recovering from panics, which had been bugging me for a long time). Note that the actual type expected is a `Matcher` interface, that `cascadia.Selector` implements. Other matcher implementations could be used.
-* **2014-11-06** : Change import paths of net/html to golang.org/x/net/html (see https://groups.google.com/forum/#!topic/golang-nuts/eD8dh3T9yyA). Make sure to update your code to use the new import path too when you call goquery with `html.Node`s.
-* **v0.3.2** : Add `NewDocumentFromReader()` (thanks jweir) which allows creating a goquery document from an io.Reader.
-* **v0.3.1** : Add `NewDocumentFromResponse()` (thanks assassingj) which allows creating a goquery document from an http response.
-* **v0.3.0** : Add `EachWithBreak()` which allows to break out of an `Each()` loop by returning false. This function was added instead of changing the existing `Each()` to avoid breaking compatibility.
-* **v0.2.1** : Make go-getable, now that [go.net/html is Go1.0-compatible][gonet] (thanks to @matrixik for pointing this out).
-* **v0.2.0** : Add support for negative indices in Slice(). **BREAKING CHANGE** `Document.Root` is removed, `Document` is now a `Selection` itself (a selection of one, the root element, just like `Document.Root` was before). Add jQuery's Closest() method.
-* **v0.1.1** : Add benchmarks to use as baseline for refactorings, refactor Next...() and Prev...() methods to use the new html package's linked list features (Next/PrevSibling, FirstChild). Good performance boost (40+% in some cases).
-* **v0.1.0** : Initial release.
-
-## API
-
-goquery exposes two structs, `Document` and `Selection`, and the `Matcher` interface. Unlike jQuery, which is loaded as part of a DOM document, and thus acts on its containing document, goquery doesn't know which HTML document to act upon. So it needs to be told, and that's what the `Document` type is for. It holds the root document node as the initial Selection value to manipulate.
-
-jQuery often has many variants for the same function (no argument, a selector string argument, a jQuery object argument, a DOM element argument, ...). Instead of exposing the same features in goquery as a single method with variadic empty interface arguments, statically-typed signatures are used following this naming convention:
-
-* When the jQuery equivalent can be called with no argument, it has the same name as jQuery for the no argument signature (e.g.: `Prev()`), and the version with a selector string argument is called `XxxFiltered()` (e.g.: `PrevFiltered()`)
-* When the jQuery equivalent **requires** one argument, the same name as jQuery is used for the selector string version (e.g.: `Is()`)
-* The signatures accepting a jQuery object as argument are defined in goquery as `XxxSelection()` and take a `*Selection` object as argument (e.g.: `FilterSelection()`)
-* The signatures accepting a DOM element as argument in jQuery are defined in goquery as `XxxNodes()` and take a variadic argument of type `*html.Node` (e.g.: `FilterNodes()`)
-* The signatures accepting a function as argument in jQuery are defined in goquery as `XxxFunction()` and take a function as argument (e.g.: `FilterFunction()`)
-* The goquery methods that can be called with a selector string have a corresponding version that take a `Matcher` interface and are defined as `XxxMatcher()` (e.g.: `IsMatcher()`)
-
-Utility functions that are not in jQuery but are useful in Go are implemented as functions (that take a `*Selection` as parameter), to avoid a potential naming clash on the `*Selection`'s methods (reserved for jQuery-equivalent behaviour).
-
-The complete [godoc reference documentation can be found here][doc].
-
-Please note that Cascadia's selectors do not necessarily match all supported selectors of jQuery (Sizzle). See the [cascadia project][cascadia] for details. Invalid selector strings compile to a `Matcher` that fails to match any node. Behaviour of the various functions that take a selector string as argument follows from that fact, e.g. (where `~` is an invalid selector string):
-
-* `Find("~")` returns an empty selection because the selector string doesn't match anything.
-* `Add("~")` returns a new selection that holds the same nodes as the original selection, because it didn't add any node (selector string didn't match anything).
-* `ParentsFiltered("~")` returns an empty selection because the selector string doesn't match anything.
-* `ParentsUntil("~")` returns all parents of the selection because the selector string didn't match any element to stop before the top element.
-
-## Examples
-
-See some tips and tricks in the [wiki][].
-
-Adapted from example_test.go:
-
-```Go
-package main
-
-import (
- "fmt"
- "log"
- "net/http"
-
- "github.com/PuerkitoBio/goquery"
-)
-
-func ExampleScrape() {
- // Request the HTML page.
- res, err := http.Get("http://metalsucks.net")
- if err != nil {
- log.Fatal(err)
- }
- defer res.Body.Close()
- if res.StatusCode != 200 {
- log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
- }
-
- // Load the HTML document
- doc, err := goquery.NewDocumentFromReader(res.Body)
- if err != nil {
- log.Fatal(err)
- }
-
- // Find the review items
- doc.Find(".sidebar-reviews article .content-block").Each(func(i int, s *goquery.Selection) {
- // For each item found, get the band and title
- band := s.Find("a").Text()
- title := s.Find("i").Text()
- fmt.Printf("Review %d: %s - %s\n", i, band, title)
- })
-}
-
-func main() {
- ExampleScrape()
-}
-```
-
-## Related Projects
-
-- [Goq][goq], an HTML deserialization and scraping library based on goquery and struct tags.
-- [andybalholm/cascadia][cascadia], the CSS selector library used by goquery.
-- [suntong/cascadia][cascadiacli], a command-line interface to the cascadia CSS selector library, useful to test selectors.
-- [asciimoo/colly](https://github.com/asciimoo/colly), a lightning fast and elegant Scraping Framework
-- [gnulnx/goperf](https://github.com/gnulnx/goperf), a website performance test tool that also fetches static assets.
-- [MontFerret/ferret](https://github.com/MontFerret/ferret), declarative web scraping.
-
-## Support
-
-There are a number of ways you can support the project:
-
-* Use it, star it, build something with it, spread the word!
- - If you do build something open-source or otherwise publicly-visible, let me know so I can add it to the [Related Projects](#related-projects) section!
-* Raise issues to improve the project (note: doc typos and clarifications are issues too!)
- - Please search existing issues before opening a new one - it may have already been adressed.
-* Pull requests: please discuss new code in an issue first, unless the fix is really trivial.
- - Make sure new code is tested.
- - Be mindful of existing code - PRs that break existing code have a high probability of being declined, unless it fixes a serious issue.
-
-If you desperately want to send money my way, I have a BuyMeACoffee.com page:
-
-
-
-## License
-
-The [BSD 3-Clause license][bsd], the same as the [Go language][golic]. Cascadia's license is [here][caslic].
-
-[jquery]: http://jquery.com/
-[go]: http://golang.org/
-[cascadia]: https://github.com/andybalholm/cascadia
-[cascadiacli]: https://github.com/suntong/cascadia
-[bsd]: http://opensource.org/licenses/BSD-3-Clause
-[golic]: http://golang.org/LICENSE
-[caslic]: https://github.com/andybalholm/cascadia/blob/master/LICENSE
-[doc]: http://godoc.org/github.com/PuerkitoBio/goquery
-[index]: http://api.jquery.com/index/
-[gonet]: https://github.com/golang/net/
-[html]: http://godoc.org/golang.org/x/net/html
-[wiki]: https://github.com/PuerkitoBio/goquery/wiki/Tips-and-tricks
-[thatguystone]: https://github.com/thatguystone
-[piotr]: https://github.com/piotrkowalczuk
-[goq]: https://github.com/andrewstuart/goq
diff --git a/vendor/github.com/PuerkitoBio/goquery/array.go b/vendor/github.com/PuerkitoBio/goquery/array.go
deleted file mode 100644
index 1b1f6cb..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/array.go
+++ /dev/null
@@ -1,124 +0,0 @@
-package goquery
-
-import (
- "golang.org/x/net/html"
-)
-
-const (
- maxUint = ^uint(0)
- maxInt = int(maxUint >> 1)
-
- // ToEnd is a special index value that can be used as end index in a call
- // to Slice so that all elements are selected until the end of the Selection.
- // It is equivalent to passing (*Selection).Length().
- ToEnd = maxInt
-)
-
-// First reduces the set of matched elements to the first in the set.
-// It returns a new Selection object, and an empty Selection object if the
-// the selection is empty.
-func (s *Selection) First() *Selection {
- return s.Eq(0)
-}
-
-// Last reduces the set of matched elements to the last in the set.
-// It returns a new Selection object, and an empty Selection object if
-// the selection is empty.
-func (s *Selection) Last() *Selection {
- return s.Eq(-1)
-}
-
-// Eq reduces the set of matched elements to the one at the specified index.
-// If a negative index is given, it counts backwards starting at the end of the
-// set. It returns a new Selection object, and an empty Selection object if the
-// index is invalid.
-func (s *Selection) Eq(index int) *Selection {
- if index < 0 {
- index += len(s.Nodes)
- }
-
- if index >= len(s.Nodes) || index < 0 {
- return newEmptySelection(s.document)
- }
-
- return s.Slice(index, index+1)
-}
-
-// Slice reduces the set of matched elements to a subset specified by a range
-// of indices. The start index is 0-based and indicates the index of the first
-// element to select. The end index is 0-based and indicates the index at which
-// the elements stop being selected (the end index is not selected).
-//
-// The indices may be negative, in which case they represent an offset from the
-// end of the selection.
-//
-// The special value ToEnd may be specified as end index, in which case all elements
-// until the end are selected. This works both for a positive and negative start
-// index.
-func (s *Selection) Slice(start, end int) *Selection {
- if start < 0 {
- start += len(s.Nodes)
- }
- if end == ToEnd {
- end = len(s.Nodes)
- } else if end < 0 {
- end += len(s.Nodes)
- }
- return pushStack(s, s.Nodes[start:end])
-}
-
-// Get retrieves the underlying node at the specified index.
-// Get without parameter is not implemented, since the node array is available
-// on the Selection object.
-func (s *Selection) Get(index int) *html.Node {
- if index < 0 {
- index += len(s.Nodes) // Negative index gets from the end
- }
- return s.Nodes[index]
-}
-
-// Index returns the position of the first element within the Selection object
-// relative to its sibling elements.
-func (s *Selection) Index() int {
- if len(s.Nodes) > 0 {
- return newSingleSelection(s.Nodes[0], s.document).PrevAll().Length()
- }
- return -1
-}
-
-// IndexSelector returns the position of the first element within the
-// Selection object relative to the elements matched by the selector, or -1 if
-// not found.
-func (s *Selection) IndexSelector(selector string) int {
- if len(s.Nodes) > 0 {
- sel := s.document.Find(selector)
- return indexInSlice(sel.Nodes, s.Nodes[0])
- }
- return -1
-}
-
-// IndexMatcher returns the position of the first element within the
-// Selection object relative to the elements matched by the matcher, or -1 if
-// not found.
-func (s *Selection) IndexMatcher(m Matcher) int {
- if len(s.Nodes) > 0 {
- sel := s.document.FindMatcher(m)
- return indexInSlice(sel.Nodes, s.Nodes[0])
- }
- return -1
-}
-
-// IndexOfNode returns the position of the specified node within the Selection
-// object, or -1 if not found.
-func (s *Selection) IndexOfNode(node *html.Node) int {
- return indexInSlice(s.Nodes, node)
-}
-
-// IndexOfSelection returns the position of the first node in the specified
-// Selection object within this Selection object, or -1 if not found.
-func (s *Selection) IndexOfSelection(sel *Selection) int {
- if sel != nil && len(sel.Nodes) > 0 {
- return indexInSlice(s.Nodes, sel.Nodes[0])
- }
- return -1
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/doc.go b/vendor/github.com/PuerkitoBio/goquery/doc.go
deleted file mode 100644
index 71146a7..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/doc.go
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright (c) 2012-2016, Martin Angers & Contributors
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// * Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or
-// other materials provided with the distribution.
-// * Neither the name of the author nor the names of its contributors may be used to
-// endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
-// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
-// WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-/*
-Package goquery implements features similar to jQuery, including the chainable
-syntax, to manipulate and query an HTML document.
-
-It brings a syntax and a set of features similar to jQuery to the Go language.
-It is based on Go's net/html package and the CSS Selector library cascadia.
-Since the net/html parser returns nodes, and not a full-featured DOM
-tree, jQuery's stateful manipulation functions (like height(), css(), detach())
-have been left off.
-
-Also, because the net/html parser requires UTF-8 encoding, so does goquery: it is
-the caller's responsibility to ensure that the source document provides UTF-8 encoded HTML.
-See the repository's wiki for various options on how to do this.
-
-Syntax-wise, it is as close as possible to jQuery, with the same method names when
-possible, and that warm and fuzzy chainable interface. jQuery being the
-ultra-popular library that it is, writing a similar HTML-manipulating
-library was better to follow its API than to start anew (in the same spirit as
-Go's fmt package), even though some of its methods are less than intuitive (looking
-at you, index()...).
-
-It is hosted on GitHub, along with additional documentation in the README.md
-file: https://github.com/puerkitobio/goquery
-
-Please note that because of the net/html dependency, goquery requires Go1.1+.
-
-The various methods are split into files based on the category of behavior.
-The three dots (...) indicate that various "overloads" are available.
-
-* array.go : array-like positional manipulation of the selection.
- - Eq()
- - First()
- - Get()
- - Index...()
- - Last()
- - Slice()
-
-* expand.go : methods that expand or augment the selection's set.
- - Add...()
- - AndSelf()
- - Union(), which is an alias for AddSelection()
-
-* filter.go : filtering methods, that reduce the selection's set.
- - End()
- - Filter...()
- - Has...()
- - Intersection(), which is an alias of FilterSelection()
- - Not...()
-
-* iteration.go : methods to loop over the selection's nodes.
- - Each()
- - EachWithBreak()
- - Map()
-
-* manipulation.go : methods for modifying the document
- - After...()
- - Append...()
- - Before...()
- - Clone()
- - Empty()
- - Prepend...()
- - Remove...()
- - ReplaceWith...()
- - Unwrap()
- - Wrap...()
- - WrapAll...()
- - WrapInner...()
-
-* property.go : methods that inspect and get the node's properties values.
- - Attr*(), RemoveAttr(), SetAttr()
- - AddClass(), HasClass(), RemoveClass(), ToggleClass()
- - Html()
- - Length()
- - Size(), which is an alias for Length()
- - Text()
-
-* query.go : methods that query, or reflect, a node's identity.
- - Contains()
- - Is...()
-
-* traversal.go : methods to traverse the HTML document tree.
- - Children...()
- - Contents()
- - Find...()
- - Next...()
- - Parent[s]...()
- - Prev...()
- - Siblings...()
-
-* type.go : definition of the types exposed by goquery.
- - Document
- - Selection
- - Matcher
-
-* utilities.go : definition of helper functions (and not methods on a *Selection)
-that are not part of jQuery, but are useful to goquery.
- - NodeName
- - OuterHtml
-*/
-package goquery
diff --git a/vendor/github.com/PuerkitoBio/goquery/expand.go b/vendor/github.com/PuerkitoBio/goquery/expand.go
deleted file mode 100644
index 7caade5..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/expand.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package goquery
-
-import "golang.org/x/net/html"
-
-// Add adds the selector string's matching nodes to those in the current
-// selection and returns a new Selection object.
-// The selector string is run in the context of the document of the current
-// Selection object.
-func (s *Selection) Add(selector string) *Selection {
- return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, compileMatcher(selector))...)
-}
-
-// AddMatcher adds the matcher's matching nodes to those in the current
-// selection and returns a new Selection object.
-// The matcher is run in the context of the document of the current
-// Selection object.
-func (s *Selection) AddMatcher(m Matcher) *Selection {
- return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, m)...)
-}
-
-// AddSelection adds the specified Selection object's nodes to those in the
-// current selection and returns a new Selection object.
-func (s *Selection) AddSelection(sel *Selection) *Selection {
- if sel == nil {
- return s.AddNodes()
- }
- return s.AddNodes(sel.Nodes...)
-}
-
-// Union is an alias for AddSelection.
-func (s *Selection) Union(sel *Selection) *Selection {
- return s.AddSelection(sel)
-}
-
-// AddNodes adds the specified nodes to those in the
-// current selection and returns a new Selection object.
-func (s *Selection) AddNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, appendWithoutDuplicates(s.Nodes, nodes, nil))
-}
-
-// AndSelf adds the previous set of elements on the stack to the current set.
-// It returns a new Selection object containing the current Selection combined
-// with the previous one.
-// Deprecated: This function has been deprecated and is now an alias for AddBack().
-func (s *Selection) AndSelf() *Selection {
- return s.AddBack()
-}
-
-// AddBack adds the previous set of elements on the stack to the current set.
-// It returns a new Selection object containing the current Selection combined
-// with the previous one.
-func (s *Selection) AddBack() *Selection {
- return s.AddSelection(s.prevSel)
-}
-
-// AddBackFiltered reduces the previous set of elements on the stack to those that
-// match the selector string, and adds them to the current set.
-// It returns a new Selection object containing the current Selection combined
-// with the filtered previous one
-func (s *Selection) AddBackFiltered(selector string) *Selection {
- return s.AddSelection(s.prevSel.Filter(selector))
-}
-
-// AddBackMatcher reduces the previous set of elements on the stack to those that match
-// the mateher, and adds them to the curernt set.
-// It returns a new Selection object containing the current Selection combined
-// with the filtered previous one
-func (s *Selection) AddBackMatcher(m Matcher) *Selection {
- return s.AddSelection(s.prevSel.FilterMatcher(m))
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/filter.go b/vendor/github.com/PuerkitoBio/goquery/filter.go
deleted file mode 100644
index 9138ffb..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/filter.go
+++ /dev/null
@@ -1,163 +0,0 @@
-package goquery
-
-import "golang.org/x/net/html"
-
-// Filter reduces the set of matched elements to those that match the selector string.
-// It returns a new Selection object for this subset of matching elements.
-func (s *Selection) Filter(selector string) *Selection {
- return s.FilterMatcher(compileMatcher(selector))
-}
-
-// FilterMatcher reduces the set of matched elements to those that match
-// the given matcher. It returns a new Selection object for this subset
-// of matching elements.
-func (s *Selection) FilterMatcher(m Matcher) *Selection {
- return pushStack(s, winnow(s, m, true))
-}
-
-// Not removes elements from the Selection that match the selector string.
-// It returns a new Selection object with the matching elements removed.
-func (s *Selection) Not(selector string) *Selection {
- return s.NotMatcher(compileMatcher(selector))
-}
-
-// NotMatcher removes elements from the Selection that match the given matcher.
-// It returns a new Selection object with the matching elements removed.
-func (s *Selection) NotMatcher(m Matcher) *Selection {
- return pushStack(s, winnow(s, m, false))
-}
-
-// FilterFunction reduces the set of matched elements to those that pass the function's test.
-// It returns a new Selection object for this subset of elements.
-func (s *Selection) FilterFunction(f func(int, *Selection) bool) *Selection {
- return pushStack(s, winnowFunction(s, f, true))
-}
-
-// NotFunction removes elements from the Selection that pass the function's test.
-// It returns a new Selection object with the matching elements removed.
-func (s *Selection) NotFunction(f func(int, *Selection) bool) *Selection {
- return pushStack(s, winnowFunction(s, f, false))
-}
-
-// FilterNodes reduces the set of matched elements to those that match the specified nodes.
-// It returns a new Selection object for this subset of elements.
-func (s *Selection) FilterNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, winnowNodes(s, nodes, true))
-}
-
-// NotNodes removes elements from the Selection that match the specified nodes.
-// It returns a new Selection object with the matching elements removed.
-func (s *Selection) NotNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, winnowNodes(s, nodes, false))
-}
-
-// FilterSelection reduces the set of matched elements to those that match a
-// node in the specified Selection object.
-// It returns a new Selection object for this subset of elements.
-func (s *Selection) FilterSelection(sel *Selection) *Selection {
- if sel == nil {
- return pushStack(s, winnowNodes(s, nil, true))
- }
- return pushStack(s, winnowNodes(s, sel.Nodes, true))
-}
-
-// NotSelection removes elements from the Selection that match a node in the specified
-// Selection object. It returns a new Selection object with the matching elements removed.
-func (s *Selection) NotSelection(sel *Selection) *Selection {
- if sel == nil {
- return pushStack(s, winnowNodes(s, nil, false))
- }
- return pushStack(s, winnowNodes(s, sel.Nodes, false))
-}
-
-// Intersection is an alias for FilterSelection.
-func (s *Selection) Intersection(sel *Selection) *Selection {
- return s.FilterSelection(sel)
-}
-
-// Has reduces the set of matched elements to those that have a descendant
-// that matches the selector.
-// It returns a new Selection object with the matching elements.
-func (s *Selection) Has(selector string) *Selection {
- return s.HasSelection(s.document.Find(selector))
-}
-
-// HasMatcher reduces the set of matched elements to those that have a descendant
-// that matches the matcher.
-// It returns a new Selection object with the matching elements.
-func (s *Selection) HasMatcher(m Matcher) *Selection {
- return s.HasSelection(s.document.FindMatcher(m))
-}
-
-// HasNodes reduces the set of matched elements to those that have a
-// descendant that matches one of the nodes.
-// It returns a new Selection object with the matching elements.
-func (s *Selection) HasNodes(nodes ...*html.Node) *Selection {
- return s.FilterFunction(func(_ int, sel *Selection) bool {
- // Add all nodes that contain one of the specified nodes
- for _, n := range nodes {
- if sel.Contains(n) {
- return true
- }
- }
- return false
- })
-}
-
-// HasSelection reduces the set of matched elements to those that have a
-// descendant that matches one of the nodes of the specified Selection object.
-// It returns a new Selection object with the matching elements.
-func (s *Selection) HasSelection(sel *Selection) *Selection {
- if sel == nil {
- return s.HasNodes()
- }
- return s.HasNodes(sel.Nodes...)
-}
-
-// End ends the most recent filtering operation in the current chain and
-// returns the set of matched elements to its previous state.
-func (s *Selection) End() *Selection {
- if s.prevSel != nil {
- return s.prevSel
- }
- return newEmptySelection(s.document)
-}
-
-// Filter based on the matcher, and the indicator to keep (Filter) or
-// to get rid of (Not) the matching elements.
-func winnow(sel *Selection, m Matcher, keep bool) []*html.Node {
- // Optimize if keep is requested
- if keep {
- return m.Filter(sel.Nodes)
- }
- // Use grep
- return grep(sel, func(i int, s *Selection) bool {
- return !m.Match(s.Get(0))
- })
-}
-
-// Filter based on an array of nodes, and the indicator to keep (Filter) or
-// to get rid of (Not) the matching elements.
-func winnowNodes(sel *Selection, nodes []*html.Node, keep bool) []*html.Node {
- if len(nodes)+len(sel.Nodes) < minNodesForSet {
- return grep(sel, func(i int, s *Selection) bool {
- return isInSlice(nodes, s.Get(0)) == keep
- })
- }
-
- set := make(map[*html.Node]bool)
- for _, n := range nodes {
- set[n] = true
- }
- return grep(sel, func(i int, s *Selection) bool {
- return set[s.Get(0)] == keep
- })
-}
-
-// Filter based on a function test, and the indicator to keep (Filter) or
-// to get rid of (Not) the matching elements.
-func winnowFunction(sel *Selection, f func(int, *Selection) bool, keep bool) []*html.Node {
- return grep(sel, func(i int, s *Selection) bool {
- return f(i, s) == keep
- })
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/go.mod b/vendor/github.com/PuerkitoBio/goquery/go.mod
deleted file mode 100644
index 2fa1332..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/go.mod
+++ /dev/null
@@ -1,6 +0,0 @@
-module github.com/PuerkitoBio/goquery
-
-require (
- github.com/andybalholm/cascadia v1.0.0
- golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
-)
diff --git a/vendor/github.com/PuerkitoBio/goquery/go.sum b/vendor/github.com/PuerkitoBio/goquery/go.sum
deleted file mode 100644
index 11c5757..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/go.sum
+++ /dev/null
@@ -1,5 +0,0 @@
-github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o=
-github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
-golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
-golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U=
-golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
diff --git a/vendor/github.com/PuerkitoBio/goquery/iteration.go b/vendor/github.com/PuerkitoBio/goquery/iteration.go
deleted file mode 100644
index e246f2e..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/iteration.go
+++ /dev/null
@@ -1,39 +0,0 @@
-package goquery
-
-// Each iterates over a Selection object, executing a function for each
-// matched element. It returns the current Selection object. The function
-// f is called for each element in the selection with the index of the
-// element in that selection starting at 0, and a *Selection that contains
-// only that element.
-func (s *Selection) Each(f func(int, *Selection)) *Selection {
- for i, n := range s.Nodes {
- f(i, newSingleSelection(n, s.document))
- }
- return s
-}
-
-// EachWithBreak iterates over a Selection object, executing a function for each
-// matched element. It is identical to Each except that it is possible to break
-// out of the loop by returning false in the callback function. It returns the
-// current Selection object.
-func (s *Selection) EachWithBreak(f func(int, *Selection) bool) *Selection {
- for i, n := range s.Nodes {
- if !f(i, newSingleSelection(n, s.document)) {
- return s
- }
- }
- return s
-}
-
-// Map passes each element in the current matched set through a function,
-// producing a slice of string holding the returned values. The function
-// f is called for each element in the selection with the index of the
-// element in that selection starting at 0, and a *Selection that contains
-// only that element.
-func (s *Selection) Map(f func(int, *Selection) string) (result []string) {
- for i, n := range s.Nodes {
- result = append(result, f(i, newSingleSelection(n, s.document)))
- }
-
- return result
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/manipulation.go b/vendor/github.com/PuerkitoBio/goquery/manipulation.go
deleted file mode 100644
index 34eb757..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/manipulation.go
+++ /dev/null
@@ -1,574 +0,0 @@
-package goquery
-
-import (
- "strings"
-
- "golang.org/x/net/html"
-)
-
-// After applies the selector from the root document and inserts the matched elements
-// after the elements in the set of matched elements.
-//
-// If one of the matched elements in the selection is not currently in the
-// document, it's impossible to insert nodes after it, so it will be ignored.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) After(selector string) *Selection {
- return s.AfterMatcher(compileMatcher(selector))
-}
-
-// AfterMatcher applies the matcher from the root document and inserts the matched elements
-// after the elements in the set of matched elements.
-//
-// If one of the matched elements in the selection is not currently in the
-// document, it's impossible to insert nodes after it, so it will be ignored.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AfterMatcher(m Matcher) *Selection {
- return s.AfterNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// AfterSelection inserts the elements in the selection after each element in the set of matched
-// elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AfterSelection(sel *Selection) *Selection {
- return s.AfterNodes(sel.Nodes...)
-}
-
-// AfterHtml parses the html and inserts it after the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AfterHtml(html string) *Selection {
- return s.AfterNodes(parseHtml(html)...)
-}
-
-// AfterNodes inserts the nodes after each element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AfterNodes(ns ...*html.Node) *Selection {
- return s.manipulateNodes(ns, true, func(sn *html.Node, n *html.Node) {
- if sn.Parent != nil {
- sn.Parent.InsertBefore(n, sn.NextSibling)
- }
- })
-}
-
-// Append appends the elements specified by the selector to the end of each element
-// in the set of matched elements, following those rules:
-//
-// 1) The selector is applied to the root document.
-//
-// 2) Elements that are part of the document will be moved to the new location.
-//
-// 3) If there are multiple locations to append to, cloned nodes will be
-// appended to all target locations except the last one, which will be moved
-// as noted in (2).
-func (s *Selection) Append(selector string) *Selection {
- return s.AppendMatcher(compileMatcher(selector))
-}
-
-// AppendMatcher appends the elements specified by the matcher to the end of each element
-// in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AppendMatcher(m Matcher) *Selection {
- return s.AppendNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// AppendSelection appends the elements in the selection to the end of each element
-// in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AppendSelection(sel *Selection) *Selection {
- return s.AppendNodes(sel.Nodes...)
-}
-
-// AppendHtml parses the html and appends it to the set of matched elements.
-func (s *Selection) AppendHtml(html string) *Selection {
- return s.AppendNodes(parseHtml(html)...)
-}
-
-// AppendNodes appends the specified nodes to each node in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) AppendNodes(ns ...*html.Node) *Selection {
- return s.manipulateNodes(ns, false, func(sn *html.Node, n *html.Node) {
- sn.AppendChild(n)
- })
-}
-
-// Before inserts the matched elements before each element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) Before(selector string) *Selection {
- return s.BeforeMatcher(compileMatcher(selector))
-}
-
-// BeforeMatcher inserts the matched elements before each element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) BeforeMatcher(m Matcher) *Selection {
- return s.BeforeNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// BeforeSelection inserts the elements in the selection before each element in the set of matched
-// elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) BeforeSelection(sel *Selection) *Selection {
- return s.BeforeNodes(sel.Nodes...)
-}
-
-// BeforeHtml parses the html and inserts it before the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) BeforeHtml(html string) *Selection {
- return s.BeforeNodes(parseHtml(html)...)
-}
-
-// BeforeNodes inserts the nodes before each element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) BeforeNodes(ns ...*html.Node) *Selection {
- return s.manipulateNodes(ns, false, func(sn *html.Node, n *html.Node) {
- if sn.Parent != nil {
- sn.Parent.InsertBefore(n, sn)
- }
- })
-}
-
-// Clone creates a deep copy of the set of matched nodes. The new nodes will not be
-// attached to the document.
-func (s *Selection) Clone() *Selection {
- ns := newEmptySelection(s.document)
- ns.Nodes = cloneNodes(s.Nodes)
- return ns
-}
-
-// Empty removes all children nodes from the set of matched elements.
-// It returns the children nodes in a new Selection.
-func (s *Selection) Empty() *Selection {
- var nodes []*html.Node
-
- for _, n := range s.Nodes {
- for c := n.FirstChild; c != nil; c = n.FirstChild {
- n.RemoveChild(c)
- nodes = append(nodes, c)
- }
- }
-
- return pushStack(s, nodes)
-}
-
-// Prepend prepends the elements specified by the selector to each element in
-// the set of matched elements, following the same rules as Append.
-func (s *Selection) Prepend(selector string) *Selection {
- return s.PrependMatcher(compileMatcher(selector))
-}
-
-// PrependMatcher prepends the elements specified by the matcher to each
-// element in the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) PrependMatcher(m Matcher) *Selection {
- return s.PrependNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// PrependSelection prepends the elements in the selection to each element in
-// the set of matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) PrependSelection(sel *Selection) *Selection {
- return s.PrependNodes(sel.Nodes...)
-}
-
-// PrependHtml parses the html and prepends it to the set of matched elements.
-func (s *Selection) PrependHtml(html string) *Selection {
- return s.PrependNodes(parseHtml(html)...)
-}
-
-// PrependNodes prepends the specified nodes to each node in the set of
-// matched elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) PrependNodes(ns ...*html.Node) *Selection {
- return s.manipulateNodes(ns, true, func(sn *html.Node, n *html.Node) {
- // sn.FirstChild may be nil, in which case this functions like
- // sn.AppendChild()
- sn.InsertBefore(n, sn.FirstChild)
- })
-}
-
-// Remove removes the set of matched elements from the document.
-// It returns the same selection, now consisting of nodes not in the document.
-func (s *Selection) Remove() *Selection {
- for _, n := range s.Nodes {
- if n.Parent != nil {
- n.Parent.RemoveChild(n)
- }
- }
-
- return s
-}
-
-// RemoveFiltered removes the set of matched elements by selector.
-// It returns the Selection of removed nodes.
-func (s *Selection) RemoveFiltered(selector string) *Selection {
- return s.RemoveMatcher(compileMatcher(selector))
-}
-
-// RemoveMatcher removes the set of matched elements.
-// It returns the Selection of removed nodes.
-func (s *Selection) RemoveMatcher(m Matcher) *Selection {
- return s.FilterMatcher(m).Remove()
-}
-
-// ReplaceWith replaces each element in the set of matched elements with the
-// nodes matched by the given selector.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWith(selector string) *Selection {
- return s.ReplaceWithMatcher(compileMatcher(selector))
-}
-
-// ReplaceWithMatcher replaces each element in the set of matched elements with
-// the nodes matched by the given Matcher.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWithMatcher(m Matcher) *Selection {
- return s.ReplaceWithNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// ReplaceWithSelection replaces each element in the set of matched elements with
-// the nodes from the given Selection.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWithSelection(sel *Selection) *Selection {
- return s.ReplaceWithNodes(sel.Nodes...)
-}
-
-// ReplaceWithHtml replaces each element in the set of matched elements with
-// the parsed HTML.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWithHtml(html string) *Selection {
- return s.ReplaceWithNodes(parseHtml(html)...)
-}
-
-// ReplaceWithNodes replaces each element in the set of matched elements with
-// the given nodes.
-// It returns the removed elements.
-//
-// This follows the same rules as Selection.Append.
-func (s *Selection) ReplaceWithNodes(ns ...*html.Node) *Selection {
- s.AfterNodes(ns...)
- return s.Remove()
-}
-
-// SetHtml sets the html content of each element in the selection to
-// specified html string.
-func (s *Selection) SetHtml(html string) *Selection {
- return setHtmlNodes(s, parseHtml(html)...)
-}
-
-// SetText sets the content of each element in the selection to specified content.
-// The provided text string is escaped.
-func (s *Selection) SetText(text string) *Selection {
- return s.SetHtml(html.EscapeString(text))
-}
-
-// Unwrap removes the parents of the set of matched elements, leaving the matched
-// elements (and their siblings, if any) in their place.
-// It returns the original selection.
-func (s *Selection) Unwrap() *Selection {
- s.Parent().Each(func(i int, ss *Selection) {
- // For some reason, jquery allows unwrap to remove the
element, so
- // allowing it here too. Same for . Why it allows those elements to
- // be unwrapped while not allowing body is a mystery to me.
- if ss.Nodes[0].Data != "body" {
- ss.ReplaceWithSelection(ss.Contents())
- }
- })
-
- return s
-}
-
-// Wrap wraps each element in the set of matched elements inside the first
-// element matched by the given selector. The matched child is cloned before
-// being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) Wrap(selector string) *Selection {
- return s.WrapMatcher(compileMatcher(selector))
-}
-
-// WrapMatcher wraps each element in the set of matched elements inside the
-// first element matched by the given matcher. The matched child is cloned
-// before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapMatcher(m Matcher) *Selection {
- return s.wrapNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// WrapSelection wraps each element in the set of matched elements inside the
-// first element in the given Selection. The element is cloned before being
-// inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapSelection(sel *Selection) *Selection {
- return s.wrapNodes(sel.Nodes...)
-}
-
-// WrapHtml wraps each element in the set of matched elements inside the inner-
-// most child of the given HTML.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapHtml(html string) *Selection {
- return s.wrapNodes(parseHtml(html)...)
-}
-
-// WrapNode wraps each element in the set of matched elements inside the inner-
-// most child of the given node. The given node is copied before being inserted
-// into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapNode(n *html.Node) *Selection {
- return s.wrapNodes(n)
-}
-
-func (s *Selection) wrapNodes(ns ...*html.Node) *Selection {
- s.Each(func(i int, ss *Selection) {
- ss.wrapAllNodes(ns...)
- })
-
- return s
-}
-
-// WrapAll wraps a single HTML structure, matched by the given selector, around
-// all elements in the set of matched elements. The matched child is cloned
-// before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapAll(selector string) *Selection {
- return s.WrapAllMatcher(compileMatcher(selector))
-}
-
-// WrapAllMatcher wraps a single HTML structure, matched by the given Matcher,
-// around all elements in the set of matched elements. The matched child is
-// cloned before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapAllMatcher(m Matcher) *Selection {
- return s.wrapAllNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// WrapAllSelection wraps a single HTML structure, the first node of the given
-// Selection, around all elements in the set of matched elements. The matched
-// child is cloned before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapAllSelection(sel *Selection) *Selection {
- return s.wrapAllNodes(sel.Nodes...)
-}
-
-// WrapAllHtml wraps the given HTML structure around all elements in the set of
-// matched elements. The matched child is cloned before being inserted into the
-// document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapAllHtml(html string) *Selection {
- return s.wrapAllNodes(parseHtml(html)...)
-}
-
-func (s *Selection) wrapAllNodes(ns ...*html.Node) *Selection {
- if len(ns) > 0 {
- return s.WrapAllNode(ns[0])
- }
- return s
-}
-
-// WrapAllNode wraps the given node around the first element in the Selection,
-// making all other nodes in the Selection children of the given node. The node
-// is cloned before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapAllNode(n *html.Node) *Selection {
- if s.Size() == 0 {
- return s
- }
-
- wrap := cloneNode(n)
-
- first := s.Nodes[0]
- if first.Parent != nil {
- first.Parent.InsertBefore(wrap, first)
- first.Parent.RemoveChild(first)
- }
-
- for c := getFirstChildEl(wrap); c != nil; c = getFirstChildEl(wrap) {
- wrap = c
- }
-
- newSingleSelection(wrap, s.document).AppendSelection(s)
-
- return s
-}
-
-// WrapInner wraps an HTML structure, matched by the given selector, around the
-// content of element in the set of matched elements. The matched child is
-// cloned before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapInner(selector string) *Selection {
- return s.WrapInnerMatcher(compileMatcher(selector))
-}
-
-// WrapInnerMatcher wraps an HTML structure, matched by the given selector,
-// around the content of element in the set of matched elements. The matched
-// child is cloned before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapInnerMatcher(m Matcher) *Selection {
- return s.wrapInnerNodes(m.MatchAll(s.document.rootNode)...)
-}
-
-// WrapInnerSelection wraps an HTML structure, matched by the given selector,
-// around the content of element in the set of matched elements. The matched
-// child is cloned before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapInnerSelection(sel *Selection) *Selection {
- return s.wrapInnerNodes(sel.Nodes...)
-}
-
-// WrapInnerHtml wraps an HTML structure, matched by the given selector, around
-// the content of element in the set of matched elements. The matched child is
-// cloned before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapInnerHtml(html string) *Selection {
- return s.wrapInnerNodes(parseHtml(html)...)
-}
-
-// WrapInnerNode wraps an HTML structure, matched by the given selector, around
-// the content of element in the set of matched elements. The matched child is
-// cloned before being inserted into the document.
-//
-// It returns the original set of elements.
-func (s *Selection) WrapInnerNode(n *html.Node) *Selection {
- return s.wrapInnerNodes(n)
-}
-
-func (s *Selection) wrapInnerNodes(ns ...*html.Node) *Selection {
- if len(ns) == 0 {
- return s
- }
-
- s.Each(func(i int, s *Selection) {
- contents := s.Contents()
-
- if contents.Size() > 0 {
- contents.wrapAllNodes(ns...)
- } else {
- s.AppendNodes(cloneNode(ns[0]))
- }
- })
-
- return s
-}
-
-func parseHtml(h string) []*html.Node {
- // Errors are only returned when the io.Reader returns any error besides
- // EOF, but strings.Reader never will
- nodes, err := html.ParseFragment(strings.NewReader(h), &html.Node{Type: html.ElementNode})
- if err != nil {
- panic("goquery: failed to parse HTML: " + err.Error())
- }
- return nodes
-}
-
-func setHtmlNodes(s *Selection, ns ...*html.Node) *Selection {
- for _, n := range s.Nodes {
- for c := n.FirstChild; c != nil; c = n.FirstChild {
- n.RemoveChild(c)
- }
- for _, c := range ns {
- n.AppendChild(cloneNode(c))
- }
- }
- return s
-}
-
-// Get the first child that is an ElementNode
-func getFirstChildEl(n *html.Node) *html.Node {
- c := n.FirstChild
- for c != nil && c.Type != html.ElementNode {
- c = c.NextSibling
- }
- return c
-}
-
-// Deep copy a slice of nodes.
-func cloneNodes(ns []*html.Node) []*html.Node {
- cns := make([]*html.Node, 0, len(ns))
-
- for _, n := range ns {
- cns = append(cns, cloneNode(n))
- }
-
- return cns
-}
-
-// Deep copy a node. The new node has clones of all the original node's
-// children but none of its parents or siblings.
-func cloneNode(n *html.Node) *html.Node {
- nn := &html.Node{
- Type: n.Type,
- DataAtom: n.DataAtom,
- Data: n.Data,
- Attr: make([]html.Attribute, len(n.Attr)),
- }
-
- copy(nn.Attr, n.Attr)
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- nn.AppendChild(cloneNode(c))
- }
-
- return nn
-}
-
-func (s *Selection) manipulateNodes(ns []*html.Node, reverse bool,
- f func(sn *html.Node, n *html.Node)) *Selection {
-
- lasti := s.Size() - 1
-
- // net.Html doesn't provide document fragments for insertion, so to get
- // things in the correct order with After() and Prepend(), the callback
- // needs to be called on the reverse of the nodes.
- if reverse {
- for i, j := 0, len(ns)-1; i < j; i, j = i+1, j-1 {
- ns[i], ns[j] = ns[j], ns[i]
- }
- }
-
- for i, sn := range s.Nodes {
- for _, n := range ns {
- if i != lasti {
- f(sn, cloneNode(n))
- } else {
- if n.Parent != nil {
- n.Parent.RemoveChild(n)
- }
- f(sn, n)
- }
- }
- }
-
- return s
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/property.go b/vendor/github.com/PuerkitoBio/goquery/property.go
deleted file mode 100644
index 411126d..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/property.go
+++ /dev/null
@@ -1,275 +0,0 @@
-package goquery
-
-import (
- "bytes"
- "regexp"
- "strings"
-
- "golang.org/x/net/html"
-)
-
-var rxClassTrim = regexp.MustCompile("[\t\r\n]")
-
-// Attr gets the specified attribute's value for the first element in the
-// Selection. To get the value for each element individually, use a looping
-// construct such as Each or Map method.
-func (s *Selection) Attr(attrName string) (val string, exists bool) {
- if len(s.Nodes) == 0 {
- return
- }
- return getAttributeValue(attrName, s.Nodes[0])
-}
-
-// AttrOr works like Attr but returns default value if attribute is not present.
-func (s *Selection) AttrOr(attrName, defaultValue string) string {
- if len(s.Nodes) == 0 {
- return defaultValue
- }
-
- val, exists := getAttributeValue(attrName, s.Nodes[0])
- if !exists {
- return defaultValue
- }
-
- return val
-}
-
-// RemoveAttr removes the named attribute from each element in the set of matched elements.
-func (s *Selection) RemoveAttr(attrName string) *Selection {
- for _, n := range s.Nodes {
- removeAttr(n, attrName)
- }
-
- return s
-}
-
-// SetAttr sets the given attribute on each element in the set of matched elements.
-func (s *Selection) SetAttr(attrName, val string) *Selection {
- for _, n := range s.Nodes {
- attr := getAttributePtr(attrName, n)
- if attr == nil {
- n.Attr = append(n.Attr, html.Attribute{Key: attrName, Val: val})
- } else {
- attr.Val = val
- }
- }
-
- return s
-}
-
-// Text gets the combined text contents of each element in the set of matched
-// elements, including their descendants.
-func (s *Selection) Text() string {
- var buf bytes.Buffer
-
- // Slightly optimized vs calling Each: no single selection object created
- var f func(*html.Node)
- f = func(n *html.Node) {
- if n.Type == html.TextNode {
- // Keep newlines and spaces, like jQuery
- buf.WriteString(n.Data)
- }
- if n.FirstChild != nil {
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- f(c)
- }
- }
- }
- for _, n := range s.Nodes {
- f(n)
- }
-
- return buf.String()
-}
-
-// Size is an alias for Length.
-func (s *Selection) Size() int {
- return s.Length()
-}
-
-// Length returns the number of elements in the Selection object.
-func (s *Selection) Length() int {
- return len(s.Nodes)
-}
-
-// Html gets the HTML contents of the first element in the set of matched
-// elements. It includes text and comment nodes.
-func (s *Selection) Html() (ret string, e error) {
- // Since there is no .innerHtml, the HTML content must be re-created from
- // the nodes using html.Render.
- var buf bytes.Buffer
-
- if len(s.Nodes) > 0 {
- for c := s.Nodes[0].FirstChild; c != nil; c = c.NextSibling {
- e = html.Render(&buf, c)
- if e != nil {
- return
- }
- }
- ret = buf.String()
- }
-
- return
-}
-
-// AddClass adds the given class(es) to each element in the set of matched elements.
-// Multiple class names can be specified, separated by a space or via multiple arguments.
-func (s *Selection) AddClass(class ...string) *Selection {
- classStr := strings.TrimSpace(strings.Join(class, " "))
-
- if classStr == "" {
- return s
- }
-
- tcls := getClassesSlice(classStr)
- for _, n := range s.Nodes {
- curClasses, attr := getClassesAndAttr(n, true)
- for _, newClass := range tcls {
- if !strings.Contains(curClasses, " "+newClass+" ") {
- curClasses += newClass + " "
- }
- }
-
- setClasses(n, attr, curClasses)
- }
-
- return s
-}
-
-// HasClass determines whether any of the matched elements are assigned the
-// given class.
-func (s *Selection) HasClass(class string) bool {
- class = " " + class + " "
- for _, n := range s.Nodes {
- classes, _ := getClassesAndAttr(n, false)
- if strings.Contains(classes, class) {
- return true
- }
- }
- return false
-}
-
-// RemoveClass removes the given class(es) from each element in the set of matched elements.
-// Multiple class names can be specified, separated by a space or via multiple arguments.
-// If no class name is provided, all classes are removed.
-func (s *Selection) RemoveClass(class ...string) *Selection {
- var rclasses []string
-
- classStr := strings.TrimSpace(strings.Join(class, " "))
- remove := classStr == ""
-
- if !remove {
- rclasses = getClassesSlice(classStr)
- }
-
- for _, n := range s.Nodes {
- if remove {
- removeAttr(n, "class")
- } else {
- classes, attr := getClassesAndAttr(n, true)
- for _, rcl := range rclasses {
- classes = strings.Replace(classes, " "+rcl+" ", " ", -1)
- }
-
- setClasses(n, attr, classes)
- }
- }
-
- return s
-}
-
-// ToggleClass adds or removes the given class(es) for each element in the set of matched elements.
-// Multiple class names can be specified, separated by a space or via multiple arguments.
-func (s *Selection) ToggleClass(class ...string) *Selection {
- classStr := strings.TrimSpace(strings.Join(class, " "))
-
- if classStr == "" {
- return s
- }
-
- tcls := getClassesSlice(classStr)
-
- for _, n := range s.Nodes {
- classes, attr := getClassesAndAttr(n, true)
- for _, tcl := range tcls {
- if strings.Contains(classes, " "+tcl+" ") {
- classes = strings.Replace(classes, " "+tcl+" ", " ", -1)
- } else {
- classes += tcl + " "
- }
- }
-
- setClasses(n, attr, classes)
- }
-
- return s
-}
-
-func getAttributePtr(attrName string, n *html.Node) *html.Attribute {
- if n == nil {
- return nil
- }
-
- for i, a := range n.Attr {
- if a.Key == attrName {
- return &n.Attr[i]
- }
- }
- return nil
-}
-
-// Private function to get the specified attribute's value from a node.
-func getAttributeValue(attrName string, n *html.Node) (val string, exists bool) {
- if a := getAttributePtr(attrName, n); a != nil {
- val = a.Val
- exists = true
- }
- return
-}
-
-// Get and normalize the "class" attribute from the node.
-func getClassesAndAttr(n *html.Node, create bool) (classes string, attr *html.Attribute) {
- // Applies only to element nodes
- if n.Type == html.ElementNode {
- attr = getAttributePtr("class", n)
- if attr == nil && create {
- n.Attr = append(n.Attr, html.Attribute{
- Key: "class",
- Val: "",
- })
- attr = &n.Attr[len(n.Attr)-1]
- }
- }
-
- if attr == nil {
- classes = " "
- } else {
- classes = rxClassTrim.ReplaceAllString(" "+attr.Val+" ", " ")
- }
-
- return
-}
-
-func getClassesSlice(classes string) []string {
- return strings.Split(rxClassTrim.ReplaceAllString(" "+classes+" ", " "), " ")
-}
-
-func removeAttr(n *html.Node, attrName string) {
- for i, a := range n.Attr {
- if a.Key == attrName {
- n.Attr[i], n.Attr[len(n.Attr)-1], n.Attr =
- n.Attr[len(n.Attr)-1], html.Attribute{}, n.Attr[:len(n.Attr)-1]
- return
- }
- }
-}
-
-func setClasses(n *html.Node, attr *html.Attribute, classes string) {
- classes = strings.TrimSpace(classes)
- if classes == "" {
- removeAttr(n, "class")
- return
- }
-
- attr.Val = classes
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/query.go b/vendor/github.com/PuerkitoBio/goquery/query.go
deleted file mode 100644
index fe86bf0..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/query.go
+++ /dev/null
@@ -1,49 +0,0 @@
-package goquery
-
-import "golang.org/x/net/html"
-
-// Is checks the current matched set of elements against a selector and
-// returns true if at least one of these elements matches.
-func (s *Selection) Is(selector string) bool {
- return s.IsMatcher(compileMatcher(selector))
-}
-
-// IsMatcher checks the current matched set of elements against a matcher and
-// returns true if at least one of these elements matches.
-func (s *Selection) IsMatcher(m Matcher) bool {
- if len(s.Nodes) > 0 {
- if len(s.Nodes) == 1 {
- return m.Match(s.Nodes[0])
- }
- return len(m.Filter(s.Nodes)) > 0
- }
-
- return false
-}
-
-// IsFunction checks the current matched set of elements against a predicate and
-// returns true if at least one of these elements matches.
-func (s *Selection) IsFunction(f func(int, *Selection) bool) bool {
- return s.FilterFunction(f).Length() > 0
-}
-
-// IsSelection checks the current matched set of elements against a Selection object
-// and returns true if at least one of these elements matches.
-func (s *Selection) IsSelection(sel *Selection) bool {
- return s.FilterSelection(sel).Length() > 0
-}
-
-// IsNodes checks the current matched set of elements against the specified nodes
-// and returns true if at least one of these elements matches.
-func (s *Selection) IsNodes(nodes ...*html.Node) bool {
- return s.FilterNodes(nodes...).Length() > 0
-}
-
-// Contains returns true if the specified Node is within,
-// at any depth, one of the nodes in the Selection object.
-// It is NOT inclusive, to behave like jQuery's implementation, and
-// unlike Javascript's .contains, so if the contained
-// node is itself in the selection, it returns false.
-func (s *Selection) Contains(n *html.Node) bool {
- return sliceContains(s.Nodes, n)
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/traversal.go b/vendor/github.com/PuerkitoBio/goquery/traversal.go
deleted file mode 100644
index 5fa5315..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/traversal.go
+++ /dev/null
@@ -1,698 +0,0 @@
-package goquery
-
-import "golang.org/x/net/html"
-
-type siblingType int
-
-// Sibling type, used internally when iterating over children at the same
-// level (siblings) to specify which nodes are requested.
-const (
- siblingPrevUntil siblingType = iota - 3
- siblingPrevAll
- siblingPrev
- siblingAll
- siblingNext
- siblingNextAll
- siblingNextUntil
- siblingAllIncludingNonElements
-)
-
-// Find gets the descendants of each element in the current set of matched
-// elements, filtered by a selector. It returns a new Selection object
-// containing these matched elements.
-func (s *Selection) Find(selector string) *Selection {
- return pushStack(s, findWithMatcher(s.Nodes, compileMatcher(selector)))
-}
-
-// FindMatcher gets the descendants of each element in the current set of matched
-// elements, filtered by the matcher. It returns a new Selection object
-// containing these matched elements.
-func (s *Selection) FindMatcher(m Matcher) *Selection {
- return pushStack(s, findWithMatcher(s.Nodes, m))
-}
-
-// FindSelection gets the descendants of each element in the current
-// Selection, filtered by a Selection. It returns a new Selection object
-// containing these matched elements.
-func (s *Selection) FindSelection(sel *Selection) *Selection {
- if sel == nil {
- return pushStack(s, nil)
- }
- return s.FindNodes(sel.Nodes...)
-}
-
-// FindNodes gets the descendants of each element in the current
-// Selection, filtered by some nodes. It returns a new Selection object
-// containing these matched elements.
-func (s *Selection) FindNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, mapNodes(nodes, func(i int, n *html.Node) []*html.Node {
- if sliceContains(s.Nodes, n) {
- return []*html.Node{n}
- }
- return nil
- }))
-}
-
-// Contents gets the children of each element in the Selection,
-// including text and comment nodes. It returns a new Selection object
-// containing these elements.
-func (s *Selection) Contents() *Selection {
- return pushStack(s, getChildrenNodes(s.Nodes, siblingAllIncludingNonElements))
-}
-
-// ContentsFiltered gets the children of each element in the Selection,
-// filtered by the specified selector. It returns a new Selection
-// object containing these elements. Since selectors only act on Element nodes,
-// this function is an alias to ChildrenFiltered unless the selector is empty,
-// in which case it is an alias to Contents.
-func (s *Selection) ContentsFiltered(selector string) *Selection {
- if selector != "" {
- return s.ChildrenFiltered(selector)
- }
- return s.Contents()
-}
-
-// ContentsMatcher gets the children of each element in the Selection,
-// filtered by the specified matcher. It returns a new Selection
-// object containing these elements. Since matchers only act on Element nodes,
-// this function is an alias to ChildrenMatcher.
-func (s *Selection) ContentsMatcher(m Matcher) *Selection {
- return s.ChildrenMatcher(m)
-}
-
-// Children gets the child elements of each element in the Selection.
-// It returns a new Selection object containing these elements.
-func (s *Selection) Children() *Selection {
- return pushStack(s, getChildrenNodes(s.Nodes, siblingAll))
-}
-
-// ChildrenFiltered gets the child elements of each element in the Selection,
-// filtered by the specified selector. It returns a new
-// Selection object containing these elements.
-func (s *Selection) ChildrenFiltered(selector string) *Selection {
- return filterAndPush(s, getChildrenNodes(s.Nodes, siblingAll), compileMatcher(selector))
-}
-
-// ChildrenMatcher gets the child elements of each element in the Selection,
-// filtered by the specified matcher. It returns a new
-// Selection object containing these elements.
-func (s *Selection) ChildrenMatcher(m Matcher) *Selection {
- return filterAndPush(s, getChildrenNodes(s.Nodes, siblingAll), m)
-}
-
-// Parent gets the parent of each element in the Selection. It returns a
-// new Selection object containing the matched elements.
-func (s *Selection) Parent() *Selection {
- return pushStack(s, getParentNodes(s.Nodes))
-}
-
-// ParentFiltered gets the parent of each element in the Selection filtered by a
-// selector. It returns a new Selection object containing the matched elements.
-func (s *Selection) ParentFiltered(selector string) *Selection {
- return filterAndPush(s, getParentNodes(s.Nodes), compileMatcher(selector))
-}
-
-// ParentMatcher gets the parent of each element in the Selection filtered by a
-// matcher. It returns a new Selection object containing the matched elements.
-func (s *Selection) ParentMatcher(m Matcher) *Selection {
- return filterAndPush(s, getParentNodes(s.Nodes), m)
-}
-
-// Closest gets the first element that matches the selector by testing the
-// element itself and traversing up through its ancestors in the DOM tree.
-func (s *Selection) Closest(selector string) *Selection {
- cs := compileMatcher(selector)
- return s.ClosestMatcher(cs)
-}
-
-// ClosestMatcher gets the first element that matches the matcher by testing the
-// element itself and traversing up through its ancestors in the DOM tree.
-func (s *Selection) ClosestMatcher(m Matcher) *Selection {
- return pushStack(s, mapNodes(s.Nodes, func(i int, n *html.Node) []*html.Node {
- // For each node in the selection, test the node itself, then each parent
- // until a match is found.
- for ; n != nil; n = n.Parent {
- if m.Match(n) {
- return []*html.Node{n}
- }
- }
- return nil
- }))
-}
-
-// ClosestNodes gets the first element that matches one of the nodes by testing the
-// element itself and traversing up through its ancestors in the DOM tree.
-func (s *Selection) ClosestNodes(nodes ...*html.Node) *Selection {
- set := make(map[*html.Node]bool)
- for _, n := range nodes {
- set[n] = true
- }
- return pushStack(s, mapNodes(s.Nodes, func(i int, n *html.Node) []*html.Node {
- // For each node in the selection, test the node itself, then each parent
- // until a match is found.
- for ; n != nil; n = n.Parent {
- if set[n] {
- return []*html.Node{n}
- }
- }
- return nil
- }))
-}
-
-// ClosestSelection gets the first element that matches one of the nodes in the
-// Selection by testing the element itself and traversing up through its ancestors
-// in the DOM tree.
-func (s *Selection) ClosestSelection(sel *Selection) *Selection {
- if sel == nil {
- return pushStack(s, nil)
- }
- return s.ClosestNodes(sel.Nodes...)
-}
-
-// Parents gets the ancestors of each element in the current Selection. It
-// returns a new Selection object with the matched elements.
-func (s *Selection) Parents() *Selection {
- return pushStack(s, getParentsNodes(s.Nodes, nil, nil))
-}
-
-// ParentsFiltered gets the ancestors of each element in the current
-// Selection. It returns a new Selection object with the matched elements.
-func (s *Selection) ParentsFiltered(selector string) *Selection {
- return filterAndPush(s, getParentsNodes(s.Nodes, nil, nil), compileMatcher(selector))
-}
-
-// ParentsMatcher gets the ancestors of each element in the current
-// Selection. It returns a new Selection object with the matched elements.
-func (s *Selection) ParentsMatcher(m Matcher) *Selection {
- return filterAndPush(s, getParentsNodes(s.Nodes, nil, nil), m)
-}
-
-// ParentsUntil gets the ancestors of each element in the Selection, up to but
-// not including the element matched by the selector. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) ParentsUntil(selector string) *Selection {
- return pushStack(s, getParentsNodes(s.Nodes, compileMatcher(selector), nil))
-}
-
-// ParentsUntilMatcher gets the ancestors of each element in the Selection, up to but
-// not including the element matched by the matcher. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) ParentsUntilMatcher(m Matcher) *Selection {
- return pushStack(s, getParentsNodes(s.Nodes, m, nil))
-}
-
-// ParentsUntilSelection gets the ancestors of each element in the Selection,
-// up to but not including the elements in the specified Selection. It returns a
-// new Selection object containing the matched elements.
-func (s *Selection) ParentsUntilSelection(sel *Selection) *Selection {
- if sel == nil {
- return s.Parents()
- }
- return s.ParentsUntilNodes(sel.Nodes...)
-}
-
-// ParentsUntilNodes gets the ancestors of each element in the Selection,
-// up to but not including the specified nodes. It returns a
-// new Selection object containing the matched elements.
-func (s *Selection) ParentsUntilNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, getParentsNodes(s.Nodes, nil, nodes))
-}
-
-// ParentsFilteredUntil is like ParentsUntil, with the option to filter the
-// results based on a selector string. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) ParentsFilteredUntil(filterSelector, untilSelector string) *Selection {
- return filterAndPush(s, getParentsNodes(s.Nodes, compileMatcher(untilSelector), nil), compileMatcher(filterSelector))
-}
-
-// ParentsFilteredUntilMatcher is like ParentsUntilMatcher, with the option to filter the
-// results based on a matcher. It returns a new Selection object containing the matched elements.
-func (s *Selection) ParentsFilteredUntilMatcher(filter, until Matcher) *Selection {
- return filterAndPush(s, getParentsNodes(s.Nodes, until, nil), filter)
-}
-
-// ParentsFilteredUntilSelection is like ParentsUntilSelection, with the
-// option to filter the results based on a selector string. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) ParentsFilteredUntilSelection(filterSelector string, sel *Selection) *Selection {
- return s.ParentsMatcherUntilSelection(compileMatcher(filterSelector), sel)
-}
-
-// ParentsMatcherUntilSelection is like ParentsUntilSelection, with the
-// option to filter the results based on a matcher. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) ParentsMatcherUntilSelection(filter Matcher, sel *Selection) *Selection {
- if sel == nil {
- return s.ParentsMatcher(filter)
- }
- return s.ParentsMatcherUntilNodes(filter, sel.Nodes...)
-}
-
-// ParentsFilteredUntilNodes is like ParentsUntilNodes, with the
-// option to filter the results based on a selector string. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) ParentsFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection {
- return filterAndPush(s, getParentsNodes(s.Nodes, nil, nodes), compileMatcher(filterSelector))
-}
-
-// ParentsMatcherUntilNodes is like ParentsUntilNodes, with the
-// option to filter the results based on a matcher. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) ParentsMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection {
- return filterAndPush(s, getParentsNodes(s.Nodes, nil, nodes), filter)
-}
-
-// Siblings gets the siblings of each element in the Selection. It returns
-// a new Selection object containing the matched elements.
-func (s *Selection) Siblings() *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingAll, nil, nil))
-}
-
-// SiblingsFiltered gets the siblings of each element in the Selection
-// filtered by a selector. It returns a new Selection object containing the
-// matched elements.
-func (s *Selection) SiblingsFiltered(selector string) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingAll, nil, nil), compileMatcher(selector))
-}
-
-// SiblingsMatcher gets the siblings of each element in the Selection
-// filtered by a matcher. It returns a new Selection object containing the
-// matched elements.
-func (s *Selection) SiblingsMatcher(m Matcher) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingAll, nil, nil), m)
-}
-
-// Next gets the immediately following sibling of each element in the
-// Selection. It returns a new Selection object containing the matched elements.
-func (s *Selection) Next() *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingNext, nil, nil))
-}
-
-// NextFiltered gets the immediately following sibling of each element in the
-// Selection filtered by a selector. It returns a new Selection object
-// containing the matched elements.
-func (s *Selection) NextFiltered(selector string) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNext, nil, nil), compileMatcher(selector))
-}
-
-// NextMatcher gets the immediately following sibling of each element in the
-// Selection filtered by a matcher. It returns a new Selection object
-// containing the matched elements.
-func (s *Selection) NextMatcher(m Matcher) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNext, nil, nil), m)
-}
-
-// NextAll gets all the following siblings of each element in the
-// Selection. It returns a new Selection object containing the matched elements.
-func (s *Selection) NextAll() *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingNextAll, nil, nil))
-}
-
-// NextAllFiltered gets all the following siblings of each element in the
-// Selection filtered by a selector. It returns a new Selection object
-// containing the matched elements.
-func (s *Selection) NextAllFiltered(selector string) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextAll, nil, nil), compileMatcher(selector))
-}
-
-// NextAllMatcher gets all the following siblings of each element in the
-// Selection filtered by a matcher. It returns a new Selection object
-// containing the matched elements.
-func (s *Selection) NextAllMatcher(m Matcher) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextAll, nil, nil), m)
-}
-
-// Prev gets the immediately preceding sibling of each element in the
-// Selection. It returns a new Selection object containing the matched elements.
-func (s *Selection) Prev() *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingPrev, nil, nil))
-}
-
-// PrevFiltered gets the immediately preceding sibling of each element in the
-// Selection filtered by a selector. It returns a new Selection object
-// containing the matched elements.
-func (s *Selection) PrevFiltered(selector string) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrev, nil, nil), compileMatcher(selector))
-}
-
-// PrevMatcher gets the immediately preceding sibling of each element in the
-// Selection filtered by a matcher. It returns a new Selection object
-// containing the matched elements.
-func (s *Selection) PrevMatcher(m Matcher) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrev, nil, nil), m)
-}
-
-// PrevAll gets all the preceding siblings of each element in the
-// Selection. It returns a new Selection object containing the matched elements.
-func (s *Selection) PrevAll() *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingPrevAll, nil, nil))
-}
-
-// PrevAllFiltered gets all the preceding siblings of each element in the
-// Selection filtered by a selector. It returns a new Selection object
-// containing the matched elements.
-func (s *Selection) PrevAllFiltered(selector string) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevAll, nil, nil), compileMatcher(selector))
-}
-
-// PrevAllMatcher gets all the preceding siblings of each element in the
-// Selection filtered by a matcher. It returns a new Selection object
-// containing the matched elements.
-func (s *Selection) PrevAllMatcher(m Matcher) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevAll, nil, nil), m)
-}
-
-// NextUntil gets all following siblings of each element up to but not
-// including the element matched by the selector. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) NextUntil(selector string) *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingNextUntil,
- compileMatcher(selector), nil))
-}
-
-// NextUntilMatcher gets all following siblings of each element up to but not
-// including the element matched by the matcher. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) NextUntilMatcher(m Matcher) *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingNextUntil,
- m, nil))
-}
-
-// NextUntilSelection gets all following siblings of each element up to but not
-// including the element matched by the Selection. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) NextUntilSelection(sel *Selection) *Selection {
- if sel == nil {
- return s.NextAll()
- }
- return s.NextUntilNodes(sel.Nodes...)
-}
-
-// NextUntilNodes gets all following siblings of each element up to but not
-// including the element matched by the nodes. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) NextUntilNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingNextUntil,
- nil, nodes))
-}
-
-// PrevUntil gets all preceding siblings of each element up to but not
-// including the element matched by the selector. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) PrevUntil(selector string) *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
- compileMatcher(selector), nil))
-}
-
-// PrevUntilMatcher gets all preceding siblings of each element up to but not
-// including the element matched by the matcher. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) PrevUntilMatcher(m Matcher) *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
- m, nil))
-}
-
-// PrevUntilSelection gets all preceding siblings of each element up to but not
-// including the element matched by the Selection. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) PrevUntilSelection(sel *Selection) *Selection {
- if sel == nil {
- return s.PrevAll()
- }
- return s.PrevUntilNodes(sel.Nodes...)
-}
-
-// PrevUntilNodes gets all preceding siblings of each element up to but not
-// including the element matched by the nodes. It returns a new Selection
-// object containing the matched elements.
-func (s *Selection) PrevUntilNodes(nodes ...*html.Node) *Selection {
- return pushStack(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
- nil, nodes))
-}
-
-// NextFilteredUntil is like NextUntil, with the option to filter
-// the results based on a selector string.
-// It returns a new Selection object containing the matched elements.
-func (s *Selection) NextFilteredUntil(filterSelector, untilSelector string) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextUntil,
- compileMatcher(untilSelector), nil), compileMatcher(filterSelector))
-}
-
-// NextFilteredUntilMatcher is like NextUntilMatcher, with the option to filter
-// the results based on a matcher.
-// It returns a new Selection object containing the matched elements.
-func (s *Selection) NextFilteredUntilMatcher(filter, until Matcher) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextUntil,
- until, nil), filter)
-}
-
-// NextFilteredUntilSelection is like NextUntilSelection, with the
-// option to filter the results based on a selector string. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) NextFilteredUntilSelection(filterSelector string, sel *Selection) *Selection {
- return s.NextMatcherUntilSelection(compileMatcher(filterSelector), sel)
-}
-
-// NextMatcherUntilSelection is like NextUntilSelection, with the
-// option to filter the results based on a matcher. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) NextMatcherUntilSelection(filter Matcher, sel *Selection) *Selection {
- if sel == nil {
- return s.NextMatcher(filter)
- }
- return s.NextMatcherUntilNodes(filter, sel.Nodes...)
-}
-
-// NextFilteredUntilNodes is like NextUntilNodes, with the
-// option to filter the results based on a selector string. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) NextFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextUntil,
- nil, nodes), compileMatcher(filterSelector))
-}
-
-// NextMatcherUntilNodes is like NextUntilNodes, with the
-// option to filter the results based on a matcher. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) NextMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextUntil,
- nil, nodes), filter)
-}
-
-// PrevFilteredUntil is like PrevUntil, with the option to filter
-// the results based on a selector string.
-// It returns a new Selection object containing the matched elements.
-func (s *Selection) PrevFilteredUntil(filterSelector, untilSelector string) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
- compileMatcher(untilSelector), nil), compileMatcher(filterSelector))
-}
-
-// PrevFilteredUntilMatcher is like PrevUntilMatcher, with the option to filter
-// the results based on a matcher.
-// It returns a new Selection object containing the matched elements.
-func (s *Selection) PrevFilteredUntilMatcher(filter, until Matcher) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
- until, nil), filter)
-}
-
-// PrevFilteredUntilSelection is like PrevUntilSelection, with the
-// option to filter the results based on a selector string. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) PrevFilteredUntilSelection(filterSelector string, sel *Selection) *Selection {
- return s.PrevMatcherUntilSelection(compileMatcher(filterSelector), sel)
-}
-
-// PrevMatcherUntilSelection is like PrevUntilSelection, with the
-// option to filter the results based on a matcher. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) PrevMatcherUntilSelection(filter Matcher, sel *Selection) *Selection {
- if sel == nil {
- return s.PrevMatcher(filter)
- }
- return s.PrevMatcherUntilNodes(filter, sel.Nodes...)
-}
-
-// PrevFilteredUntilNodes is like PrevUntilNodes, with the
-// option to filter the results based on a selector string. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) PrevFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
- nil, nodes), compileMatcher(filterSelector))
-}
-
-// PrevMatcherUntilNodes is like PrevUntilNodes, with the
-// option to filter the results based on a matcher. It returns a new
-// Selection object containing the matched elements.
-func (s *Selection) PrevMatcherUntilNodes(filter Matcher, nodes ...*html.Node) *Selection {
- return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
- nil, nodes), filter)
-}
-
-// Filter and push filters the nodes based on a matcher, and pushes the results
-// on the stack, with the srcSel as previous selection.
-func filterAndPush(srcSel *Selection, nodes []*html.Node, m Matcher) *Selection {
- // Create a temporary Selection with the specified nodes to filter using winnow
- sel := &Selection{nodes, srcSel.document, nil}
- // Filter based on matcher and push on stack
- return pushStack(srcSel, winnow(sel, m, true))
-}
-
-// Internal implementation of Find that return raw nodes.
-func findWithMatcher(nodes []*html.Node, m Matcher) []*html.Node {
- // Map nodes to find the matches within the children of each node
- return mapNodes(nodes, func(i int, n *html.Node) (result []*html.Node) {
- // Go down one level, becausejQuery's Find selects only within descendants
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- if c.Type == html.ElementNode {
- result = append(result, m.MatchAll(c)...)
- }
- }
- return
- })
-}
-
-// Internal implementation to get all parent nodes, stopping at the specified
-// node (or nil if no stop).
-func getParentsNodes(nodes []*html.Node, stopm Matcher, stopNodes []*html.Node) []*html.Node {
- return mapNodes(nodes, func(i int, n *html.Node) (result []*html.Node) {
- for p := n.Parent; p != nil; p = p.Parent {
- sel := newSingleSelection(p, nil)
- if stopm != nil {
- if sel.IsMatcher(stopm) {
- break
- }
- } else if len(stopNodes) > 0 {
- if sel.IsNodes(stopNodes...) {
- break
- }
- }
- if p.Type == html.ElementNode {
- result = append(result, p)
- }
- }
- return
- })
-}
-
-// Internal implementation of sibling nodes that return a raw slice of matches.
-func getSiblingNodes(nodes []*html.Node, st siblingType, untilm Matcher, untilNodes []*html.Node) []*html.Node {
- var f func(*html.Node) bool
-
- // If the requested siblings are ...Until, create the test function to
- // determine if the until condition is reached (returns true if it is)
- if st == siblingNextUntil || st == siblingPrevUntil {
- f = func(n *html.Node) bool {
- if untilm != nil {
- // Matcher-based condition
- sel := newSingleSelection(n, nil)
- return sel.IsMatcher(untilm)
- } else if len(untilNodes) > 0 {
- // Nodes-based condition
- sel := newSingleSelection(n, nil)
- return sel.IsNodes(untilNodes...)
- }
- return false
- }
- }
-
- return mapNodes(nodes, func(i int, n *html.Node) []*html.Node {
- return getChildrenWithSiblingType(n.Parent, st, n, f)
- })
-}
-
-// Gets the children nodes of each node in the specified slice of nodes,
-// based on the sibling type request.
-func getChildrenNodes(nodes []*html.Node, st siblingType) []*html.Node {
- return mapNodes(nodes, func(i int, n *html.Node) []*html.Node {
- return getChildrenWithSiblingType(n, st, nil, nil)
- })
-}
-
-// Gets the children of the specified parent, based on the requested sibling
-// type, skipping a specified node if required.
-func getChildrenWithSiblingType(parent *html.Node, st siblingType, skipNode *html.Node,
- untilFunc func(*html.Node) bool) (result []*html.Node) {
-
- // Create the iterator function
- var iter = func(cur *html.Node) (ret *html.Node) {
- // Based on the sibling type requested, iterate the right way
- for {
- switch st {
- case siblingAll, siblingAllIncludingNonElements:
- if cur == nil {
- // First iteration, start with first child of parent
- // Skip node if required
- if ret = parent.FirstChild; ret == skipNode && skipNode != nil {
- ret = skipNode.NextSibling
- }
- } else {
- // Skip node if required
- if ret = cur.NextSibling; ret == skipNode && skipNode != nil {
- ret = skipNode.NextSibling
- }
- }
- case siblingPrev, siblingPrevAll, siblingPrevUntil:
- if cur == nil {
- // Start with previous sibling of the skip node
- ret = skipNode.PrevSibling
- } else {
- ret = cur.PrevSibling
- }
- case siblingNext, siblingNextAll, siblingNextUntil:
- if cur == nil {
- // Start with next sibling of the skip node
- ret = skipNode.NextSibling
- } else {
- ret = cur.NextSibling
- }
- default:
- panic("Invalid sibling type.")
- }
- if ret == nil || ret.Type == html.ElementNode || st == siblingAllIncludingNonElements {
- return
- }
- // Not a valid node, try again from this one
- cur = ret
- }
- }
-
- for c := iter(nil); c != nil; c = iter(c) {
- // If this is an ...Until case, test before append (returns true
- // if the until condition is reached)
- if st == siblingNextUntil || st == siblingPrevUntil {
- if untilFunc(c) {
- return
- }
- }
- result = append(result, c)
- if st == siblingNext || st == siblingPrev {
- // Only one node was requested (immediate next or previous), so exit
- return
- }
- }
- return
-}
-
-// Internal implementation of parent nodes that return a raw slice of Nodes.
-func getParentNodes(nodes []*html.Node) []*html.Node {
- return mapNodes(nodes, func(i int, n *html.Node) []*html.Node {
- if n.Parent != nil && n.Parent.Type == html.ElementNode {
- return []*html.Node{n.Parent}
- }
- return nil
- })
-}
-
-// Internal map function used by many traversing methods. Takes the source nodes
-// to iterate on and the mapping function that returns an array of nodes.
-// Returns an array of nodes mapped by calling the callback function once for
-// each node in the source nodes.
-func mapNodes(nodes []*html.Node, f func(int, *html.Node) []*html.Node) (result []*html.Node) {
- set := make(map[*html.Node]bool)
- for i, n := range nodes {
- if vals := f(i, n); len(vals) > 0 {
- result = appendWithoutDuplicates(result, vals, set)
- }
- }
- return result
-}
diff --git a/vendor/github.com/PuerkitoBio/goquery/type.go b/vendor/github.com/PuerkitoBio/goquery/type.go
deleted file mode 100644
index 6ad51db..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/type.go
+++ /dev/null
@@ -1,141 +0,0 @@
-package goquery
-
-import (
- "errors"
- "io"
- "net/http"
- "net/url"
-
- "github.com/andybalholm/cascadia"
-
- "golang.org/x/net/html"
-)
-
-// Document represents an HTML document to be manipulated. Unlike jQuery, which
-// is loaded as part of a DOM document, and thus acts upon its containing
-// document, GoQuery doesn't know which HTML document to act upon. So it needs
-// to be told, and that's what the Document class is for. It holds the root
-// document node to manipulate, and can make selections on this document.
-type Document struct {
- *Selection
- Url *url.URL
- rootNode *html.Node
-}
-
-// NewDocumentFromNode is a Document constructor that takes a root html Node
-// as argument.
-func NewDocumentFromNode(root *html.Node) *Document {
- return newDocument(root, nil)
-}
-
-// NewDocument is a Document constructor that takes a string URL as argument.
-// It loads the specified document, parses it, and stores the root Document
-// node, ready to be manipulated.
-//
-// Deprecated: Use the net/http standard library package to make the request
-// and validate the response before calling goquery.NewDocumentFromReader
-// with the response's body.
-func NewDocument(url string) (*Document, error) {
- // Load the URL
- res, e := http.Get(url)
- if e != nil {
- return nil, e
- }
- return NewDocumentFromResponse(res)
-}
-
-// NewDocumentFromReader returns a Document from an io.Reader.
-// It returns an error as second value if the reader's data cannot be parsed
-// as html. It does not check if the reader is also an io.Closer, the
-// provided reader is never closed by this call. It is the responsibility
-// of the caller to close it if required.
-func NewDocumentFromReader(r io.Reader) (*Document, error) {
- root, e := html.Parse(r)
- if e != nil {
- return nil, e
- }
- return newDocument(root, nil), nil
-}
-
-// NewDocumentFromResponse is another Document constructor that takes an http response as argument.
-// It loads the specified response's document, parses it, and stores the root Document
-// node, ready to be manipulated. The response's body is closed on return.
-//
-// Deprecated: Use goquery.NewDocumentFromReader with the response's body.
-func NewDocumentFromResponse(res *http.Response) (*Document, error) {
- if res == nil {
- return nil, errors.New("Response is nil")
- }
- defer res.Body.Close()
- if res.Request == nil {
- return nil, errors.New("Response.Request is nil")
- }
-
- // Parse the HTML into nodes
- root, e := html.Parse(res.Body)
- if e != nil {
- return nil, e
- }
-
- // Create and fill the document
- return newDocument(root, res.Request.URL), nil
-}
-
-// CloneDocument creates a deep-clone of a document.
-func CloneDocument(doc *Document) *Document {
- return newDocument(cloneNode(doc.rootNode), doc.Url)
-}
-
-// Private constructor, make sure all fields are correctly filled.
-func newDocument(root *html.Node, url *url.URL) *Document {
- // Create and fill the document
- d := &Document{nil, url, root}
- d.Selection = newSingleSelection(root, d)
- return d
-}
-
-// Selection represents a collection of nodes matching some criteria. The
-// initial Selection can be created by using Document.Find, and then
-// manipulated using the jQuery-like chainable syntax and methods.
-type Selection struct {
- Nodes []*html.Node
- document *Document
- prevSel *Selection
-}
-
-// Helper constructor to create an empty selection
-func newEmptySelection(doc *Document) *Selection {
- return &Selection{nil, doc, nil}
-}
-
-// Helper constructor to create a selection of only one node
-func newSingleSelection(node *html.Node, doc *Document) *Selection {
- return &Selection{[]*html.Node{node}, doc, nil}
-}
-
-// Matcher is an interface that defines the methods to match
-// HTML nodes against a compiled selector string. Cascadia's
-// Selector implements this interface.
-type Matcher interface {
- Match(*html.Node) bool
- MatchAll(*html.Node) []*html.Node
- Filter([]*html.Node) []*html.Node
-}
-
-// compileMatcher compiles the selector string s and returns
-// the corresponding Matcher. If s is an invalid selector string,
-// it returns a Matcher that fails all matches.
-func compileMatcher(s string) Matcher {
- cs, err := cascadia.Compile(s)
- if err != nil {
- return invalidMatcher{}
- }
- return cs
-}
-
-// invalidMatcher is a Matcher that always fails to match.
-type invalidMatcher struct{}
-
-func (invalidMatcher) Match(n *html.Node) bool { return false }
-func (invalidMatcher) MatchAll(n *html.Node) []*html.Node { return nil }
-func (invalidMatcher) Filter(ns []*html.Node) []*html.Node { return nil }
diff --git a/vendor/github.com/PuerkitoBio/goquery/utilities.go b/vendor/github.com/PuerkitoBio/goquery/utilities.go
deleted file mode 100644
index b4c061a..0000000
--- a/vendor/github.com/PuerkitoBio/goquery/utilities.go
+++ /dev/null
@@ -1,161 +0,0 @@
-package goquery
-
-import (
- "bytes"
-
- "golang.org/x/net/html"
-)
-
-// used to determine if a set (map[*html.Node]bool) should be used
-// instead of iterating over a slice. The set uses more memory and
-// is slower than slice iteration for small N.
-const minNodesForSet = 1000
-
-var nodeNames = []string{
- html.ErrorNode: "#error",
- html.TextNode: "#text",
- html.DocumentNode: "#document",
- html.CommentNode: "#comment",
-}
-
-// NodeName returns the node name of the first element in the selection.
-// It tries to behave in a similar way as the DOM's nodeName property
-// (https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName).
-//
-// Go's net/html package defines the following node types, listed with
-// the corresponding returned value from this function:
-//
-// ErrorNode : #error
-// TextNode : #text
-// DocumentNode : #document
-// ElementNode : the element's tag name
-// CommentNode : #comment
-// DoctypeNode : the name of the document type
-//
-func NodeName(s *Selection) string {
- if s.Length() == 0 {
- return ""
- }
- switch n := s.Get(0); n.Type {
- case html.ElementNode, html.DoctypeNode:
- return n.Data
- default:
- if n.Type >= 0 && int(n.Type) < len(nodeNames) {
- return nodeNames[n.Type]
- }
- return ""
- }
-}
-
-// OuterHtml returns the outer HTML rendering of the first item in
-// the selection - that is, the HTML including the first element's
-// tag and attributes.
-//
-// Unlike InnerHtml, this is a function and not a method on the Selection,
-// because this is not a jQuery method (in javascript-land, this is
-// a property provided by the DOM).
-func OuterHtml(s *Selection) (string, error) {
- var buf bytes.Buffer
-
- if s.Length() == 0 {
- return "", nil
- }
- n := s.Get(0)
- if err := html.Render(&buf, n); err != nil {
- return "", err
- }
- return buf.String(), nil
-}
-
-// Loop through all container nodes to search for the target node.
-func sliceContains(container []*html.Node, contained *html.Node) bool {
- for _, n := range container {
- if nodeContains(n, contained) {
- return true
- }
- }
-
- return false
-}
-
-// Checks if the contained node is within the container node.
-func nodeContains(container *html.Node, contained *html.Node) bool {
- // Check if the parent of the contained node is the container node, traversing
- // upward until the top is reached, or the container is found.
- for contained = contained.Parent; contained != nil; contained = contained.Parent {
- if container == contained {
- return true
- }
- }
- return false
-}
-
-// Checks if the target node is in the slice of nodes.
-func isInSlice(slice []*html.Node, node *html.Node) bool {
- return indexInSlice(slice, node) > -1
-}
-
-// Returns the index of the target node in the slice, or -1.
-func indexInSlice(slice []*html.Node, node *html.Node) int {
- if node != nil {
- for i, n := range slice {
- if n == node {
- return i
- }
- }
- }
- return -1
-}
-
-// Appends the new nodes to the target slice, making sure no duplicate is added.
-// There is no check to the original state of the target slice, so it may still
-// contain duplicates. The target slice is returned because append() may create
-// a new underlying array. If targetSet is nil, a local set is created with the
-// target if len(target) + len(nodes) is greater than minNodesForSet.
-func appendWithoutDuplicates(target []*html.Node, nodes []*html.Node, targetSet map[*html.Node]bool) []*html.Node {
- // if there are not that many nodes, don't use the map, faster to just use nested loops
- // (unless a non-nil targetSet is passed, in which case the caller knows better).
- if targetSet == nil && len(target)+len(nodes) < minNodesForSet {
- for _, n := range nodes {
- if !isInSlice(target, n) {
- target = append(target, n)
- }
- }
- return target
- }
-
- // if a targetSet is passed, then assume it is reliable, otherwise create one
- // and initialize it with the current target contents.
- if targetSet == nil {
- targetSet = make(map[*html.Node]bool, len(target))
- for _, n := range target {
- targetSet[n] = true
- }
- }
- for _, n := range nodes {
- if !targetSet[n] {
- target = append(target, n)
- targetSet[n] = true
- }
- }
-
- return target
-}
-
-// Loop through a selection, returning only those nodes that pass the predicate
-// function.
-func grep(sel *Selection, predicate func(i int, s *Selection) bool) (result []*html.Node) {
- for i, n := range sel.Nodes {
- if predicate(i, newSingleSelection(n, sel.document)) {
- result = append(result, n)
- }
- }
- return result
-}
-
-// Creates a new Selection object based on the specified nodes, and keeps the
-// source Selection object on the stack (linked list).
-func pushStack(fromSel *Selection, nodes []*html.Node) *Selection {
- result := &Selection{nodes, fromSel.document, fromSel}
- return result
-}
diff --git a/vendor/github.com/andybalholm/cascadia/.travis.yml b/vendor/github.com/andybalholm/cascadia/.travis.yml
deleted file mode 100644
index 6f22751..0000000
--- a/vendor/github.com/andybalholm/cascadia/.travis.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-language: go
-
-go:
- - 1.3
- - 1.4
-
-install:
- - go get github.com/andybalholm/cascadia
-
-script:
- - go test -v
-
-notifications:
- email: false
diff --git a/vendor/github.com/andybalholm/cascadia/LICENSE b/vendor/github.com/andybalholm/cascadia/LICENSE
deleted file mode 100644
index ee5ad35..0000000
--- a/vendor/github.com/andybalholm/cascadia/LICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-Copyright (c) 2011 Andy Balholm. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/andybalholm/cascadia/README.md b/vendor/github.com/andybalholm/cascadia/README.md
deleted file mode 100644
index 9021cb9..0000000
--- a/vendor/github.com/andybalholm/cascadia/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# cascadia
-
-[![](https://travis-ci.org/andybalholm/cascadia.svg)](https://travis-ci.org/andybalholm/cascadia)
-
-The Cascadia package implements CSS selectors for use with the parse trees produced by the html package.
-
-To test CSS selectors without writing Go code, check out [cascadia](https://github.com/suntong/cascadia) the command line tool, a thin wrapper around this package.
diff --git a/vendor/github.com/andybalholm/cascadia/go.mod b/vendor/github.com/andybalholm/cascadia/go.mod
deleted file mode 100644
index e6febbb..0000000
--- a/vendor/github.com/andybalholm/cascadia/go.mod
+++ /dev/null
@@ -1,3 +0,0 @@
-module "github.com/andybalholm/cascadia"
-
-require "golang.org/x/net" v0.0.0-20180218175443-cbe0f9307d01
diff --git a/vendor/github.com/andybalholm/cascadia/parser.go b/vendor/github.com/andybalholm/cascadia/parser.go
deleted file mode 100644
index 495db9c..0000000
--- a/vendor/github.com/andybalholm/cascadia/parser.go
+++ /dev/null
@@ -1,835 +0,0 @@
-// Package cascadia is an implementation of CSS selectors.
-package cascadia
-
-import (
- "errors"
- "fmt"
- "regexp"
- "strconv"
- "strings"
-
- "golang.org/x/net/html"
-)
-
-// a parser for CSS selectors
-type parser struct {
- s string // the source text
- i int // the current position
-}
-
-// parseEscape parses a backslash escape.
-func (p *parser) parseEscape() (result string, err error) {
- if len(p.s) < p.i+2 || p.s[p.i] != '\\' {
- return "", errors.New("invalid escape sequence")
- }
-
- start := p.i + 1
- c := p.s[start]
- switch {
- case c == '\r' || c == '\n' || c == '\f':
- return "", errors.New("escaped line ending outside string")
- case hexDigit(c):
- // unicode escape (hex)
- var i int
- for i = start; i < p.i+6 && i < len(p.s) && hexDigit(p.s[i]); i++ {
- // empty
- }
- v, _ := strconv.ParseUint(p.s[start:i], 16, 21)
- if len(p.s) > i {
- switch p.s[i] {
- case '\r':
- i++
- if len(p.s) > i && p.s[i] == '\n' {
- i++
- }
- case ' ', '\t', '\n', '\f':
- i++
- }
- }
- p.i = i
- return string(rune(v)), nil
- }
-
- // Return the literal character after the backslash.
- result = p.s[start : start+1]
- p.i += 2
- return result, nil
-}
-
-func hexDigit(c byte) bool {
- return '0' <= c && c <= '9' || 'a' <= c && c <= 'f' || 'A' <= c && c <= 'F'
-}
-
-// nameStart returns whether c can be the first character of an identifier
-// (not counting an initial hyphen, or an escape sequence).
-func nameStart(c byte) bool {
- return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_' || c > 127
-}
-
-// nameChar returns whether c can be a character within an identifier
-// (not counting an escape sequence).
-func nameChar(c byte) bool {
- return 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_' || c > 127 ||
- c == '-' || '0' <= c && c <= '9'
-}
-
-// parseIdentifier parses an identifier.
-func (p *parser) parseIdentifier() (result string, err error) {
- startingDash := false
- if len(p.s) > p.i && p.s[p.i] == '-' {
- startingDash = true
- p.i++
- }
-
- if len(p.s) <= p.i {
- return "", errors.New("expected identifier, found EOF instead")
- }
-
- if c := p.s[p.i]; !(nameStart(c) || c == '\\') {
- return "", fmt.Errorf("expected identifier, found %c instead", c)
- }
-
- result, err = p.parseName()
- if startingDash && err == nil {
- result = "-" + result
- }
- return
-}
-
-// parseName parses a name (which is like an identifier, but doesn't have
-// extra restrictions on the first character).
-func (p *parser) parseName() (result string, err error) {
- i := p.i
-loop:
- for i < len(p.s) {
- c := p.s[i]
- switch {
- case nameChar(c):
- start := i
- for i < len(p.s) && nameChar(p.s[i]) {
- i++
- }
- result += p.s[start:i]
- case c == '\\':
- p.i = i
- val, err := p.parseEscape()
- if err != nil {
- return "", err
- }
- i = p.i
- result += val
- default:
- break loop
- }
- }
-
- if result == "" {
- return "", errors.New("expected name, found EOF instead")
- }
-
- p.i = i
- return result, nil
-}
-
-// parseString parses a single- or double-quoted string.
-func (p *parser) parseString() (result string, err error) {
- i := p.i
- if len(p.s) < i+2 {
- return "", errors.New("expected string, found EOF instead")
- }
-
- quote := p.s[i]
- i++
-
-loop:
- for i < len(p.s) {
- switch p.s[i] {
- case '\\':
- if len(p.s) > i+1 {
- switch c := p.s[i+1]; c {
- case '\r':
- if len(p.s) > i+2 && p.s[i+2] == '\n' {
- i += 3
- continue loop
- }
- fallthrough
- case '\n', '\f':
- i += 2
- continue loop
- }
- }
- p.i = i
- val, err := p.parseEscape()
- if err != nil {
- return "", err
- }
- i = p.i
- result += val
- case quote:
- break loop
- case '\r', '\n', '\f':
- return "", errors.New("unexpected end of line in string")
- default:
- start := i
- for i < len(p.s) {
- if c := p.s[i]; c == quote || c == '\\' || c == '\r' || c == '\n' || c == '\f' {
- break
- }
- i++
- }
- result += p.s[start:i]
- }
- }
-
- if i >= len(p.s) {
- return "", errors.New("EOF in string")
- }
-
- // Consume the final quote.
- i++
-
- p.i = i
- return result, nil
-}
-
-// parseRegex parses a regular expression; the end is defined by encountering an
-// unmatched closing ')' or ']' which is not consumed
-func (p *parser) parseRegex() (rx *regexp.Regexp, err error) {
- i := p.i
- if len(p.s) < i+2 {
- return nil, errors.New("expected regular expression, found EOF instead")
- }
-
- // number of open parens or brackets;
- // when it becomes negative, finished parsing regex
- open := 0
-
-loop:
- for i < len(p.s) {
- switch p.s[i] {
- case '(', '[':
- open++
- case ')', ']':
- open--
- if open < 0 {
- break loop
- }
- }
- i++
- }
-
- if i >= len(p.s) {
- return nil, errors.New("EOF in regular expression")
- }
- rx, err = regexp.Compile(p.s[p.i:i])
- p.i = i
- return rx, err
-}
-
-// skipWhitespace consumes whitespace characters and comments.
-// It returns true if there was actually anything to skip.
-func (p *parser) skipWhitespace() bool {
- i := p.i
- for i < len(p.s) {
- switch p.s[i] {
- case ' ', '\t', '\r', '\n', '\f':
- i++
- continue
- case '/':
- if strings.HasPrefix(p.s[i:], "/*") {
- end := strings.Index(p.s[i+len("/*"):], "*/")
- if end != -1 {
- i += end + len("/**/")
- continue
- }
- }
- }
- break
- }
-
- if i > p.i {
- p.i = i
- return true
- }
-
- return false
-}
-
-// consumeParenthesis consumes an opening parenthesis and any following
-// whitespace. It returns true if there was actually a parenthesis to skip.
-func (p *parser) consumeParenthesis() bool {
- if p.i < len(p.s) && p.s[p.i] == '(' {
- p.i++
- p.skipWhitespace()
- return true
- }
- return false
-}
-
-// consumeClosingParenthesis consumes a closing parenthesis and any preceding
-// whitespace. It returns true if there was actually a parenthesis to skip.
-func (p *parser) consumeClosingParenthesis() bool {
- i := p.i
- p.skipWhitespace()
- if p.i < len(p.s) && p.s[p.i] == ')' {
- p.i++
- return true
- }
- p.i = i
- return false
-}
-
-// parseTypeSelector parses a type selector (one that matches by tag name).
-func (p *parser) parseTypeSelector() (result Selector, err error) {
- tag, err := p.parseIdentifier()
- if err != nil {
- return nil, err
- }
-
- return typeSelector(tag), nil
-}
-
-// parseIDSelector parses a selector that matches by id attribute.
-func (p *parser) parseIDSelector() (Selector, error) {
- if p.i >= len(p.s) {
- return nil, fmt.Errorf("expected id selector (#id), found EOF instead")
- }
- if p.s[p.i] != '#' {
- return nil, fmt.Errorf("expected id selector (#id), found '%c' instead", p.s[p.i])
- }
-
- p.i++
- id, err := p.parseName()
- if err != nil {
- return nil, err
- }
-
- return attributeEqualsSelector("id", id), nil
-}
-
-// parseClassSelector parses a selector that matches by class attribute.
-func (p *parser) parseClassSelector() (Selector, error) {
- if p.i >= len(p.s) {
- return nil, fmt.Errorf("expected class selector (.class), found EOF instead")
- }
- if p.s[p.i] != '.' {
- return nil, fmt.Errorf("expected class selector (.class), found '%c' instead", p.s[p.i])
- }
-
- p.i++
- class, err := p.parseIdentifier()
- if err != nil {
- return nil, err
- }
-
- return attributeIncludesSelector("class", class), nil
-}
-
-// parseAttributeSelector parses a selector that matches by attribute value.
-func (p *parser) parseAttributeSelector() (Selector, error) {
- if p.i >= len(p.s) {
- return nil, fmt.Errorf("expected attribute selector ([attribute]), found EOF instead")
- }
- if p.s[p.i] != '[' {
- return nil, fmt.Errorf("expected attribute selector ([attribute]), found '%c' instead", p.s[p.i])
- }
-
- p.i++
- p.skipWhitespace()
- key, err := p.parseIdentifier()
- if err != nil {
- return nil, err
- }
-
- p.skipWhitespace()
- if p.i >= len(p.s) {
- return nil, errors.New("unexpected EOF in attribute selector")
- }
-
- if p.s[p.i] == ']' {
- p.i++
- return attributeExistsSelector(key), nil
- }
-
- if p.i+2 >= len(p.s) {
- return nil, errors.New("unexpected EOF in attribute selector")
- }
-
- op := p.s[p.i : p.i+2]
- if op[0] == '=' {
- op = "="
- } else if op[1] != '=' {
- return nil, fmt.Errorf(`expected equality operator, found "%s" instead`, op)
- }
- p.i += len(op)
-
- p.skipWhitespace()
- if p.i >= len(p.s) {
- return nil, errors.New("unexpected EOF in attribute selector")
- }
- var val string
- var rx *regexp.Regexp
- if op == "#=" {
- rx, err = p.parseRegex()
- } else {
- switch p.s[p.i] {
- case '\'', '"':
- val, err = p.parseString()
- default:
- val, err = p.parseIdentifier()
- }
- }
- if err != nil {
- return nil, err
- }
-
- p.skipWhitespace()
- if p.i >= len(p.s) {
- return nil, errors.New("unexpected EOF in attribute selector")
- }
- if p.s[p.i] != ']' {
- return nil, fmt.Errorf("expected ']', found '%c' instead", p.s[p.i])
- }
- p.i++
-
- switch op {
- case "=":
- return attributeEqualsSelector(key, val), nil
- case "!=":
- return attributeNotEqualSelector(key, val), nil
- case "~=":
- return attributeIncludesSelector(key, val), nil
- case "|=":
- return attributeDashmatchSelector(key, val), nil
- case "^=":
- return attributePrefixSelector(key, val), nil
- case "$=":
- return attributeSuffixSelector(key, val), nil
- case "*=":
- return attributeSubstringSelector(key, val), nil
- case "#=":
- return attributeRegexSelector(key, rx), nil
- }
-
- return nil, fmt.Errorf("attribute operator %q is not supported", op)
-}
-
-var errExpectedParenthesis = errors.New("expected '(' but didn't find it")
-var errExpectedClosingParenthesis = errors.New("expected ')' but didn't find it")
-var errUnmatchedParenthesis = errors.New("unmatched '('")
-
-// parsePseudoclassSelector parses a pseudoclass selector like :not(p).
-func (p *parser) parsePseudoclassSelector() (Selector, error) {
- if p.i >= len(p.s) {
- return nil, fmt.Errorf("expected pseudoclass selector (:pseudoclass), found EOF instead")
- }
- if p.s[p.i] != ':' {
- return nil, fmt.Errorf("expected attribute selector (:pseudoclass), found '%c' instead", p.s[p.i])
- }
-
- p.i++
- name, err := p.parseIdentifier()
- if err != nil {
- return nil, err
- }
- name = toLowerASCII(name)
-
- switch name {
- case "not", "has", "haschild":
- if !p.consumeParenthesis() {
- return nil, errExpectedParenthesis
- }
- sel, parseErr := p.parseSelectorGroup()
- if parseErr != nil {
- return nil, parseErr
- }
- if !p.consumeClosingParenthesis() {
- return nil, errExpectedClosingParenthesis
- }
-
- switch name {
- case "not":
- return negatedSelector(sel), nil
- case "has":
- return hasDescendantSelector(sel), nil
- case "haschild":
- return hasChildSelector(sel), nil
- }
-
- case "contains", "containsown":
- if !p.consumeParenthesis() {
- return nil, errExpectedParenthesis
- }
- if p.i == len(p.s) {
- return nil, errUnmatchedParenthesis
- }
- var val string
- switch p.s[p.i] {
- case '\'', '"':
- val, err = p.parseString()
- default:
- val, err = p.parseIdentifier()
- }
- if err != nil {
- return nil, err
- }
- val = strings.ToLower(val)
- p.skipWhitespace()
- if p.i >= len(p.s) {
- return nil, errors.New("unexpected EOF in pseudo selector")
- }
- if !p.consumeClosingParenthesis() {
- return nil, errExpectedClosingParenthesis
- }
-
- switch name {
- case "contains":
- return textSubstrSelector(val), nil
- case "containsown":
- return ownTextSubstrSelector(val), nil
- }
-
- case "matches", "matchesown":
- if !p.consumeParenthesis() {
- return nil, errExpectedParenthesis
- }
- rx, err := p.parseRegex()
- if err != nil {
- return nil, err
- }
- if p.i >= len(p.s) {
- return nil, errors.New("unexpected EOF in pseudo selector")
- }
- if !p.consumeClosingParenthesis() {
- return nil, errExpectedClosingParenthesis
- }
-
- switch name {
- case "matches":
- return textRegexSelector(rx), nil
- case "matchesown":
- return ownTextRegexSelector(rx), nil
- }
-
- case "nth-child", "nth-last-child", "nth-of-type", "nth-last-of-type":
- if !p.consumeParenthesis() {
- return nil, errExpectedParenthesis
- }
- a, b, err := p.parseNth()
- if err != nil {
- return nil, err
- }
- if !p.consumeClosingParenthesis() {
- return nil, errExpectedClosingParenthesis
- }
- if a == 0 {
- switch name {
- case "nth-child":
- return simpleNthChildSelector(b, false), nil
- case "nth-of-type":
- return simpleNthChildSelector(b, true), nil
- case "nth-last-child":
- return simpleNthLastChildSelector(b, false), nil
- case "nth-last-of-type":
- return simpleNthLastChildSelector(b, true), nil
- }
- }
- return nthChildSelector(a, b,
- name == "nth-last-child" || name == "nth-last-of-type",
- name == "nth-of-type" || name == "nth-last-of-type"),
- nil
-
- case "first-child":
- return simpleNthChildSelector(1, false), nil
- case "last-child":
- return simpleNthLastChildSelector(1, false), nil
- case "first-of-type":
- return simpleNthChildSelector(1, true), nil
- case "last-of-type":
- return simpleNthLastChildSelector(1, true), nil
- case "only-child":
- return onlyChildSelector(false), nil
- case "only-of-type":
- return onlyChildSelector(true), nil
- case "input":
- return inputSelector, nil
- case "empty":
- return emptyElementSelector, nil
- case "root":
- return rootSelector, nil
- }
-
- return nil, fmt.Errorf("unknown pseudoclass :%s", name)
-}
-
-// parseInteger parses a decimal integer.
-func (p *parser) parseInteger() (int, error) {
- i := p.i
- start := i
- for i < len(p.s) && '0' <= p.s[i] && p.s[i] <= '9' {
- i++
- }
- if i == start {
- return 0, errors.New("expected integer, but didn't find it")
- }
- p.i = i
-
- val, err := strconv.Atoi(p.s[start:i])
- if err != nil {
- return 0, err
- }
-
- return val, nil
-}
-
-// parseNth parses the argument for :nth-child (normally of the form an+b).
-func (p *parser) parseNth() (a, b int, err error) {
- // initial state
- if p.i >= len(p.s) {
- goto eof
- }
- switch p.s[p.i] {
- case '-':
- p.i++
- goto negativeA
- case '+':
- p.i++
- goto positiveA
- case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- goto positiveA
- case 'n', 'N':
- a = 1
- p.i++
- goto readN
- case 'o', 'O', 'e', 'E':
- id, nameErr := p.parseName()
- if nameErr != nil {
- return 0, 0, nameErr
- }
- id = toLowerASCII(id)
- if id == "odd" {
- return 2, 1, nil
- }
- if id == "even" {
- return 2, 0, nil
- }
- return 0, 0, fmt.Errorf("expected 'odd' or 'even', but found '%s' instead", id)
- default:
- goto invalid
- }
-
-positiveA:
- if p.i >= len(p.s) {
- goto eof
- }
- switch p.s[p.i] {
- case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- a, err = p.parseInteger()
- if err != nil {
- return 0, 0, err
- }
- goto readA
- case 'n', 'N':
- a = 1
- p.i++
- goto readN
- default:
- goto invalid
- }
-
-negativeA:
- if p.i >= len(p.s) {
- goto eof
- }
- switch p.s[p.i] {
- case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- a, err = p.parseInteger()
- if err != nil {
- return 0, 0, err
- }
- a = -a
- goto readA
- case 'n', 'N':
- a = -1
- p.i++
- goto readN
- default:
- goto invalid
- }
-
-readA:
- if p.i >= len(p.s) {
- goto eof
- }
- switch p.s[p.i] {
- case 'n', 'N':
- p.i++
- goto readN
- default:
- // The number we read as a is actually b.
- return 0, a, nil
- }
-
-readN:
- p.skipWhitespace()
- if p.i >= len(p.s) {
- goto eof
- }
- switch p.s[p.i] {
- case '+':
- p.i++
- p.skipWhitespace()
- b, err = p.parseInteger()
- if err != nil {
- return 0, 0, err
- }
- return a, b, nil
- case '-':
- p.i++
- p.skipWhitespace()
- b, err = p.parseInteger()
- if err != nil {
- return 0, 0, err
- }
- return a, -b, nil
- default:
- return a, 0, nil
- }
-
-eof:
- return 0, 0, errors.New("unexpected EOF while attempting to parse expression of form an+b")
-
-invalid:
- return 0, 0, errors.New("unexpected character while attempting to parse expression of form an+b")
-}
-
-// parseSimpleSelectorSequence parses a selector sequence that applies to
-// a single element.
-func (p *parser) parseSimpleSelectorSequence() (Selector, error) {
- var result Selector
-
- if p.i >= len(p.s) {
- return nil, errors.New("expected selector, found EOF instead")
- }
-
- switch p.s[p.i] {
- case '*':
- // It's the universal selector. Just skip over it, since it doesn't affect the meaning.
- p.i++
- case '#', '.', '[', ':':
- // There's no type selector. Wait to process the other till the main loop.
- default:
- r, err := p.parseTypeSelector()
- if err != nil {
- return nil, err
- }
- result = r
- }
-
-loop:
- for p.i < len(p.s) {
- var ns Selector
- var err error
- switch p.s[p.i] {
- case '#':
- ns, err = p.parseIDSelector()
- case '.':
- ns, err = p.parseClassSelector()
- case '[':
- ns, err = p.parseAttributeSelector()
- case ':':
- ns, err = p.parsePseudoclassSelector()
- default:
- break loop
- }
- if err != nil {
- return nil, err
- }
- if result == nil {
- result = ns
- } else {
- result = intersectionSelector(result, ns)
- }
- }
-
- if result == nil {
- result = func(n *html.Node) bool {
- return n.Type == html.ElementNode
- }
- }
-
- return result, nil
-}
-
-// parseSelector parses a selector that may include combinators.
-func (p *parser) parseSelector() (result Selector, err error) {
- p.skipWhitespace()
- result, err = p.parseSimpleSelectorSequence()
- if err != nil {
- return
- }
-
- for {
- var combinator byte
- if p.skipWhitespace() {
- combinator = ' '
- }
- if p.i >= len(p.s) {
- return
- }
-
- switch p.s[p.i] {
- case '+', '>', '~':
- combinator = p.s[p.i]
- p.i++
- p.skipWhitespace()
- case ',', ')':
- // These characters can't begin a selector, but they can legally occur after one.
- return
- }
-
- if combinator == 0 {
- return
- }
-
- c, err := p.parseSimpleSelectorSequence()
- if err != nil {
- return nil, err
- }
-
- switch combinator {
- case ' ':
- result = descendantSelector(result, c)
- case '>':
- result = childSelector(result, c)
- case '+':
- result = siblingSelector(result, c, true)
- case '~':
- result = siblingSelector(result, c, false)
- }
- }
-
- panic("unreachable")
-}
-
-// parseSelectorGroup parses a group of selectors, separated by commas.
-func (p *parser) parseSelectorGroup() (result Selector, err error) {
- result, err = p.parseSelector()
- if err != nil {
- return
- }
-
- for p.i < len(p.s) {
- if p.s[p.i] != ',' {
- return result, nil
- }
- p.i++
- c, err := p.parseSelector()
- if err != nil {
- return nil, err
- }
- result = unionSelector(result, c)
- }
-
- return
-}
diff --git a/vendor/github.com/andybalholm/cascadia/selector.go b/vendor/github.com/andybalholm/cascadia/selector.go
deleted file mode 100644
index 9fb05cc..0000000
--- a/vendor/github.com/andybalholm/cascadia/selector.go
+++ /dev/null
@@ -1,622 +0,0 @@
-package cascadia
-
-import (
- "bytes"
- "fmt"
- "regexp"
- "strings"
-
- "golang.org/x/net/html"
-)
-
-// the Selector type, and functions for creating them
-
-// A Selector is a function which tells whether a node matches or not.
-type Selector func(*html.Node) bool
-
-// hasChildMatch returns whether n has any child that matches a.
-func hasChildMatch(n *html.Node, a Selector) bool {
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- if a(c) {
- return true
- }
- }
- return false
-}
-
-// hasDescendantMatch performs a depth-first search of n's descendants,
-// testing whether any of them match a. It returns true as soon as a match is
-// found, or false if no match is found.
-func hasDescendantMatch(n *html.Node, a Selector) bool {
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- if a(c) || (c.Type == html.ElementNode && hasDescendantMatch(c, a)) {
- return true
- }
- }
- return false
-}
-
-// Compile parses a selector and returns, if successful, a Selector object
-// that can be used to match against html.Node objects.
-func Compile(sel string) (Selector, error) {
- p := &parser{s: sel}
- compiled, err := p.parseSelectorGroup()
- if err != nil {
- return nil, err
- }
-
- if p.i < len(sel) {
- return nil, fmt.Errorf("parsing %q: %d bytes left over", sel, len(sel)-p.i)
- }
-
- return compiled, nil
-}
-
-// MustCompile is like Compile, but panics instead of returning an error.
-func MustCompile(sel string) Selector {
- compiled, err := Compile(sel)
- if err != nil {
- panic(err)
- }
- return compiled
-}
-
-// MatchAll returns a slice of the nodes that match the selector,
-// from n and its children.
-func (s Selector) MatchAll(n *html.Node) []*html.Node {
- return s.matchAllInto(n, nil)
-}
-
-func (s Selector) matchAllInto(n *html.Node, storage []*html.Node) []*html.Node {
- if s(n) {
- storage = append(storage, n)
- }
-
- for child := n.FirstChild; child != nil; child = child.NextSibling {
- storage = s.matchAllInto(child, storage)
- }
-
- return storage
-}
-
-// Match returns true if the node matches the selector.
-func (s Selector) Match(n *html.Node) bool {
- return s(n)
-}
-
-// MatchFirst returns the first node that matches s, from n and its children.
-func (s Selector) MatchFirst(n *html.Node) *html.Node {
- if s.Match(n) {
- return n
- }
-
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- m := s.MatchFirst(c)
- if m != nil {
- return m
- }
- }
- return nil
-}
-
-// Filter returns the nodes in nodes that match the selector.
-func (s Selector) Filter(nodes []*html.Node) (result []*html.Node) {
- for _, n := range nodes {
- if s(n) {
- result = append(result, n)
- }
- }
- return result
-}
-
-// typeSelector returns a Selector that matches elements with a given tag name.
-func typeSelector(tag string) Selector {
- tag = toLowerASCII(tag)
- return func(n *html.Node) bool {
- return n.Type == html.ElementNode && n.Data == tag
- }
-}
-
-// toLowerASCII returns s with all ASCII capital letters lowercased.
-func toLowerASCII(s string) string {
- var b []byte
- for i := 0; i < len(s); i++ {
- if c := s[i]; 'A' <= c && c <= 'Z' {
- if b == nil {
- b = make([]byte, len(s))
- copy(b, s)
- }
- b[i] = s[i] + ('a' - 'A')
- }
- }
-
- if b == nil {
- return s
- }
-
- return string(b)
-}
-
-// attributeSelector returns a Selector that matches elements
-// where the attribute named key satisifes the function f.
-func attributeSelector(key string, f func(string) bool) Selector {
- key = toLowerASCII(key)
- return func(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
- for _, a := range n.Attr {
- if a.Key == key && f(a.Val) {
- return true
- }
- }
- return false
- }
-}
-
-// attributeExistsSelector returns a Selector that matches elements that have
-// an attribute named key.
-func attributeExistsSelector(key string) Selector {
- return attributeSelector(key, func(string) bool { return true })
-}
-
-// attributeEqualsSelector returns a Selector that matches elements where
-// the attribute named key has the value val.
-func attributeEqualsSelector(key, val string) Selector {
- return attributeSelector(key,
- func(s string) bool {
- return s == val
- })
-}
-
-// attributeNotEqualSelector returns a Selector that matches elements where
-// the attribute named key does not have the value val.
-func attributeNotEqualSelector(key, val string) Selector {
- key = toLowerASCII(key)
- return func(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
- for _, a := range n.Attr {
- if a.Key == key && a.Val == val {
- return false
- }
- }
- return true
- }
-}
-
-// attributeIncludesSelector returns a Selector that matches elements where
-// the attribute named key is a whitespace-separated list that includes val.
-func attributeIncludesSelector(key, val string) Selector {
- return attributeSelector(key,
- func(s string) bool {
- for s != "" {
- i := strings.IndexAny(s, " \t\r\n\f")
- if i == -1 {
- return s == val
- }
- if s[:i] == val {
- return true
- }
- s = s[i+1:]
- }
- return false
- })
-}
-
-// attributeDashmatchSelector returns a Selector that matches elements where
-// the attribute named key equals val or starts with val plus a hyphen.
-func attributeDashmatchSelector(key, val string) Selector {
- return attributeSelector(key,
- func(s string) bool {
- if s == val {
- return true
- }
- if len(s) <= len(val) {
- return false
- }
- if s[:len(val)] == val && s[len(val)] == '-' {
- return true
- }
- return false
- })
-}
-
-// attributePrefixSelector returns a Selector that matches elements where
-// the attribute named key starts with val.
-func attributePrefixSelector(key, val string) Selector {
- return attributeSelector(key,
- func(s string) bool {
- if strings.TrimSpace(s) == "" {
- return false
- }
- return strings.HasPrefix(s, val)
- })
-}
-
-// attributeSuffixSelector returns a Selector that matches elements where
-// the attribute named key ends with val.
-func attributeSuffixSelector(key, val string) Selector {
- return attributeSelector(key,
- func(s string) bool {
- if strings.TrimSpace(s) == "" {
- return false
- }
- return strings.HasSuffix(s, val)
- })
-}
-
-// attributeSubstringSelector returns a Selector that matches nodes where
-// the attribute named key contains val.
-func attributeSubstringSelector(key, val string) Selector {
- return attributeSelector(key,
- func(s string) bool {
- if strings.TrimSpace(s) == "" {
- return false
- }
- return strings.Contains(s, val)
- })
-}
-
-// attributeRegexSelector returns a Selector that matches nodes where
-// the attribute named key matches the regular expression rx
-func attributeRegexSelector(key string, rx *regexp.Regexp) Selector {
- return attributeSelector(key,
- func(s string) bool {
- return rx.MatchString(s)
- })
-}
-
-// intersectionSelector returns a selector that matches nodes that match
-// both a and b.
-func intersectionSelector(a, b Selector) Selector {
- return func(n *html.Node) bool {
- return a(n) && b(n)
- }
-}
-
-// unionSelector returns a selector that matches elements that match
-// either a or b.
-func unionSelector(a, b Selector) Selector {
- return func(n *html.Node) bool {
- return a(n) || b(n)
- }
-}
-
-// negatedSelector returns a selector that matches elements that do not match a.
-func negatedSelector(a Selector) Selector {
- return func(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
- return !a(n)
- }
-}
-
-// writeNodeText writes the text contained in n and its descendants to b.
-func writeNodeText(n *html.Node, b *bytes.Buffer) {
- switch n.Type {
- case html.TextNode:
- b.WriteString(n.Data)
- case html.ElementNode:
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- writeNodeText(c, b)
- }
- }
-}
-
-// nodeText returns the text contained in n and its descendants.
-func nodeText(n *html.Node) string {
- var b bytes.Buffer
- writeNodeText(n, &b)
- return b.String()
-}
-
-// nodeOwnText returns the contents of the text nodes that are direct
-// children of n.
-func nodeOwnText(n *html.Node) string {
- var b bytes.Buffer
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- if c.Type == html.TextNode {
- b.WriteString(c.Data)
- }
- }
- return b.String()
-}
-
-// textSubstrSelector returns a selector that matches nodes that
-// contain the given text.
-func textSubstrSelector(val string) Selector {
- return func(n *html.Node) bool {
- text := strings.ToLower(nodeText(n))
- return strings.Contains(text, val)
- }
-}
-
-// ownTextSubstrSelector returns a selector that matches nodes that
-// directly contain the given text
-func ownTextSubstrSelector(val string) Selector {
- return func(n *html.Node) bool {
- text := strings.ToLower(nodeOwnText(n))
- return strings.Contains(text, val)
- }
-}
-
-// textRegexSelector returns a selector that matches nodes whose text matches
-// the specified regular expression
-func textRegexSelector(rx *regexp.Regexp) Selector {
- return func(n *html.Node) bool {
- return rx.MatchString(nodeText(n))
- }
-}
-
-// ownTextRegexSelector returns a selector that matches nodes whose text
-// directly matches the specified regular expression
-func ownTextRegexSelector(rx *regexp.Regexp) Selector {
- return func(n *html.Node) bool {
- return rx.MatchString(nodeOwnText(n))
- }
-}
-
-// hasChildSelector returns a selector that matches elements
-// with a child that matches a.
-func hasChildSelector(a Selector) Selector {
- return func(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
- return hasChildMatch(n, a)
- }
-}
-
-// hasDescendantSelector returns a selector that matches elements
-// with any descendant that matches a.
-func hasDescendantSelector(a Selector) Selector {
- return func(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
- return hasDescendantMatch(n, a)
- }
-}
-
-// nthChildSelector returns a selector that implements :nth-child(an+b).
-// If last is true, implements :nth-last-child instead.
-// If ofType is true, implements :nth-of-type instead.
-func nthChildSelector(a, b int, last, ofType bool) Selector {
- return func(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
-
- parent := n.Parent
- if parent == nil {
- return false
- }
-
- if parent.Type == html.DocumentNode {
- return false
- }
-
- i := -1
- count := 0
- for c := parent.FirstChild; c != nil; c = c.NextSibling {
- if (c.Type != html.ElementNode) || (ofType && c.Data != n.Data) {
- continue
- }
- count++
- if c == n {
- i = count
- if !last {
- break
- }
- }
- }
-
- if i == -1 {
- // This shouldn't happen, since n should always be one of its parent's children.
- return false
- }
-
- if last {
- i = count - i + 1
- }
-
- i -= b
- if a == 0 {
- return i == 0
- }
-
- return i%a == 0 && i/a >= 0
- }
-}
-
-// simpleNthChildSelector returns a selector that implements :nth-child(b).
-// If ofType is true, implements :nth-of-type instead.
-func simpleNthChildSelector(b int, ofType bool) Selector {
- return func(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
-
- parent := n.Parent
- if parent == nil {
- return false
- }
-
- if parent.Type == html.DocumentNode {
- return false
- }
-
- count := 0
- for c := parent.FirstChild; c != nil; c = c.NextSibling {
- if c.Type != html.ElementNode || (ofType && c.Data != n.Data) {
- continue
- }
- count++
- if c == n {
- return count == b
- }
- if count >= b {
- return false
- }
- }
- return false
- }
-}
-
-// simpleNthLastChildSelector returns a selector that implements
-// :nth-last-child(b). If ofType is true, implements :nth-last-of-type
-// instead.
-func simpleNthLastChildSelector(b int, ofType bool) Selector {
- return func(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
-
- parent := n.Parent
- if parent == nil {
- return false
- }
-
- if parent.Type == html.DocumentNode {
- return false
- }
-
- count := 0
- for c := parent.LastChild; c != nil; c = c.PrevSibling {
- if c.Type != html.ElementNode || (ofType && c.Data != n.Data) {
- continue
- }
- count++
- if c == n {
- return count == b
- }
- if count >= b {
- return false
- }
- }
- return false
- }
-}
-
-// onlyChildSelector returns a selector that implements :only-child.
-// If ofType is true, it implements :only-of-type instead.
-func onlyChildSelector(ofType bool) Selector {
- return func(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
-
- parent := n.Parent
- if parent == nil {
- return false
- }
-
- if parent.Type == html.DocumentNode {
- return false
- }
-
- count := 0
- for c := parent.FirstChild; c != nil; c = c.NextSibling {
- if (c.Type != html.ElementNode) || (ofType && c.Data != n.Data) {
- continue
- }
- count++
- if count > 1 {
- return false
- }
- }
-
- return count == 1
- }
-}
-
-// inputSelector is a Selector that matches input, select, textarea and button elements.
-func inputSelector(n *html.Node) bool {
- return n.Type == html.ElementNode && (n.Data == "input" || n.Data == "select" || n.Data == "textarea" || n.Data == "button")
-}
-
-// emptyElementSelector is a Selector that matches empty elements.
-func emptyElementSelector(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
-
- for c := n.FirstChild; c != nil; c = c.NextSibling {
- switch c.Type {
- case html.ElementNode, html.TextNode:
- return false
- }
- }
-
- return true
-}
-
-// descendantSelector returns a Selector that matches an element if
-// it matches d and has an ancestor that matches a.
-func descendantSelector(a, d Selector) Selector {
- return func(n *html.Node) bool {
- if !d(n) {
- return false
- }
-
- for p := n.Parent; p != nil; p = p.Parent {
- if a(p) {
- return true
- }
- }
-
- return false
- }
-}
-
-// childSelector returns a Selector that matches an element if
-// it matches d and its parent matches a.
-func childSelector(a, d Selector) Selector {
- return func(n *html.Node) bool {
- return d(n) && n.Parent != nil && a(n.Parent)
- }
-}
-
-// siblingSelector returns a Selector that matches an element
-// if it matches s2 and in is preceded by an element that matches s1.
-// If adjacent is true, the sibling must be immediately before the element.
-func siblingSelector(s1, s2 Selector, adjacent bool) Selector {
- return func(n *html.Node) bool {
- if !s2(n) {
- return false
- }
-
- if adjacent {
- for n = n.PrevSibling; n != nil; n = n.PrevSibling {
- if n.Type == html.TextNode || n.Type == html.CommentNode {
- continue
- }
- return s1(n)
- }
- return false
- }
-
- // Walk backwards looking for element that matches s1
- for c := n.PrevSibling; c != nil; c = c.PrevSibling {
- if s1(c) {
- return true
- }
- }
-
- return false
- }
-}
-
-// rootSelector implements :root
-func rootSelector(n *html.Node) bool {
- if n.Type != html.ElementNode {
- return false
- }
- if n.Parent == nil {
- return false
- }
- return n.Parent.Type == html.DocumentNode
-}
diff --git a/vendor/github.com/boj/redistore/.gitignore b/vendor/github.com/boj/redistore/.gitignore
deleted file mode 100644
index 5ca0973..0000000
--- a/vendor/github.com/boj/redistore/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-.DS_Store
-
diff --git a/vendor/github.com/boj/redistore/.travis.yml b/vendor/github.com/boj/redistore/.travis.yml
deleted file mode 100644
index ee2e196..0000000
--- a/vendor/github.com/boj/redistore/.travis.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-language: go
-sudo: false
-
-services:
- - redis-server
-
-matrix:
- include:
- - go: 1.5
- - go: 1.6
- - go: 1.7
- - go: 1.8
- - go: 1.9
- - go: tip
- allow_failures:
- - go: tip
-
-install:
- - # skip
-
-script:
- - go get -t -v ./...
- - diff -u <(echo -n) <(gofmt -d .)
- - go tool vet .
- - go test -v -race ./...
diff --git a/vendor/github.com/boj/redistore/LICENSE b/vendor/github.com/boj/redistore/LICENSE
deleted file mode 100644
index fabd7b9..0000000
--- a/vendor/github.com/boj/redistore/LICENSE
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2013 Brian Jones
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/vendor/github.com/boj/redistore/README.md b/vendor/github.com/boj/redistore/README.md
deleted file mode 100644
index 117c935..0000000
--- a/vendor/github.com/boj/redistore/README.md
+++ /dev/null
@@ -1,53 +0,0 @@
-# redistore
-
-[![GoDoc](https://godoc.org/github.com/boj/redistore?status.svg)](https://godoc.org/github.com/boj/redistore)
-[![Build Status](https://travis-ci.org/boj/redistore.svg?branch=master)](https://travis-ci.org/boj/redistore)
-
-A session store backend for [gorilla/sessions](http://www.gorillatoolkit.org/pkg/sessions) - [src](https://github.com/gorilla/sessions).
-
-## Requirements
-
-Depends on the [Redigo](https://github.com/gomodule/redigo) Redis library.
-
-## Installation
-
- go get gopkg.in/boj/redistore.v1
-
-## Documentation
-
-Available on [godoc.org](http://www.godoc.org/gopkg.in/boj/redistore.v1).
-
-See http://www.gorillatoolkit.org/pkg/sessions for full documentation on underlying interface.
-
-### Example
-``` go
-// Fetch new store.
-store, err := NewRediStore(10, "tcp", ":6379", "", []byte("secret-key"))
-if err != nil {
- panic(err)
-}
-defer store.Close()
-
-// Get a session.
-session, err = store.Get(req, "session-key")
-if err != nil {
- log.Error(err.Error())
-}
-
-// Add a value.
-session.Values["foo"] = "bar"
-
-// Save.
-if err = sessions.Save(req, rsp); err != nil {
- t.Fatalf("Error saving session: %v", err)
-}
-
-// Delete session.
-session.Options.MaxAge = -1
-if err = sessions.Save(req, rsp); err != nil {
- t.Fatalf("Error saving session: %v", err)
-}
-
-// Change session storage configuration for MaxAge = 10 days.
-store.SetMaxAge(10 * 24 * 3600)
-```
diff --git a/vendor/github.com/boj/redistore/doc.go b/vendor/github.com/boj/redistore/doc.go
deleted file mode 100644
index 43fb829..0000000
--- a/vendor/github.com/boj/redistore/doc.go
+++ /dev/null
@@ -1,4 +0,0 @@
-/*
-Package redistore is a session store backend for gorilla/sessions
-*/
-package redistore
diff --git a/vendor/github.com/boj/redistore/go.mod b/vendor/github.com/boj/redistore/go.mod
deleted file mode 100644
index 15eac8c..0000000
--- a/vendor/github.com/boj/redistore/go.mod
+++ /dev/null
@@ -1,7 +0,0 @@
-module github.com/boj/redistore
-
-require (
- github.com/gomodule/redigo v2.0.0+incompatible
- github.com/gorilla/securecookie v1.1.1
- github.com/gorilla/sessions v1.1.1
-)
diff --git a/vendor/github.com/boj/redistore/redistore.go b/vendor/github.com/boj/redistore/redistore.go
deleted file mode 100644
index 170d446..0000000
--- a/vendor/github.com/boj/redistore/redistore.go
+++ /dev/null
@@ -1,361 +0,0 @@
-// Copyright 2012 Brian "bojo" Jones. All rights reserved.
-// Use of this source code is governed by a MIT-style
-// license that can be found in the LICENSE file.
-
-package redistore
-
-import (
- "bytes"
- "encoding/base32"
- "encoding/gob"
- "encoding/json"
- "errors"
- "fmt"
- "net/http"
- "strings"
- "time"
-
- "github.com/gomodule/redigo/redis"
- "github.com/gorilla/securecookie"
- "github.com/gorilla/sessions"
-)
-
-// Amount of time for cookies/redis keys to expire.
-var sessionExpire = 86400 * 30
-
-// SessionSerializer provides an interface hook for alternative serializers
-type SessionSerializer interface {
- Deserialize(d []byte, ss *sessions.Session) error
- Serialize(ss *sessions.Session) ([]byte, error)
-}
-
-// JSONSerializer encode the session map to JSON.
-type JSONSerializer struct{}
-
-// Serialize to JSON. Will err if there are unmarshalable key values
-func (s JSONSerializer) Serialize(ss *sessions.Session) ([]byte, error) {
- m := make(map[string]interface{}, len(ss.Values))
- for k, v := range ss.Values {
- ks, ok := k.(string)
- if !ok {
- err := fmt.Errorf("Non-string key value, cannot serialize session to JSON: %v", k)
- fmt.Printf("redistore.JSONSerializer.serialize() Error: %v", err)
- return nil, err
- }
- m[ks] = v
- }
- return json.Marshal(m)
-}
-
-// Deserialize back to map[string]interface{}
-func (s JSONSerializer) Deserialize(d []byte, ss *sessions.Session) error {
- m := make(map[string]interface{})
- err := json.Unmarshal(d, &m)
- if err != nil {
- fmt.Printf("redistore.JSONSerializer.deserialize() Error: %v", err)
- return err
- }
- for k, v := range m {
- ss.Values[k] = v
- }
- return nil
-}
-
-// GobSerializer uses gob package to encode the session map
-type GobSerializer struct{}
-
-// Serialize using gob
-func (s GobSerializer) Serialize(ss *sessions.Session) ([]byte, error) {
- buf := new(bytes.Buffer)
- enc := gob.NewEncoder(buf)
- err := enc.Encode(ss.Values)
- if err == nil {
- return buf.Bytes(), nil
- }
- return nil, err
-}
-
-// Deserialize back to map[interface{}]interface{}
-func (s GobSerializer) Deserialize(d []byte, ss *sessions.Session) error {
- dec := gob.NewDecoder(bytes.NewBuffer(d))
- return dec.Decode(&ss.Values)
-}
-
-// RediStore stores sessions in a redis backend.
-type RediStore struct {
- Pool *redis.Pool
- Codecs []securecookie.Codec
- Options *sessions.Options // default configuration
- DefaultMaxAge int // default Redis TTL for a MaxAge == 0 session
- maxLength int
- keyPrefix string
- serializer SessionSerializer
-}
-
-// SetMaxLength sets RediStore.maxLength if the `l` argument is greater or equal 0
-// maxLength restricts the maximum length of new sessions to l.
-// If l is 0 there is no limit to the size of a session, use with caution.
-// The default for a new RediStore is 4096. Redis allows for max.
-// value sizes of up to 512MB (http://redis.io/topics/data-types)
-// Default: 4096,
-func (s *RediStore) SetMaxLength(l int) {
- if l >= 0 {
- s.maxLength = l
- }
-}
-
-// SetKeyPrefix set the prefix
-func (s *RediStore) SetKeyPrefix(p string) {
- s.keyPrefix = p
-}
-
-// SetSerializer sets the serializer
-func (s *RediStore) SetSerializer(ss SessionSerializer) {
- s.serializer = ss
-}
-
-// SetMaxAge restricts the maximum age, in seconds, of the session record
-// both in database and a browser. This is to change session storage configuration.
-// If you want just to remove session use your session `s` object and change it's
-// `Options.MaxAge` to -1, as specified in
-// http://godoc.org/github.com/gorilla/sessions#Options
-//
-// Default is the one provided by this package value - `sessionExpire`.
-// Set it to 0 for no restriction.
-// Because we use `MaxAge` also in SecureCookie crypting algorithm you should
-// use this function to change `MaxAge` value.
-func (s *RediStore) SetMaxAge(v int) {
- var c *securecookie.SecureCookie
- var ok bool
- s.Options.MaxAge = v
- for i := range s.Codecs {
- if c, ok = s.Codecs[i].(*securecookie.SecureCookie); ok {
- c.MaxAge(v)
- } else {
- fmt.Printf("Can't change MaxAge on codec %v\n", s.Codecs[i])
- }
- }
-}
-
-func dial(network, address, password string) (redis.Conn, error) {
- c, err := redis.Dial(network, address)
- if err != nil {
- return nil, err
- }
- if password != "" {
- if _, err := c.Do("AUTH", password); err != nil {
- c.Close()
- return nil, err
- }
- }
- return c, err
-}
-
-// NewRediStore returns a new RediStore.
-// size: maximum number of idle connections.
-func NewRediStore(size int, network, address, password string, keyPairs ...[]byte) (*RediStore, error) {
- return NewRediStoreWithPool(&redis.Pool{
- MaxIdle: size,
- IdleTimeout: 240 * time.Second,
- TestOnBorrow: func(c redis.Conn, t time.Time) error {
- _, err := c.Do("PING")
- return err
- },
- Dial: func() (redis.Conn, error) {
- return dial(network, address, password)
- },
- }, keyPairs...)
-}
-
-func dialWithDB(network, address, password, DB string) (redis.Conn, error) {
- c, err := dial(network, address, password)
- if err != nil {
- return nil, err
- }
- if _, err := c.Do("SELECT", DB); err != nil {
- c.Close()
- return nil, err
- }
- return c, err
-}
-
-// NewRediStoreWithDB - like NewRedisStore but accepts `DB` parameter to select
-// redis DB instead of using the default one ("0")
-func NewRediStoreWithDB(size int, network, address, password, DB string, keyPairs ...[]byte) (*RediStore, error) {
- return NewRediStoreWithPool(&redis.Pool{
- MaxIdle: size,
- IdleTimeout: 240 * time.Second,
- TestOnBorrow: func(c redis.Conn, t time.Time) error {
- _, err := c.Do("PING")
- return err
- },
- Dial: func() (redis.Conn, error) {
- return dialWithDB(network, address, password, DB)
- },
- }, keyPairs...)
-}
-
-// NewRediStoreWithPool instantiates a RediStore with a *redis.Pool passed in.
-func NewRediStoreWithPool(pool *redis.Pool, keyPairs ...[]byte) (*RediStore, error) {
- rs := &RediStore{
- // http://godoc.org/github.com/gomodule/redigo/redis#Pool
- Pool: pool,
- Codecs: securecookie.CodecsFromPairs(keyPairs...),
- Options: &sessions.Options{
- Path: "/",
- MaxAge: sessionExpire,
- },
- DefaultMaxAge: 60 * 20, // 20 minutes seems like a reasonable default
- maxLength: 4096,
- keyPrefix: "session_",
- serializer: GobSerializer{},
- }
- _, err := rs.ping()
- return rs, err
-}
-
-// Close closes the underlying *redis.Pool
-func (s *RediStore) Close() error {
- return s.Pool.Close()
-}
-
-// Get returns a session for the given name after adding it to the registry.
-//
-// See gorilla/sessions FilesystemStore.Get().
-func (s *RediStore) Get(r *http.Request, name string) (*sessions.Session, error) {
- return sessions.GetRegistry(r).Get(s, name)
-}
-
-// New returns a session for the given name without adding it to the registry.
-//
-// See gorilla/sessions FilesystemStore.New().
-func (s *RediStore) New(r *http.Request, name string) (*sessions.Session, error) {
- var (
- err error
- ok bool
- )
- session := sessions.NewSession(s, name)
- // make a copy
- options := *s.Options
- session.Options = &options
- session.IsNew = true
- if c, errCookie := r.Cookie(name); errCookie == nil {
- err = securecookie.DecodeMulti(name, c.Value, &session.ID, s.Codecs...)
- if err == nil {
- ok, err = s.load(session)
- session.IsNew = !(err == nil && ok) // not new if no error and data available
- }
- }
- return session, err
-}
-
-// Save adds a single session to the response.
-func (s *RediStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error {
- // Marked for deletion.
- if session.Options.MaxAge <= 0 {
- if err := s.delete(session); err != nil {
- return err
- }
- http.SetCookie(w, sessions.NewCookie(session.Name(), "", session.Options))
- } else {
- // Build an alphanumeric key for the redis store.
- if session.ID == "" {
- session.ID = strings.TrimRight(base32.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(32)), "=")
- }
- if err := s.save(session); err != nil {
- return err
- }
- encoded, err := securecookie.EncodeMulti(session.Name(), session.ID, s.Codecs...)
- if err != nil {
- return err
- }
- http.SetCookie(w, sessions.NewCookie(session.Name(), encoded, session.Options))
- }
- return nil
-}
-
-// Delete removes the session from redis, and sets the cookie to expire.
-//
-// WARNING: This method should be considered deprecated since it is not exposed via the gorilla/sessions interface.
-// Set session.Options.MaxAge = -1 and call Save instead. - July 18th, 2013
-func (s *RediStore) Delete(r *http.Request, w http.ResponseWriter, session *sessions.Session) error {
- conn := s.Pool.Get()
- defer conn.Close()
- if _, err := conn.Do("DEL", s.keyPrefix+session.ID); err != nil {
- return err
- }
- // Set cookie to expire.
- options := *session.Options
- options.MaxAge = -1
- http.SetCookie(w, sessions.NewCookie(session.Name(), "", &options))
- // Clear session values.
- for k := range session.Values {
- delete(session.Values, k)
- }
- return nil
-}
-
-// ping does an internal ping against a server to check if it is alive.
-func (s *RediStore) ping() (bool, error) {
- conn := s.Pool.Get()
- defer conn.Close()
- data, err := conn.Do("PING")
- if err != nil || data == nil {
- return false, err
- }
- return (data == "PONG"), nil
-}
-
-// save stores the session in redis.
-func (s *RediStore) save(session *sessions.Session) error {
- b, err := s.serializer.Serialize(session)
- if err != nil {
- return err
- }
- if s.maxLength != 0 && len(b) > s.maxLength {
- return errors.New("SessionStore: the value to store is too big")
- }
- conn := s.Pool.Get()
- defer conn.Close()
- if err = conn.Err(); err != nil {
- return err
- }
- age := session.Options.MaxAge
- if age == 0 {
- age = s.DefaultMaxAge
- }
- _, err = conn.Do("SETEX", s.keyPrefix+session.ID, age, b)
- return err
-}
-
-// load reads the session from redis.
-// returns true if there is a sessoin data in DB
-func (s *RediStore) load(session *sessions.Session) (bool, error) {
- conn := s.Pool.Get()
- defer conn.Close()
- if err := conn.Err(); err != nil {
- return false, err
- }
- data, err := conn.Do("GET", s.keyPrefix+session.ID)
- if err != nil {
- return false, err
- }
- if data == nil {
- return false, nil // no data was associated with this key
- }
- b, err := redis.Bytes(data, err)
- if err != nil {
- return false, err
- }
- return true, s.serializer.Deserialize(b, session)
-}
-
-// delete removes keys from redis if MaxAge<0
-func (s *RediStore) delete(session *sessions.Session) error {
- conn := s.Pool.Get()
- defer conn.Close()
- if _, err := conn.Do("DEL", s.keyPrefix+session.ID); err != nil {
- return err
- }
- return nil
-}
diff --git a/vendor/github.com/gin-contrib/cors/.gitignore b/vendor/github.com/gin-contrib/cors/.gitignore
deleted file mode 100644
index b4ecae3..0000000
--- a/vendor/github.com/gin-contrib/cors/.gitignore
+++ /dev/null
@@ -1,23 +0,0 @@
-*.o
-*.a
-*.so
-
-_obj
-_test
-
-*.[568vq]
-[568vq].out
-
-*.cgo1.go
-*.cgo2.c
-_cgo_defun.c
-_cgo_gotypes.go
-_cgo_export.*
-
-_testmain.go
-
-*.exe
-*.test
-*.prof
-
-coverage.out
diff --git a/vendor/github.com/gin-contrib/cors/.travis.yml b/vendor/github.com/gin-contrib/cors/.travis.yml
deleted file mode 100644
index 7c176e3..0000000
--- a/vendor/github.com/gin-contrib/cors/.travis.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-language: go
-sudo: false
-
-go:
- - 1.6.x
- - 1.7.x
- - 1.8.x
- - 1.9.x
- - 1.10.x
- - 1.11.x
- - tip
-
-script:
- - go test -v -covermode=atomic -coverprofile=coverage.out
-
-after_success:
- - bash <(curl -s https://codecov.io/bash)
-
-notifications:
- webhooks:
- urls:
- - https://webhooks.gitter.im/e/acc2c57482e94b44f557
- on_success: change
- on_failure: always
- on_start: false
diff --git a/vendor/github.com/gin-contrib/cors/LICENSE b/vendor/github.com/gin-contrib/cors/LICENSE
deleted file mode 100644
index 4e2cfb0..0000000
--- a/vendor/github.com/gin-contrib/cors/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2016 Gin-Gonic
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/vendor/github.com/gin-contrib/cors/README.md b/vendor/github.com/gin-contrib/cors/README.md
deleted file mode 100644
index bd567b1..0000000
--- a/vendor/github.com/gin-contrib/cors/README.md
+++ /dev/null
@@ -1,91 +0,0 @@
-# CORS gin's middleware
-
-[![Build Status](https://travis-ci.org/gin-contrib/cors.svg)](https://travis-ci.org/gin-contrib/cors)
-[![codecov](https://codecov.io/gh/gin-contrib/cors/branch/master/graph/badge.svg)](https://codecov.io/gh/gin-contrib/cors)
-[![Go Report Card](https://goreportcard.com/badge/github.com/gin-contrib/cors)](https://goreportcard.com/report/github.com/gin-contrib/cors)
-[![GoDoc](https://godoc.org/github.com/gin-contrib/cors?status.svg)](https://godoc.org/github.com/gin-contrib/cors)
-[![Join the chat at https://gitter.im/gin-gonic/gin](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gin-gonic/gin)
-
-Gin middleware/handler to enable CORS support.
-
-## Usage
-
-### Start using it
-
-Download and install it:
-
-```sh
-$ go get github.com/gin-contrib/cors
-```
-
-Import it in your code:
-
-```go
-import "github.com/gin-contrib/cors"
-```
-
-### Canonical example:
-
-```go
-package main
-
-import (
- "time"
-
- "github.com/gin-contrib/cors"
- "github.com/gin-gonic/gin"
-)
-
-func main() {
- router := gin.Default()
- // CORS for https://foo.com and https://github.com origins, allowing:
- // - PUT and PATCH methods
- // - Origin header
- // - Credentials share
- // - Preflight requests cached for 12 hours
- router.Use(cors.New(cors.Config{
- AllowOrigins: []string{"https://foo.com"},
- AllowMethods: []string{"PUT", "PATCH"},
- AllowHeaders: []string{"Origin"},
- ExposeHeaders: []string{"Content-Length"},
- AllowCredentials: true,
- AllowOriginFunc: func(origin string) bool {
- return origin == "https://github.com"
- },
- MaxAge: 12 * time.Hour,
- }))
- router.Run()
-}
-```
-
-### Using DefaultConfig as start point
-
-```go
-func main() {
- router := gin.Default()
- // - No origin allowed by default
- // - GET,POST, PUT, HEAD methods
- // - Credentials share disabled
- // - Preflight requests cached for 12 hours
- config := cors.DefaultConfig()
- config.AllowOrigins = []string{"http://google.com"}
- // config.AllowOrigins == []string{"http://google.com", "http://facebook.com"}
-
- router.Use(cors.New(config))
- router.Run()
-}
-```
-
-### Default() allows all origins
-
-```go
-func main() {
- router := gin.Default()
- // same as
- // config := cors.DefaultConfig()
- // config.AllowAllOrigins = true
- // router.Use(cors.New(config))
- router.Use(cors.Default())
- router.Run()
-}
-```
diff --git a/vendor/github.com/gin-contrib/cors/config.go b/vendor/github.com/gin-contrib/cors/config.go
deleted file mode 100644
index 72f85b2..0000000
--- a/vendor/github.com/gin-contrib/cors/config.go
+++ /dev/null
@@ -1,134 +0,0 @@
-package cors
-
-import (
- "net/http"
- "strings"
-
- "github.com/gin-gonic/gin"
-)
-
-type cors struct {
- allowAllOrigins bool
- allowCredentials bool
- allowOriginFunc func(string) bool
- allowOrigins []string
- exposeHeaders []string
- normalHeaders http.Header
- preflightHeaders http.Header
- wildcardOrigins [][]string
-}
-
-var (
- DefaultSchemas = []string{
- "http://",
- "https://",
- }
- ExtensionSchemas = []string{
- "chrome-extension://",
- "safari-extension://",
- "moz-extension://",
- "ms-browser-extension://",
- }
- FileSchemas = []string{
- "file://",
- }
- WebSocketSchemas = []string{
- "ws://",
- "wss://",
- }
-)
-
-func newCors(config Config) *cors {
- if err := config.Validate(); err != nil {
- panic(err.Error())
- }
-
- return &cors{
- allowOriginFunc: config.AllowOriginFunc,
- allowAllOrigins: config.AllowAllOrigins,
- allowCredentials: config.AllowCredentials,
- allowOrigins: normalize(config.AllowOrigins),
- normalHeaders: generateNormalHeaders(config),
- preflightHeaders: generatePreflightHeaders(config),
- wildcardOrigins: config.parseWildcardRules(),
- }
-}
-
-func (cors *cors) applyCors(c *gin.Context) {
- origin := c.Request.Header.Get("Origin")
- if len(origin) == 0 {
- // request is not a CORS request
- return
- }
- host := c.Request.Header.Get("Host")
-
- if origin == "http://"+host || origin == "https://"+host {
- // request is not a CORS request but have origin header.
- // for example, use fetch api
- return
- }
-
- if !cors.validateOrigin(origin) {
- c.AbortWithStatus(http.StatusForbidden)
- return
- }
-
- if c.Request.Method == "OPTIONS" {
- cors.handlePreflight(c)
- defer c.AbortWithStatus(http.StatusNoContent) // Using 204 is better than 200 when the request status is OPTIONS
- } else {
- cors.handleNormal(c)
- }
-
- if !cors.allowAllOrigins {
- c.Header("Access-Control-Allow-Origin", origin)
- }
-}
-
-func (cors *cors) validateWildcardOrigin(origin string) bool {
- for _, w := range cors.wildcardOrigins {
- if w[0] == "*" && strings.HasSuffix(origin, w[1]) {
- return true
- }
- if w[1] == "*" && strings.HasPrefix(origin, w[0]) {
- return true
- }
- if strings.HasPrefix(origin, w[0]) && strings.HasSuffix(origin, w[1]) {
- return true
- }
- }
-
- return false
-}
-
-func (cors *cors) validateOrigin(origin string) bool {
- if cors.allowAllOrigins {
- return true
- }
- for _, value := range cors.allowOrigins {
- if value == origin {
- return true
- }
- }
- if len(cors.wildcardOrigins) > 0 && cors.validateWildcardOrigin(origin) {
- return true
- }
- if cors.allowOriginFunc != nil {
- return cors.allowOriginFunc(origin)
- }
- return false
-}
-
-func (cors *cors) handlePreflight(c *gin.Context) {
- header := c.Writer.Header()
- for key, value := range cors.preflightHeaders {
- header[key] = value
- }
-}
-
-func (cors *cors) handleNormal(c *gin.Context) {
- header := c.Writer.Header()
- for key, value := range cors.normalHeaders {
- header[key] = value
- }
-}
diff --git a/vendor/github.com/gin-contrib/cors/cors.go b/vendor/github.com/gin-contrib/cors/cors.go
deleted file mode 100644
index 6900e7e..0000000
--- a/vendor/github.com/gin-contrib/cors/cors.go
+++ /dev/null
@@ -1,168 +0,0 @@
-package cors
-
-import (
- "errors"
- "strings"
- "time"
-
- "github.com/gin-gonic/gin"
-)
-
-// Config represents all available options for the middleware.
-type Config struct {
- AllowAllOrigins bool
-
- // AllowedOrigins is a list of origins a cross-domain request can be executed from.
- // If the special "*" value is present in the list, all origins will be allowed.
- // Default value is []
- AllowOrigins []string
-
- // AllowOriginFunc is a custom function to validate the origin. It take the origin
- // as argument and returns true if allowed or false otherwise. If this option is
- // set, the content of AllowedOrigins is ignored.
- AllowOriginFunc func(origin string) bool
-
- // AllowedMethods is a list of methods the client is allowed to use with
- // cross-domain requests. Default value is simple methods (GET and POST)
- AllowMethods []string
-
- // AllowedHeaders is list of non simple headers the client is allowed to use with
- // cross-domain requests.
- AllowHeaders []string
-
- // AllowCredentials indicates whether the request can include user credentials like
- // cookies, HTTP authentication or client side SSL certificates.
- AllowCredentials bool
-
- // ExposedHeaders indicates which headers are safe to expose to the API of a CORS
- // API specification
- ExposeHeaders []string
-
- // MaxAge indicates how long (in seconds) the results of a preflight request
- // can be cached
- MaxAge time.Duration
-
- // Allows to add origins like http://some-domain/*, https://api.* or http://some.*.subdomain.com
- AllowWildcard bool
-
- // Allows usage of popular browser extensions schemas
- AllowBrowserExtensions bool
-
- // Allows usage of WebSocket protocol
- AllowWebSockets bool
-
- // Allows usage of file:// schema (dangerous!) use it only when you 100% sure it's needed
- AllowFiles bool
-}
-
-// AddAllowMethods is allowed to add custom methods
-func (c *Config) AddAllowMethods(methods ...string) {
- c.AllowMethods = append(c.AllowMethods, methods...)
-}
-
-// AddAllowHeaders is allowed to add custom headers
-func (c *Config) AddAllowHeaders(headers ...string) {
- c.AllowHeaders = append(c.AllowHeaders, headers...)
-}
-
-// AddExposeHeaders is allowed to add custom expose headers
-func (c *Config) AddExposeHeaders(headers ...string) {
- c.ExposeHeaders = append(c.ExposeHeaders, headers...)
-}
-
-func (c Config) getAllowedSchemas() []string {
- allowedSchemas := DefaultSchemas
- if c.AllowBrowserExtensions {
- allowedSchemas = append(allowedSchemas, ExtensionSchemas...)
- }
- if c.AllowWebSockets {
- allowedSchemas = append(allowedSchemas, WebSocketSchemas...)
- }
- if c.AllowFiles {
- allowedSchemas = append(allowedSchemas, FileSchemas...)
- }
- return allowedSchemas
-}
-
-func (c Config) validateAllowedSchemas(origin string) bool {
- allowedSchemas := c.getAllowedSchemas()
- for _, schema := range allowedSchemas {
- if strings.HasPrefix(origin, schema) {
- return true
- }
- }
- return false
-}
-
-// Validate is check configuration of user defined.
-func (c Config) Validate() error {
- if c.AllowAllOrigins && (c.AllowOriginFunc != nil || len(c.AllowOrigins) > 0) {
- return errors.New("conflict settings: all origins are allowed. AllowOriginFunc or AllowedOrigins is not needed")
- }
- if !c.AllowAllOrigins && c.AllowOriginFunc == nil && len(c.AllowOrigins) == 0 {
- return errors.New("conflict settings: all origins disabled")
- }
- for _, origin := range c.AllowOrigins {
- if !strings.Contains(origin, "*") && !c.validateAllowedSchemas(origin) {
- return errors.New("bad origin: origins must contain '*' or include " + strings.Join(c.getAllowedSchemas(), ","))
- }
- }
- return nil
-}
-
-func (c Config) parseWildcardRules() [][]string {
- var wRules [][]string
-
- if !c.AllowWildcard {
- return wRules
- }
-
- for _, o := range c.AllowOrigins {
- if !strings.Contains(o, "*") {
- continue
- }
-
- if c := strings.Count(o, "*"); c > 1 {
- panic(errors.New("only one * is allowed").Error())
- }
-
- i := strings.Index(o, "*")
- if i == 0 {
- wRules = append(wRules, []string{"*", o[1:]})
- continue
- }
- if i == (len(o) - 1) {
- wRules = append(wRules, []string{o[:i-1], "*"})
- continue
- }
-
- wRules = append(wRules, []string{o[:i], o[i+1:]})
- }
-
- return wRules
-}
-
-// DefaultConfig returns a generic default configuration mapped to localhost.
-func DefaultConfig() Config {
- return Config{
- AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"},
- AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"},
- AllowCredentials: false,
- MaxAge: 12 * time.Hour,
- }
-}
-
-// Default returns the location middleware with default configuration.
-func Default() gin.HandlerFunc {
- config := DefaultConfig()
- config.AllowAllOrigins = true
- return New(config)
-}
-
-// New returns the location middleware with user-defined custom configuration.
-func New(config Config) gin.HandlerFunc {
- cors := newCors(config)
- return func(c *gin.Context) {
- cors.applyCors(c)
- }
-}
diff --git a/vendor/github.com/gin-contrib/cors/utils.go b/vendor/github.com/gin-contrib/cors/utils.go
deleted file mode 100644
index 460ef17..0000000
--- a/vendor/github.com/gin-contrib/cors/utils.go
+++ /dev/null
@@ -1,85 +0,0 @@
-package cors
-
-import (
- "net/http"
- "strconv"
- "strings"
- "time"
-)
-
-type converter func(string) string
-
-func generateNormalHeaders(c Config) http.Header {
- headers := make(http.Header)
- if c.AllowCredentials {
- headers.Set("Access-Control-Allow-Credentials", "true")
- }
- if len(c.ExposeHeaders) > 0 {
- exposeHeaders := convert(normalize(c.ExposeHeaders), http.CanonicalHeaderKey)
- headers.Set("Access-Control-Expose-Headers", strings.Join(exposeHeaders, ","))
- }
- if c.AllowAllOrigins {
- headers.Set("Access-Control-Allow-Origin", "*")
- } else {
- headers.Set("Vary", "Origin")
- }
- return headers
-}
-
-func generatePreflightHeaders(c Config) http.Header {
- headers := make(http.Header)
- if c.AllowCredentials {
- headers.Set("Access-Control-Allow-Credentials", "true")
- }
- if len(c.AllowMethods) > 0 {
- allowMethods := convert(normalize(c.AllowMethods), strings.ToUpper)
- value := strings.Join(allowMethods, ",")
- headers.Set("Access-Control-Allow-Methods", value)
- }
- if len(c.AllowHeaders) > 0 {
- allowHeaders := convert(normalize(c.AllowHeaders), http.CanonicalHeaderKey)
- value := strings.Join(allowHeaders, ",")
- headers.Set("Access-Control-Allow-Headers", value)
- }
- if c.MaxAge > time.Duration(0) {
- value := strconv.FormatInt(int64(c.MaxAge/time.Second), 10)
- headers.Set("Access-Control-Max-Age", value)
- }
- if c.AllowAllOrigins {
- headers.Set("Access-Control-Allow-Origin", "*")
- } else {
- // Always set Vary headers
- // see https://github.com/rs/cors/issues/10,
- // https://github.com/rs/cors/commit/dbdca4d95feaa7511a46e6f1efb3b3aa505bc43f#commitcomment-12352001
-
- headers.Add("Vary", "Origin")
- headers.Add("Vary", "Access-Control-Request-Method")
- headers.Add("Vary", "Access-Control-Request-Headers")
- }
- return headers
-}
-
-func normalize(values []string) []string {
- if values == nil {
- return nil
- }
- distinctMap := make(map[string]bool, len(values))
- normalized := make([]string, 0, len(values))
- for _, value := range values {
- value = strings.TrimSpace(value)
- value = strings.ToLower(value)
- if _, seen := distinctMap[value]; !seen {
- normalized = append(normalized, value)
- distinctMap[value] = true
- }
- }
- return normalized
-}
-
-func convert(s []string, c converter) []string {
- var out []string
- for _, i := range s {
- out = append(out, c(i))
- }
- return out
-}
diff --git a/vendor/github.com/gin-contrib/sse/.travis.yml b/vendor/github.com/gin-contrib/sse/.travis.yml
deleted file mode 100644
index a556ac0..0000000
--- a/vendor/github.com/gin-contrib/sse/.travis.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-language: go
-sudo: false
-go:
- - 1.6.4
- - 1.7.4
- - tip
-
-git:
- depth: 3
-
-script:
- - go test -v -covermode=count -coverprofile=coverage.out
-
-after_success:
- - bash <(curl -s https://codecov.io/bash)
\ No newline at end of file
diff --git a/vendor/github.com/gin-contrib/sse/LICENSE b/vendor/github.com/gin-contrib/sse/LICENSE
deleted file mode 100644
index 1ff7f37..0000000
--- a/vendor/github.com/gin-contrib/sse/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2014 Manuel Martínez-Almeida
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/vendor/github.com/gin-contrib/sse/README.md b/vendor/github.com/gin-contrib/sse/README.md
deleted file mode 100644
index c9c49cf..0000000
--- a/vendor/github.com/gin-contrib/sse/README.md
+++ /dev/null
@@ -1,58 +0,0 @@
-# Server-Sent Events
-
-[![GoDoc](https://godoc.org/github.com/gin-contrib/sse?status.svg)](https://godoc.org/github.com/gin-contrib/sse)
-[![Build Status](https://travis-ci.org/gin-contrib/sse.svg)](https://travis-ci.org/gin-contrib/sse)
-[![codecov](https://codecov.io/gh/gin-contrib/sse/branch/master/graph/badge.svg)](https://codecov.io/gh/gin-contrib/sse)
-[![Go Report Card](https://goreportcard.com/badge/github.com/gin-contrib/sse)](https://goreportcard.com/report/github.com/gin-contrib/sse)
-
-Server-sent events (SSE) is a technology where a browser receives automatic updates from a server via HTTP connection. The Server-Sent Events EventSource API is [standardized as part of HTML5[1] by the W3C](http://www.w3.org/TR/2009/WD-eventsource-20091029/).
-
-- [Read this great SSE introduction by the HTML5Rocks guys](http://www.html5rocks.com/en/tutorials/eventsource/basics/)
-- [Browser support](http://caniuse.com/#feat=eventsource)
-
-## Sample code
-
-```go
-import "github.com/gin-contrib/sse"
-
-func httpHandler(w http.ResponseWriter, req *http.Request) {
- // data can be a primitive like a string, an integer or a float
- sse.Encode(w, sse.Event{
- Event: "message",
- Data: "some data\nmore data",
- })
-
- // also a complex type, like a map, a struct or a slice
- sse.Encode(w, sse.Event{
- Id: "124",
- Event: "message",
- Data: map[string]interface{}{
- "user": "manu",
- "date": time.Now().Unix(),
- "content": "hi!",
- },
- })
-}
-```
-```
-event: message
-data: some data\\nmore data
-
-id: 124
-event: message
-data: {"content":"hi!","date":1431540810,"user":"manu"}
-
-```
-
-## Content-Type
-
-```go
-fmt.Println(sse.ContentType)
-```
-```
-text/event-stream
-```
-
-## Decoding support
-
-There is a client-side implementation of SSE coming soon.
diff --git a/vendor/github.com/gin-contrib/sse/sse-decoder.go b/vendor/github.com/gin-contrib/sse/sse-decoder.go
deleted file mode 100644
index fd49b9c..0000000
--- a/vendor/github.com/gin-contrib/sse/sse-decoder.go
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package sse
-
-import (
- "bytes"
- "io"
- "io/ioutil"
-)
-
-type decoder struct {
- events []Event
-}
-
-func Decode(r io.Reader) ([]Event, error) {
- var dec decoder
- return dec.decode(r)
-}
-
-func (d *decoder) dispatchEvent(event Event, data string) {
- dataLength := len(data)
- if dataLength > 0 {
- //If the data buffer's last character is a U+000A LINE FEED (LF) character, then remove the last character from the data buffer.
- data = data[:dataLength-1]
- dataLength--
- }
- if dataLength == 0 && event.Event == "" {
- return
- }
- if event.Event == "" {
- event.Event = "message"
- }
- event.Data = data
- d.events = append(d.events, event)
-}
-
-func (d *decoder) decode(r io.Reader) ([]Event, error) {
- buf, err := ioutil.ReadAll(r)
- if err != nil {
- return nil, err
- }
-
- var currentEvent Event
- var dataBuffer *bytes.Buffer = new(bytes.Buffer)
- // TODO (and unit tests)
- // Lines must be separated by either a U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pair,
- // a single U+000A LINE FEED (LF) character,
- // or a single U+000D CARRIAGE RETURN (CR) character.
- lines := bytes.Split(buf, []byte{'\n'})
- for _, line := range lines {
- if len(line) == 0 {
- // If the line is empty (a blank line). Dispatch the event.
- d.dispatchEvent(currentEvent, dataBuffer.String())
-
- // reset current event and data buffer
- currentEvent = Event{}
- dataBuffer.Reset()
- continue
- }
- if line[0] == byte(':') {
- // If the line starts with a U+003A COLON character (:), ignore the line.
- continue
- }
-
- var field, value []byte
- colonIndex := bytes.IndexRune(line, ':')
- if colonIndex != -1 {
- // If the line contains a U+003A COLON character character (:)
- // Collect the characters on the line before the first U+003A COLON character (:),
- // and let field be that string.
- field = line[:colonIndex]
- // Collect the characters on the line after the first U+003A COLON character (:),
- // and let value be that string.
- value = line[colonIndex+1:]
- // If value starts with a single U+0020 SPACE character, remove it from value.
- if len(value) > 0 && value[0] == ' ' {
- value = value[1:]
- }
- } else {
- // Otherwise, the string is not empty but does not contain a U+003A COLON character character (:)
- // Use the whole line as the field name, and the empty string as the field value.
- field = line
- value = []byte{}
- }
- // The steps to process the field given a field name and a field value depend on the field name,
- // as given in the following list. Field names must be compared literally,
- // with no case folding performed.
- switch string(field) {
- case "event":
- // Set the event name buffer to field value.
- currentEvent.Event = string(value)
- case "id":
- // Set the event stream's last event ID to the field value.
- currentEvent.Id = string(value)
- case "retry":
- // If the field value consists of only characters in the range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9),
- // then interpret the field value as an integer in base ten, and set the event stream's reconnection time to that integer.
- // Otherwise, ignore the field.
- currentEvent.Id = string(value)
- case "data":
- // Append the field value to the data buffer,
- dataBuffer.Write(value)
- // then append a single U+000A LINE FEED (LF) character to the data buffer.
- dataBuffer.WriteString("\n")
- default:
- //Otherwise. The field is ignored.
- continue
- }
- }
- // Once the end of the file is reached, the user agent must dispatch the event one final time.
- d.dispatchEvent(currentEvent, dataBuffer.String())
-
- return d.events, nil
-}
diff --git a/vendor/github.com/gin-contrib/sse/sse-encoder.go b/vendor/github.com/gin-contrib/sse/sse-encoder.go
deleted file mode 100644
index f9c8087..0000000
--- a/vendor/github.com/gin-contrib/sse/sse-encoder.go
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package sse
-
-import (
- "encoding/json"
- "fmt"
- "io"
- "net/http"
- "reflect"
- "strconv"
- "strings"
-)
-
-// Server-Sent Events
-// W3C Working Draft 29 October 2009
-// http://www.w3.org/TR/2009/WD-eventsource-20091029/
-
-const ContentType = "text/event-stream"
-
-var contentType = []string{ContentType}
-var noCache = []string{"no-cache"}
-
-var fieldReplacer = strings.NewReplacer(
- "\n", "\\n",
- "\r", "\\r")
-
-var dataReplacer = strings.NewReplacer(
- "\n", "\ndata:",
- "\r", "\\r")
-
-type Event struct {
- Event string
- Id string
- Retry uint
- Data interface{}
-}
-
-func Encode(writer io.Writer, event Event) error {
- w := checkWriter(writer)
- writeId(w, event.Id)
- writeEvent(w, event.Event)
- writeRetry(w, event.Retry)
- return writeData(w, event.Data)
-}
-
-func writeId(w stringWriter, id string) {
- if len(id) > 0 {
- w.WriteString("id:")
- fieldReplacer.WriteString(w, id)
- w.WriteString("\n")
- }
-}
-
-func writeEvent(w stringWriter, event string) {
- if len(event) > 0 {
- w.WriteString("event:")
- fieldReplacer.WriteString(w, event)
- w.WriteString("\n")
- }
-}
-
-func writeRetry(w stringWriter, retry uint) {
- if retry > 0 {
- w.WriteString("retry:")
- w.WriteString(strconv.FormatUint(uint64(retry), 10))
- w.WriteString("\n")
- }
-}
-
-func writeData(w stringWriter, data interface{}) error {
- w.WriteString("data:")
- switch kindOfData(data) {
- case reflect.Struct, reflect.Slice, reflect.Map:
- err := json.NewEncoder(w).Encode(data)
- if err != nil {
- return err
- }
- w.WriteString("\n")
- default:
- dataReplacer.WriteString(w, fmt.Sprint(data))
- w.WriteString("\n\n")
- }
- return nil
-}
-
-func (r Event) Render(w http.ResponseWriter) error {
- r.WriteContentType(w)
- return Encode(w, r)
-}
-
-func (r Event) WriteContentType(w http.ResponseWriter) {
- header := w.Header()
- header["Content-Type"] = contentType
-
- if _, exist := header["Cache-Control"]; !exist {
- header["Cache-Control"] = noCache
- }
-}
-
-func kindOfData(data interface{}) reflect.Kind {
- value := reflect.ValueOf(data)
- valueType := value.Kind()
- if valueType == reflect.Ptr {
- valueType = value.Elem().Kind()
- }
- return valueType
-}
diff --git a/vendor/github.com/gin-contrib/sse/writer.go b/vendor/github.com/gin-contrib/sse/writer.go
deleted file mode 100644
index 6f9806c..0000000
--- a/vendor/github.com/gin-contrib/sse/writer.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package sse
-
-import "io"
-
-type stringWriter interface {
- io.Writer
- WriteString(string) (int, error)
-}
-
-type stringWrapper struct {
- io.Writer
-}
-
-func (w stringWrapper) WriteString(str string) (int, error) {
- return w.Writer.Write([]byte(str))
-}
-
-func checkWriter(writer io.Writer) stringWriter {
- if w, ok := writer.(stringWriter); ok {
- return w
- } else {
- return stringWrapper{writer}
- }
-}
diff --git a/vendor/github.com/gin-gonic/contrib/sessions/README.md b/vendor/github.com/gin-gonic/contrib/sessions/README.md
deleted file mode 100644
index 16966b3..0000000
--- a/vendor/github.com/gin-gonic/contrib/sessions/README.md
+++ /dev/null
@@ -1,75 +0,0 @@
-# sessions
-
-Gin middleware for session management with multi-backend support (currently cookie, Redis).
-
-## EOL-warning
-
-**This package has been abandoned on 2016-12-07. Please use [gin-contrib/sessions](https://github.com/gin-contrib/sessions) instead.**
-
-## Examples
-
-#### cookie-based
-
-```go
-package main
-
-import (
- "github.com/gin-gonic/contrib/sessions"
- "github.com/gin-gonic/gin"
-)
-
-func main() {
- r := gin.Default()
- store := sessions.NewCookieStore([]byte("secret"))
- r.Use(sessions.Sessions("mysession", store))
-
- r.GET("/incr", func(c *gin.Context) {
- session := sessions.Default(c)
- var count int
- v := session.Get("count")
- if v == nil {
- count = 0
- } else {
- count = v.(int)
- count += 1
- }
- session.Set("count", count)
- session.Save()
- c.JSON(200, gin.H{"count": count})
- })
- r.Run(":8000")
-}
-```
-
-#### Redis
-
-```go
-package main
-
-import (
- "github.com/gin-gonic/contrib/sessions"
- "github.com/gin-gonic/gin"
-)
-
-func main() {
- r := gin.Default()
- store, _ := sessions.NewRedisStore(10, "tcp", "localhost:6379", "", []byte("secret"))
- r.Use(sessions.Sessions("session", store))
-
- r.GET("/incr", func(c *gin.Context) {
- session := sessions.Default(c)
- var count int
- v := session.Get("count")
- if v == nil {
- count = 0
- } else {
- count = v.(int)
- count += 1
- }
- session.Set("count", count)
- session.Save()
- c.JSON(200, gin.H{"count": count})
- })
- r.Run(":8000")
-}
-```
diff --git a/vendor/github.com/gin-gonic/contrib/sessions/cookie.go b/vendor/github.com/gin-gonic/contrib/sessions/cookie.go
deleted file mode 100644
index c1f66a9..0000000
--- a/vendor/github.com/gin-gonic/contrib/sessions/cookie.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package sessions
-
-import (
- "github.com/gorilla/sessions"
-)
-
-type CookieStore interface {
- Store
-}
-
-// Keys are defined in pairs to allow key rotation, but the common case is to set a single
-// authentication key and optionally an encryption key.
-//
-// The first key in a pair is used for authentication and the second for encryption. The
-// encryption key can be set to nil or omitted in the last pair, but the authentication key
-// is required in all pairs.
-//
-// It is recommended to use an authentication key with 32 or 64 bytes. The encryption key,
-// if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
-func NewCookieStore(keyPairs ...[]byte) CookieStore {
- return &cookieStore{sessions.NewCookieStore(keyPairs...)}
-}
-
-type cookieStore struct {
- *sessions.CookieStore
-}
-
-func (c *cookieStore) Options(options Options) {
- c.CookieStore.Options = &sessions.Options{
- Path: options.Path,
- Domain: options.Domain,
- MaxAge: options.MaxAge,
- Secure: options.Secure,
- HttpOnly: options.HttpOnly,
- }
-}
diff --git a/vendor/github.com/gin-gonic/contrib/sessions/redis.go b/vendor/github.com/gin-gonic/contrib/sessions/redis.go
deleted file mode 100644
index 8110ec8..0000000
--- a/vendor/github.com/gin-gonic/contrib/sessions/redis.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package sessions
-
-import (
- "github.com/boj/redistore"
- "github.com/gorilla/sessions"
-)
-
-type RedisStore interface {
- Store
-}
-
-// size: maximum number of idle connections.
-// network: tcp or udp
-// address: host:port
-// password: redis-password
-// Keys are defined in pairs to allow key rotation, but the common case is to set a single
-// authentication key and optionally an encryption key.
-//
-// The first key in a pair is used for authentication and the second for encryption. The
-// encryption key can be set to nil or omitted in the last pair, but the authentication key
-// is required in all pairs.
-//
-// It is recommended to use an authentication key with 32 or 64 bytes. The encryption key,
-// if set, must be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256 modes.
-func NewRedisStore(size int, network, address, password string, keyPairs ...[]byte) (RedisStore, error) {
- store, err := redistore.NewRediStore(size, network, address, password, keyPairs...)
- if err != nil {
- return nil, err
- }
- return &redisStore{store}, nil
-}
-
-type redisStore struct {
- *redistore.RediStore
-}
-
-func (c *redisStore) Options(options Options) {
- c.RediStore.Options = &sessions.Options{
- Path: options.Path,
- Domain: options.Domain,
- MaxAge: options.MaxAge,
- Secure: options.Secure,
- HttpOnly: options.HttpOnly,
- }
-}
diff --git a/vendor/github.com/gin-gonic/contrib/sessions/sessions.go b/vendor/github.com/gin-gonic/contrib/sessions/sessions.go
deleted file mode 100644
index ca26513..0000000
--- a/vendor/github.com/gin-gonic/contrib/sessions/sessions.go
+++ /dev/null
@@ -1,147 +0,0 @@
-package sessions
-
-import (
- "log"
- "net/http"
-
- "github.com/gin-gonic/gin"
- "github.com/gorilla/context"
- "github.com/gorilla/sessions"
-)
-
-const (
- DefaultKey = "github.com/gin-gonic/contrib/sessions"
- errorFormat = "[sessions] ERROR! %s\n"
-)
-
-type Store interface {
- sessions.Store
- Options(Options)
-}
-
-// Options stores configuration for a session or session store.
-// Fields are a subset of http.Cookie fields.
-type Options struct {
- Path string
- Domain string
- // MaxAge=0 means no 'Max-Age' attribute specified.
- // MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'.
- // MaxAge>0 means Max-Age attribute present and given in seconds.
- MaxAge int
- Secure bool
- HttpOnly bool
-}
-
-// Wraps thinly gorilla-session methods.
-// Session stores the values and optional configuration for a session.
-type Session interface {
- // Get returns the session value associated to the given key.
- Get(key interface{}) interface{}
- // Set sets the session value associated to the given key.
- Set(key interface{}, val interface{})
- // Delete removes the session value associated to the given key.
- Delete(key interface{})
- // Clear deletes all values in the session.
- Clear()
- // AddFlash adds a flash message to the session.
- // A single variadic argument is accepted, and it is optional: it defines the flash key.
- // If not defined "_flash" is used by default.
- AddFlash(value interface{}, vars ...string)
- // Flashes returns a slice of flash messages from the session.
- // A single variadic argument is accepted, and it is optional: it defines the flash key.
- // If not defined "_flash" is used by default.
- Flashes(vars ...string) []interface{}
- // Options sets confuguration for a session.
- Options(Options)
- // Save saves all sessions used during the current request.
- Save() error
-}
-
-func Sessions(name string, store Store) gin.HandlerFunc {
- return func(c *gin.Context) {
- s := &session{name, c.Request, store, nil, false, c.Writer}
- c.Set(DefaultKey, s)
- defer context.Clear(c.Request)
- c.Next()
- }
-}
-
-type session struct {
- name string
- request *http.Request
- store Store
- session *sessions.Session
- written bool
- writer http.ResponseWriter
-}
-
-func (s *session) Get(key interface{}) interface{} {
- return s.Session().Values[key]
-}
-
-func (s *session) Set(key interface{}, val interface{}) {
- s.Session().Values[key] = val
- s.written = true
-}
-
-func (s *session) Delete(key interface{}) {
- delete(s.Session().Values, key)
- s.written = true
-}
-
-func (s *session) Clear() {
- for key := range s.Session().Values {
- s.Delete(key)
- }
-}
-
-func (s *session) AddFlash(value interface{}, vars ...string) {
- s.Session().AddFlash(value, vars...)
- s.written = true
-}
-
-func (s *session) Flashes(vars ...string) []interface{} {
- s.written = true
- return s.Session().Flashes(vars...)
-}
-
-func (s *session) Options(options Options) {
- s.Session().Options = &sessions.Options{
- Path: options.Path,
- Domain: options.Domain,
- MaxAge: options.MaxAge,
- Secure: options.Secure,
- HttpOnly: options.HttpOnly,
- }
-}
-
-func (s *session) Save() error {
- if s.Written() {
- e := s.Session().Save(s.request, s.writer)
- if e == nil {
- s.written = false
- }
- return e
- }
- return nil
-}
-
-func (s *session) Session() *sessions.Session {
- if s.session == nil {
- var err error
- s.session, err = s.store.Get(s.request, s.name)
- if err != nil {
- log.Printf(errorFormat, err)
- }
- }
- return s.session
-}
-
-func (s *session) Written() bool {
- return s.written
-}
-
-// shortcut to get session
-func Default(c *gin.Context) Session {
- return c.MustGet(DefaultKey).(Session)
-}
diff --git a/vendor/github.com/gin-gonic/gin/.gitignore b/vendor/github.com/gin-gonic/gin/.gitignore
deleted file mode 100644
index 14dc8f2..0000000
--- a/vendor/github.com/gin-gonic/gin/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
-vendor/*
-!vendor/vendor.json
-coverage.out
-count.out
-test
diff --git a/vendor/github.com/gin-gonic/gin/.travis.yml b/vendor/github.com/gin-gonic/gin/.travis.yml
deleted file mode 100644
index e910156..0000000
--- a/vendor/github.com/gin-gonic/gin/.travis.yml
+++ /dev/null
@@ -1,35 +0,0 @@
-language: go
-sudo: false
-go:
- - 1.6.x
- - 1.7.x
- - 1.8.x
- - 1.9.x
- - 1.10.x
- - master
-
-git:
- depth: 10
-
-install:
- - make install
-
-go_import_path: github.com/gin-gonic/gin
-
-script:
- - make vet
- - make fmt-check
- - make embedmd
- - make misspell-check
- - make test
-
-after_success:
- - bash <(curl -s https://codecov.io/bash)
-
-notifications:
- webhooks:
- urls:
- - https://webhooks.gitter.im/e/7f95bf605c4d356372f4
- on_success: change # options: [always|never|change] default: always
- on_failure: always # options: [always|never|change] default: always
- on_start: false # default: false
diff --git a/vendor/github.com/gin-gonic/gin/AUTHORS.md b/vendor/github.com/gin-gonic/gin/AUTHORS.md
deleted file mode 100644
index dda19bc..0000000
--- a/vendor/github.com/gin-gonic/gin/AUTHORS.md
+++ /dev/null
@@ -1,231 +0,0 @@
-List of all the awesome people working to make Gin the best Web Framework in Go.
-
-## gin 1.x series authors
-
-**Gin Core Team:** Bo-Yi Wu (@appleboy), 田欧 (@thinkerou), Javier Provecho (@javierprovecho)
-
-## gin 0.x series authors
-
-**Maintainers:** Manu Martinez-Almeida (@manucorporat), Javier Provecho (@javierprovecho)
-
-People and companies, who have contributed, in alphabetical order.
-
-**@858806258 (杰哥)**
-- Fix typo in example
-
-
-**@achedeuzot (Klemen Sever)**
-- Fix newline debug printing
-
-
-**@adammck (Adam Mckaig)**
-- Add MIT license
-
-
-**@AlexanderChen1989 (Alexander)**
-- Typos in README
-
-
-**@alexanderdidenko (Aleksandr Didenko)**
-- Add support multipart/form-data
-
-
-**@alexandernyquist (Alexander Nyquist)**
-- Using template.Must to fix multiple return issue
-- ★ Added support for OPTIONS verb
-- ★ Setting response headers before calling WriteHeader
-- Improved documentation for model binding
-- ★ Added Content.Redirect()
-- ★ Added tons of Unit tests
-
-
-**@austinheap (Austin Heap)**
-- Added travis CI integration
-
-
-**@andredublin (Andre Dublin)**
-- Fix typo in comment
-
-
-**@bredov (Ludwig Valda Vasquez)**
-- Fix html templating in debug mode
-
-
-**@bluele (Jun Kimura)**
-- Fixes code examples in README
-
-
-**@chad-russell**
-- ★ Support for serializing gin.H into XML
-
-
-**@dickeyxxx (Jeff Dickey)**
-- Typos in README
-- Add example about serving static files
-
-
-**@donileo (Adonis)**
-- Add NoMethod handler
-
-
-**@dutchcoders (DutchCoders)**
-- ★ Fix security bug that allows client to spoof ip
-- Fix typo. r.HTMLTemplates -> SetHTMLTemplate
-
-
-**@el3ctro- (Joshua Loper)**
-- Fix typo in example
-
-
-**@ethankan (Ethan Kan)**
-- Unsigned integers in binding
-
-
-**(Evgeny Persienko)**
-- Validate sub structures
-
-
-**@frankbille (Frank Bille)**
-- Add support for HTTP Realm Auth
-
-
-**@fmd (Fareed Dudhia)**
-- Fix typo. SetHTTPTemplate -> SetHTMLTemplate
-
-
-**@ironiridis (Christopher Harrington)**
-- Remove old reference
-
-
-**@jammie-stackhouse (Jamie Stackhouse)**
-- Add more shortcuts for router methods
-
-
-**@jasonrhansen**
-- Fix spelling and grammar errors in documentation
-
-
-**@JasonSoft (Jason Lee)**
-- Fix typo in comment
-
-
-**@joiggama (Ignacio Galindo)**
-- Add utf-8 charset header on renders
-
-
-**@julienschmidt (Julien Schmidt)**
-- gofmt the code examples
-
-
-**@kelcecil (Kel Cecil)**
-- Fix readme typo
-
-
-**@kyledinh (Kyle Dinh)**
-- Adds RunTLS()
-
-
-**@LinusU (Linus Unnebäck)**
-- Small fixes in README
-
-
-**@loongmxbt (Saint Asky)**
-- Fix typo in example
-
-
-**@lucas-clemente (Lucas Clemente)**
-- ★ work around path.Join removing trailing slashes from routes
-
-
-**@mattn (Yasuhiro Matsumoto)**
-- Improve color logger
-
-
-**@mdigger (Dmitry Sedykh)**
-- Fixes Form binding when content-type is x-www-form-urlencoded
-- No repeat call c.Writer.Status() in gin.Logger
-- Fixes Content-Type for json render
-
-
-**@mirzac (Mirza Ceric)**
-- Fix debug printing
-
-
-**@mopemope (Yutaka Matsubara)**
-- ★ Adds Godep support (Dependencies Manager)
-- Fix variadic parameter in the flexible render API
-- Fix Corrupted plain render
-- Add Pluggable View Renderer Example
-
-
-**@msemenistyi (Mykyta Semenistyi)**
-- update Readme.md. Add code to String method
-
-
-**@msoedov (Sasha Myasoedov)**
-- ★ Adds tons of unit tests.
-
-
-**@ngerakines (Nick Gerakines)**
-- ★ Improves API, c.GET() doesn't panic
-- Adds MustGet() method
-
-
-**@r8k (Rajiv Kilaparti)**
-- Fix Port usage in README.
-
-
-**@rayrod2030 (Ray Rodriguez)**
-- Fix typo in example
-
-
-**@rns**
-- Fix typo in example
-
-
-**@RobAWilkinson (Robert Wilkinson)**
-- Add example of forms and params
-
-
-**@rogierlommers (Rogier Lommers)**
-- Add updated static serve example
-
-
-**@se77en (Damon Zhao)**
-- Improve color logging
-
-
-**@silasb (Silas Baronda)**
-- Fixing quotes in README
-
-
-**@SkuliOskarsson (Skuli Oskarsson)**
-- Fixes some texts in README II
-
-
-**@slimmy (Jimmy Pettersson)**
-- Added messages for required bindings
-
-
-**@smira (Andrey Smirnov)**
-- Add support for ignored/unexported fields in binding
-
-
-**@superalsrk (SRK.Lyu)**
-- Update httprouter godeps
-
-
-**@tebeka (Miki Tebeka)**
-- Use net/http constants instead of numeric values
-
-
-**@techjanitor**
-- Update context.go reserved IPs
-
-
-**@yosssi (Keiji Yoshida)**
-- Fix link in README
-
-
-**@yuyabee**
-- Fixed README
diff --git a/vendor/github.com/gin-gonic/gin/BENCHMARKS.md b/vendor/github.com/gin-gonic/gin/BENCHMARKS.md
deleted file mode 100644
index 9a7df86..0000000
--- a/vendor/github.com/gin-gonic/gin/BENCHMARKS.md
+++ /dev/null
@@ -1,604 +0,0 @@
-
-## Benchmark System
-
-**VM HOST:** DigitalOcean
-**Machine:** 4 CPU, 8 GB RAM. Ubuntu 16.04.2 x64
-**Date:** July 19th, 2017
-**Go Version:** 1.8.3 linux/amd64
-**Source:** [Go HTTP Router Benchmark](https://github.com/julienschmidt/go-http-routing-benchmark)
-
-## Static Routes: 157
-
-```
-Gin: 30512 Bytes
-
-HttpServeMux: 17344 Bytes
-Ace: 30080 Bytes
-Bear: 30472 Bytes
-Beego: 96408 Bytes
-Bone: 37904 Bytes
-Denco: 10464 Bytes
-Echo: 73680 Bytes
-GocraftWeb: 55720 Bytes
-Goji: 27200 Bytes
-Gojiv2: 104464 Bytes
-GoJsonRest: 136472 Bytes
-GoRestful: 914904 Bytes
-GorillaMux: 675568 Bytes
-HttpRouter: 21128 Bytes
-HttpTreeMux: 73448 Bytes
-Kocha: 115072 Bytes
-LARS: 30120 Bytes
-Macaron: 37984 Bytes
-Martini: 310832 Bytes
-Pat: 20464 Bytes
-Possum: 91328 Bytes
-R2router: 23712 Bytes
-Rivet: 23880 Bytes
-Tango: 28008 Bytes
-TigerTonic: 80368 Bytes
-Traffic: 626480 Bytes
-Vulcan: 369064 Bytes
-```
-
-## GithubAPI Routes: 203
-
-```
-Gin: 52672 Bytes
-
-Ace: 48992 Bytes
-Bear: 161592 Bytes
-Beego: 147992 Bytes
-Bone: 97728 Bytes
-Denco: 36440 Bytes
-Echo: 95672 Bytes
-GocraftWeb: 95640 Bytes
-Goji: 86088 Bytes
-Gojiv2: 144392 Bytes
-GoJsonRest: 134648 Bytes
-GoRestful: 1410760 Bytes
-GorillaMux: 1509488 Bytes
-HttpRouter: 37464 Bytes
-HttpTreeMux: 78800 Bytes
-Kocha: 785408 Bytes
-LARS: 49032 Bytes
-Macaron: 132712 Bytes
-Martini: 564352 Bytes
-Pat: 21200 Bytes
-Possum: 83888 Bytes
-R2router: 47104 Bytes
-Rivet: 42840 Bytes
-Tango: 54584 Bytes
-TigerTonic: 96384 Bytes
-Traffic: 1061920 Bytes
-Vulcan: 465296 Bytes
-```
-
-## GPlusAPI Routes: 13
-
-```
-Gin: 3968 Bytes
-
-Ace: 3600 Bytes
-Bear: 7112 Bytes
-Beego: 10048 Bytes
-Bone: 6480 Bytes
-Denco: 3256 Bytes
-Echo: 9000 Bytes
-GocraftWeb: 7496 Bytes
-Goji: 2912 Bytes
-Gojiv2: 7376 Bytes
-GoJsonRest: 11544 Bytes
-GoRestful: 88776 Bytes
-GorillaMux: 71488 Bytes
-HttpRouter: 2712 Bytes
-HttpTreeMux: 7440 Bytes
-Kocha: 128880 Bytes
-LARS: 3640 Bytes
-Macaron: 8656 Bytes
-Martini: 23936 Bytes
-Pat: 1856 Bytes
-Possum: 7248 Bytes
-R2router: 3928 Bytes
-Rivet: 3064 Bytes
-Tango: 4912 Bytes
-TigerTonic: 9408 Bytes
-Traffic: 49472 Bytes
-Vulcan: 25496 Bytes
-```
-
-## ParseAPI Routes: 26
-
-```
-Gin: 6928 Bytes
-
-Ace: 6592 Bytes
-Bear: 12320 Bytes
-Beego: 18960 Bytes
-Bone: 11024 Bytes
-Denco: 4184 Bytes
-Echo: 11168 Bytes
-GocraftWeb: 12800 Bytes
-Goji: 5232 Bytes
-Gojiv2: 14464 Bytes
-GoJsonRest: 14216 Bytes
-GoRestful: 127368 Bytes
-GorillaMux: 123016 Bytes
-HttpRouter: 4976 Bytes
-HttpTreeMux: 7848 Bytes
-Kocha: 181712 Bytes
-LARS: 6632 Bytes
-Macaron: 13648 Bytes
-Martini: 45952 Bytes
-Pat: 2560 Bytes
-Possum: 9200 Bytes
-R2router: 7056 Bytes
-Rivet: 5680 Bytes
-Tango: 8664 Bytes
-TigerTonic: 9840 Bytes
-Traffic: 93480 Bytes
-Vulcan: 44504 Bytes
-```
-
-## Static Routes
-
-```
-BenchmarkGin_StaticAll 50000 34506 ns/op 0 B/op 0 allocs/op
-
-BenchmarkAce_StaticAll 30000 49657 ns/op 0 B/op 0 allocs/op
-BenchmarkHttpServeMux_StaticAll 2000 1183737 ns/op 96 B/op 8 allocs/op
-BenchmarkBeego_StaticAll 5000 412621 ns/op 57776 B/op 628 allocs/op
-BenchmarkBear_StaticAll 10000 149242 ns/op 20336 B/op 461 allocs/op
-BenchmarkBone_StaticAll 10000 118583 ns/op 0 B/op 0 allocs/op
-BenchmarkDenco_StaticAll 100000 13247 ns/op 0 B/op 0 allocs/op
-BenchmarkEcho_StaticAll 20000 79914 ns/op 5024 B/op 157 allocs/op
-BenchmarkGocraftWeb_StaticAll 10000 211823 ns/op 46440 B/op 785 allocs/op
-BenchmarkGoji_StaticAll 10000 109390 ns/op 0 B/op 0 allocs/op
-BenchmarkGojiv2_StaticAll 3000 415533 ns/op 145696 B/op 1099 allocs/op
-BenchmarkGoJsonRest_StaticAll 5000 364403 ns/op 51653 B/op 1727 allocs/op
-BenchmarkGoRestful_StaticAll 500 2578579 ns/op 314936 B/op 3144 allocs/op
-BenchmarkGorillaMux_StaticAll 500 2704856 ns/op 115648 B/op 1578 allocs/op
-BenchmarkHttpRouter_StaticAll 100000 18541 ns/op 0 B/op 0 allocs/op
-BenchmarkHttpTreeMux_StaticAll 100000 22332 ns/op 0 B/op 0 allocs/op
-BenchmarkKocha_StaticAll 50000 31176 ns/op 0 B/op 0 allocs/op
-BenchmarkLARS_StaticAll 50000 40840 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_StaticAll 5000 517656 ns/op 120576 B/op 1413 allocs/op
-BenchmarkMartini_StaticAll 300 4462289 ns/op 125442 B/op 1717 allocs/op
-BenchmarkPat_StaticAll 500 2157275 ns/op 533904 B/op 11123 allocs/op
-BenchmarkPossum_StaticAll 10000 254701 ns/op 65312 B/op 471 allocs/op
-BenchmarkR2router_StaticAll 10000 133956 ns/op 22608 B/op 628 allocs/op
-BenchmarkRivet_StaticAll 30000 46812 ns/op 0 B/op 0 allocs/op
-BenchmarkTango_StaticAll 5000 390613 ns/op 39225 B/op 1256 allocs/op
-BenchmarkTigerTonic_StaticAll 20000 88060 ns/op 7504 B/op 157 allocs/op
-BenchmarkTraffic_StaticAll 500 2910236 ns/op 729736 B/op 14287 allocs/op
-BenchmarkVulcan_StaticAll 5000 277366 ns/op 15386 B/op 471 allocs/op
-```
-
-## Micro Benchmarks
-
-```
-BenchmarkGin_Param 20000000 113 ns/op 0 B/op 0 allocs/op
-
-BenchmarkAce_Param 5000000 375 ns/op 32 B/op 1 allocs/op
-BenchmarkBear_Param 1000000 1709 ns/op 456 B/op 5 allocs/op
-BenchmarkBeego_Param 1000000 2484 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_Param 1000000 2391 ns/op 688 B/op 5 allocs/op
-BenchmarkDenco_Param 10000000 240 ns/op 32 B/op 1 allocs/op
-BenchmarkEcho_Param 5000000 366 ns/op 32 B/op 1 allocs/op
-BenchmarkGocraftWeb_Param 1000000 2343 ns/op 648 B/op 8 allocs/op
-BenchmarkGoji_Param 1000000 1197 ns/op 336 B/op 2 allocs/op
-BenchmarkGojiv2_Param 1000000 2771 ns/op 944 B/op 8 allocs/op
-BenchmarkGoJsonRest_Param 1000000 2993 ns/op 649 B/op 13 allocs/op
-BenchmarkGoRestful_Param 200000 8860 ns/op 2296 B/op 21 allocs/op
-BenchmarkGorillaMux_Param 500000 4461 ns/op 1056 B/op 11 allocs/op
-BenchmarkHttpRouter_Param 10000000 175 ns/op 32 B/op 1 allocs/op
-BenchmarkHttpTreeMux_Param 1000000 1167 ns/op 352 B/op 3 allocs/op
-BenchmarkKocha_Param 3000000 429 ns/op 56 B/op 3 allocs/op
-BenchmarkLARS_Param 10000000 134 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_Param 500000 4635 ns/op 1056 B/op 10 allocs/op
-BenchmarkMartini_Param 200000 9933 ns/op 1072 B/op 10 allocs/op
-BenchmarkPat_Param 1000000 2929 ns/op 648 B/op 12 allocs/op
-BenchmarkPossum_Param 1000000 2503 ns/op 560 B/op 6 allocs/op
-BenchmarkR2router_Param 1000000 1507 ns/op 432 B/op 5 allocs/op
-BenchmarkRivet_Param 5000000 297 ns/op 48 B/op 1 allocs/op
-BenchmarkTango_Param 1000000 1862 ns/op 248 B/op 8 allocs/op
-BenchmarkTigerTonic_Param 500000 5660 ns/op 992 B/op 17 allocs/op
-BenchmarkTraffic_Param 200000 8408 ns/op 1960 B/op 21 allocs/op
-BenchmarkVulcan_Param 2000000 963 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_Param5 2000000 740 ns/op 160 B/op 1 allocs/op
-BenchmarkBear_Param5 1000000 2777 ns/op 501 B/op 5 allocs/op
-BenchmarkBeego_Param5 1000000 3740 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_Param5 1000000 2950 ns/op 736 B/op 5 allocs/op
-BenchmarkDenco_Param5 2000000 644 ns/op 160 B/op 1 allocs/op
-BenchmarkEcho_Param5 3000000 558 ns/op 32 B/op 1 allocs/op
-BenchmarkGin_Param5 10000000 198 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_Param5 500000 3870 ns/op 920 B/op 11 allocs/op
-BenchmarkGoji_Param5 1000000 1746 ns/op 336 B/op 2 allocs/op
-BenchmarkGojiv2_Param5 1000000 3214 ns/op 1008 B/op 8 allocs/op
-BenchmarkGoJsonRest_Param5 500000 5509 ns/op 1097 B/op 16 allocs/op
-BenchmarkGoRestful_Param5 200000 11232 ns/op 2392 B/op 21 allocs/op
-BenchmarkGorillaMux_Param5 300000 7777 ns/op 1184 B/op 11 allocs/op
-BenchmarkHttpRouter_Param5 3000000 631 ns/op 160 B/op 1 allocs/op
-BenchmarkHttpTreeMux_Param5 1000000 2800 ns/op 576 B/op 6 allocs/op
-BenchmarkKocha_Param5 1000000 2053 ns/op 440 B/op 10 allocs/op
-BenchmarkLARS_Param5 10000000 232 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_Param5 500000 5888 ns/op 1056 B/op 10 allocs/op
-BenchmarkMartini_Param5 200000 12807 ns/op 1232 B/op 11 allocs/op
-BenchmarkPat_Param5 300000 7320 ns/op 964 B/op 32 allocs/op
-BenchmarkPossum_Param5 1000000 2495 ns/op 560 B/op 6 allocs/op
-BenchmarkR2router_Param5 1000000 1844 ns/op 432 B/op 5 allocs/op
-BenchmarkRivet_Param5 2000000 935 ns/op 240 B/op 1 allocs/op
-BenchmarkTango_Param5 1000000 2327 ns/op 360 B/op 8 allocs/op
-BenchmarkTigerTonic_Param5 100000 18514 ns/op 2551 B/op 43 allocs/op
-BenchmarkTraffic_Param5 200000 11997 ns/op 2248 B/op 25 allocs/op
-BenchmarkVulcan_Param5 1000000 1333 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_Param20 1000000 2031 ns/op 640 B/op 1 allocs/op
-BenchmarkBear_Param20 200000 7285 ns/op 1664 B/op 5 allocs/op
-BenchmarkBeego_Param20 300000 6224 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_Param20 200000 8023 ns/op 1903 B/op 5 allocs/op
-BenchmarkDenco_Param20 1000000 2262 ns/op 640 B/op 1 allocs/op
-BenchmarkEcho_Param20 1000000 1387 ns/op 32 B/op 1 allocs/op
-BenchmarkGin_Param20 3000000 503 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_Param20 100000 14408 ns/op 3795 B/op 15 allocs/op
-BenchmarkGoji_Param20 500000 5272 ns/op 1247 B/op 2 allocs/op
-BenchmarkGojiv2_Param20 1000000 4163 ns/op 1248 B/op 8 allocs/op
-BenchmarkGoJsonRest_Param20 100000 17866 ns/op 4485 B/op 20 allocs/op
-BenchmarkGoRestful_Param20 100000 21022 ns/op 4724 B/op 23 allocs/op
-BenchmarkGorillaMux_Param20 100000 17055 ns/op 3547 B/op 13 allocs/op
-BenchmarkHttpRouter_Param20 1000000 1748 ns/op 640 B/op 1 allocs/op
-BenchmarkHttpTreeMux_Param20 200000 12246 ns/op 3196 B/op 10 allocs/op
-BenchmarkKocha_Param20 300000 6861 ns/op 1808 B/op 27 allocs/op
-BenchmarkLARS_Param20 3000000 526 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_Param20 100000 13069 ns/op 2906 B/op 12 allocs/op
-BenchmarkMartini_Param20 100000 23602 ns/op 3597 B/op 13 allocs/op
-BenchmarkPat_Param20 50000 32143 ns/op 4688 B/op 111 allocs/op
-BenchmarkPossum_Param20 1000000 2396 ns/op 560 B/op 6 allocs/op
-BenchmarkR2router_Param20 200000 8907 ns/op 2283 B/op 7 allocs/op
-BenchmarkRivet_Param20 1000000 3280 ns/op 1024 B/op 1 allocs/op
-BenchmarkTango_Param20 500000 4640 ns/op 856 B/op 8 allocs/op
-BenchmarkTigerTonic_Param20 20000 67581 ns/op 10532 B/op 138 allocs/op
-BenchmarkTraffic_Param20 50000 40313 ns/op 7941 B/op 45 allocs/op
-BenchmarkVulcan_Param20 1000000 2264 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_ParamWrite 3000000 532 ns/op 40 B/op 2 allocs/op
-BenchmarkBear_ParamWrite 1000000 1778 ns/op 456 B/op 5 allocs/op
-BenchmarkBeego_ParamWrite 1000000 2596 ns/op 376 B/op 5 allocs/op
-BenchmarkBone_ParamWrite 1000000 2519 ns/op 688 B/op 5 allocs/op
-BenchmarkDenco_ParamWrite 5000000 411 ns/op 32 B/op 1 allocs/op
-BenchmarkEcho_ParamWrite 2000000 718 ns/op 40 B/op 2 allocs/op
-BenchmarkGin_ParamWrite 5000000 283 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_ParamWrite 1000000 2561 ns/op 656 B/op 9 allocs/op
-BenchmarkGoji_ParamWrite 1000000 1378 ns/op 336 B/op 2 allocs/op
-BenchmarkGojiv2_ParamWrite 1000000 3128 ns/op 976 B/op 10 allocs/op
-BenchmarkGoJsonRest_ParamWrite 500000 4446 ns/op 1128 B/op 18 allocs/op
-BenchmarkGoRestful_ParamWrite 200000 10291 ns/op 2304 B/op 22 allocs/op
-BenchmarkGorillaMux_ParamWrite 500000 5153 ns/op 1064 B/op 12 allocs/op
-BenchmarkHttpRouter_ParamWrite 5000000 263 ns/op 32 B/op 1 allocs/op
-BenchmarkHttpTreeMux_ParamWrite 1000000 1351 ns/op 352 B/op 3 allocs/op
-BenchmarkKocha_ParamWrite 3000000 538 ns/op 56 B/op 3 allocs/op
-BenchmarkLARS_ParamWrite 5000000 316 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_ParamWrite 500000 5756 ns/op 1160 B/op 14 allocs/op
-BenchmarkMartini_ParamWrite 200000 13097 ns/op 1176 B/op 14 allocs/op
-BenchmarkPat_ParamWrite 500000 4954 ns/op 1072 B/op 17 allocs/op
-BenchmarkPossum_ParamWrite 1000000 2499 ns/op 560 B/op 6 allocs/op
-BenchmarkR2router_ParamWrite 1000000 1531 ns/op 432 B/op 5 allocs/op
-BenchmarkRivet_ParamWrite 3000000 570 ns/op 112 B/op 2 allocs/op
-BenchmarkTango_ParamWrite 2000000 957 ns/op 136 B/op 4 allocs/op
-BenchmarkTigerTonic_ParamWrite 200000 7025 ns/op 1424 B/op 23 allocs/op
-BenchmarkTraffic_ParamWrite 200000 10112 ns/op 2384 B/op 25 allocs/op
-BenchmarkVulcan_ParamWrite 1000000 1006 ns/op 98 B/op 3 allocs/op
-```
-
-## GitHub
-
-```
-BenchmarkGin_GithubStatic 10000000 156 ns/op 0 B/op 0 allocs/op
-
-BenchmarkAce_GithubStatic 5000000 294 ns/op 0 B/op 0 allocs/op
-BenchmarkBear_GithubStatic 2000000 893 ns/op 120 B/op 3 allocs/op
-BenchmarkBeego_GithubStatic 1000000 2491 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_GithubStatic 50000 25300 ns/op 2880 B/op 60 allocs/op
-BenchmarkDenco_GithubStatic 20000000 76.0 ns/op 0 B/op 0 allocs/op
-BenchmarkEcho_GithubStatic 2000000 516 ns/op 32 B/op 1 allocs/op
-BenchmarkGocraftWeb_GithubStatic 1000000 1448 ns/op 296 B/op 5 allocs/op
-BenchmarkGoji_GithubStatic 3000000 496 ns/op 0 B/op 0 allocs/op
-BenchmarkGojiv2_GithubStatic 1000000 2941 ns/op 928 B/op 7 allocs/op
-BenchmarkGoRestful_GithubStatic 100000 27256 ns/op 3224 B/op 22 allocs/op
-BenchmarkGoJsonRest_GithubStatic 1000000 2196 ns/op 329 B/op 11 allocs/op
-BenchmarkGorillaMux_GithubStatic 50000 31617 ns/op 736 B/op 10 allocs/op
-BenchmarkHttpRouter_GithubStatic 20000000 88.4 ns/op 0 B/op 0 allocs/op
-BenchmarkHttpTreeMux_GithubStatic 10000000 134 ns/op 0 B/op 0 allocs/op
-BenchmarkKocha_GithubStatic 20000000 113 ns/op 0 B/op 0 allocs/op
-BenchmarkLARS_GithubStatic 10000000 195 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_GithubStatic 500000 3740 ns/op 768 B/op 9 allocs/op
-BenchmarkMartini_GithubStatic 50000 27673 ns/op 768 B/op 9 allocs/op
-BenchmarkPat_GithubStatic 100000 19470 ns/op 3648 B/op 76 allocs/op
-BenchmarkPossum_GithubStatic 1000000 1729 ns/op 416 B/op 3 allocs/op
-BenchmarkR2router_GithubStatic 2000000 879 ns/op 144 B/op 4 allocs/op
-BenchmarkRivet_GithubStatic 10000000 231 ns/op 0 B/op 0 allocs/op
-BenchmarkTango_GithubStatic 1000000 2325 ns/op 248 B/op 8 allocs/op
-BenchmarkTigerTonic_GithubStatic 3000000 610 ns/op 48 B/op 1 allocs/op
-BenchmarkTraffic_GithubStatic 20000 62973 ns/op 18904 B/op 148 allocs/op
-BenchmarkVulcan_GithubStatic 1000000 1447 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_GithubParam 2000000 686 ns/op 96 B/op 1 allocs/op
-BenchmarkBear_GithubParam 1000000 2155 ns/op 496 B/op 5 allocs/op
-BenchmarkBeego_GithubParam 1000000 2713 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_GithubParam 100000 15088 ns/op 1760 B/op 18 allocs/op
-BenchmarkDenco_GithubParam 2000000 629 ns/op 128 B/op 1 allocs/op
-BenchmarkEcho_GithubParam 2000000 653 ns/op 32 B/op 1 allocs/op
-BenchmarkGin_GithubParam 5000000 255 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_GithubParam 1000000 3145 ns/op 712 B/op 9 allocs/op
-BenchmarkGoji_GithubParam 1000000 1916 ns/op 336 B/op 2 allocs/op
-BenchmarkGojiv2_GithubParam 1000000 3975 ns/op 1024 B/op 10 allocs/op
-BenchmarkGoJsonRest_GithubParam 300000 4134 ns/op 713 B/op 14 allocs/op
-BenchmarkGoRestful_GithubParam 50000 30782 ns/op 2360 B/op 21 allocs/op
-BenchmarkGorillaMux_GithubParam 100000 17148 ns/op 1088 B/op 11 allocs/op
-BenchmarkHttpRouter_GithubParam 3000000 523 ns/op 96 B/op 1 allocs/op
-BenchmarkHttpTreeMux_GithubParam 1000000 1671 ns/op 384 B/op 4 allocs/op
-BenchmarkKocha_GithubParam 1000000 1021 ns/op 128 B/op 5 allocs/op
-BenchmarkLARS_GithubParam 5000000 283 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_GithubParam 500000 4270 ns/op 1056 B/op 10 allocs/op
-BenchmarkMartini_GithubParam 100000 21728 ns/op 1152 B/op 11 allocs/op
-BenchmarkPat_GithubParam 200000 11208 ns/op 2464 B/op 48 allocs/op
-BenchmarkPossum_GithubParam 1000000 2334 ns/op 560 B/op 6 allocs/op
-BenchmarkR2router_GithubParam 1000000 1487 ns/op 432 B/op 5 allocs/op
-BenchmarkRivet_GithubParam 2000000 782 ns/op 96 B/op 1 allocs/op
-BenchmarkTango_GithubParam 1000000 2653 ns/op 344 B/op 8 allocs/op
-BenchmarkTigerTonic_GithubParam 300000 14073 ns/op 1440 B/op 24 allocs/op
-BenchmarkTraffic_GithubParam 50000 29164 ns/op 5992 B/op 52 allocs/op
-BenchmarkVulcan_GithubParam 1000000 2529 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_GithubAll 10000 134059 ns/op 13792 B/op 167 allocs/op
-BenchmarkBear_GithubAll 5000 534445 ns/op 86448 B/op 943 allocs/op
-BenchmarkBeego_GithubAll 3000 592444 ns/op 74705 B/op 812 allocs/op
-BenchmarkBone_GithubAll 200 6957308 ns/op 698784 B/op 8453 allocs/op
-BenchmarkDenco_GithubAll 10000 158819 ns/op 20224 B/op 167 allocs/op
-BenchmarkEcho_GithubAll 10000 154700 ns/op 6496 B/op 203 allocs/op
-BenchmarkGin_GithubAll 30000 48375 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_GithubAll 3000 570806 ns/op 131656 B/op 1686 allocs/op
-BenchmarkGoji_GithubAll 2000 818034 ns/op 56112 B/op 334 allocs/op
-BenchmarkGojiv2_GithubAll 2000 1213973 ns/op 274768 B/op 3712 allocs/op
-BenchmarkGoJsonRest_GithubAll 2000 785796 ns/op 134371 B/op 2737 allocs/op
-BenchmarkGoRestful_GithubAll 300 5238188 ns/op 689672 B/op 4519 allocs/op
-BenchmarkGorillaMux_GithubAll 100 10257726 ns/op 211840 B/op 2272 allocs/op
-BenchmarkHttpRouter_GithubAll 20000 105414 ns/op 13792 B/op 167 allocs/op
-BenchmarkHttpTreeMux_GithubAll 10000 319934 ns/op 65856 B/op 671 allocs/op
-BenchmarkKocha_GithubAll 10000 209442 ns/op 23304 B/op 843 allocs/op
-BenchmarkLARS_GithubAll 20000 62565 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_GithubAll 2000 1161270 ns/op 204194 B/op 2000 allocs/op
-BenchmarkMartini_GithubAll 200 9991713 ns/op 226549 B/op 2325 allocs/op
-BenchmarkPat_GithubAll 200 5590793 ns/op 1499568 B/op 27435 allocs/op
-BenchmarkPossum_GithubAll 10000 319768 ns/op 84448 B/op 609 allocs/op
-BenchmarkR2router_GithubAll 10000 305134 ns/op 77328 B/op 979 allocs/op
-BenchmarkRivet_GithubAll 10000 132134 ns/op 16272 B/op 167 allocs/op
-BenchmarkTango_GithubAll 3000 552754 ns/op 63826 B/op 1618 allocs/op
-BenchmarkTigerTonic_GithubAll 1000 1439483 ns/op 239104 B/op 5374 allocs/op
-BenchmarkTraffic_GithubAll 100 11383067 ns/op 2659329 B/op 21848 allocs/op
-BenchmarkVulcan_GithubAll 5000 394253 ns/op 19894 B/op 609 allocs/op
-```
-
-## Google+
-
-```
-BenchmarkGin_GPlusStatic 10000000 183 ns/op 0 B/op 0 allocs/op
-
-BenchmarkAce_GPlusStatic 5000000 276 ns/op 0 B/op 0 allocs/op
-BenchmarkBear_GPlusStatic 2000000 652 ns/op 104 B/op 3 allocs/op
-BenchmarkBeego_GPlusStatic 1000000 2239 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_GPlusStatic 5000000 380 ns/op 32 B/op 1 allocs/op
-BenchmarkDenco_GPlusStatic 30000000 45.8 ns/op 0 B/op 0 allocs/op
-BenchmarkEcho_GPlusStatic 5000000 338 ns/op 32 B/op 1 allocs/op
-BenchmarkGocraftWeb_GPlusStatic 1000000 1158 ns/op 280 B/op 5 allocs/op
-BenchmarkGoji_GPlusStatic 5000000 331 ns/op 0 B/op 0 allocs/op
-BenchmarkGojiv2_GPlusStatic 1000000 2106 ns/op 928 B/op 7 allocs/op
-BenchmarkGoJsonRest_GPlusStatic 1000000 1626 ns/op 329 B/op 11 allocs/op
-BenchmarkGoRestful_GPlusStatic 300000 7598 ns/op 1976 B/op 20 allocs/op
-BenchmarkGorillaMux_GPlusStatic 1000000 2629 ns/op 736 B/op 10 allocs/op
-BenchmarkHttpRouter_GPlusStatic 30000000 52.5 ns/op 0 B/op 0 allocs/op
-BenchmarkHttpTreeMux_GPlusStatic 20000000 85.8 ns/op 0 B/op 0 allocs/op
-BenchmarkKocha_GPlusStatic 20000000 89.2 ns/op 0 B/op 0 allocs/op
-BenchmarkLARS_GPlusStatic 10000000 162 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_GPlusStatic 500000 3479 ns/op 768 B/op 9 allocs/op
-BenchmarkMartini_GPlusStatic 200000 9092 ns/op 768 B/op 9 allocs/op
-BenchmarkPat_GPlusStatic 3000000 493 ns/op 96 B/op 2 allocs/op
-BenchmarkPossum_GPlusStatic 1000000 1467 ns/op 416 B/op 3 allocs/op
-BenchmarkR2router_GPlusStatic 2000000 788 ns/op 144 B/op 4 allocs/op
-BenchmarkRivet_GPlusStatic 20000000 114 ns/op 0 B/op 0 allocs/op
-BenchmarkTango_GPlusStatic 1000000 1534 ns/op 200 B/op 8 allocs/op
-BenchmarkTigerTonic_GPlusStatic 5000000 282 ns/op 32 B/op 1 allocs/op
-BenchmarkTraffic_GPlusStatic 500000 3798 ns/op 1192 B/op 15 allocs/op
-BenchmarkVulcan_GPlusStatic 2000000 1125 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_GPlusParam 3000000 528 ns/op 64 B/op 1 allocs/op
-BenchmarkBear_GPlusParam 1000000 1570 ns/op 480 B/op 5 allocs/op
-BenchmarkBeego_GPlusParam 1000000 2369 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_GPlusParam 1000000 2028 ns/op 688 B/op 5 allocs/op
-BenchmarkDenco_GPlusParam 5000000 385 ns/op 64 B/op 1 allocs/op
-BenchmarkEcho_GPlusParam 3000000 441 ns/op 32 B/op 1 allocs/op
-BenchmarkGin_GPlusParam 10000000 174 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_GPlusParam 1000000 2033 ns/op 648 B/op 8 allocs/op
-BenchmarkGoji_GPlusParam 1000000 1399 ns/op 336 B/op 2 allocs/op
-BenchmarkGojiv2_GPlusParam 1000000 2641 ns/op 944 B/op 8 allocs/op
-BenchmarkGoJsonRest_GPlusParam 1000000 2824 ns/op 649 B/op 13 allocs/op
-BenchmarkGoRestful_GPlusParam 200000 8875 ns/op 2296 B/op 21 allocs/op
-BenchmarkGorillaMux_GPlusParam 200000 6291 ns/op 1056 B/op 11 allocs/op
-BenchmarkHttpRouter_GPlusParam 5000000 316 ns/op 64 B/op 1 allocs/op
-BenchmarkHttpTreeMux_GPlusParam 1000000 1129 ns/op 352 B/op 3 allocs/op
-BenchmarkKocha_GPlusParam 3000000 538 ns/op 56 B/op 3 allocs/op
-BenchmarkLARS_GPlusParam 10000000 198 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_GPlusParam 500000 3554 ns/op 1056 B/op 10 allocs/op
-BenchmarkMartini_GPlusParam 200000 9831 ns/op 1072 B/op 10 allocs/op
-BenchmarkPat_GPlusParam 1000000 2706 ns/op 688 B/op 12 allocs/op
-BenchmarkPossum_GPlusParam 1000000 2297 ns/op 560 B/op 6 allocs/op
-BenchmarkR2router_GPlusParam 1000000 1318 ns/op 432 B/op 5 allocs/op
-BenchmarkRivet_GPlusParam 5000000 399 ns/op 48 B/op 1 allocs/op
-BenchmarkTango_GPlusParam 1000000 2070 ns/op 264 B/op 8 allocs/op
-BenchmarkTigerTonic_GPlusParam 500000 4853 ns/op 1056 B/op 17 allocs/op
-BenchmarkTraffic_GPlusParam 200000 8278 ns/op 1976 B/op 21 allocs/op
-BenchmarkVulcan_GPlusParam 1000000 1243 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_GPlus2Params 3000000 549 ns/op 64 B/op 1 allocs/op
-BenchmarkBear_GPlus2Params 1000000 2112 ns/op 496 B/op 5 allocs/op
-BenchmarkBeego_GPlus2Params 500000 2750 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_GPlus2Params 300000 7032 ns/op 1040 B/op 9 allocs/op
-BenchmarkDenco_GPlus2Params 3000000 502 ns/op 64 B/op 1 allocs/op
-BenchmarkEcho_GPlus2Params 3000000 641 ns/op 32 B/op 1 allocs/op
-BenchmarkGin_GPlus2Params 5000000 250 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_GPlus2Params 1000000 2681 ns/op 712 B/op 9 allocs/op
-BenchmarkGoji_GPlus2Params 1000000 1926 ns/op 336 B/op 2 allocs/op
-BenchmarkGojiv2_GPlus2Params 500000 3996 ns/op 1024 B/op 11 allocs/op
-BenchmarkGoJsonRest_GPlus2Params 500000 3886 ns/op 713 B/op 14 allocs/op
-BenchmarkGoRestful_GPlus2Params 200000 10376 ns/op 2360 B/op 21 allocs/op
-BenchmarkGorillaMux_GPlus2Params 100000 14162 ns/op 1088 B/op 11 allocs/op
-BenchmarkHttpRouter_GPlus2Params 5000000 336 ns/op 64 B/op 1 allocs/op
-BenchmarkHttpTreeMux_GPlus2Params 1000000 1523 ns/op 384 B/op 4 allocs/op
-BenchmarkKocha_GPlus2Params 2000000 970 ns/op 128 B/op 5 allocs/op
-BenchmarkLARS_GPlus2Params 5000000 238 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_GPlus2Params 500000 4016 ns/op 1056 B/op 10 allocs/op
-BenchmarkMartini_GPlus2Params 100000 21253 ns/op 1200 B/op 13 allocs/op
-BenchmarkPat_GPlus2Params 200000 8632 ns/op 2256 B/op 34 allocs/op
-BenchmarkPossum_GPlus2Params 1000000 2171 ns/op 560 B/op 6 allocs/op
-BenchmarkR2router_GPlus2Params 1000000 1340 ns/op 432 B/op 5 allocs/op
-BenchmarkRivet_GPlus2Params 3000000 557 ns/op 96 B/op 1 allocs/op
-BenchmarkTango_GPlus2Params 1000000 2186 ns/op 344 B/op 8 allocs/op
-BenchmarkTigerTonic_GPlus2Params 200000 9060 ns/op 1488 B/op 24 allocs/op
-BenchmarkTraffic_GPlus2Params 100000 20324 ns/op 3272 B/op 31 allocs/op
-BenchmarkVulcan_GPlus2Params 1000000 2039 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_GPlusAll 300000 6603 ns/op 640 B/op 11 allocs/op
-BenchmarkBear_GPlusAll 100000 22363 ns/op 5488 B/op 61 allocs/op
-BenchmarkBeego_GPlusAll 50000 38757 ns/op 4784 B/op 52 allocs/op
-BenchmarkBone_GPlusAll 20000 54916 ns/op 10336 B/op 98 allocs/op
-BenchmarkDenco_GPlusAll 300000 4959 ns/op 672 B/op 11 allocs/op
-BenchmarkEcho_GPlusAll 200000 6558 ns/op 416 B/op 13 allocs/op
-BenchmarkGin_GPlusAll 500000 2757 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_GPlusAll 50000 34615 ns/op 8040 B/op 103 allocs/op
-BenchmarkGoji_GPlusAll 100000 16002 ns/op 3696 B/op 22 allocs/op
-BenchmarkGojiv2_GPlusAll 50000 35060 ns/op 12624 B/op 115 allocs/op
-BenchmarkGoJsonRest_GPlusAll 50000 41479 ns/op 8117 B/op 170 allocs/op
-BenchmarkGoRestful_GPlusAll 10000 131653 ns/op 32024 B/op 275 allocs/op
-BenchmarkGorillaMux_GPlusAll 10000 101380 ns/op 13296 B/op 142 allocs/op
-BenchmarkHttpRouter_GPlusAll 500000 3711 ns/op 640 B/op 11 allocs/op
-BenchmarkHttpTreeMux_GPlusAll 100000 14438 ns/op 4032 B/op 38 allocs/op
-BenchmarkKocha_GPlusAll 200000 8039 ns/op 976 B/op 43 allocs/op
-BenchmarkLARS_GPlusAll 500000 2630 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_GPlusAll 30000 51123 ns/op 13152 B/op 128 allocs/op
-BenchmarkMartini_GPlusAll 10000 176157 ns/op 14016 B/op 145 allocs/op
-BenchmarkPat_GPlusAll 20000 69911 ns/op 16576 B/op 298 allocs/op
-BenchmarkPossum_GPlusAll 100000 20716 ns/op 5408 B/op 39 allocs/op
-BenchmarkR2router_GPlusAll 100000 17463 ns/op 5040 B/op 63 allocs/op
-BenchmarkRivet_GPlusAll 300000 5142 ns/op 768 B/op 11 allocs/op
-BenchmarkTango_GPlusAll 50000 27321 ns/op 3656 B/op 104 allocs/op
-BenchmarkTigerTonic_GPlusAll 20000 77597 ns/op 14512 B/op 288 allocs/op
-BenchmarkTraffic_GPlusAll 10000 151406 ns/op 37360 B/op 392 allocs/op
-BenchmarkVulcan_GPlusAll 100000 18555 ns/op 1274 B/op 39 allocs/op
-```
-
-## Parse.com
-
-```
-BenchmarkGin_ParseStatic 10000000 133 ns/op 0 B/op 0 allocs/op
-
-BenchmarkAce_ParseStatic 5000000 241 ns/op 0 B/op 0 allocs/op
-BenchmarkBear_ParseStatic 2000000 728 ns/op 120 B/op 3 allocs/op
-BenchmarkBeego_ParseStatic 1000000 2623 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_ParseStatic 1000000 1285 ns/op 144 B/op 3 allocs/op
-BenchmarkDenco_ParseStatic 30000000 57.8 ns/op 0 B/op 0 allocs/op
-BenchmarkEcho_ParseStatic 5000000 342 ns/op 32 B/op 1 allocs/op
-BenchmarkGocraftWeb_ParseStatic 1000000 1478 ns/op 296 B/op 5 allocs/op
-BenchmarkGoji_ParseStatic 3000000 415 ns/op 0 B/op 0 allocs/op
-BenchmarkGojiv2_ParseStatic 1000000 2087 ns/op 928 B/op 7 allocs/op
-BenchmarkGoJsonRest_ParseStatic 1000000 1712 ns/op 329 B/op 11 allocs/op
-BenchmarkGoRestful_ParseStatic 200000 11072 ns/op 3224 B/op 22 allocs/op
-BenchmarkGorillaMux_ParseStatic 500000 4129 ns/op 752 B/op 11 allocs/op
-BenchmarkHttpRouter_ParseStatic 30000000 52.4 ns/op 0 B/op 0 allocs/op
-BenchmarkHttpTreeMux_ParseStatic 20000000 109 ns/op 0 B/op 0 allocs/op
-BenchmarkKocha_ParseStatic 20000000 81.8 ns/op 0 B/op 0 allocs/op
-BenchmarkLARS_ParseStatic 10000000 150 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_ParseStatic 1000000 3288 ns/op 768 B/op 9 allocs/op
-BenchmarkMartini_ParseStatic 200000 9110 ns/op 768 B/op 9 allocs/op
-BenchmarkPat_ParseStatic 1000000 1135 ns/op 240 B/op 5 allocs/op
-BenchmarkPossum_ParseStatic 1000000 1557 ns/op 416 B/op 3 allocs/op
-BenchmarkR2router_ParseStatic 2000000 730 ns/op 144 B/op 4 allocs/op
-BenchmarkRivet_ParseStatic 10000000 121 ns/op 0 B/op 0 allocs/op
-BenchmarkTango_ParseStatic 1000000 1688 ns/op 248 B/op 8 allocs/op
-BenchmarkTigerTonic_ParseStatic 3000000 427 ns/op 48 B/op 1 allocs/op
-BenchmarkTraffic_ParseStatic 500000 5962 ns/op 1816 B/op 20 allocs/op
-BenchmarkVulcan_ParseStatic 2000000 969 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_ParseParam 3000000 497 ns/op 64 B/op 1 allocs/op
-BenchmarkBear_ParseParam 1000000 1473 ns/op 467 B/op 5 allocs/op
-BenchmarkBeego_ParseParam 1000000 2384 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_ParseParam 1000000 2513 ns/op 768 B/op 6 allocs/op
-BenchmarkDenco_ParseParam 5000000 364 ns/op 64 B/op 1 allocs/op
-BenchmarkEcho_ParseParam 5000000 418 ns/op 32 B/op 1 allocs/op
-BenchmarkGin_ParseParam 10000000 163 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_ParseParam 1000000 2361 ns/op 664 B/op 8 allocs/op
-BenchmarkGoji_ParseParam 1000000 1590 ns/op 336 B/op 2 allocs/op
-BenchmarkGojiv2_ParseParam 1000000 2851 ns/op 976 B/op 9 allocs/op
-BenchmarkGoJsonRest_ParseParam 1000000 2965 ns/op 649 B/op 13 allocs/op
-BenchmarkGoRestful_ParseParam 200000 12207 ns/op 3544 B/op 23 allocs/op
-BenchmarkGorillaMux_ParseParam 500000 5187 ns/op 1088 B/op 12 allocs/op
-BenchmarkHttpRouter_ParseParam 5000000 275 ns/op 64 B/op 1 allocs/op
-BenchmarkHttpTreeMux_ParseParam 1000000 1108 ns/op 352 B/op 3 allocs/op
-BenchmarkKocha_ParseParam 3000000 495 ns/op 56 B/op 3 allocs/op
-BenchmarkLARS_ParseParam 10000000 192 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_ParseParam 500000 4103 ns/op 1056 B/op 10 allocs/op
-BenchmarkMartini_ParseParam 200000 9878 ns/op 1072 B/op 10 allocs/op
-BenchmarkPat_ParseParam 500000 3657 ns/op 1120 B/op 17 allocs/op
-BenchmarkPossum_ParseParam 1000000 2084 ns/op 560 B/op 6 allocs/op
-BenchmarkR2router_ParseParam 1000000 1251 ns/op 432 B/op 5 allocs/op
-BenchmarkRivet_ParseParam 5000000 335 ns/op 48 B/op 1 allocs/op
-BenchmarkTango_ParseParam 1000000 1854 ns/op 280 B/op 8 allocs/op
-BenchmarkTigerTonic_ParseParam 500000 4582 ns/op 1008 B/op 17 allocs/op
-BenchmarkTraffic_ParseParam 200000 8125 ns/op 2248 B/op 23 allocs/op
-BenchmarkVulcan_ParseParam 1000000 1148 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_Parse2Params 3000000 539 ns/op 64 B/op 1 allocs/op
-BenchmarkBear_Parse2Params 1000000 1778 ns/op 496 B/op 5 allocs/op
-BenchmarkBeego_Parse2Params 1000000 2519 ns/op 368 B/op 4 allocs/op
-BenchmarkBone_Parse2Params 1000000 2596 ns/op 720 B/op 5 allocs/op
-BenchmarkDenco_Parse2Params 3000000 492 ns/op 64 B/op 1 allocs/op
-BenchmarkEcho_Parse2Params 3000000 484 ns/op 32 B/op 1 allocs/op
-BenchmarkGin_Parse2Params 10000000 193 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_Parse2Params 1000000 2575 ns/op 712 B/op 9 allocs/op
-BenchmarkGoji_Parse2Params 1000000 1373 ns/op 336 B/op 2 allocs/op
-BenchmarkGojiv2_Parse2Params 500000 2416 ns/op 960 B/op 8 allocs/op
-BenchmarkGoJsonRest_Parse2Params 300000 3452 ns/op 713 B/op 14 allocs/op
-BenchmarkGoRestful_Parse2Params 100000 17719 ns/op 6008 B/op 25 allocs/op
-BenchmarkGorillaMux_Parse2Params 300000 5102 ns/op 1088 B/op 11 allocs/op
-BenchmarkHttpRouter_Parse2Params 5000000 303 ns/op 64 B/op 1 allocs/op
-BenchmarkHttpTreeMux_Parse2Params 1000000 1372 ns/op 384 B/op 4 allocs/op
-BenchmarkKocha_Parse2Params 2000000 874 ns/op 128 B/op 5 allocs/op
-BenchmarkLARS_Parse2Params 10000000 192 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_Parse2Params 500000 3871 ns/op 1056 B/op 10 allocs/op
-BenchmarkMartini_Parse2Params 200000 9954 ns/op 1152 B/op 11 allocs/op
-BenchmarkPat_Parse2Params 500000 4194 ns/op 832 B/op 17 allocs/op
-BenchmarkPossum_Parse2Params 1000000 2121 ns/op 560 B/op 6 allocs/op
-BenchmarkR2router_Parse2Params 1000000 1415 ns/op 432 B/op 5 allocs/op
-BenchmarkRivet_Parse2Params 3000000 457 ns/op 96 B/op 1 allocs/op
-BenchmarkTango_Parse2Params 1000000 1914 ns/op 312 B/op 8 allocs/op
-BenchmarkTigerTonic_Parse2Params 300000 6895 ns/op 1408 B/op 24 allocs/op
-BenchmarkTraffic_Parse2Params 200000 8317 ns/op 2040 B/op 22 allocs/op
-BenchmarkVulcan_Parse2Params 1000000 1274 ns/op 98 B/op 3 allocs/op
-BenchmarkAce_ParseAll 200000 10401 ns/op 640 B/op 16 allocs/op
-BenchmarkBear_ParseAll 50000 37743 ns/op 8928 B/op 110 allocs/op
-BenchmarkBeego_ParseAll 20000 63193 ns/op 9568 B/op 104 allocs/op
-BenchmarkBone_ParseAll 20000 61767 ns/op 14160 B/op 131 allocs/op
-BenchmarkDenco_ParseAll 300000 7036 ns/op 928 B/op 16 allocs/op
-BenchmarkEcho_ParseAll 200000 11824 ns/op 832 B/op 26 allocs/op
-BenchmarkGin_ParseAll 300000 4199 ns/op 0 B/op 0 allocs/op
-BenchmarkGocraftWeb_ParseAll 30000 51758 ns/op 13728 B/op 181 allocs/op
-BenchmarkGoji_ParseAll 50000 29614 ns/op 5376 B/op 32 allocs/op
-BenchmarkGojiv2_ParseAll 20000 68676 ns/op 24464 B/op 199 allocs/op
-BenchmarkGoJsonRest_ParseAll 20000 76135 ns/op 13866 B/op 321 allocs/op
-BenchmarkGoRestful_ParseAll 5000 389487 ns/op 110928 B/op 600 allocs/op
-BenchmarkGorillaMux_ParseAll 10000 221250 ns/op 24864 B/op 292 allocs/op
-BenchmarkHttpRouter_ParseAll 200000 6444 ns/op 640 B/op 16 allocs/op
-BenchmarkHttpTreeMux_ParseAll 50000 30702 ns/op 5728 B/op 51 allocs/op
-BenchmarkKocha_ParseAll 200000 13712 ns/op 1112 B/op 54 allocs/op
-BenchmarkLARS_ParseAll 300000 6925 ns/op 0 B/op 0 allocs/op
-BenchmarkMacaron_ParseAll 20000 96278 ns/op 24576 B/op 250 allocs/op
-BenchmarkMartini_ParseAll 5000 271352 ns/op 25072 B/op 253 allocs/op
-BenchmarkPat_ParseAll 20000 74941 ns/op 17264 B/op 343 allocs/op
-BenchmarkPossum_ParseAll 50000 39947 ns/op 10816 B/op 78 allocs/op
-BenchmarkR2router_ParseAll 50000 42479 ns/op 8352 B/op 120 allocs/op
-BenchmarkRivet_ParseAll 200000 7726 ns/op 912 B/op 16 allocs/op
-BenchmarkTango_ParseAll 30000 50014 ns/op 7168 B/op 208 allocs/op
-BenchmarkTigerTonic_ParseAll 10000 106550 ns/op 19728 B/op 379 allocs/op
-BenchmarkTraffic_ParseAll 10000 216037 ns/op 57776 B/op 642 allocs/op
-BenchmarkVulcan_ParseAll 50000 34379 ns/op 2548 B/op 78 allocs/op
-```
diff --git a/vendor/github.com/gin-gonic/gin/CHANGELOG.md b/vendor/github.com/gin-gonic/gin/CHANGELOG.md
deleted file mode 100644
index e6a108c..0000000
--- a/vendor/github.com/gin-gonic/gin/CHANGELOG.md
+++ /dev/null
@@ -1,213 +0,0 @@
-# CHANGELOG
-
-### Gin 1.3.0
-
-- [NEW] Add [`func (*Context) QueryMap`](https://godoc.org/github.com/gin-gonic/gin#Context.QueryMap), [`func (*Context) GetQueryMap`](https://godoc.org/github.com/gin-gonic/gin#Context.GetQueryMap), [`func (*Context) PostFormMap`](https://godoc.org/github.com/gin-gonic/gin#Context.PostFormMap) and [`func (*Context) GetPostFormMap`](https://godoc.org/github.com/gin-gonic/gin#Context.GetPostFormMap) to support `type map[string]string` as query string or form parameters, see [#1383](https://github.com/gin-gonic/gin/pull/1383)
-- [NEW] Add [`func (*Context) AsciiJSON`](https://godoc.org/github.com/gin-gonic/gin#Context.AsciiJSON), see [#1358](https://github.com/gin-gonic/gin/pull/1358)
-- [NEW] Add `Pusher()` in [`type ResponseWriter`](https://godoc.org/github.com/gin-gonic/gin#ResponseWriter) for supporting http2 push, see [#1273](https://github.com/gin-gonic/gin/pull/1273)
-- [NEW] Add [`func (*Context) DataFromReader`](https://godoc.org/github.com/gin-gonic/gin#Context.DataFromReader) for serving dynamic data, see [#1304](https://github.com/gin-gonic/gin/pull/1304)
-- [NEW] Add [`func (*Context) ShouldBindBodyWith`](https://godoc.org/github.com/gin-gonic/gin#Context.ShouldBindBodyWith) allowing to call binding multiple times, see [#1341](https://github.com/gin-gonic/gin/pull/1341)
-- [NEW] Support pointers in form binding, see [#1336](https://github.com/gin-gonic/gin/pull/1336)
-- [NEW] Add [`func (*Context) JSONP`](https://godoc.org/github.com/gin-gonic/gin#Context.JSONP), see [#1333](https://github.com/gin-gonic/gin/pull/1333)
-- [NEW] Support default value in form binding, see [#1138](https://github.com/gin-gonic/gin/pull/1138)
-- [NEW] Expose validator engine in [`type StructValidator`](https://godoc.org/github.com/gin-gonic/gin/binding#StructValidator), see [#1277](https://github.com/gin-gonic/gin/pull/1277)
-- [NEW] Add [`func (*Context) ShouldBind`](https://godoc.org/github.com/gin-gonic/gin#Context.ShouldBind), [`func (*Context) ShouldBindQuery`](https://godoc.org/github.com/gin-gonic/gin#Context.ShouldBindQuery) and [`func (*Context) ShouldBindJSON`](https://godoc.org/github.com/gin-gonic/gin#Context.ShouldBindJSON), see [#1047](https://github.com/gin-gonic/gin/pull/1047)
-- [NEW] Add support for `time.Time` location in form binding, see [#1117](https://github.com/gin-gonic/gin/pull/1117)
-- [NEW] Add [`func (*Context) BindQuery`](https://godoc.org/github.com/gin-gonic/gin#Context.BindQuery), see [#1029](https://github.com/gin-gonic/gin/pull/1029)
-- [NEW] Make [jsonite](https://github.com/json-iterator/go) optional with build tags, see [#1026](https://github.com/gin-gonic/gin/pull/1026)
-- [NEW] Show query string in logger, see [#999](https://github.com/gin-gonic/gin/pull/999)
-- [NEW] Add [`func (*Context) SecureJSON`](https://godoc.org/github.com/gin-gonic/gin#Context.SecureJSON), see [#987](https://github.com/gin-gonic/gin/pull/987) and [#993](https://github.com/gin-gonic/gin/pull/993)
-- [DEPRECATE] `func (*Context) GetCookie` for [`func (*Context) Cookie`](https://godoc.org/github.com/gin-gonic/gin#Context.Cookie)
-- [FIX] Don't display color tags if [`func DisableConsoleColor`](https://godoc.org/github.com/gin-gonic/gin#DisableConsoleColor) called, see [#1072](https://github.com/gin-gonic/gin/pull/1072)
-- [FIX] Gin Mode `""` when calling [`func Mode`](https://godoc.org/github.com/gin-gonic/gin#Mode) now returns `const DebugMode`, see [#1250](https://github.com/gin-gonic/gin/pull/1250)
-- [FIX] `Flush()` now doesn't overwrite `responseWriter` status code, see [#1460](https://github.com/gin-gonic/gin/pull/1460)
-
-### Gin 1.2.0
-
-- [NEW] Switch from godeps to govendor
-- [NEW] Add support for Let's Encrypt via gin-gonic/autotls
-- [NEW] Improve README examples and add extra at examples folder
-- [NEW] Improved support with App Engine
-- [NEW] Add custom template delimiters, see #860
-- [NEW] Add Template Func Maps, see #962
-- [NEW] Add \*context.Handler(), see #928
-- [NEW] Add \*context.GetRawData()
-- [NEW] Add \*context.GetHeader() (request)
-- [NEW] Add \*context.AbortWithStatusJSON() (JSON content type)
-- [NEW] Add \*context.Keys type cast helpers
-- [NEW] Add \*context.ShouldBindWith()
-- [NEW] Add \*context.MustBindWith()
-- [NEW] Add \*engine.SetFuncMap()
-- [DEPRECATE] On next release: \*context.BindWith(), see #855
-- [FIX] Refactor render
-- [FIX] Reworked tests
-- [FIX] logger now supports cygwin
-- [FIX] Use X-Forwarded-For before X-Real-Ip
-- [FIX] time.Time binding (#904)
-
-### Gin 1.1.4
-
-- [NEW] Support google appengine for IsTerminal func
-
-### Gin 1.1.3
-
-- [FIX] Reverted Logger: skip ANSI color commands
-
-### Gin 1.1
-
-- [NEW] Implement QueryArray and PostArray methods
-- [NEW] Refactor GetQuery and GetPostForm
-- [NEW] Add contribution guide
-- [FIX] Corrected typos in README
-- [FIX] Removed additional Iota
-- [FIX] Changed imports to gopkg instead of github in README (#733)
-- [FIX] Logger: skip ANSI color commands if output is not a tty
-
-### Gin 1.0rc2 (...)
-
-- [PERFORMANCE] Fast path for writing Content-Type.
-- [PERFORMANCE] Much faster 404 routing
-- [PERFORMANCE] Allocation optimizations
-- [PERFORMANCE] Faster root tree lookup
-- [PERFORMANCE] Zero overhead, String() and JSON() rendering.
-- [PERFORMANCE] Faster ClientIP parsing
-- [PERFORMANCE] Much faster SSE implementation
-- [NEW] Benchmarks suite
-- [NEW] Bind validation can be disabled and replaced with custom validators.
-- [NEW] More flexible HTML render
-- [NEW] Multipart and PostForm bindings
-- [NEW] Adds method to return all the registered routes
-- [NEW] Context.HandlerName() returns the main handler's name
-- [NEW] Adds Error.IsType() helper
-- [FIX] Binding multipart form
-- [FIX] Integration tests
-- [FIX] Crash when binding non struct object in Context.
-- [FIX] RunTLS() implementation
-- [FIX] Logger() unit tests
-- [FIX] Adds SetHTMLTemplate() warning
-- [FIX] Context.IsAborted()
-- [FIX] More unit tests
-- [FIX] JSON, XML, HTML renders accept custom content-types
-- [FIX] gin.AbortIndex is unexported
-- [FIX] Better approach to avoid directory listing in StaticFS()
-- [FIX] Context.ClientIP() always returns the IP with trimmed spaces.
-- [FIX] Better warning when running in debug mode.
-- [FIX] Google App Engine integration. debugPrint does not use os.Stdout
-- [FIX] Fixes integer overflow in error type
-- [FIX] Error implements the json.Marshaller interface
-- [FIX] MIT license in every file
-
-
-### Gin 1.0rc1 (May 22, 2015)
-
-- [PERFORMANCE] Zero allocation router
-- [PERFORMANCE] Faster JSON, XML and text rendering
-- [PERFORMANCE] Custom hand optimized HttpRouter for Gin
-- [PERFORMANCE] Misc code optimizations. Inlining, tail call optimizations
-- [NEW] Built-in support for golang.org/x/net/context
-- [NEW] Any(path, handler). Create a route that matches any path
-- [NEW] Refactored rendering pipeline (faster and static typeded)
-- [NEW] Refactored errors API
-- [NEW] IndentedJSON() prints pretty JSON
-- [NEW] Added gin.DefaultWriter
-- [NEW] UNIX socket support
-- [NEW] RouterGroup.BasePath is exposed
-- [NEW] JSON validation using go-validate-yourself (very powerful options)
-- [NEW] Completed suite of unit tests
-- [NEW] HTTP streaming with c.Stream()
-- [NEW] StaticFile() creates a router for serving just one file.
-- [NEW] StaticFS() has an option to disable directory listing.
-- [NEW] StaticFS() for serving static files through virtual filesystems
-- [NEW] Server-Sent Events native support
-- [NEW] WrapF() and WrapH() helpers for wrapping http.HandlerFunc and http.Handler
-- [NEW] Added LoggerWithWriter() middleware
-- [NEW] Added RecoveryWithWriter() middleware
-- [NEW] Added DefaultPostFormValue()
-- [NEW] Added DefaultFormValue()
-- [NEW] Added DefaultParamValue()
-- [FIX] BasicAuth() when using custom realm
-- [FIX] Bug when serving static files in nested routing group
-- [FIX] Redirect using built-in http.Redirect()
-- [FIX] Logger when printing the requested path
-- [FIX] Documentation typos
-- [FIX] Context.Engine renamed to Context.engine
-- [FIX] Better debugging messages
-- [FIX] ErrorLogger
-- [FIX] Debug HTTP render
-- [FIX] Refactored binding and render modules
-- [FIX] Refactored Context initialization
-- [FIX] Refactored BasicAuth()
-- [FIX] NoMethod/NoRoute handlers
-- [FIX] Hijacking http
-- [FIX] Better support for Google App Engine (using log instead of fmt)
-
-
-### Gin 0.6 (Mar 9, 2015)
-
-- [NEW] Support multipart/form-data
-- [NEW] NoMethod handler
-- [NEW] Validate sub structures
-- [NEW] Support for HTTP Realm Auth
-- [FIX] Unsigned integers in binding
-- [FIX] Improve color logger
-
-
-### Gin 0.5 (Feb 7, 2015)
-
-- [NEW] Content Negotiation
-- [FIX] Solved security bug that allow a client to spoof ip
-- [FIX] Fix unexported/ignored fields in binding
-
-
-### Gin 0.4 (Aug 21, 2014)
-
-- [NEW] Development mode
-- [NEW] Unit tests
-- [NEW] Add Content.Redirect()
-- [FIX] Deferring WriteHeader()
-- [FIX] Improved documentation for model binding
-
-
-### Gin 0.3 (Jul 18, 2014)
-
-- [PERFORMANCE] Normal log and error log are printed in the same call.
-- [PERFORMANCE] Improve performance of NoRouter()
-- [PERFORMANCE] Improve context's memory locality, reduce CPU cache faults.
-- [NEW] Flexible rendering API
-- [NEW] Add Context.File()
-- [NEW] Add shorcut RunTLS() for http.ListenAndServeTLS
-- [FIX] Rename NotFound404() to NoRoute()
-- [FIX] Errors in context are purged
-- [FIX] Adds HEAD method in Static file serving
-- [FIX] Refactors Static() file serving
-- [FIX] Using keyed initialization to fix app-engine integration
-- [FIX] Can't unmarshal JSON array, #63
-- [FIX] Renaming Context.Req to Context.Request
-- [FIX] Check application/x-www-form-urlencoded when parsing form
-
-
-### Gin 0.2b (Jul 08, 2014)
-- [PERFORMANCE] Using sync.Pool to allocatio/gc overhead
-- [NEW] Travis CI integration
-- [NEW] Completely new logger
-- [NEW] New API for serving static files. gin.Static()
-- [NEW] gin.H() can be serialized into XML
-- [NEW] Typed errors. Errors can be typed. Internet/external/custom.
-- [NEW] Support for Godeps
-- [NEW] Travis/Godocs badges in README
-- [NEW] New Bind() and BindWith() methods for parsing request body.
-- [NEW] Add Content.Copy()
-- [NEW] Add context.LastError()
-- [NEW] Add shorcut for OPTIONS HTTP method
-- [FIX] Tons of README fixes
-- [FIX] Header is written before body
-- [FIX] BasicAuth() and changes API a little bit
-- [FIX] Recovery() middleware only prints panics
-- [FIX] Context.Get() does not panic anymore. Use MustGet() instead.
-- [FIX] Multiple http.WriteHeader() in NotFound handlers
-- [FIX] Engine.Run() panics if http server can't be setted up
-- [FIX] Crash when route path doesn't start with '/'
-- [FIX] Do not update header when status code is negative
-- [FIX] Setting response headers before calling WriteHeader in context.String()
-- [FIX] Add MIT license
-- [FIX] Changes behaviour of ErrorLogger() and Logger()
diff --git a/vendor/github.com/gin-gonic/gin/CODE_OF_CONDUCT.md b/vendor/github.com/gin-gonic/gin/CODE_OF_CONDUCT.md
deleted file mode 100644
index 4ea14f3..0000000
--- a/vendor/github.com/gin-gonic/gin/CODE_OF_CONDUCT.md
+++ /dev/null
@@ -1,46 +0,0 @@
-# Contributor Covenant Code of Conduct
-
-## Our Pledge
-
-In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
-
-## Our Standards
-
-Examples of behavior that contributes to creating a positive environment include:
-
-* Using welcoming and inclusive language
-* Being respectful of differing viewpoints and experiences
-* Gracefully accepting constructive criticism
-* Focusing on what is best for the community
-* Showing empathy towards other community members
-
-Examples of unacceptable behavior by participants include:
-
-* The use of sexualized language or imagery and unwelcome sexual attention or advances
-* Trolling, insulting/derogatory comments, and personal or political attacks
-* Public or private harassment
-* Publishing others' private information, such as a physical or electronic address, without explicit permission
-* Other conduct which could reasonably be considered inappropriate in a professional setting
-
-## Our Responsibilities
-
-Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
-
-Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
-
-## Scope
-
-This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
-
-## Enforcement
-
-Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at teamgingonic@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
-
-Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
-
-## Attribution
-
-This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
-
-[homepage]: http://contributor-covenant.org
-[version]: http://contributor-covenant.org/version/1/4/
diff --git a/vendor/github.com/gin-gonic/gin/CONTRIBUTING.md b/vendor/github.com/gin-gonic/gin/CONTRIBUTING.md
deleted file mode 100644
index 547b777..0000000
--- a/vendor/github.com/gin-gonic/gin/CONTRIBUTING.md
+++ /dev/null
@@ -1,13 +0,0 @@
-## Contributing
-
-- With issues:
- - Use the search tool before opening a new issue.
- - Please provide source code and commit sha if you found a bug.
- - Review existing issues and provide feedback or react to them.
-
-- With pull requests:
- - Open your pull request against `master`
- - Your pull request should have no more than two commits, if not you should squash them.
- - It should pass all tests in the available continuous integrations systems such as TravisCI.
- - You should add/modify tests to cover your proposed code changes.
- - If your pull request contains a new feature, please document it on the README.
diff --git a/vendor/github.com/gin-gonic/gin/LICENSE b/vendor/github.com/gin-gonic/gin/LICENSE
deleted file mode 100644
index 1ff7f37..0000000
--- a/vendor/github.com/gin-gonic/gin/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2014 Manuel Martínez-Almeida
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
diff --git a/vendor/github.com/gin-gonic/gin/Makefile b/vendor/github.com/gin-gonic/gin/Makefile
deleted file mode 100644
index 51b9969..0000000
--- a/vendor/github.com/gin-gonic/gin/Makefile
+++ /dev/null
@@ -1,62 +0,0 @@
-GOFMT ?= gofmt "-s"
-PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
-VETPACKAGES ?= $(shell go list ./... | grep -v /vendor/ | grep -v /examples/)
-GOFILES := $(shell find . -name "*.go" -type f -not -path "./vendor/*")
-
-all: install
-
-install: deps
- govendor sync
-
-.PHONY: test
-test:
- sh coverage.sh
-
-.PHONY: fmt
-fmt:
- $(GOFMT) -w $(GOFILES)
-
-.PHONY: fmt-check
-fmt-check:
- # get all go files and run go fmt on them
- @diff=$$($(GOFMT) -d $(GOFILES)); \
- if [ -n "$$diff" ]; then \
- echo "Please run 'make fmt' and commit the result:"; \
- echo "$${diff}"; \
- exit 1; \
- fi;
-
-vet:
- go vet $(VETPACKAGES)
-
-deps:
- @hash govendor > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
- go get -u github.com/kardianos/govendor; \
- fi
- @hash embedmd > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
- go get -u github.com/campoy/embedmd; \
- fi
-
-embedmd:
- embedmd -d *.md
-
-.PHONY: lint
-lint:
- @hash golint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
- go get -u github.com/golang/lint/golint; \
- fi
- for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
-
-.PHONY: misspell-check
-misspell-check:
- @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
- go get -u github.com/client9/misspell/cmd/misspell; \
- fi
- misspell -error $(GOFILES)
-
-.PHONY: misspell
-misspell:
- @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
- go get -u github.com/client9/misspell/cmd/misspell; \
- fi
- misspell -w $(GOFILES)
diff --git a/vendor/github.com/gin-gonic/gin/README.md b/vendor/github.com/gin-gonic/gin/README.md
deleted file mode 100644
index 28598ba..0000000
--- a/vendor/github.com/gin-gonic/gin/README.md
+++ /dev/null
@@ -1,1820 +0,0 @@
-# Gin Web Framework
-
-
-
-[![Build Status](https://travis-ci.org/gin-gonic/gin.svg)](https://travis-ci.org/gin-gonic/gin)
-[![codecov](https://codecov.io/gh/gin-gonic/gin/branch/master/graph/badge.svg)](https://codecov.io/gh/gin-gonic/gin)
-[![Go Report Card](https://goreportcard.com/badge/github.com/gin-gonic/gin)](https://goreportcard.com/report/github.com/gin-gonic/gin)
-[![GoDoc](https://godoc.org/github.com/gin-gonic/gin?status.svg)](https://godoc.org/github.com/gin-gonic/gin)
-[![Join the chat at https://gitter.im/gin-gonic/gin](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gin-gonic/gin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
-[![Sourcegraph](https://sourcegraph.com/github.com/gin-gonic/gin/-/badge.svg)](https://sourcegraph.com/github.com/gin-gonic/gin?badge)
-[![Open Source Helpers](https://www.codetriage.com/gin-gonic/gin/badges/users.svg)](https://www.codetriage.com/gin-gonic/gin)
-
-Gin is a web framework written in Go (Golang). It features a martini-like API with much better performance, up to 40 times faster thanks to [httprouter](https://github.com/julienschmidt/httprouter). If you need performance and good productivity, you will love Gin.
-
-![Gin console logger](https://gin-gonic.github.io/gin/other/console.png)
-
-## Contents
-
-- [Installation](#installation)
-- [Prerequisite](#prerequisite)
-- [Quick start](#quick-start)
-- [Benchmarks](#benchmarks)
-- [Gin v1.stable](#gin-v1-stable)
-- [Build with jsoniter](#build-with-jsoniter)
-- [API Examples](#api-examples)
- - [Using GET,POST,PUT,PATCH,DELETE and OPTIONS](#using-get-post-put-patch-delete-and-options)
- - [Parameters in path](#parameters-in-path)
- - [Querystring parameters](#querystring-parameters)
- - [Multipart/Urlencoded Form](#multiparturlencoded-form)
- - [Another example: query + post form](#another-example-query--post-form)
- - [Map as querystring or postform parameters](#map-as-querystring-or-postform-parameters)
- - [Upload files](#upload-files)
- - [Grouping routes](#grouping-routes)
- - [Blank Gin without middleware by default](#blank-gin-without-middleware-by-default)
- - [Using middleware](#using-middleware)
- - [How to write log file](#how-to-write-log-file)
- - [Model binding and validation](#model-binding-and-validation)
- - [Custom Validators](#custom-validators)
- - [Only Bind Query String](#only-bind-query-string)
- - [Bind Query String or Post Data](#bind-query-string-or-post-data)
- - [Bind HTML checkboxes](#bind-html-checkboxes)
- - [Multipart/Urlencoded binding](#multiparturlencoded-binding)
- - [XML, JSON and YAML rendering](#xml-json-and-yaml-rendering)
- - [JSONP rendering](#jsonp)
- - [Serving static files](#serving-static-files)
- - [Serving data from reader](#serving-data-from-reader)
- - [HTML rendering](#html-rendering)
- - [Multitemplate](#multitemplate)
- - [Redirects](#redirects)
- - [Custom Middleware](#custom-middleware)
- - [Using BasicAuth() middleware](#using-basicauth-middleware)
- - [Goroutines inside a middleware](#goroutines-inside-a-middleware)
- - [Custom HTTP configuration](#custom-http-configuration)
- - [Support Let's Encrypt](#support-lets-encrypt)
- - [Run multiple service using Gin](#run-multiple-service-using-gin)
- - [Graceful restart or stop](#graceful-restart-or-stop)
- - [Build a single binary with templates](#build-a-single-binary-with-templates)
- - [Bind form-data request with custom struct](#bind-form-data-request-with-custom-struct)
- - [Try to bind body into different structs](#try-to-bind-body-into-different-structs)
- - [http2 server push](#http2-server-push)
-- [Testing](#testing)
-- [Users](#users--)
-
-## Installation
-
-To install Gin package, you need to install Go and set your Go workspace first.
-
-1. Download and install it:
-
-```sh
-$ go get -u github.com/gin-gonic/gin
-```
-
-2. Import it in your code:
-
-```go
-import "github.com/gin-gonic/gin"
-```
-
-3. (Optional) Import `net/http`. This is required for example if using constants such as `http.StatusOK`.
-
-```go
-import "net/http"
-```
-
-### Use a vendor tool like [Govendor](https://github.com/kardianos/govendor)
-
-1. `go get` govendor
-
-```sh
-$ go get github.com/kardianos/govendor
-```
-2. Create your project folder and `cd` inside
-
-```sh
-$ mkdir -p $GOPATH/src/github.com/myusername/project && cd "$_"
-```
-
-3. Vendor init your project and add gin
-
-```sh
-$ govendor init
-$ govendor fetch github.com/gin-gonic/gin@v1.2
-```
-
-4. Copy a starting template inside your project
-
-```sh
-$ curl https://raw.githubusercontent.com/gin-gonic/gin/master/examples/basic/main.go > main.go
-```
-
-5. Run your project
-
-```sh
-$ go run main.go
-```
-
-## Prerequisite
-
-Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.
-
-## Quick start
-
-```sh
-# assume the following codes in example.go file
-$ cat example.go
-```
-
-```go
-package main
-
-import "github.com/gin-gonic/gin"
-
-func main() {
- r := gin.Default()
- r.GET("/ping", func(c *gin.Context) {
- c.JSON(200, gin.H{
- "message": "pong",
- })
- })
- r.Run() // listen and serve on 0.0.0.0:8080
-}
-```
-
-```
-# run example.go and visit 0.0.0.0:8080/ping on browser
-$ go run example.go
-```
-
-## Benchmarks
-
-Gin uses a custom version of [HttpRouter](https://github.com/julienschmidt/httprouter)
-
-[See all benchmarks](/BENCHMARKS.md)
-
-Benchmark name | (1) | (2) | (3) | (4)
---------------------------------------------|-----------:|------------:|-----------:|---------:
-**BenchmarkGin_GithubAll** | **30000** | **48375** | **0** | **0**
-BenchmarkAce_GithubAll | 10000 | 134059 | 13792 | 167
-BenchmarkBear_GithubAll | 5000 | 534445 | 86448 | 943
-BenchmarkBeego_GithubAll | 3000 | 592444 | 74705 | 812
-BenchmarkBone_GithubAll | 200 | 6957308 | 698784 | 8453
-BenchmarkDenco_GithubAll | 10000 | 158819 | 20224 | 167
-BenchmarkEcho_GithubAll | 10000 | 154700 | 6496 | 203
-BenchmarkGocraftWeb_GithubAll | 3000 | 570806 | 131656 | 1686
-BenchmarkGoji_GithubAll | 2000 | 818034 | 56112 | 334
-BenchmarkGojiv2_GithubAll | 2000 | 1213973 | 274768 | 3712
-BenchmarkGoJsonRest_GithubAll | 2000 | 785796 | 134371 | 2737
-BenchmarkGoRestful_GithubAll | 300 | 5238188 | 689672 | 4519
-BenchmarkGorillaMux_GithubAll | 100 | 10257726 | 211840 | 2272
-BenchmarkHttpRouter_GithubAll | 20000 | 105414 | 13792 | 167
-BenchmarkHttpTreeMux_GithubAll | 10000 | 319934 | 65856 | 671
-BenchmarkKocha_GithubAll | 10000 | 209442 | 23304 | 843
-BenchmarkLARS_GithubAll | 20000 | 62565 | 0 | 0
-BenchmarkMacaron_GithubAll | 2000 | 1161270 | 204194 | 2000
-BenchmarkMartini_GithubAll | 200 | 9991713 | 226549 | 2325
-BenchmarkPat_GithubAll | 200 | 5590793 | 1499568 | 27435
-BenchmarkPossum_GithubAll | 10000 | 319768 | 84448 | 609
-BenchmarkR2router_GithubAll | 10000 | 305134 | 77328 | 979
-BenchmarkRivet_GithubAll | 10000 | 132134 | 16272 | 167
-BenchmarkTango_GithubAll | 3000 | 552754 | 63826 | 1618
-BenchmarkTigerTonic_GithubAll | 1000 | 1439483 | 239104 | 5374
-BenchmarkTraffic_GithubAll | 100 | 11383067 | 2659329 | 21848
-BenchmarkVulcan_GithubAll | 5000 | 394253 | 19894 | 609
-
-- (1): Total Repetitions achieved in constant time, higher means more confident result
-- (2): Single Repetition Duration (ns/op), lower is better
-- (3): Heap Memory (B/op), lower is better
-- (4): Average Allocations per Repetition (allocs/op), lower is better
-
-## Gin v1. stable
-
-- [x] Zero allocation router.
-- [x] Still the fastest http router and framework. From routing to writing.
-- [x] Complete suite of unit tests
-- [x] Battle tested
-- [x] API frozen, new releases will not break your code.
-
-## Build with [jsoniter](https://github.com/json-iterator/go)
-
-Gin use `encoding/json` as default json package but you can change to [jsoniter](https://github.com/json-iterator/go) by build from other tags.
-
-```sh
-$ go build -tags=jsoniter .
-```
-
-## API Examples
-
-### Using GET, POST, PUT, PATCH, DELETE and OPTIONS
-
-```go
-func main() {
- // Disable Console Color
- // gin.DisableConsoleColor()
-
- // Creates a gin router with default middleware:
- // logger and recovery (crash-free) middleware
- router := gin.Default()
-
- router.GET("/someGet", getting)
- router.POST("/somePost", posting)
- router.PUT("/somePut", putting)
- router.DELETE("/someDelete", deleting)
- router.PATCH("/somePatch", patching)
- router.HEAD("/someHead", head)
- router.OPTIONS("/someOptions", options)
-
- // By default it serves on :8080 unless a
- // PORT environment variable was defined.
- router.Run()
- // router.Run(":3000") for a hard coded port
-}
-```
-
-### Parameters in path
-
-```go
-func main() {
- router := gin.Default()
-
- // This handler will match /user/john but will not match /user/ or /user
- router.GET("/user/:name", func(c *gin.Context) {
- name := c.Param("name")
- c.String(http.StatusOK, "Hello %s", name)
- })
-
- // However, this one will match /user/john/ and also /user/john/send
- // If no other routers match /user/john, it will redirect to /user/john/
- router.GET("/user/:name/*action", func(c *gin.Context) {
- name := c.Param("name")
- action := c.Param("action")
- message := name + " is " + action
- c.String(http.StatusOK, message)
- })
-
- router.Run(":8080")
-}
-```
-
-### Querystring parameters
-
-```go
-func main() {
- router := gin.Default()
-
- // Query string parameters are parsed using the existing underlying request object.
- // The request responds to a url matching: /welcome?firstname=Jane&lastname=Doe
- router.GET("/welcome", func(c *gin.Context) {
- firstname := c.DefaultQuery("firstname", "Guest")
- lastname := c.Query("lastname") // shortcut for c.Request.URL.Query().Get("lastname")
-
- c.String(http.StatusOK, "Hello %s %s", firstname, lastname)
- })
- router.Run(":8080")
-}
-```
-
-### Multipart/Urlencoded Form
-
-```go
-func main() {
- router := gin.Default()
-
- router.POST("/form_post", func(c *gin.Context) {
- message := c.PostForm("message")
- nick := c.DefaultPostForm("nick", "anonymous")
-
- c.JSON(200, gin.H{
- "status": "posted",
- "message": message,
- "nick": nick,
- })
- })
- router.Run(":8080")
-}
-```
-
-### Another example: query + post form
-
-```
-POST /post?id=1234&page=1 HTTP/1.1
-Content-Type: application/x-www-form-urlencoded
-
-name=manu&message=this_is_great
-```
-
-```go
-func main() {
- router := gin.Default()
-
- router.POST("/post", func(c *gin.Context) {
-
- id := c.Query("id")
- page := c.DefaultQuery("page", "0")
- name := c.PostForm("name")
- message := c.PostForm("message")
-
- fmt.Printf("id: %s; page: %s; name: %s; message: %s", id, page, name, message)
- })
- router.Run(":8080")
-}
-```
-
-```
-id: 1234; page: 1; name: manu; message: this_is_great
-```
-
-### Map as querystring or postform parameters
-
-```
-POST /post?ids[a]=1234&ids[b]=hello HTTP/1.1
-Content-Type: application/x-www-form-urlencoded
-
-names[first]=thinkerou&names[second]=tianou
-```
-
-```go
-func main() {
- router := gin.Default()
-
- router.POST("/post", func(c *gin.Context) {
-
- ids := c.QueryMap("ids")
- names := c.PostFormMap("names")
-
- fmt.Printf("ids: %v; names: %v", ids, names)
- })
- router.Run(":8080")
-}
-```
-
-```
-ids: map[b:hello a:1234], names: map[second:tianou first:thinkerou]
-```
-
-### Upload files
-
-#### Single file
-
-References issue [#774](https://github.com/gin-gonic/gin/issues/774) and detail [example code](examples/upload-file/single).
-
-```go
-func main() {
- router := gin.Default()
- // Set a lower memory limit for multipart forms (default is 32 MiB)
- // router.MaxMultipartMemory = 8 << 20 // 8 MiB
- router.POST("/upload", func(c *gin.Context) {
- // single file
- file, _ := c.FormFile("file")
- log.Println(file.Filename)
-
- // Upload the file to specific dst.
- // c.SaveUploadedFile(file, dst)
-
- c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))
- })
- router.Run(":8080")
-}
-```
-
-How to `curl`:
-
-```bash
-curl -X POST http://localhost:8080/upload \
- -F "file=@/Users/appleboy/test.zip" \
- -H "Content-Type: multipart/form-data"
-```
-
-#### Multiple files
-
-See the detail [example code](examples/upload-file/multiple).
-
-```go
-func main() {
- router := gin.Default()
- // Set a lower memory limit for multipart forms (default is 32 MiB)
- // router.MaxMultipartMemory = 8 << 20 // 8 MiB
- router.POST("/upload", func(c *gin.Context) {
- // Multipart form
- form, _ := c.MultipartForm()
- files := form.File["upload[]"]
-
- for _, file := range files {
- log.Println(file.Filename)
-
- // Upload the file to specific dst.
- // c.SaveUploadedFile(file, dst)
- }
- c.String(http.StatusOK, fmt.Sprintf("%d files uploaded!", len(files)))
- })
- router.Run(":8080")
-}
-```
-
-How to `curl`:
-
-```bash
-curl -X POST http://localhost:8080/upload \
- -F "upload[]=@/Users/appleboy/test1.zip" \
- -F "upload[]=@/Users/appleboy/test2.zip" \
- -H "Content-Type: multipart/form-data"
-```
-
-### Grouping routes
-
-```go
-func main() {
- router := gin.Default()
-
- // Simple group: v1
- v1 := router.Group("/v1")
- {
- v1.POST("/login", loginEndpoint)
- v1.POST("/submit", submitEndpoint)
- v1.POST("/read", readEndpoint)
- }
-
- // Simple group: v2
- v2 := router.Group("/v2")
- {
- v2.POST("/login", loginEndpoint)
- v2.POST("/submit", submitEndpoint)
- v2.POST("/read", readEndpoint)
- }
-
- router.Run(":8080")
-}
-```
-
-### Blank Gin without middleware by default
-
-Use
-
-```go
-r := gin.New()
-```
-
-instead of
-
-```go
-// Default With the Logger and Recovery middleware already attached
-r := gin.Default()
-```
-
-
-### Using middleware
-```go
-func main() {
- // Creates a router without any middleware by default
- r := gin.New()
-
- // Global middleware
- // Logger middleware will write the logs to gin.DefaultWriter even if you set with GIN_MODE=release.
- // By default gin.DefaultWriter = os.Stdout
- r.Use(gin.Logger())
-
- // Recovery middleware recovers from any panics and writes a 500 if there was one.
- r.Use(gin.Recovery())
-
- // Per route middleware, you can add as many as you desire.
- r.GET("/benchmark", MyBenchLogger(), benchEndpoint)
-
- // Authorization group
- // authorized := r.Group("/", AuthRequired())
- // exactly the same as:
- authorized := r.Group("/")
- // per group middleware! in this case we use the custom created
- // AuthRequired() middleware just in the "authorized" group.
- authorized.Use(AuthRequired())
- {
- authorized.POST("/login", loginEndpoint)
- authorized.POST("/submit", submitEndpoint)
- authorized.POST("/read", readEndpoint)
-
- // nested group
- testing := authorized.Group("testing")
- testing.GET("/analytics", analyticsEndpoint)
- }
-
- // Listen and serve on 0.0.0.0:8080
- r.Run(":8080")
-}
-```
-
-### How to write log file
-```go
-func main() {
- // Disable Console Color, you don't need console color when writing the logs to file.
- gin.DisableConsoleColor()
-
- // Logging to a file.
- f, _ := os.Create("gin.log")
- gin.DefaultWriter = io.MultiWriter(f)
-
- // Use the following code if you need to write the logs to file and console at the same time.
- // gin.DefaultWriter = io.MultiWriter(f, os.Stdout)
-
- router := gin.Default()
- router.GET("/ping", func(c *gin.Context) {
- c.String(200, "pong")
- })
-
- router.Run(":8080")
-}
-```
-
-### Model binding and validation
-
-To bind a request body into a type, use model binding. We currently support binding of JSON, XML and standard form values (foo=bar&boo=baz).
-
-Gin uses [**go-playground/validator.v8**](https://github.com/go-playground/validator) for validation. Check the full docs on tags usage [here](http://godoc.org/gopkg.in/go-playground/validator.v8#hdr-Baked_In_Validators_and_Tags).
-
-Note that you need to set the corresponding binding tag on all fields you want to bind. For example, when binding from JSON, set `json:"fieldname"`.
-
-Also, Gin provides two sets of methods for binding:
-- **Type** - Must bind
- - **Methods** - `Bind`, `BindJSON`, `BindQuery`
- - **Behavior** - These methods use `MustBindWith` under the hood. If there is a binding error, the request is aborted with `c.AbortWithError(400, err).SetType(ErrorTypeBind)`. This sets the response status code to 400 and the `Content-Type` header is set to `text/plain; charset=utf-8`. Note that if you try to set the response code after this, it will result in a warning `[GIN-debug] [WARNING] Headers were already written. Wanted to override status code 400 with 422`. If you wish to have greater control over the behavior, consider using the `ShouldBind` equivalent method.
-- **Type** - Should bind
- - **Methods** - `ShouldBind`, `ShouldBindJSON`, `ShouldBindQuery`
- - **Behavior** - These methods use `ShouldBindWith` under the hood. If there is a binding error, the error is returned and it is the developer's responsibility to handle the request and error appropriately.
-
-When using the Bind-method, Gin tries to infer the binder depending on the Content-Type header. If you are sure what you are binding, you can use `MustBindWith` or `ShouldBindWith`.
-
-You can also specify that specific fields are required. If a field is decorated with `binding:"required"` and has a empty value when binding, an error will be returned.
-
-```go
-// Binding from JSON
-type Login struct {
- User string `form:"user" json:"user" binding:"required"`
- Password string `form:"password" json:"password" binding:"required"`
-}
-
-func main() {
- router := gin.Default()
-
- // Example for binding JSON ({"user": "manu", "password": "123"})
- router.POST("/loginJSON", func(c *gin.Context) {
- var json Login
- if err := c.ShouldBindJSON(&json); err == nil {
- if json.User == "manu" && json.Password == "123" {
- c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
- } else {
- c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
- }
- } else {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- }
- })
-
- // Example for binding a HTML form (user=manu&password=123)
- router.POST("/loginForm", func(c *gin.Context) {
- var form Login
- // This will infer what binder to use depending on the content-type header.
- if err := c.ShouldBind(&form); err == nil {
- if form.User == "manu" && form.Password == "123" {
- c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
- } else {
- c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
- }
- } else {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- }
- })
-
- // Listen and serve on 0.0.0.0:8080
- router.Run(":8080")
-}
-```
-
-**Sample request**
-```shell
-$ curl -v -X POST \
- http://localhost:8080/loginJSON \
- -H 'content-type: application/json' \
- -d '{ "user": "manu" }'
-> POST /loginJSON HTTP/1.1
-> Host: localhost:8080
-> User-Agent: curl/7.51.0
-> Accept: */*
-> content-type: application/json
-> Content-Length: 18
->
-* upload completely sent off: 18 out of 18 bytes
-< HTTP/1.1 400 Bad Request
-< Content-Type: application/json; charset=utf-8
-< Date: Fri, 04 Aug 2017 03:51:31 GMT
-< Content-Length: 100
-<
-{"error":"Key: 'Login.Password' Error:Field validation for 'Password' failed on the 'required' tag"}
-```
-
-**Skip validate**
-
-When running the above example using the above the `curl` command, it returns error. Because the example use `binding:"required"` for `Password`. If use `binding:"-"` for `Password`, then it will not return error when running the above example again.
-
-### Custom Validators
-
-It is also possible to register custom validators. See the [example code](examples/custom-validation/server.go).
-
-[embedmd]:# (examples/custom-validation/server.go go)
-```go
-package main
-
-import (
- "net/http"
- "reflect"
- "time"
-
- "github.com/gin-gonic/gin"
- "github.com/gin-gonic/gin/binding"
- "gopkg.in/go-playground/validator.v8"
-)
-
-type Booking struct {
- CheckIn time.Time `form:"check_in" binding:"required,bookabledate" time_format:"2006-01-02"`
- CheckOut time.Time `form:"check_out" binding:"required,gtfield=CheckIn" time_format:"2006-01-02"`
-}
-
-func bookableDate(
- v *validator.Validate, topStruct reflect.Value, currentStructOrField reflect.Value,
- field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string,
-) bool {
- if date, ok := field.Interface().(time.Time); ok {
- today := time.Now()
- if today.Year() > date.Year() || today.YearDay() > date.YearDay() {
- return false
- }
- }
- return true
-}
-
-func main() {
- route := gin.Default()
-
- if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
- v.RegisterValidation("bookabledate", bookableDate)
- }
-
- route.GET("/bookable", getBookable)
- route.Run(":8085")
-}
-
-func getBookable(c *gin.Context) {
- var b Booking
- if err := c.ShouldBindWith(&b, binding.Query); err == nil {
- c.JSON(http.StatusOK, gin.H{"message": "Booking dates are valid!"})
- } else {
- c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
- }
-}
-```
-
-```console
-$ curl "localhost:8085/bookable?check_in=2018-04-16&check_out=2018-04-17"
-{"message":"Booking dates are valid!"}
-
-$ curl "localhost:8085/bookable?check_in=2018-03-08&check_out=2018-03-09"
-{"error":"Key: 'Booking.CheckIn' Error:Field validation for 'CheckIn' failed on the 'bookabledate' tag"}
-```
-
-[Struct level validations](https://github.com/go-playground/validator/releases/tag/v8.7) can also be registed this way.
-See the [struct-lvl-validation example](examples/struct-lvl-validations) to learn more.
-
-### Only Bind Query String
-
-`ShouldBindQuery` function only binds the query params and not the post data. See the [detail information](https://github.com/gin-gonic/gin/issues/742#issuecomment-315953017).
-
-```go
-package main
-
-import (
- "log"
-
- "github.com/gin-gonic/gin"
-)
-
-type Person struct {
- Name string `form:"name"`
- Address string `form:"address"`
-}
-
-func main() {
- route := gin.Default()
- route.Any("/testing", startPage)
- route.Run(":8085")
-}
-
-func startPage(c *gin.Context) {
- var person Person
- if c.ShouldBindQuery(&person) == nil {
- log.Println("====== Only Bind By Query String ======")
- log.Println(person.Name)
- log.Println(person.Address)
- }
- c.String(200, "Success")
-}
-
-```
-
-### Bind Query String or Post Data
-
-See the [detail information](https://github.com/gin-gonic/gin/issues/742#issuecomment-264681292).
-
-```go
-package main
-
-import "log"
-import "github.com/gin-gonic/gin"
-import "time"
-
-type Person struct {
- Name string `form:"name"`
- Address string `form:"address"`
- Birthday time.Time `form:"birthday" time_format:"2006-01-02" time_utc:"1"`
-}
-
-func main() {
- route := gin.Default()
- route.GET("/testing", startPage)
- route.Run(":8085")
-}
-
-func startPage(c *gin.Context) {
- var person Person
- // If `GET`, only `Form` binding engine (`query`) used.
- // If `POST`, first checks the `content-type` for `JSON` or `XML`, then uses `Form` (`form-data`).
- // See more at https://github.com/gin-gonic/gin/blob/master/binding/binding.go#L48
- if c.ShouldBind(&person) == nil {
- log.Println(person.Name)
- log.Println(person.Address)
- log.Println(person.Birthday)
- }
-
- c.String(200, "Success")
-}
-```
-
-Test it with:
-```sh
-$ curl -X GET "localhost:8085/testing?name=appleboy&address=xyz&birthday=1992-03-15"
-```
-
-### Bind HTML checkboxes
-
-See the [detail information](https://github.com/gin-gonic/gin/issues/129#issuecomment-124260092)
-
-main.go
-
-```go
-...
-
-type myForm struct {
- Colors []string `form:"colors[]"`
-}
-
-...
-
-func formHandler(c *gin.Context) {
- var fakeForm myForm
- c.ShouldBind(&fakeForm)
- c.JSON(200, gin.H{"color": fakeForm.Colors})
-}
-
-...
-
-```
-
-form.html
-
-```html
-
-```
-
-result:
-
-```
-{"color":["red","green","blue"]}
-```
-
-### Multipart/Urlencoded binding
-
-```go
-package main
-
-import (
- "github.com/gin-gonic/gin"
-)
-
-type LoginForm struct {
- User string `form:"user" binding:"required"`
- Password string `form:"password" binding:"required"`
-}
-
-func main() {
- router := gin.Default()
- router.POST("/login", func(c *gin.Context) {
- // you can bind multipart form with explicit binding declaration:
- // c.ShouldBindWith(&form, binding.Form)
- // or you can simply use autobinding with ShouldBind method:
- var form LoginForm
- // in this case proper binding will be automatically selected
- if c.ShouldBind(&form) == nil {
- if form.User == "user" && form.Password == "password" {
- c.JSON(200, gin.H{"status": "you are logged in"})
- } else {
- c.JSON(401, gin.H{"status": "unauthorized"})
- }
- }
- })
- router.Run(":8080")
-}
-```
-
-Test it with:
-```sh
-$ curl -v --form user=user --form password=password http://localhost:8080/login
-```
-
-### XML, JSON and YAML rendering
-
-```go
-func main() {
- r := gin.Default()
-
- // gin.H is a shortcut for map[string]interface{}
- r.GET("/someJSON", func(c *gin.Context) {
- c.JSON(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
- })
-
- r.GET("/moreJSON", func(c *gin.Context) {
- // You also can use a struct
- var msg struct {
- Name string `json:"user"`
- Message string
- Number int
- }
- msg.Name = "Lena"
- msg.Message = "hey"
- msg.Number = 123
- // Note that msg.Name becomes "user" in the JSON
- // Will output : {"user": "Lena", "Message": "hey", "Number": 123}
- c.JSON(http.StatusOK, msg)
- })
-
- r.GET("/someXML", func(c *gin.Context) {
- c.XML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
- })
-
- r.GET("/someYAML", func(c *gin.Context) {
- c.YAML(http.StatusOK, gin.H{"message": "hey", "status": http.StatusOK})
- })
-
- // Listen and serve on 0.0.0.0:8080
- r.Run(":8080")
-}
-```
-
-#### SecureJSON
-
-Using SecureJSON to prevent json hijacking. Default prepends `"while(1),"` to response body if the given struct is array values.
-
-```go
-func main() {
- r := gin.Default()
-
- // You can also use your own secure json prefix
- // r.SecureJsonPrefix(")]}',\n")
-
- r.GET("/someJSON", func(c *gin.Context) {
- names := []string{"lena", "austin", "foo"}
-
- // Will output : while(1);["lena","austin","foo"]
- c.SecureJSON(http.StatusOK, names)
- })
-
- // Listen and serve on 0.0.0.0:8080
- r.Run(":8080")
-}
-```
-#### JSONP
-
-Using JSONP to request data from a server in a different domain. Add callback to response body if the query parameter callback exists.
-
-```go
-func main() {
- r := gin.Default()
-
- r.GET("/JSONP?callback=x", func(c *gin.Context) {
- data := map[string]interface{}{
- "foo": "bar",
- }
-
- //callback is x
- // Will output : x({\"foo\":\"bar\"})
- c.JSONP(http.StatusOK, data)
- })
-
- // Listen and serve on 0.0.0.0:8080
- r.Run(":8080")
-}
-```
-
-#### AsciiJSON
-
-Using AsciiJSON to Generates ASCII-only JSON with escaped non-ASCII chracters.
-
-```go
-func main() {
- r := gin.Default()
-
- r.GET("/someJSON", func(c *gin.Context) {
- data := map[string]interface{}{
- "lang": "GO语言",
- "tag": " ",
- }
-
- // will output : {"lang":"GO\u8bed\u8a00","tag":"\u003cbr\u003e"}
- c.AsciiJSON(http.StatusOK, data)
- })
-
- // Listen and serve on 0.0.0.0:8080
- r.Run(":8080")
-}
-```
-
-### Serving static files
-
-```go
-func main() {
- router := gin.Default()
- router.Static("/assets", "./assets")
- router.StaticFS("/more_static", http.Dir("my_file_system"))
- router.StaticFile("/favicon.ico", "./resources/favicon.ico")
-
- // Listen and serve on 0.0.0.0:8080
- router.Run(":8080")
-}
-```
-
-### Serving data from reader
-
-```go
-func main() {
- router := gin.Default()
- router.GET("/someDataFromReader", func(c *gin.Context) {
- response, err := http.Get("https://raw.githubusercontent.com/gin-gonic/logo/master/color.png")
- if err != nil || response.StatusCode != http.StatusOK {
- c.Status(http.StatusServiceUnavailable)
- return
- }
-
- reader := response.Body
- contentLength := response.ContentLength
- contentType := response.Header.Get("Content-Type")
-
- extraHeaders := map[string]string{
- "Content-Disposition": `attachment; filename="gopher.png"`,
- }
-
- c.DataFromReader(http.StatusOK, contentLength, contentType, reader, extraHeaders)
- })
- router.Run(":8080")
-}
-```
-
-### HTML rendering
-
-Using LoadHTMLGlob() or LoadHTMLFiles()
-
-```go
-func main() {
- router := gin.Default()
- router.LoadHTMLGlob("templates/*")
- //router.LoadHTMLFiles("templates/template1.html", "templates/template2.html")
- router.GET("/index", func(c *gin.Context) {
- c.HTML(http.StatusOK, "index.tmpl", gin.H{
- "title": "Main website",
- })
- })
- router.Run(":8080")
-}
-```
-
-templates/index.tmpl
-
-```html
-
-
-
-{{ end }}
-```
-
-#### Custom Template renderer
-
-You can also use your own html template render
-
-```go
-import "html/template"
-
-func main() {
- router := gin.Default()
- html := template.Must(template.ParseFiles("file1", "file2"))
- router.SetHTMLTemplate(html)
- router.Run(":8080")
-}
-```
-
-#### Custom Delimiters
-
-You may use custom delims
-
-```go
- r := gin.Default()
- r.Delims("{[{", "}]}")
- r.LoadHTMLGlob("/path/to/templates"))
-```
-
-#### Custom Template Funcs
-
-See the detail [example code](examples/template).
-
-main.go
-
-```go
-import (
- "fmt"
- "html/template"
- "net/http"
- "time"
-
- "github.com/gin-gonic/gin"
-)
-
-func formatAsDate(t time.Time) string {
- year, month, day := t.Date()
- return fmt.Sprintf("%d%02d/%02d", year, month, day)
-}
-
-func main() {
- router := gin.Default()
- router.Delims("{[{", "}]}")
- router.SetFuncMap(template.FuncMap{
- "formatAsDate": formatAsDate,
- })
- router.LoadHTMLFiles("./testdata/template/raw.tmpl")
-
- router.GET("/raw", func(c *gin.Context) {
- c.HTML(http.StatusOK, "raw.tmpl", map[string]interface{}{
- "now": time.Date(2017, 07, 01, 0, 0, 0, 0, time.UTC),
- })
- })
-
- router.Run(":8080")
-}
-
-```
-
-raw.tmpl
-
-```html
-Date: {[{.now | formatAsDate}]}
-```
-
-Result:
-```
-Date: 2017/07/01
-```
-
-### Multitemplate
-
-Gin allow by default use only one html.Template. Check [a multitemplate render](https://github.com/gin-contrib/multitemplate) for using features like go 1.6 `block template`.
-
-### Redirects
-
-Issuing a HTTP redirect is easy. Both internal and external locations are supported.
-
-```go
-r.GET("/test", func(c *gin.Context) {
- c.Redirect(http.StatusMovedPermanently, "http://www.google.com/")
-})
-```
-
-
-Issuing a Router redirect, use `HandleContext` like below.
-
-``` go
-r.GET("/test", func(c *gin.Context) {
- c.Request.URL.Path = "/test2"
- r.HandleContext(c)
-})
-r.GET("/test2", func(c *gin.Context) {
- c.JSON(200, gin.H{"hello": "world"})
-})
-```
-
-
-### Custom Middleware
-
-```go
-func Logger() gin.HandlerFunc {
- return func(c *gin.Context) {
- t := time.Now()
-
- // Set example variable
- c.Set("example", "12345")
-
- // before request
-
- c.Next()
-
- // after request
- latency := time.Since(t)
- log.Print(latency)
-
- // access the status we are sending
- status := c.Writer.Status()
- log.Println(status)
- }
-}
-
-func main() {
- r := gin.New()
- r.Use(Logger())
-
- r.GET("/test", func(c *gin.Context) {
- example := c.MustGet("example").(string)
-
- // it would print: "12345"
- log.Println(example)
- })
-
- // Listen and serve on 0.0.0.0:8080
- r.Run(":8080")
-}
-```
-
-### Using BasicAuth() middleware
-
-```go
-// simulate some private data
-var secrets = gin.H{
- "foo": gin.H{"email": "foo@bar.com", "phone": "123433"},
- "austin": gin.H{"email": "austin@example.com", "phone": "666"},
- "lena": gin.H{"email": "lena@guapa.com", "phone": "523443"},
-}
-
-func main() {
- r := gin.Default()
-
- // Group using gin.BasicAuth() middleware
- // gin.Accounts is a shortcut for map[string]string
- authorized := r.Group("/admin", gin.BasicAuth(gin.Accounts{
- "foo": "bar",
- "austin": "1234",
- "lena": "hello2",
- "manu": "4321",
- }))
-
- // /admin/secrets endpoint
- // hit "localhost:8080/admin/secrets
- authorized.GET("/secrets", func(c *gin.Context) {
- // get user, it was set by the BasicAuth middleware
- user := c.MustGet(gin.AuthUserKey).(string)
- if secret, ok := secrets[user]; ok {
- c.JSON(http.StatusOK, gin.H{"user": user, "secret": secret})
- } else {
- c.JSON(http.StatusOK, gin.H{"user": user, "secret": "NO SECRET :("})
- }
- })
-
- // Listen and serve on 0.0.0.0:8080
- r.Run(":8080")
-}
-```
-
-### Goroutines inside a middleware
-
-When starting new Goroutines inside a middleware or handler, you **SHOULD NOT** use the original context inside it, you have to use a read-only copy.
-
-```go
-func main() {
- r := gin.Default()
-
- r.GET("/long_async", func(c *gin.Context) {
- // create copy to be used inside the goroutine
- cCp := c.Copy()
- go func() {
- // simulate a long task with time.Sleep(). 5 seconds
- time.Sleep(5 * time.Second)
-
- // note that you are using the copied context "cCp", IMPORTANT
- log.Println("Done! in path " + cCp.Request.URL.Path)
- }()
- })
-
- r.GET("/long_sync", func(c *gin.Context) {
- // simulate a long task with time.Sleep(). 5 seconds
- time.Sleep(5 * time.Second)
-
- // since we are NOT using a goroutine, we do not have to copy the context
- log.Println("Done! in path " + c.Request.URL.Path)
- })
-
- // Listen and serve on 0.0.0.0:8080
- r.Run(":8080")
-}
-```
-
-### Custom HTTP configuration
-
-Use `http.ListenAndServe()` directly, like this:
-
-```go
-func main() {
- router := gin.Default()
- http.ListenAndServe(":8080", router)
-}
-```
-or
-
-```go
-func main() {
- router := gin.Default()
-
- s := &http.Server{
- Addr: ":8080",
- Handler: router,
- ReadTimeout: 10 * time.Second,
- WriteTimeout: 10 * time.Second,
- MaxHeaderBytes: 1 << 20,
- }
- s.ListenAndServe()
-}
-```
-
-### Support Let's Encrypt
-
-example for 1-line LetsEncrypt HTTPS servers.
-
-[embedmd]:# (examples/auto-tls/example1/main.go go)
-```go
-package main
-
-import (
- "log"
-
- "github.com/gin-gonic/autotls"
- "github.com/gin-gonic/gin"
-)
-
-func main() {
- r := gin.Default()
-
- // Ping handler
- r.GET("/ping", func(c *gin.Context) {
- c.String(200, "pong")
- })
-
- log.Fatal(autotls.Run(r, "example1.com", "example2.com"))
-}
-```
-
-example for custom autocert manager.
-
-[embedmd]:# (examples/auto-tls/example2/main.go go)
-```go
-package main
-
-import (
- "log"
-
- "github.com/gin-gonic/autotls"
- "github.com/gin-gonic/gin"
- "golang.org/x/crypto/acme/autocert"
-)
-
-func main() {
- r := gin.Default()
-
- // Ping handler
- r.GET("/ping", func(c *gin.Context) {
- c.String(200, "pong")
- })
-
- m := autocert.Manager{
- Prompt: autocert.AcceptTOS,
- HostPolicy: autocert.HostWhitelist("example1.com", "example2.com"),
- Cache: autocert.DirCache("/var/www/.cache"),
- }
-
- log.Fatal(autotls.RunWithManager(r, &m))
-}
-```
-
-### Run multiple service using Gin
-
-See the [question](https://github.com/gin-gonic/gin/issues/346) and try the following example:
-
-[embedmd]:# (examples/multiple-service/main.go go)
-```go
-package main
-
-import (
- "log"
- "net/http"
- "time"
-
- "github.com/gin-gonic/gin"
- "golang.org/x/sync/errgroup"
-)
-
-var (
- g errgroup.Group
-)
-
-func router01() http.Handler {
- e := gin.New()
- e.Use(gin.Recovery())
- e.GET("/", func(c *gin.Context) {
- c.JSON(
- http.StatusOK,
- gin.H{
- "code": http.StatusOK,
- "error": "Welcome server 01",
- },
- )
- })
-
- return e
-}
-
-func router02() http.Handler {
- e := gin.New()
- e.Use(gin.Recovery())
- e.GET("/", func(c *gin.Context) {
- c.JSON(
- http.StatusOK,
- gin.H{
- "code": http.StatusOK,
- "error": "Welcome server 02",
- },
- )
- })
-
- return e
-}
-
-func main() {
- server01 := &http.Server{
- Addr: ":8080",
- Handler: router01(),
- ReadTimeout: 5 * time.Second,
- WriteTimeout: 10 * time.Second,
- }
-
- server02 := &http.Server{
- Addr: ":8081",
- Handler: router02(),
- ReadTimeout: 5 * time.Second,
- WriteTimeout: 10 * time.Second,
- }
-
- g.Go(func() error {
- return server01.ListenAndServe()
- })
-
- g.Go(func() error {
- return server02.ListenAndServe()
- })
-
- if err := g.Wait(); err != nil {
- log.Fatal(err)
- }
-}
-```
-
-### Graceful restart or stop
-
-Do you want to graceful restart or stop your web server?
-There are some ways this can be done.
-
-We can use [fvbock/endless](https://github.com/fvbock/endless) to replace the default `ListenAndServe`. Refer issue [#296](https://github.com/gin-gonic/gin/issues/296) for more details.
-
-```go
-router := gin.Default()
-router.GET("/", handler)
-// [...]
-endless.ListenAndServe(":4242", router)
-```
-
-An alternative to endless:
-
-* [manners](https://github.com/braintree/manners): A polite Go HTTP server that shuts down gracefully.
-* [graceful](https://github.com/tylerb/graceful): Graceful is a Go package enabling graceful shutdown of an http.Handler server.
-* [grace](https://github.com/facebookgo/grace): Graceful restart & zero downtime deploy for Go servers.
-
-If you are using Go 1.8, you may not need to use this library! Consider using http.Server's built-in [Shutdown()](https://golang.org/pkg/net/http/#Server.Shutdown) method for graceful shutdowns. See the full [graceful-shutdown](./examples/graceful-shutdown) example with gin.
-
-[embedmd]:# (examples/graceful-shutdown/graceful-shutdown/server.go go)
-```go
-// +build go1.8
-
-package main
-
-import (
- "context"
- "log"
- "net/http"
- "os"
- "os/signal"
- "time"
-
- "github.com/gin-gonic/gin"
-)
-
-func main() {
- router := gin.Default()
- router.GET("/", func(c *gin.Context) {
- time.Sleep(5 * time.Second)
- c.String(http.StatusOK, "Welcome Gin Server")
- })
-
- srv := &http.Server{
- Addr: ":8080",
- Handler: router,
- }
-
- go func() {
- // service connections
- if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
- log.Fatalf("listen: %s\n", err)
- }
- }()
-
- // Wait for interrupt signal to gracefully shutdown the server with
- // a timeout of 5 seconds.
- quit := make(chan os.Signal)
- signal.Notify(quit, os.Interrupt)
- <-quit
- log.Println("Shutdown Server ...")
-
- ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
- defer cancel()
- if err := srv.Shutdown(ctx); err != nil {
- log.Fatal("Server Shutdown:", err)
- }
- log.Println("Server exiting")
-}
-```
-
-### Build a single binary with templates
-
-You can build a server into a single binary containing templates by using [go-assets][].
-
-[go-assets]: https://github.com/jessevdk/go-assets
-
-```go
-func main() {
- r := gin.New()
-
- t, err := loadTemplate()
- if err != nil {
- panic(err)
- }
- r.SetHTMLTemplate(t)
-
- r.GET("/", func(c *gin.Context) {
- c.HTML(http.StatusOK, "/html/index.tmpl",nil)
- })
- r.Run(":8080")
-}
-
-// loadTemplate loads templates embedded by go-assets-builder
-func loadTemplate() (*template.Template, error) {
- t := template.New("")
- for name, file := range Assets.Files {
- if file.IsDir() || !strings.HasSuffix(name, ".tmpl") {
- continue
- }
- h, err := ioutil.ReadAll(file)
- if err != nil {
- return nil, err
- }
- t, err = t.New(name).Parse(string(h))
- if err != nil {
- return nil, err
- }
- }
- return t, nil
-}
-```
-
-See a complete example in the `examples/assets-in-binary` directory.
-
-### Bind form-data request with custom struct
-
-The follow example using custom struct:
-
-```go
-type StructA struct {
- FieldA string `form:"field_a"`
-}
-
-type StructB struct {
- NestedStruct StructA
- FieldB string `form:"field_b"`
-}
-
-type StructC struct {
- NestedStructPointer *StructA
- FieldC string `form:"field_c"`
-}
-
-type StructD struct {
- NestedAnonyStruct struct {
- FieldX string `form:"field_x"`
- }
- FieldD string `form:"field_d"`
-}
-
-func GetDataB(c *gin.Context) {
- var b StructB
- c.Bind(&b)
- c.JSON(200, gin.H{
- "a": b.NestedStruct,
- "b": b.FieldB,
- })
-}
-
-func GetDataC(c *gin.Context) {
- var b StructC
- c.Bind(&b)
- c.JSON(200, gin.H{
- "a": b.NestedStructPointer,
- "c": b.FieldC,
- })
-}
-
-func GetDataD(c *gin.Context) {
- var b StructD
- c.Bind(&b)
- c.JSON(200, gin.H{
- "x": b.NestedAnonyStruct,
- "d": b.FieldD,
- })
-}
-
-func main() {
- r := gin.Default()
- r.GET("/getb", GetDataB)
- r.GET("/getc", GetDataC)
- r.GET("/getd", GetDataD)
-
- r.Run()
-}
-```
-
-Using the command `curl` command result:
-
-```
-$ curl "http://localhost:8080/getb?field_a=hello&field_b=world"
-{"a":{"FieldA":"hello"},"b":"world"}
-$ curl "http://localhost:8080/getc?field_a=hello&field_c=world"
-{"a":{"FieldA":"hello"},"c":"world"}
-$ curl "http://localhost:8080/getd?field_x=hello&field_d=world"
-{"d":"world","x":{"FieldX":"hello"}}
-```
-
-**NOTE**: NOT support the follow style struct:
-
-```go
-type StructX struct {
- X struct {} `form:"name_x"` // HERE have form
-}
-
-type StructY struct {
- Y StructX `form:"name_y"` // HERE hava form
-}
-
-type StructZ struct {
- Z *StructZ `form:"name_z"` // HERE hava form
-}
-```
-
-In a word, only support nested custom struct which have no `form` now.
-
-### Try to bind body into different structs
-
-The normal methods for binding request body consumes `c.Request.Body` and they
-cannot be called multiple times.
-
-```go
-type formA struct {
- Foo string `json:"foo" xml:"foo" binding:"required"`
-}
-
-type formB struct {
- Bar string `json:"bar" xml:"bar" binding:"required"`
-}
-
-func SomeHandler(c *gin.Context) {
- objA := formA{}
- objB := formB{}
- // This c.ShouldBind consumes c.Request.Body and it cannot be reused.
- if errA := c.ShouldBind(&objA); errA == nil {
- c.String(http.StatusOK, `the body should be formA`)
- // Always an error is occurred by this because c.Request.Body is EOF now.
- } else if errB := c.ShouldBind(&objB); errB == nil {
- c.String(http.StatusOK, `the body should be formB`)
- } else {
- ...
- }
-}
-```
-
-For this, you can use `c.ShouldBindBodyWith`.
-
-```go
-func SomeHandler(c *gin.Context) {
- objA := formA{}
- objB := formB{}
- // This reads c.Request.Body and stores the result into the context.
- if errA := c.ShouldBindBodyWith(&objA, binding.JSON); errA == nil {
- c.String(http.StatusOK, `the body should be formA`)
- // At this time, it reuses body stored in the context.
- } else if errB := c.ShouldBindBodyWith(&objB, binding.JSON); errB == nil {
- c.String(http.StatusOK, `the body should be formB JSON`)
- // And it can accepts other formats
- } else if errB2 := c.ShouldBindBodyWith(&objB, binding.XML); errB2 == nil {
- c.String(http.StatusOK, `the body should be formB XML`)
- } else {
- ...
- }
-}
-```
-
-* `c.ShouldBindBodyWith` stores body into the context before binding. This has
-a slight impact to performance, so you should not use this method if you are
-enough to call binding at once.
-* This feature is only needed for some formats -- `JSON`, `XML`, `MsgPack`,
-`ProtoBuf`. For other formats, `Query`, `Form`, `FormPost`, `FormMultipart`,
-can be called by `c.ShouldBind()` multiple times without any damage to
-performance (See [#1341](https://github.com/gin-gonic/gin/pull/1341)).
-
-### http2 server push
-
-http.Pusher is supported only **go1.8+**. See the [golang blog](https://blog.golang.org/h2push) for detail information.
-
-[embedmd]:# (examples/http-pusher/main.go go)
-```go
-package main
-
-import (
- "html/template"
- "log"
-
- "github.com/gin-gonic/gin"
-)
-
-var html = template.Must(template.New("https").Parse(`
-
-
- Https Test
-
-
-
-
Welcome, Ginner!
-
-
-`))
-
-func main() {
- r := gin.Default()
- r.Static("/assets", "./assets")
- r.SetHTMLTemplate(html)
-
- r.GET("/", func(c *gin.Context) {
- if pusher := c.Writer.Pusher(); pusher != nil {
- // use pusher.Push() to do server push
- if err := pusher.Push("/assets/app.js", nil); err != nil {
- log.Printf("Failed to push: %v", err)
- }
- }
- c.HTML(200, "https", gin.H{
- "status": "success",
- })
- })
-
- // Listen and Server in https://127.0.0.1:8080
- r.RunTLS(":8080", "./testdata/server.pem", "./testdata/server.key")
-}
-```
-
-## Testing
-
-The `net/http/httptest` package is preferable way for HTTP testing.
-
-```go
-package main
-
-func setupRouter() *gin.Engine {
- r := gin.Default()
- r.GET("/ping", func(c *gin.Context) {
- c.String(200, "pong")
- })
- return r
-}
-
-func main() {
- r := setupRouter()
- r.Run(":8080")
-}
-```
-
-Test for code example above:
-
-```go
-package main
-
-import (
- "net/http"
- "net/http/httptest"
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestPingRoute(t *testing.T) {
- router := setupRouter()
-
- w := httptest.NewRecorder()
- req, _ := http.NewRequest("GET", "/ping", nil)
- router.ServeHTTP(w, req)
-
- assert.Equal(t, 200, w.Code)
- assert.Equal(t, "pong", w.Body.String())
-}
-```
-
-## Users
-
-Awesome project lists using [Gin](https://github.com/gin-gonic/gin) web framework.
-
-* [drone](https://github.com/drone/drone): Drone is a Continuous Delivery platform built on Docker, written in Go
-* [gorush](https://github.com/appleboy/gorush): A push notification server written in Go.
diff --git a/vendor/github.com/gin-gonic/gin/auth.go b/vendor/github.com/gin-gonic/gin/auth.go
deleted file mode 100644
index 9ed81b5..0000000
--- a/vendor/github.com/gin-gonic/gin/auth.go
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "crypto/subtle"
- "encoding/base64"
- "net/http"
- "strconv"
-)
-
-// AuthUserKey is the cookie name for user credential in basic auth.
-const AuthUserKey = "user"
-
-// Accounts defines a key/value for user/pass list of authorized logins.
-type Accounts map[string]string
-
-type authPair struct {
- value string
- user string
-}
-
-type authPairs []authPair
-
-func (a authPairs) searchCredential(authValue string) (string, bool) {
- if authValue == "" {
- return "", false
- }
- for _, pair := range a {
- if pair.value == authValue {
- return pair.user, true
- }
- }
- return "", false
-}
-
-// BasicAuthForRealm returns a Basic HTTP Authorization middleware. It takes as arguments a map[string]string where
-// the key is the user name and the value is the password, as well as the name of the Realm.
-// If the realm is empty, "Authorization Required" will be used by default.
-// (see http://tools.ietf.org/html/rfc2617#section-1.2)
-func BasicAuthForRealm(accounts Accounts, realm string) HandlerFunc {
- if realm == "" {
- realm = "Authorization Required"
- }
- realm = "Basic realm=" + strconv.Quote(realm)
- pairs := processAccounts(accounts)
- return func(c *Context) {
- // Search user in the slice of allowed credentials
- user, found := pairs.searchCredential(c.requestHeader("Authorization"))
- if !found {
- // Credentials doesn't match, we return 401 and abort handlers chain.
- c.Header("WWW-Authenticate", realm)
- c.AbortWithStatus(http.StatusUnauthorized)
- return
- }
-
- // The user credentials was found, set user's id to key AuthUserKey in this context, the user's id can be read later using
- // c.MustGet(gin.AuthUserKey).
- c.Set(AuthUserKey, user)
- }
-}
-
-// BasicAuth returns a Basic HTTP Authorization middleware. It takes as argument a map[string]string where
-// the key is the user name and the value is the password.
-func BasicAuth(accounts Accounts) HandlerFunc {
- return BasicAuthForRealm(accounts, "")
-}
-
-func processAccounts(accounts Accounts) authPairs {
- assert1(len(accounts) > 0, "Empty list of authorized credentials")
- pairs := make(authPairs, 0, len(accounts))
- for user, password := range accounts {
- assert1(user != "", "User can not be empty")
- value := authorizationHeader(user, password)
- pairs = append(pairs, authPair{
- value: value,
- user: user,
- })
- }
- return pairs
-}
-
-func authorizationHeader(user, password string) string {
- base := user + ":" + password
- return "Basic " + base64.StdEncoding.EncodeToString([]byte(base))
-}
-
-func secureCompare(given, actual string) bool {
- if subtle.ConstantTimeEq(int32(len(given)), int32(len(actual))) == 1 {
- return subtle.ConstantTimeCompare([]byte(given), []byte(actual)) == 1
- }
- // Securely compare actual to itself to keep constant time, but always return false.
- return subtle.ConstantTimeCompare([]byte(actual), []byte(actual)) == 1 && false
-}
diff --git a/vendor/github.com/gin-gonic/gin/binding/binding.go b/vendor/github.com/gin-gonic/gin/binding/binding.go
deleted file mode 100644
index 3a2aad9..0000000
--- a/vendor/github.com/gin-gonic/gin/binding/binding.go
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package binding
-
-import "net/http"
-
-// Content-Type MIME of the most common data formats.
-const (
- MIMEJSON = "application/json"
- MIMEHTML = "text/html"
- MIMEXML = "application/xml"
- MIMEXML2 = "text/xml"
- MIMEPlain = "text/plain"
- MIMEPOSTForm = "application/x-www-form-urlencoded"
- MIMEMultipartPOSTForm = "multipart/form-data"
- MIMEPROTOBUF = "application/x-protobuf"
- MIMEMSGPACK = "application/x-msgpack"
- MIMEMSGPACK2 = "application/msgpack"
-)
-
-// Binding describes the interface which needs to be implemented for binding the
-// data present in the request such as JSON request body, query parameters or
-// the form POST.
-type Binding interface {
- Name() string
- Bind(*http.Request, interface{}) error
-}
-
-// BindingBody adds BindBody method to Binding. BindBody is similar with Bind,
-// but it reads the body from supplied bytes instead of req.Body.
-type BindingBody interface {
- Binding
- BindBody([]byte, interface{}) error
-}
-
-// StructValidator is the minimal interface which needs to be implemented in
-// order for it to be used as the validator engine for ensuring the correctness
-// of the reqest. Gin provides a default implementation for this using
-// https://github.com/go-playground/validator/tree/v8.18.2.
-type StructValidator interface {
- // ValidateStruct can receive any kind of type and it should never panic, even if the configuration is not right.
- // If the received type is not a struct, any validation should be skipped and nil must be returned.
- // If the received type is a struct or pointer to a struct, the validation should be performed.
- // If the struct is not valid or the validation itself fails, a descriptive error should be returned.
- // Otherwise nil must be returned.
- ValidateStruct(interface{}) error
-
- // Engine returns the underlying validator engine which powers the
- // StructValidator implementation.
- Engine() interface{}
-}
-
-// Validator is the default validator which implements the StructValidator
-// interface. It uses https://github.com/go-playground/validator/tree/v8.18.2
-// under the hood.
-var Validator StructValidator = &defaultValidator{}
-
-// These implement the Binding interface and can be used to bind the data
-// present in the request to struct instances.
-var (
- JSON = jsonBinding{}
- XML = xmlBinding{}
- Form = formBinding{}
- Query = queryBinding{}
- FormPost = formPostBinding{}
- FormMultipart = formMultipartBinding{}
- ProtoBuf = protobufBinding{}
- MsgPack = msgpackBinding{}
-)
-
-// Default returns the appropriate Binding instance based on the HTTP method
-// and the content type.
-func Default(method, contentType string) Binding {
- if method == "GET" {
- return Form
- }
-
- switch contentType {
- case MIMEJSON:
- return JSON
- case MIMEXML, MIMEXML2:
- return XML
- case MIMEPROTOBUF:
- return ProtoBuf
- case MIMEMSGPACK, MIMEMSGPACK2:
- return MsgPack
- default: //case MIMEPOSTForm, MIMEMultipartPOSTForm:
- return Form
- }
-}
-
-func validate(obj interface{}) error {
- if Validator == nil {
- return nil
- }
- return Validator.ValidateStruct(obj)
-}
diff --git a/vendor/github.com/gin-gonic/gin/binding/default_validator.go b/vendor/github.com/gin-gonic/gin/binding/default_validator.go
deleted file mode 100644
index e7a302d..0000000
--- a/vendor/github.com/gin-gonic/gin/binding/default_validator.go
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package binding
-
-import (
- "reflect"
- "sync"
-
- "gopkg.in/go-playground/validator.v8"
-)
-
-type defaultValidator struct {
- once sync.Once
- validate *validator.Validate
-}
-
-var _ StructValidator = &defaultValidator{}
-
-// ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.
-func (v *defaultValidator) ValidateStruct(obj interface{}) error {
- value := reflect.ValueOf(obj)
- valueType := value.Kind()
- if valueType == reflect.Ptr {
- valueType = value.Elem().Kind()
- }
- if valueType == reflect.Struct {
- v.lazyinit()
- if err := v.validate.Struct(obj); err != nil {
- return err
- }
- }
- return nil
-}
-
-// Engine returns the underlying validator engine which powers the default
-// Validator instance. This is useful if you want to register custom validations
-// or struct level validations. See validator GoDoc for more info -
-// https://godoc.org/gopkg.in/go-playground/validator.v8
-func (v *defaultValidator) Engine() interface{} {
- v.lazyinit()
- return v.validate
-}
-
-func (v *defaultValidator) lazyinit() {
- v.once.Do(func() {
- config := &validator.Config{TagName: "binding"}
- v.validate = validator.New(config)
- })
-}
diff --git a/vendor/github.com/gin-gonic/gin/binding/form.go b/vendor/github.com/gin-gonic/gin/binding/form.go
deleted file mode 100644
index 0be5966..0000000
--- a/vendor/github.com/gin-gonic/gin/binding/form.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package binding
-
-import "net/http"
-
-const defaultMemory = 32 * 1024 * 1024
-
-type formBinding struct{}
-type formPostBinding struct{}
-type formMultipartBinding struct{}
-
-func (formBinding) Name() string {
- return "form"
-}
-
-func (formBinding) Bind(req *http.Request, obj interface{}) error {
- if err := req.ParseForm(); err != nil {
- return err
- }
- req.ParseMultipartForm(defaultMemory)
- if err := mapForm(obj, req.Form); err != nil {
- return err
- }
- return validate(obj)
-}
-
-func (formPostBinding) Name() string {
- return "form-urlencoded"
-}
-
-func (formPostBinding) Bind(req *http.Request, obj interface{}) error {
- if err := req.ParseForm(); err != nil {
- return err
- }
- if err := mapForm(obj, req.PostForm); err != nil {
- return err
- }
- return validate(obj)
-}
-
-func (formMultipartBinding) Name() string {
- return "multipart/form-data"
-}
-
-func (formMultipartBinding) Bind(req *http.Request, obj interface{}) error {
- if err := req.ParseMultipartForm(defaultMemory); err != nil {
- return err
- }
- if err := mapForm(obj, req.MultipartForm.Value); err != nil {
- return err
- }
- return validate(obj)
-}
diff --git a/vendor/github.com/gin-gonic/gin/binding/form_mapping.go b/vendor/github.com/gin-gonic/gin/binding/form_mapping.go
deleted file mode 100644
index 3f6b9bf..0000000
--- a/vendor/github.com/gin-gonic/gin/binding/form_mapping.go
+++ /dev/null
@@ -1,209 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package binding
-
-import (
- "errors"
- "reflect"
- "strconv"
- "strings"
- "time"
-)
-
-func mapForm(ptr interface{}, form map[string][]string) error {
- typ := reflect.TypeOf(ptr).Elem()
- val := reflect.ValueOf(ptr).Elem()
- for i := 0; i < typ.NumField(); i++ {
- typeField := typ.Field(i)
- structField := val.Field(i)
- if !structField.CanSet() {
- continue
- }
-
- structFieldKind := structField.Kind()
- inputFieldName := typeField.Tag.Get("form")
- inputFieldNameList := strings.Split(inputFieldName, ",")
- inputFieldName = inputFieldNameList[0]
- var defaultValue string
- if len(inputFieldNameList) > 1 {
- defaultList := strings.SplitN(inputFieldNameList[1], "=", 2)
- if defaultList[0] == "default" {
- defaultValue = defaultList[1]
- }
- }
- if inputFieldName == "" {
- inputFieldName = typeField.Name
-
- // if "form" tag is nil, we inspect if the field is a struct or struct pointer.
- // this would not make sense for JSON parsing but it does for a form
- // since data is flatten
- if structFieldKind == reflect.Ptr {
- if !structField.Elem().IsValid() {
- structField.Set(reflect.New(structField.Type().Elem()))
- }
- structField = structField.Elem()
- structFieldKind = structField.Kind()
- }
- if structFieldKind == reflect.Struct {
- err := mapForm(structField.Addr().Interface(), form)
- if err != nil {
- return err
- }
- continue
- }
- }
- inputValue, exists := form[inputFieldName]
-
- if !exists {
- if defaultValue == "" {
- continue
- }
- inputValue = make([]string, 1)
- inputValue[0] = defaultValue
- }
-
- numElems := len(inputValue)
- if structFieldKind == reflect.Slice && numElems > 0 {
- sliceOf := structField.Type().Elem().Kind()
- slice := reflect.MakeSlice(structField.Type(), numElems, numElems)
- for i := 0; i < numElems; i++ {
- if err := setWithProperType(sliceOf, inputValue[i], slice.Index(i)); err != nil {
- return err
- }
- }
- val.Field(i).Set(slice)
- } else {
- if _, isTime := structField.Interface().(time.Time); isTime {
- if err := setTimeField(inputValue[0], typeField, structField); err != nil {
- return err
- }
- continue
- }
- if err := setWithProperType(typeField.Type.Kind(), inputValue[0], structField); err != nil {
- return err
- }
- }
- }
- return nil
-}
-
-func setWithProperType(valueKind reflect.Kind, val string, structField reflect.Value) error {
- switch valueKind {
- case reflect.Int:
- return setIntField(val, 0, structField)
- case reflect.Int8:
- return setIntField(val, 8, structField)
- case reflect.Int16:
- return setIntField(val, 16, structField)
- case reflect.Int32:
- return setIntField(val, 32, structField)
- case reflect.Int64:
- return setIntField(val, 64, structField)
- case reflect.Uint:
- return setUintField(val, 0, structField)
- case reflect.Uint8:
- return setUintField(val, 8, structField)
- case reflect.Uint16:
- return setUintField(val, 16, structField)
- case reflect.Uint32:
- return setUintField(val, 32, structField)
- case reflect.Uint64:
- return setUintField(val, 64, structField)
- case reflect.Bool:
- return setBoolField(val, structField)
- case reflect.Float32:
- return setFloatField(val, 32, structField)
- case reflect.Float64:
- return setFloatField(val, 64, structField)
- case reflect.String:
- structField.SetString(val)
- case reflect.Ptr:
- if !structField.Elem().IsValid() {
- structField.Set(reflect.New(structField.Type().Elem()))
- }
- structFieldElem := structField.Elem()
- return setWithProperType(structFieldElem.Kind(), val, structFieldElem)
- default:
- return errors.New("Unknown type")
- }
- return nil
-}
-
-func setIntField(val string, bitSize int, field reflect.Value) error {
- if val == "" {
- val = "0"
- }
- intVal, err := strconv.ParseInt(val, 10, bitSize)
- if err == nil {
- field.SetInt(intVal)
- }
- return err
-}
-
-func setUintField(val string, bitSize int, field reflect.Value) error {
- if val == "" {
- val = "0"
- }
- uintVal, err := strconv.ParseUint(val, 10, bitSize)
- if err == nil {
- field.SetUint(uintVal)
- }
- return err
-}
-
-func setBoolField(val string, field reflect.Value) error {
- if val == "" {
- val = "false"
- }
- boolVal, err := strconv.ParseBool(val)
- if err == nil {
- field.SetBool(boolVal)
- }
- return err
-}
-
-func setFloatField(val string, bitSize int, field reflect.Value) error {
- if val == "" {
- val = "0.0"
- }
- floatVal, err := strconv.ParseFloat(val, bitSize)
- if err == nil {
- field.SetFloat(floatVal)
- }
- return err
-}
-
-func setTimeField(val string, structField reflect.StructField, value reflect.Value) error {
- timeFormat := structField.Tag.Get("time_format")
- if timeFormat == "" {
- return errors.New("Blank time format")
- }
-
- if val == "" {
- value.Set(reflect.ValueOf(time.Time{}))
- return nil
- }
-
- l := time.Local
- if isUTC, _ := strconv.ParseBool(structField.Tag.Get("time_utc")); isUTC {
- l = time.UTC
- }
-
- if locTag := structField.Tag.Get("time_location"); locTag != "" {
- loc, err := time.LoadLocation(locTag)
- if err != nil {
- return err
- }
- l = loc
- }
-
- t, err := time.ParseInLocation(timeFormat, val, l)
- if err != nil {
- return err
- }
-
- value.Set(reflect.ValueOf(t))
- return nil
-}
diff --git a/vendor/github.com/gin-gonic/gin/binding/json.go b/vendor/github.com/gin-gonic/gin/binding/json.go
deleted file mode 100644
index fea17bb..0000000
--- a/vendor/github.com/gin-gonic/gin/binding/json.go
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package binding
-
-import (
- "bytes"
- "io"
- "net/http"
-
- "github.com/gin-gonic/gin/json"
-)
-
-// EnableDecoderUseNumber is used to call the UseNumber method on the JSON
-// Decoder instance. UseNumber causes the Decoder to unmarshal a number into an
-// interface{} as a Number instead of as a float64.
-var EnableDecoderUseNumber = false
-
-type jsonBinding struct{}
-
-func (jsonBinding) Name() string {
- return "json"
-}
-
-func (jsonBinding) Bind(req *http.Request, obj interface{}) error {
- return decodeJSON(req.Body, obj)
-}
-
-func (jsonBinding) BindBody(body []byte, obj interface{}) error {
- return decodeJSON(bytes.NewReader(body), obj)
-}
-
-func decodeJSON(r io.Reader, obj interface{}) error {
- decoder := json.NewDecoder(r)
- if EnableDecoderUseNumber {
- decoder.UseNumber()
- }
- if err := decoder.Decode(obj); err != nil {
- return err
- }
- return validate(obj)
-}
diff --git a/vendor/github.com/gin-gonic/gin/binding/msgpack.go b/vendor/github.com/gin-gonic/gin/binding/msgpack.go
deleted file mode 100644
index b7f7319..0000000
--- a/vendor/github.com/gin-gonic/gin/binding/msgpack.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package binding
-
-import (
- "bytes"
- "io"
- "net/http"
-
- "github.com/ugorji/go/codec"
-)
-
-type msgpackBinding struct{}
-
-func (msgpackBinding) Name() string {
- return "msgpack"
-}
-
-func (msgpackBinding) Bind(req *http.Request, obj interface{}) error {
- return decodeMsgPack(req.Body, obj)
-}
-
-func (msgpackBinding) BindBody(body []byte, obj interface{}) error {
- return decodeMsgPack(bytes.NewReader(body), obj)
-}
-
-func decodeMsgPack(r io.Reader, obj interface{}) error {
- cdc := new(codec.MsgpackHandle)
- if err := codec.NewDecoder(r, cdc).Decode(&obj); err != nil {
- return err
- }
- return validate(obj)
-}
diff --git a/vendor/github.com/gin-gonic/gin/binding/protobuf.go b/vendor/github.com/gin-gonic/gin/binding/protobuf.go
deleted file mode 100644
index 540e9c1..0000000
--- a/vendor/github.com/gin-gonic/gin/binding/protobuf.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package binding
-
-import (
- "io/ioutil"
- "net/http"
-
- "github.com/golang/protobuf/proto"
-)
-
-type protobufBinding struct{}
-
-func (protobufBinding) Name() string {
- return "protobuf"
-}
-
-func (b protobufBinding) Bind(req *http.Request, obj interface{}) error {
- buf, err := ioutil.ReadAll(req.Body)
- if err != nil {
- return err
- }
- return b.BindBody(buf, obj)
-}
-
-func (protobufBinding) BindBody(body []byte, obj interface{}) error {
- if err := proto.Unmarshal(body, obj.(proto.Message)); err != nil {
- return err
- }
- // Here it's same to return validate(obj), but util now we cann't add
- // `binding:""` to the struct which automatically generate by gen-proto
- return nil
- // return validate(obj)
-}
diff --git a/vendor/github.com/gin-gonic/gin/binding/query.go b/vendor/github.com/gin-gonic/gin/binding/query.go
deleted file mode 100644
index 219743f..0000000
--- a/vendor/github.com/gin-gonic/gin/binding/query.go
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package binding
-
-import "net/http"
-
-type queryBinding struct{}
-
-func (queryBinding) Name() string {
- return "query"
-}
-
-func (queryBinding) Bind(req *http.Request, obj interface{}) error {
- values := req.URL.Query()
- if err := mapForm(obj, values); err != nil {
- return err
- }
- return validate(obj)
-}
diff --git a/vendor/github.com/gin-gonic/gin/binding/xml.go b/vendor/github.com/gin-gonic/gin/binding/xml.go
deleted file mode 100644
index 4e90114..0000000
--- a/vendor/github.com/gin-gonic/gin/binding/xml.go
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package binding
-
-import (
- "bytes"
- "encoding/xml"
- "io"
- "net/http"
-)
-
-type xmlBinding struct{}
-
-func (xmlBinding) Name() string {
- return "xml"
-}
-
-func (xmlBinding) Bind(req *http.Request, obj interface{}) error {
- return decodeXML(req.Body, obj)
-}
-
-func (xmlBinding) BindBody(body []byte, obj interface{}) error {
- return decodeXML(bytes.NewReader(body), obj)
-}
-func decodeXML(r io.Reader, obj interface{}) error {
- decoder := xml.NewDecoder(r)
- if err := decoder.Decode(obj); err != nil {
- return err
- }
- return validate(obj)
-}
diff --git a/vendor/github.com/gin-gonic/gin/codecov.yml b/vendor/github.com/gin-gonic/gin/codecov.yml
deleted file mode 100644
index c9c9a52..0000000
--- a/vendor/github.com/gin-gonic/gin/codecov.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-coverage:
- notify:
- gitter:
- default:
- url: https://webhooks.gitter.im/e/d90dcdeeab2f1e357165
diff --git a/vendor/github.com/gin-gonic/gin/context.go b/vendor/github.com/gin-gonic/gin/context.go
deleted file mode 100644
index 724ded7..0000000
--- a/vendor/github.com/gin-gonic/gin/context.go
+++ /dev/null
@@ -1,933 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "errors"
- "io"
- "io/ioutil"
- "math"
- "mime/multipart"
- "net"
- "net/http"
- "net/url"
- "os"
- "strings"
- "time"
-
- "github.com/gin-contrib/sse"
- "github.com/gin-gonic/gin/binding"
- "github.com/gin-gonic/gin/render"
-)
-
-// Content-Type MIME of the most common data formats.
-const (
- MIMEJSON = binding.MIMEJSON
- MIMEHTML = binding.MIMEHTML
- MIMEXML = binding.MIMEXML
- MIMEXML2 = binding.MIMEXML2
- MIMEPlain = binding.MIMEPlain
- MIMEPOSTForm = binding.MIMEPOSTForm
- MIMEMultipartPOSTForm = binding.MIMEMultipartPOSTForm
- BodyBytesKey = "_gin-gonic/gin/bodybyteskey"
-)
-
-const abortIndex int8 = math.MaxInt8 / 2
-
-// Context is the most important part of gin. It allows us to pass variables between middleware,
-// manage the flow, validate the JSON of a request and render a JSON response for example.
-type Context struct {
- writermem responseWriter
- Request *http.Request
- Writer ResponseWriter
-
- Params Params
- handlers HandlersChain
- index int8
-
- engine *Engine
-
- // Keys is a key/value pair exclusively for the context of each request.
- Keys map[string]interface{}
-
- // Errors is a list of errors attached to all the handlers/middlewares who used this context.
- Errors errorMsgs
-
- // Accepted defines a list of manually accepted formats for content negotiation.
- Accepted []string
-}
-
-/************************************/
-/********** CONTEXT CREATION ********/
-/************************************/
-
-func (c *Context) reset() {
- c.Writer = &c.writermem
- c.Params = c.Params[0:0]
- c.handlers = nil
- c.index = -1
- c.Keys = nil
- c.Errors = c.Errors[0:0]
- c.Accepted = nil
-}
-
-// Copy returns a copy of the current context that can be safely used outside the request's scope.
-// This has to be used when the context has to be passed to a goroutine.
-func (c *Context) Copy() *Context {
- var cp = *c
- cp.writermem.ResponseWriter = nil
- cp.Writer = &cp.writermem
- cp.index = abortIndex
- cp.handlers = nil
- return &cp
-}
-
-// HandlerName returns the main handler's name. For example if the handler is "handleGetUsers()",
-// this function will return "main.handleGetUsers".
-func (c *Context) HandlerName() string {
- return nameOfFunction(c.handlers.Last())
-}
-
-// Handler returns the main handler.
-func (c *Context) Handler() HandlerFunc {
- return c.handlers.Last()
-}
-
-/************************************/
-/*********** FLOW CONTROL ***********/
-/************************************/
-
-// Next should be used only inside middleware.
-// It executes the pending handlers in the chain inside the calling handler.
-// See example in GitHub.
-func (c *Context) Next() {
- c.index++
- for s := int8(len(c.handlers)); c.index < s; c.index++ {
- c.handlers[c.index](c)
- }
-}
-
-// IsAborted returns true if the current context was aborted.
-func (c *Context) IsAborted() bool {
- return c.index >= abortIndex
-}
-
-// Abort prevents pending handlers from being called. Note that this will not stop the current handler.
-// Let's say you have an authorization middleware that validates that the current request is authorized.
-// If the authorization fails (ex: the password does not match), call Abort to ensure the remaining handlers
-// for this request are not called.
-func (c *Context) Abort() {
- c.index = abortIndex
-}
-
-// AbortWithStatus calls `Abort()` and writes the headers with the specified status code.
-// For example, a failed attempt to authenticate a request could use: context.AbortWithStatus(401).
-func (c *Context) AbortWithStatus(code int) {
- c.Status(code)
- c.Writer.WriteHeaderNow()
- c.Abort()
-}
-
-// AbortWithStatusJSON calls `Abort()` and then `JSON` internally.
-// This method stops the chain, writes the status code and return a JSON body.
-// It also sets the Content-Type as "application/json".
-func (c *Context) AbortWithStatusJSON(code int, jsonObj interface{}) {
- c.Abort()
- c.JSON(code, jsonObj)
-}
-
-// AbortWithError calls `AbortWithStatus()` and `Error()` internally.
-// This method stops the chain, writes the status code and pushes the specified error to `c.Errors`.
-// See Context.Error() for more details.
-func (c *Context) AbortWithError(code int, err error) *Error {
- c.AbortWithStatus(code)
- return c.Error(err)
-}
-
-/************************************/
-/********* ERROR MANAGEMENT *********/
-/************************************/
-
-// Error attaches an error to the current context. The error is pushed to a list of errors.
-// It's a good idea to call Error for each error that occurred during the resolution of a request.
-// A middleware can be used to collect all the errors and push them to a database together,
-// print a log, or append it in the HTTP response.
-// Error will panic if err is nil.
-func (c *Context) Error(err error) *Error {
- if err == nil {
- panic("err is nil")
- }
-
- parsedError, ok := err.(*Error)
- if !ok {
- parsedError = &Error{
- Err: err,
- Type: ErrorTypePrivate,
- }
- }
-
- c.Errors = append(c.Errors, parsedError)
- return parsedError
-}
-
-/************************************/
-/******** METADATA MANAGEMENT********/
-/************************************/
-
-// Set is used to store a new key/value pair exclusively for this context.
-// It also lazy initializes c.Keys if it was not used previously.
-func (c *Context) Set(key string, value interface{}) {
- if c.Keys == nil {
- c.Keys = make(map[string]interface{})
- }
- c.Keys[key] = value
-}
-
-// Get returns the value for the given key, ie: (value, true).
-// If the value does not exists it returns (nil, false)
-func (c *Context) Get(key string) (value interface{}, exists bool) {
- value, exists = c.Keys[key]
- return
-}
-
-// MustGet returns the value for the given key if it exists, otherwise it panics.
-func (c *Context) MustGet(key string) interface{} {
- if value, exists := c.Get(key); exists {
- return value
- }
- panic("Key \"" + key + "\" does not exist")
-}
-
-// GetString returns the value associated with the key as a string.
-func (c *Context) GetString(key string) (s string) {
- if val, ok := c.Get(key); ok && val != nil {
- s, _ = val.(string)
- }
- return
-}
-
-// GetBool returns the value associated with the key as a boolean.
-func (c *Context) GetBool(key string) (b bool) {
- if val, ok := c.Get(key); ok && val != nil {
- b, _ = val.(bool)
- }
- return
-}
-
-// GetInt returns the value associated with the key as an integer.
-func (c *Context) GetInt(key string) (i int) {
- if val, ok := c.Get(key); ok && val != nil {
- i, _ = val.(int)
- }
- return
-}
-
-// GetInt64 returns the value associated with the key as an integer.
-func (c *Context) GetInt64(key string) (i64 int64) {
- if val, ok := c.Get(key); ok && val != nil {
- i64, _ = val.(int64)
- }
- return
-}
-
-// GetFloat64 returns the value associated with the key as a float64.
-func (c *Context) GetFloat64(key string) (f64 float64) {
- if val, ok := c.Get(key); ok && val != nil {
- f64, _ = val.(float64)
- }
- return
-}
-
-// GetTime returns the value associated with the key as time.
-func (c *Context) GetTime(key string) (t time.Time) {
- if val, ok := c.Get(key); ok && val != nil {
- t, _ = val.(time.Time)
- }
- return
-}
-
-// GetDuration returns the value associated with the key as a duration.
-func (c *Context) GetDuration(key string) (d time.Duration) {
- if val, ok := c.Get(key); ok && val != nil {
- d, _ = val.(time.Duration)
- }
- return
-}
-
-// GetStringSlice returns the value associated with the key as a slice of strings.
-func (c *Context) GetStringSlice(key string) (ss []string) {
- if val, ok := c.Get(key); ok && val != nil {
- ss, _ = val.([]string)
- }
- return
-}
-
-// GetStringMap returns the value associated with the key as a map of interfaces.
-func (c *Context) GetStringMap(key string) (sm map[string]interface{}) {
- if val, ok := c.Get(key); ok && val != nil {
- sm, _ = val.(map[string]interface{})
- }
- return
-}
-
-// GetStringMapString returns the value associated with the key as a map of strings.
-func (c *Context) GetStringMapString(key string) (sms map[string]string) {
- if val, ok := c.Get(key); ok && val != nil {
- sms, _ = val.(map[string]string)
- }
- return
-}
-
-// GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
-func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string) {
- if val, ok := c.Get(key); ok && val != nil {
- smss, _ = val.(map[string][]string)
- }
- return
-}
-
-/************************************/
-/************ INPUT DATA ************/
-/************************************/
-
-// Param returns the value of the URL param.
-// It is a shortcut for c.Params.ByName(key)
-// router.GET("/user/:id", func(c *gin.Context) {
-// // a GET request to /user/john
-// id := c.Param("id") // id == "john"
-// })
-func (c *Context) Param(key string) string {
- return c.Params.ByName(key)
-}
-
-// Query returns the keyed url query value if it exists,
-// otherwise it returns an empty string `("")`.
-// It is shortcut for `c.Request.URL.Query().Get(key)`
-// GET /path?id=1234&name=Manu&value=
-// c.Query("id") == "1234"
-// c.Query("name") == "Manu"
-// c.Query("value") == ""
-// c.Query("wtf") == ""
-func (c *Context) Query(key string) string {
- value, _ := c.GetQuery(key)
- return value
-}
-
-// DefaultQuery returns the keyed url query value if it exists,
-// otherwise it returns the specified defaultValue string.
-// See: Query() and GetQuery() for further information.
-// GET /?name=Manu&lastname=
-// c.DefaultQuery("name", "unknown") == "Manu"
-// c.DefaultQuery("id", "none") == "none"
-// c.DefaultQuery("lastname", "none") == ""
-func (c *Context) DefaultQuery(key, defaultValue string) string {
- if value, ok := c.GetQuery(key); ok {
- return value
- }
- return defaultValue
-}
-
-// GetQuery is like Query(), it returns the keyed url query value
-// if it exists `(value, true)` (even when the value is an empty string),
-// otherwise it returns `("", false)`.
-// It is shortcut for `c.Request.URL.Query().Get(key)`
-// GET /?name=Manu&lastname=
-// ("Manu", true) == c.GetQuery("name")
-// ("", false) == c.GetQuery("id")
-// ("", true) == c.GetQuery("lastname")
-func (c *Context) GetQuery(key string) (string, bool) {
- if values, ok := c.GetQueryArray(key); ok {
- return values[0], ok
- }
- return "", false
-}
-
-// QueryArray returns a slice of strings for a given query key.
-// The length of the slice depends on the number of params with the given key.
-func (c *Context) QueryArray(key string) []string {
- values, _ := c.GetQueryArray(key)
- return values
-}
-
-// GetQueryArray returns a slice of strings for a given query key, plus
-// a boolean value whether at least one value exists for the given key.
-func (c *Context) GetQueryArray(key string) ([]string, bool) {
- if values, ok := c.Request.URL.Query()[key]; ok && len(values) > 0 {
- return values, true
- }
- return []string{}, false
-}
-
-// QueryMap returns a map for a given query key.
-func (c *Context) QueryMap(key string) map[string]string {
- dicts, _ := c.GetQueryMap(key)
- return dicts
-}
-
-// GetQueryMap returns a map for a given query key, plus a boolean value
-// whether at least one value exists for the given key.
-func (c *Context) GetQueryMap(key string) (map[string]string, bool) {
- return c.get(c.Request.URL.Query(), key)
-}
-
-// PostForm returns the specified key from a POST urlencoded form or multipart form
-// when it exists, otherwise it returns an empty string `("")`.
-func (c *Context) PostForm(key string) string {
- value, _ := c.GetPostForm(key)
- return value
-}
-
-// DefaultPostForm returns the specified key from a POST urlencoded form or multipart form
-// when it exists, otherwise it returns the specified defaultValue string.
-// See: PostForm() and GetPostForm() for further information.
-func (c *Context) DefaultPostForm(key, defaultValue string) string {
- if value, ok := c.GetPostForm(key); ok {
- return value
- }
- return defaultValue
-}
-
-// GetPostForm is like PostForm(key). It returns the specified key from a POST urlencoded
-// form or multipart form when it exists `(value, true)` (even when the value is an empty string),
-// otherwise it returns ("", false).
-// For example, during a PATCH request to update the user's email:
-// email=mail@example.com --> ("mail@example.com", true) := GetPostForm("email") // set email to "mail@example.com"
-// email= --> ("", true) := GetPostForm("email") // set email to ""
-// --> ("", false) := GetPostForm("email") // do nothing with email
-func (c *Context) GetPostForm(key string) (string, bool) {
- if values, ok := c.GetPostFormArray(key); ok {
- return values[0], ok
- }
- return "", false
-}
-
-// PostFormArray returns a slice of strings for a given form key.
-// The length of the slice depends on the number of params with the given key.
-func (c *Context) PostFormArray(key string) []string {
- values, _ := c.GetPostFormArray(key)
- return values
-}
-
-// GetPostFormArray returns a slice of strings for a given form key, plus
-// a boolean value whether at least one value exists for the given key.
-func (c *Context) GetPostFormArray(key string) ([]string, bool) {
- req := c.Request
- req.ParseForm()
- req.ParseMultipartForm(c.engine.MaxMultipartMemory)
- if values := req.PostForm[key]; len(values) > 0 {
- return values, true
- }
- if req.MultipartForm != nil && req.MultipartForm.File != nil {
- if values := req.MultipartForm.Value[key]; len(values) > 0 {
- return values, true
- }
- }
- return []string{}, false
-}
-
-// PostFormMap returns a map for a given form key.
-func (c *Context) PostFormMap(key string) map[string]string {
- dicts, _ := c.GetPostFormMap(key)
- return dicts
-}
-
-// GetPostFormMap returns a map for a given form key, plus a boolean value
-// whether at least one value exists for the given key.
-func (c *Context) GetPostFormMap(key string) (map[string]string, bool) {
- req := c.Request
- req.ParseForm()
- req.ParseMultipartForm(c.engine.MaxMultipartMemory)
- dicts, exist := c.get(req.PostForm, key)
-
- if !exist && req.MultipartForm != nil && req.MultipartForm.File != nil {
- dicts, exist = c.get(req.MultipartForm.Value, key)
- }
-
- return dicts, exist
-}
-
-// get is an internal method and returns a map which satisfy conditions.
-func (c *Context) get(m map[string][]string, key string) (map[string]string, bool) {
- dicts := make(map[string]string)
- exist := false
- for k, v := range m {
- if i := strings.IndexByte(k, '['); i >= 1 && k[0:i] == key {
- if j := strings.IndexByte(k[i+1:], ']'); j >= 1 {
- exist = true
- dicts[k[i+1:][:j]] = v[0]
- }
- }
- }
- return dicts, exist
-}
-
-// FormFile returns the first file for the provided form key.
-func (c *Context) FormFile(name string) (*multipart.FileHeader, error) {
- _, fh, err := c.Request.FormFile(name)
- return fh, err
-}
-
-// MultipartForm is the parsed multipart form, including file uploads.
-func (c *Context) MultipartForm() (*multipart.Form, error) {
- err := c.Request.ParseMultipartForm(c.engine.MaxMultipartMemory)
- return c.Request.MultipartForm, err
-}
-
-// SaveUploadedFile uploads the form file to specific dst.
-func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string) error {
- src, err := file.Open()
- if err != nil {
- return err
- }
- defer src.Close()
-
- out, err := os.Create(dst)
- if err != nil {
- return err
- }
- defer out.Close()
-
- io.Copy(out, src)
- return nil
-}
-
-// Bind checks the Content-Type to select a binding engine automatically,
-// Depending the "Content-Type" header different bindings are used:
-// "application/json" --> JSON binding
-// "application/xml" --> XML binding
-// otherwise --> returns an error.
-// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input.
-// It decodes the json payload into the struct specified as a pointer.
-// It writes a 400 error and sets Content-Type header "text/plain" in the response if input is not valid.
-func (c *Context) Bind(obj interface{}) error {
- b := binding.Default(c.Request.Method, c.ContentType())
- return c.MustBindWith(obj, b)
-}
-
-// BindJSON is a shortcut for c.MustBindWith(obj, binding.JSON).
-func (c *Context) BindJSON(obj interface{}) error {
- return c.MustBindWith(obj, binding.JSON)
-}
-
-// BindQuery is a shortcut for c.MustBindWith(obj, binding.Query).
-func (c *Context) BindQuery(obj interface{}) error {
- return c.MustBindWith(obj, binding.Query)
-}
-
-// MustBindWith binds the passed struct pointer using the specified binding engine.
-// It will abort the request with HTTP 400 if any error ocurrs.
-// See the binding package.
-func (c *Context) MustBindWith(obj interface{}, b binding.Binding) (err error) {
- if err = c.ShouldBindWith(obj, b); err != nil {
- c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind)
- }
-
- return
-}
-
-// ShouldBind checks the Content-Type to select a binding engine automatically,
-// Depending the "Content-Type" header different bindings are used:
-// "application/json" --> JSON binding
-// "application/xml" --> XML binding
-// otherwise --> returns an error
-// It parses the request's body as JSON if Content-Type == "application/json" using JSON or XML as a JSON input.
-// It decodes the json payload into the struct specified as a pointer.
-// Like c.Bind() but this method does not set the response status code to 400 and abort if the json is not valid.
-func (c *Context) ShouldBind(obj interface{}) error {
- b := binding.Default(c.Request.Method, c.ContentType())
- return c.ShouldBindWith(obj, b)
-}
-
-// ShouldBindJSON is a shortcut for c.ShouldBindWith(obj, binding.JSON).
-func (c *Context) ShouldBindJSON(obj interface{}) error {
- return c.ShouldBindWith(obj, binding.JSON)
-}
-
-// ShouldBindQuery is a shortcut for c.ShouldBindWith(obj, binding.Query).
-func (c *Context) ShouldBindQuery(obj interface{}) error {
- return c.ShouldBindWith(obj, binding.Query)
-}
-
-// ShouldBindWith binds the passed struct pointer using the specified binding engine.
-// See the binding package.
-func (c *Context) ShouldBindWith(obj interface{}, b binding.Binding) error {
- return b.Bind(c.Request, obj)
-}
-
-// ShouldBindBodyWith is similar with ShouldBindWith, but it stores the request
-// body into the context, and reuse when it is called again.
-//
-// NOTE: This method reads the body before binding. So you should use
-// ShouldBindWith for better performance if you need to call only once.
-func (c *Context) ShouldBindBodyWith(
- obj interface{}, bb binding.BindingBody,
-) (err error) {
- var body []byte
- if cb, ok := c.Get(BodyBytesKey); ok {
- if cbb, ok := cb.([]byte); ok {
- body = cbb
- }
- }
- if body == nil {
- body, err = ioutil.ReadAll(c.Request.Body)
- if err != nil {
- return err
- }
- c.Set(BodyBytesKey, body)
- }
- return bb.BindBody(body, obj)
-}
-
-// ClientIP implements a best effort algorithm to return the real client IP, it parses
-// X-Real-IP and X-Forwarded-For in order to work properly with reverse-proxies such us: nginx or haproxy.
-// Use X-Forwarded-For before X-Real-Ip as nginx uses X-Real-Ip with the proxy's IP.
-func (c *Context) ClientIP() string {
- if c.engine.ForwardedByClientIP {
- clientIP := c.requestHeader("X-Forwarded-For")
- clientIP = strings.TrimSpace(strings.Split(clientIP, ",")[0])
- if clientIP == "" {
- clientIP = strings.TrimSpace(c.requestHeader("X-Real-Ip"))
- }
- if clientIP != "" {
- return clientIP
- }
- }
-
- if c.engine.AppEngine {
- if addr := c.requestHeader("X-Appengine-Remote-Addr"); addr != "" {
- return addr
- }
- }
-
- if ip, _, err := net.SplitHostPort(strings.TrimSpace(c.Request.RemoteAddr)); err == nil {
- return ip
- }
-
- return ""
-}
-
-// ContentType returns the Content-Type header of the request.
-func (c *Context) ContentType() string {
- return filterFlags(c.requestHeader("Content-Type"))
-}
-
-// IsWebsocket returns true if the request headers indicate that a websocket
-// handshake is being initiated by the client.
-func (c *Context) IsWebsocket() bool {
- if strings.Contains(strings.ToLower(c.requestHeader("Connection")), "upgrade") &&
- strings.ToLower(c.requestHeader("Upgrade")) == "websocket" {
- return true
- }
- return false
-}
-
-func (c *Context) requestHeader(key string) string {
- return c.Request.Header.Get(key)
-}
-
-/************************************/
-/******** RESPONSE RENDERING ********/
-/************************************/
-
-// bodyAllowedForStatus is a copy of http.bodyAllowedForStatus non-exported function.
-func bodyAllowedForStatus(status int) bool {
- switch {
- case status >= 100 && status <= 199:
- return false
- case status == http.StatusNoContent:
- return false
- case status == http.StatusNotModified:
- return false
- }
- return true
-}
-
-// Status sets the HTTP response code.
-func (c *Context) Status(code int) {
- c.writermem.WriteHeader(code)
-}
-
-// Header is a intelligent shortcut for c.Writer.Header().Set(key, value).
-// It writes a header in the response.
-// If value == "", this method removes the header `c.Writer.Header().Del(key)`
-func (c *Context) Header(key, value string) {
- if value == "" {
- c.Writer.Header().Del(key)
- } else {
- c.Writer.Header().Set(key, value)
- }
-}
-
-// GetHeader returns value from request headers.
-func (c *Context) GetHeader(key string) string {
- return c.requestHeader(key)
-}
-
-// GetRawData return stream data.
-func (c *Context) GetRawData() ([]byte, error) {
- return ioutil.ReadAll(c.Request.Body)
-}
-
-// SetCookie adds a Set-Cookie header to the ResponseWriter's headers.
-// The provided cookie must have a valid Name. Invalid cookies may be
-// silently dropped.
-func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool) {
- if path == "" {
- path = "/"
- }
- http.SetCookie(c.Writer, &http.Cookie{
- Name: name,
- Value: url.QueryEscape(value),
- MaxAge: maxAge,
- Path: path,
- Domain: domain,
- Secure: secure,
- HttpOnly: httpOnly,
- })
-}
-
-// Cookie returns the named cookie provided in the request or
-// ErrNoCookie if not found. And return the named cookie is unescaped.
-// If multiple cookies match the given name, only one cookie will
-// be returned.
-func (c *Context) Cookie(name string) (string, error) {
- cookie, err := c.Request.Cookie(name)
- if err != nil {
- return "", err
- }
- val, _ := url.QueryUnescape(cookie.Value)
- return val, nil
-}
-
-func (c *Context) Render(code int, r render.Render) {
- c.Status(code)
-
- if !bodyAllowedForStatus(code) {
- r.WriteContentType(c.Writer)
- c.Writer.WriteHeaderNow()
- return
- }
-
- if err := r.Render(c.Writer); err != nil {
- panic(err)
- }
-}
-
-// HTML renders the HTTP template specified by its file name.
-// It also updates the HTTP code and sets the Content-Type as "text/html".
-// See http://golang.org/doc/articles/wiki/
-func (c *Context) HTML(code int, name string, obj interface{}) {
- instance := c.engine.HTMLRender.Instance(name, obj)
- c.Render(code, instance)
-}
-
-// IndentedJSON serializes the given struct as pretty JSON (indented + endlines) into the response body.
-// It also sets the Content-Type as "application/json".
-// WARNING: we recommend to use this only for development purposes since printing pretty JSON is
-// more CPU and bandwidth consuming. Use Context.JSON() instead.
-func (c *Context) IndentedJSON(code int, obj interface{}) {
- c.Render(code, render.IndentedJSON{Data: obj})
-}
-
-// SecureJSON serializes the given struct as Secure JSON into the response body.
-// Default prepends "while(1)," to response body if the given struct is array values.
-// It also sets the Content-Type as "application/json".
-func (c *Context) SecureJSON(code int, obj interface{}) {
- c.Render(code, render.SecureJSON{Prefix: c.engine.secureJsonPrefix, Data: obj})
-}
-
-// JSONP serializes the given struct as JSON into the response body.
-// It add padding to response body to request data from a server residing in a different domain than the client.
-// It also sets the Content-Type as "application/javascript".
-func (c *Context) JSONP(code int, obj interface{}) {
- callback := c.DefaultQuery("callback", "")
- if callback == "" {
- c.Render(code, render.JSON{Data: obj})
- } else {
- c.Render(code, render.JsonpJSON{Callback: callback, Data: obj})
- }
-}
-
-// JSON serializes the given struct as JSON into the response body.
-// It also sets the Content-Type as "application/json".
-func (c *Context) JSON(code int, obj interface{}) {
- c.Render(code, render.JSON{Data: obj})
-}
-
-// AsciiJSON serializes the given struct as JSON into the response body with unicode to ASCII string.
-// It also sets the Content-Type as "application/json".
-func (c *Context) AsciiJSON(code int, obj interface{}) {
- c.Render(code, render.AsciiJSON{Data: obj})
-}
-
-// XML serializes the given struct as XML into the response body.
-// It also sets the Content-Type as "application/xml".
-func (c *Context) XML(code int, obj interface{}) {
- c.Render(code, render.XML{Data: obj})
-}
-
-// YAML serializes the given struct as YAML into the response body.
-func (c *Context) YAML(code int, obj interface{}) {
- c.Render(code, render.YAML{Data: obj})
-}
-
-// String writes the given string into the response body.
-func (c *Context) String(code int, format string, values ...interface{}) {
- c.Render(code, render.String{Format: format, Data: values})
-}
-
-// Redirect returns a HTTP redirect to the specific location.
-func (c *Context) Redirect(code int, location string) {
- c.Render(-1, render.Redirect{
- Code: code,
- Location: location,
- Request: c.Request,
- })
-}
-
-// Data writes some data into the body stream and updates the HTTP code.
-func (c *Context) Data(code int, contentType string, data []byte) {
- c.Render(code, render.Data{
- ContentType: contentType,
- Data: data,
- })
-}
-
-// DataFromReader writes the specified reader into the body stream and updates the HTTP code.
-func (c *Context) DataFromReader(code int, contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string) {
- c.Render(code, render.Reader{
- Headers: extraHeaders,
- ContentType: contentType,
- ContentLength: contentLength,
- Reader: reader,
- })
-}
-
-// File writes the specified file into the body stream in a efficient way.
-func (c *Context) File(filepath string) {
- http.ServeFile(c.Writer, c.Request, filepath)
-}
-
-// SSEvent writes a Server-Sent Event into the body stream.
-func (c *Context) SSEvent(name string, message interface{}) {
- c.Render(-1, sse.Event{
- Event: name,
- Data: message,
- })
-}
-
-func (c *Context) Stream(step func(w io.Writer) bool) {
- w := c.Writer
- clientGone := w.CloseNotify()
- for {
- select {
- case <-clientGone:
- return
- default:
- keepOpen := step(w)
- w.Flush()
- if !keepOpen {
- return
- }
- }
- }
-}
-
-/************************************/
-/******** CONTENT NEGOTIATION *******/
-/************************************/
-
-type Negotiate struct {
- Offered []string
- HTMLName string
- HTMLData interface{}
- JSONData interface{}
- XMLData interface{}
- Data interface{}
-}
-
-func (c *Context) Negotiate(code int, config Negotiate) {
- switch c.NegotiateFormat(config.Offered...) {
- case binding.MIMEJSON:
- data := chooseData(config.JSONData, config.Data)
- c.JSON(code, data)
-
- case binding.MIMEHTML:
- data := chooseData(config.HTMLData, config.Data)
- c.HTML(code, config.HTMLName, data)
-
- case binding.MIMEXML:
- data := chooseData(config.XMLData, config.Data)
- c.XML(code, data)
-
- default:
- c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server"))
- }
-}
-
-func (c *Context) NegotiateFormat(offered ...string) string {
- assert1(len(offered) > 0, "you must provide at least one offer")
-
- if c.Accepted == nil {
- c.Accepted = parseAccept(c.requestHeader("Accept"))
- }
- if len(c.Accepted) == 0 {
- return offered[0]
- }
- for _, accepted := range c.Accepted {
- for _, offert := range offered {
- if accepted == offert {
- return offert
- }
- }
- }
- return ""
-}
-
-func (c *Context) SetAccepted(formats ...string) {
- c.Accepted = formats
-}
-
-/************************************/
-/***** GOLANG.ORG/X/NET/CONTEXT *****/
-/************************************/
-
-// Deadline returns the time when work done on behalf of this context
-// should be canceled. Deadline returns ok==false when no deadline is
-// set. Successive calls to Deadline return the same results.
-func (c *Context) Deadline() (deadline time.Time, ok bool) {
- return
-}
-
-// Done returns a channel that's closed when work done on behalf of this
-// context should be canceled. Done may return nil if this context can
-// never be canceled. Successive calls to Done return the same value.
-func (c *Context) Done() <-chan struct{} {
- return nil
-}
-
-// Err returns a non-nil error value after Done is closed,
-// successive calls to Err return the same error.
-// If Done is not yet closed, Err returns nil.
-// If Done is closed, Err returns a non-nil error explaining why:
-// Canceled if the context was canceled
-// or DeadlineExceeded if the context's deadline passed.
-func (c *Context) Err() error {
- return nil
-}
-
-// Value returns the value associated with this context for key, or nil
-// if no value is associated with key. Successive calls to Value with
-// the same key returns the same result.
-func (c *Context) Value(key interface{}) interface{} {
- if key == 0 {
- return c.Request
- }
- if keyAsString, ok := key.(string); ok {
- val, _ := c.Get(keyAsString)
- return val
- }
- return nil
-}
diff --git a/vendor/github.com/gin-gonic/gin/context_appengine.go b/vendor/github.com/gin-gonic/gin/context_appengine.go
deleted file mode 100644
index 38c189a..0000000
--- a/vendor/github.com/gin-gonic/gin/context_appengine.go
+++ /dev/null
@@ -1,11 +0,0 @@
-// +build appengine
-
-// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-func init() {
- defaultAppEngine = true
-}
diff --git a/vendor/github.com/gin-gonic/gin/coverage.sh b/vendor/github.com/gin-gonic/gin/coverage.sh
deleted file mode 100644
index 4d1ee03..0000000
--- a/vendor/github.com/gin-gonic/gin/coverage.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-echo "mode: count" > coverage.out
-
-for d in $(go list ./... | grep -E 'gin$|binding$|render$' | grep -v 'examples'); do
- go test -v -covermode=count -coverprofile=profile.out $d
- if [ -f profile.out ]; then
- cat profile.out | grep -v "mode:" >> coverage.out
- rm profile.out
- fi
-done
diff --git a/vendor/github.com/gin-gonic/gin/debug.go b/vendor/github.com/gin-gonic/gin/debug.go
deleted file mode 100644
index f11156b..0000000
--- a/vendor/github.com/gin-gonic/gin/debug.go
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "bytes"
- "html/template"
- "log"
-)
-
-func init() {
- log.SetFlags(0)
-}
-
-// IsDebugging returns true if the framework is running in debug mode.
-// Use SetMode(gin.ReleaseMode) to disable debug mode.
-func IsDebugging() bool {
- return ginMode == debugCode
-}
-
-func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
- if IsDebugging() {
- nuHandlers := len(handlers)
- handlerName := nameOfFunction(handlers.Last())
- debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
- }
-}
-
-func debugPrintLoadTemplate(tmpl *template.Template) {
- if IsDebugging() {
- var buf bytes.Buffer
- for _, tmpl := range tmpl.Templates() {
- buf.WriteString("\t- ")
- buf.WriteString(tmpl.Name())
- buf.WriteString("\n")
- }
- debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())
- }
-}
-
-func debugPrint(format string, values ...interface{}) {
- if IsDebugging() {
- log.Printf("[GIN-debug] "+format, values...)
- }
-}
-
-func debugPrintWARNINGDefault() {
- debugPrint(`[WARNING] Now Gin requires Go 1.6 or later and Go 1.7 will be required soon.
-
-`)
- debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
-
-`)
-}
-
-func debugPrintWARNINGNew() {
- debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.
- - using env: export GIN_MODE=release
- - using code: gin.SetMode(gin.ReleaseMode)
-
-`)
-}
-
-func debugPrintWARNINGSetHTMLTemplate() {
- debugPrint(`[WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called
-at initialization. ie. before any route is registered or the router is listening in a socket:
-
- router := gin.Default()
- router.SetHTMLTemplate(template) // << good place
-
-`)
-}
-
-func debugPrintError(err error) {
- if err != nil {
- debugPrint("[ERROR] %v\n", err)
- }
-}
diff --git a/vendor/github.com/gin-gonic/gin/deprecated.go b/vendor/github.com/gin-gonic/gin/deprecated.go
deleted file mode 100644
index ab44742..0000000
--- a/vendor/github.com/gin-gonic/gin/deprecated.go
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "log"
-
- "github.com/gin-gonic/gin/binding"
-)
-
-// BindWith binds the passed struct pointer using the specified binding engine.
-// See the binding package.
-func (c *Context) BindWith(obj interface{}, b binding.Binding) error {
- log.Println(`BindWith(\"interface{}, binding.Binding\") error is going to
- be deprecated, please check issue #662 and either use MustBindWith() if you
- want HTTP 400 to be automatically returned if any error occur, or use
- ShouldBindWith() if you need to manage the error.`)
- return c.MustBindWith(obj, b)
-}
diff --git a/vendor/github.com/gin-gonic/gin/doc.go b/vendor/github.com/gin-gonic/gin/doc.go
deleted file mode 100644
index 01ac4a9..0000000
--- a/vendor/github.com/gin-gonic/gin/doc.go
+++ /dev/null
@@ -1,6 +0,0 @@
-/*
-Package gin implements a HTTP web framework called gin.
-
-See https://gin-gonic.github.io/gin/ for more information about gin.
-*/
-package gin // import "github.com/gin-gonic/gin"
diff --git a/vendor/github.com/gin-gonic/gin/errors.go b/vendor/github.com/gin-gonic/gin/errors.go
deleted file mode 100644
index dbfccd8..0000000
--- a/vendor/github.com/gin-gonic/gin/errors.go
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "bytes"
- "fmt"
- "reflect"
-
- "github.com/gin-gonic/gin/json"
-)
-
-type ErrorType uint64
-
-const (
- ErrorTypeBind ErrorType = 1 << 63 // used when c.Bind() fails
- ErrorTypeRender ErrorType = 1 << 62 // used when c.Render() fails
- ErrorTypePrivate ErrorType = 1 << 0
- ErrorTypePublic ErrorType = 1 << 1
-
- ErrorTypeAny ErrorType = 1<<64 - 1
- ErrorTypeNu = 2
-)
-
-type Error struct {
- Err error
- Type ErrorType
- Meta interface{}
-}
-
-type errorMsgs []*Error
-
-var _ error = &Error{}
-
-func (msg *Error) SetType(flags ErrorType) *Error {
- msg.Type = flags
- return msg
-}
-
-func (msg *Error) SetMeta(data interface{}) *Error {
- msg.Meta = data
- return msg
-}
-
-func (msg *Error) JSON() interface{} {
- json := H{}
- if msg.Meta != nil {
- value := reflect.ValueOf(msg.Meta)
- switch value.Kind() {
- case reflect.Struct:
- return msg.Meta
- case reflect.Map:
- for _, key := range value.MapKeys() {
- json[key.String()] = value.MapIndex(key).Interface()
- }
- default:
- json["meta"] = msg.Meta
- }
- }
- if _, ok := json["error"]; !ok {
- json["error"] = msg.Error()
- }
- return json
-}
-
-// MarshalJSON implements the json.Marshaller interface.
-func (msg *Error) MarshalJSON() ([]byte, error) {
- return json.Marshal(msg.JSON())
-}
-
-// Error implements the error interface
-func (msg Error) Error() string {
- return msg.Err.Error()
-}
-
-func (msg *Error) IsType(flags ErrorType) bool {
- return (msg.Type & flags) > 0
-}
-
-// ByType returns a readonly copy filtered the byte.
-// ie ByType(gin.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic.
-func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
- if len(a) == 0 {
- return nil
- }
- if typ == ErrorTypeAny {
- return a
- }
- var result errorMsgs
- for _, msg := range a {
- if msg.IsType(typ) {
- result = append(result, msg)
- }
- }
- return result
-}
-
-// Last returns the last error in the slice. It returns nil if the array is empty.
-// Shortcut for errors[len(errors)-1].
-func (a errorMsgs) Last() *Error {
- if length := len(a); length > 0 {
- return a[length-1]
- }
- return nil
-}
-
-// Errors returns an array will all the error messages.
-// Example:
-// c.Error(errors.New("first"))
-// c.Error(errors.New("second"))
-// c.Error(errors.New("third"))
-// c.Errors.Errors() // == []string{"first", "second", "third"}
-func (a errorMsgs) Errors() []string {
- if len(a) == 0 {
- return nil
- }
- errorStrings := make([]string, len(a))
- for i, err := range a {
- errorStrings[i] = err.Error()
- }
- return errorStrings
-}
-
-func (a errorMsgs) JSON() interface{} {
- switch len(a) {
- case 0:
- return nil
- case 1:
- return a.Last().JSON()
- default:
- json := make([]interface{}, len(a))
- for i, err := range a {
- json[i] = err.JSON()
- }
- return json
- }
-}
-
-func (a errorMsgs) MarshalJSON() ([]byte, error) {
- return json.Marshal(a.JSON())
-}
-
-func (a errorMsgs) String() string {
- if len(a) == 0 {
- return ""
- }
- var buffer bytes.Buffer
- for i, msg := range a {
- fmt.Fprintf(&buffer, "Error #%02d: %s\n", i+1, msg.Err)
- if msg.Meta != nil {
- fmt.Fprintf(&buffer, " Meta: %v\n", msg.Meta)
- }
- }
- return buffer.String()
-}
diff --git a/vendor/github.com/gin-gonic/gin/fs.go b/vendor/github.com/gin-gonic/gin/fs.go
deleted file mode 100644
index 7a6738a..0000000
--- a/vendor/github.com/gin-gonic/gin/fs.go
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "net/http"
- "os"
-)
-
-type onlyfilesFS struct {
- fs http.FileSystem
-}
-
-type neuteredReaddirFile struct {
- http.File
-}
-
-// Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally
-// in router.Static().
-// if listDirectory == true, then it works the same as http.Dir() otherwise it returns
-// a filesystem that prevents http.FileServer() to list the directory files.
-func Dir(root string, listDirectory bool) http.FileSystem {
- fs := http.Dir(root)
- if listDirectory {
- return fs
- }
- return &onlyfilesFS{fs}
-}
-
-// Open conforms to http.Filesystem.
-func (fs onlyfilesFS) Open(name string) (http.File, error) {
- f, err := fs.fs.Open(name)
- if err != nil {
- return nil, err
- }
- return neuteredReaddirFile{f}, nil
-}
-
-// Readdir overrides the http.File default implementation.
-func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
- // this disables directory listing
- return nil, nil
-}
diff --git a/vendor/github.com/gin-gonic/gin/gin.go b/vendor/github.com/gin-gonic/gin/gin.go
deleted file mode 100644
index aa62e01..0000000
--- a/vendor/github.com/gin-gonic/gin/gin.go
+++ /dev/null
@@ -1,443 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "html/template"
- "net"
- "net/http"
- "os"
- "sync"
-
- "github.com/gin-gonic/gin/render"
-)
-
-const (
- // Version is Framework's version.
- Version = "v1.3.0"
- defaultMultipartMemory = 32 << 20 // 32 MB
-)
-
-var (
- default404Body = []byte("404 page not found")
- default405Body = []byte("405 method not allowed")
- defaultAppEngine bool
-)
-
-type HandlerFunc func(*Context)
-type HandlersChain []HandlerFunc
-
-// Last returns the last handler in the chain. ie. the last handler is the main own.
-func (c HandlersChain) Last() HandlerFunc {
- if length := len(c); length > 0 {
- return c[length-1]
- }
- return nil
-}
-
-type RouteInfo struct {
- Method string
- Path string
- Handler string
-}
-
-type RoutesInfo []RouteInfo
-
-// Engine is the framework's instance, it contains the muxer, middleware and configuration settings.
-// Create an instance of Engine, by using New() or Default()
-type Engine struct {
- RouterGroup
-
- // Enables automatic redirection if the current route can't be matched but a
- // handler for the path with (without) the trailing slash exists.
- // For example if /foo/ is requested but a route only exists for /foo, the
- // client is redirected to /foo with http status code 301 for GET requests
- // and 307 for all other request methods.
- RedirectTrailingSlash bool
-
- // If enabled, the router tries to fix the current request path, if no
- // handle is registered for it.
- // First superfluous path elements like ../ or // are removed.
- // Afterwards the router does a case-insensitive lookup of the cleaned path.
- // If a handle can be found for this route, the router makes a redirection
- // to the corrected path with status code 301 for GET requests and 307 for
- // all other request methods.
- // For example /FOO and /..//Foo could be redirected to /foo.
- // RedirectTrailingSlash is independent of this option.
- RedirectFixedPath bool
-
- // If enabled, the router checks if another method is allowed for the
- // current route, if the current request can not be routed.
- // If this is the case, the request is answered with 'Method Not Allowed'
- // and HTTP status code 405.
- // If no other Method is allowed, the request is delegated to the NotFound
- // handler.
- HandleMethodNotAllowed bool
- ForwardedByClientIP bool
-
- // #726 #755 If enabled, it will thrust some headers starting with
- // 'X-AppEngine...' for better integration with that PaaS.
- AppEngine bool
-
- // If enabled, the url.RawPath will be used to find parameters.
- UseRawPath bool
-
- // If true, the path value will be unescaped.
- // If UseRawPath is false (by default), the UnescapePathValues effectively is true,
- // as url.Path gonna be used, which is already unescaped.
- UnescapePathValues bool
-
- // Value of 'maxMemory' param that is given to http.Request's ParseMultipartForm
- // method call.
- MaxMultipartMemory int64
-
- delims render.Delims
- secureJsonPrefix string
- HTMLRender render.HTMLRender
- FuncMap template.FuncMap
- allNoRoute HandlersChain
- allNoMethod HandlersChain
- noRoute HandlersChain
- noMethod HandlersChain
- pool sync.Pool
- trees methodTrees
-}
-
-var _ IRouter = &Engine{}
-
-// New returns a new blank Engine instance without any middleware attached.
-// By default the configuration is:
-// - RedirectTrailingSlash: true
-// - RedirectFixedPath: false
-// - HandleMethodNotAllowed: false
-// - ForwardedByClientIP: true
-// - UseRawPath: false
-// - UnescapePathValues: true
-func New() *Engine {
- debugPrintWARNINGNew()
- engine := &Engine{
- RouterGroup: RouterGroup{
- Handlers: nil,
- basePath: "/",
- root: true,
- },
- FuncMap: template.FuncMap{},
- RedirectTrailingSlash: true,
- RedirectFixedPath: false,
- HandleMethodNotAllowed: false,
- ForwardedByClientIP: true,
- AppEngine: defaultAppEngine,
- UseRawPath: false,
- UnescapePathValues: true,
- MaxMultipartMemory: defaultMultipartMemory,
- trees: make(methodTrees, 0, 9),
- delims: render.Delims{Left: "{{", Right: "}}"},
- secureJsonPrefix: "while(1);",
- }
- engine.RouterGroup.engine = engine
- engine.pool.New = func() interface{} {
- return engine.allocateContext()
- }
- return engine
-}
-
-// Default returns an Engine instance with the Logger and Recovery middleware already attached.
-func Default() *Engine {
- debugPrintWARNINGDefault()
- engine := New()
- engine.Use(Logger(), Recovery())
- return engine
-}
-
-func (engine *Engine) allocateContext() *Context {
- return &Context{engine: engine}
-}
-
-func (engine *Engine) Delims(left, right string) *Engine {
- engine.delims = render.Delims{Left: left, Right: right}
- return engine
-}
-
-// SecureJsonPrefix sets the secureJsonPrefix used in Context.SecureJSON.
-func (engine *Engine) SecureJsonPrefix(prefix string) *Engine {
- engine.secureJsonPrefix = prefix
- return engine
-}
-
-// LoadHTMLGlob loads HTML files identified by glob pattern
-// and associates the result with HTML renderer.
-func (engine *Engine) LoadHTMLGlob(pattern string) {
- left := engine.delims.Left
- right := engine.delims.Right
- templ := template.Must(template.New("").Delims(left, right).Funcs(engine.FuncMap).ParseGlob(pattern))
-
- if IsDebugging() {
- debugPrintLoadTemplate(templ)
- engine.HTMLRender = render.HTMLDebug{Glob: pattern, FuncMap: engine.FuncMap, Delims: engine.delims}
- return
- }
-
- engine.SetHTMLTemplate(templ)
-}
-
-// LoadHTMLFiles loads a slice of HTML files
-// and associates the result with HTML renderer.
-func (engine *Engine) LoadHTMLFiles(files ...string) {
- if IsDebugging() {
- engine.HTMLRender = render.HTMLDebug{Files: files, FuncMap: engine.FuncMap, Delims: engine.delims}
- return
- }
-
- templ := template.Must(template.New("").Delims(engine.delims.Left, engine.delims.Right).Funcs(engine.FuncMap).ParseFiles(files...))
- engine.SetHTMLTemplate(templ)
-}
-
-// SetHTMLTemplate associate a template with HTML renderer.
-func (engine *Engine) SetHTMLTemplate(templ *template.Template) {
- if len(engine.trees) > 0 {
- debugPrintWARNINGSetHTMLTemplate()
- }
-
- engine.HTMLRender = render.HTMLProduction{Template: templ.Funcs(engine.FuncMap)}
-}
-
-// SetFuncMap sets the FuncMap used for template.FuncMap.
-func (engine *Engine) SetFuncMap(funcMap template.FuncMap) {
- engine.FuncMap = funcMap
-}
-
-// NoRoute adds handlers for NoRoute. It return a 404 code by default.
-func (engine *Engine) NoRoute(handlers ...HandlerFunc) {
- engine.noRoute = handlers
- engine.rebuild404Handlers()
-}
-
-// NoMethod sets the handlers called when... TODO.
-func (engine *Engine) NoMethod(handlers ...HandlerFunc) {
- engine.noMethod = handlers
- engine.rebuild405Handlers()
-}
-
-// Use attachs a global middleware to the router. ie. the middleware attached though Use() will be
-// included in the handlers chain for every single request. Even 404, 405, static files...
-// For example, this is the right place for a logger or error management middleware.
-func (engine *Engine) Use(middleware ...HandlerFunc) IRoutes {
- engine.RouterGroup.Use(middleware...)
- engine.rebuild404Handlers()
- engine.rebuild405Handlers()
- return engine
-}
-
-func (engine *Engine) rebuild404Handlers() {
- engine.allNoRoute = engine.combineHandlers(engine.noRoute)
-}
-
-func (engine *Engine) rebuild405Handlers() {
- engine.allNoMethod = engine.combineHandlers(engine.noMethod)
-}
-
-func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
- assert1(path[0] == '/', "path must begin with '/'")
- assert1(method != "", "HTTP method can not be empty")
- assert1(len(handlers) > 0, "there must be at least one handler")
-
- debugPrintRoute(method, path, handlers)
- root := engine.trees.get(method)
- if root == nil {
- root = new(node)
- engine.trees = append(engine.trees, methodTree{method: method, root: root})
- }
- root.addRoute(path, handlers)
-}
-
-// Routes returns a slice of registered routes, including some useful information, such as:
-// the http method, path and the handler name.
-func (engine *Engine) Routes() (routes RoutesInfo) {
- for _, tree := range engine.trees {
- routes = iterate("", tree.method, routes, tree.root)
- }
- return routes
-}
-
-func iterate(path, method string, routes RoutesInfo, root *node) RoutesInfo {
- path += root.path
- if len(root.handlers) > 0 {
- routes = append(routes, RouteInfo{
- Method: method,
- Path: path,
- Handler: nameOfFunction(root.handlers.Last()),
- })
- }
- for _, child := range root.children {
- routes = iterate(path, method, routes, child)
- }
- return routes
-}
-
-// Run attaches the router to a http.Server and starts listening and serving HTTP requests.
-// It is a shortcut for http.ListenAndServe(addr, router)
-// Note: this method will block the calling goroutine indefinitely unless an error happens.
-func (engine *Engine) Run(addr ...string) (err error) {
- defer func() { debugPrintError(err) }()
-
- address := resolveAddress(addr)
- debugPrint("Listening and serving HTTP on %s\n", address)
- err = http.ListenAndServe(address, engine)
- return
-}
-
-// RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests.
-// It is a shortcut for http.ListenAndServeTLS(addr, certFile, keyFile, router)
-// Note: this method will block the calling goroutine indefinitely unless an error happens.
-func (engine *Engine) RunTLS(addr, certFile, keyFile string) (err error) {
- debugPrint("Listening and serving HTTPS on %s\n", addr)
- defer func() { debugPrintError(err) }()
-
- err = http.ListenAndServeTLS(addr, certFile, keyFile, engine)
- return
-}
-
-// RunUnix attaches the router to a http.Server and starts listening and serving HTTP requests
-// through the specified unix socket (ie. a file).
-// Note: this method will block the calling goroutine indefinitely unless an error happens.
-func (engine *Engine) RunUnix(file string) (err error) {
- debugPrint("Listening and serving HTTP on unix:/%s", file)
- defer func() { debugPrintError(err) }()
-
- os.Remove(file)
- listener, err := net.Listen("unix", file)
- if err != nil {
- return
- }
- defer listener.Close()
- err = http.Serve(listener, engine)
- return
-}
-
-// ServeHTTP conforms to the http.Handler interface.
-func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
- c := engine.pool.Get().(*Context)
- c.writermem.reset(w)
- c.Request = req
- c.reset()
-
- engine.handleHTTPRequest(c)
-
- engine.pool.Put(c)
-}
-
-// HandleContext re-enter a context that has been rewritten.
-// This can be done by setting c.Request.URL.Path to your new target.
-// Disclaimer: You can loop yourself to death with this, use wisely.
-func (engine *Engine) HandleContext(c *Context) {
- c.reset()
- engine.handleHTTPRequest(c)
- engine.pool.Put(c)
-}
-
-func (engine *Engine) handleHTTPRequest(c *Context) {
- httpMethod := c.Request.Method
- path := c.Request.URL.Path
- unescape := false
- if engine.UseRawPath && len(c.Request.URL.RawPath) > 0 {
- path = c.Request.URL.RawPath
- unescape = engine.UnescapePathValues
- }
-
- // Find root of the tree for the given HTTP method
- t := engine.trees
- for i, tl := 0, len(t); i < tl; i++ {
- if t[i].method != httpMethod {
- continue
- }
- root := t[i].root
- // Find route in tree
- handlers, params, tsr := root.getValue(path, c.Params, unescape)
- if handlers != nil {
- c.handlers = handlers
- c.Params = params
- c.Next()
- c.writermem.WriteHeaderNow()
- return
- }
- if httpMethod != "CONNECT" && path != "/" {
- if tsr && engine.RedirectTrailingSlash {
- redirectTrailingSlash(c)
- return
- }
- if engine.RedirectFixedPath && redirectFixedPath(c, root, engine.RedirectFixedPath) {
- return
- }
- }
- break
- }
-
- if engine.HandleMethodNotAllowed {
- for _, tree := range engine.trees {
- if tree.method == httpMethod {
- continue
- }
- if handlers, _, _ := tree.root.getValue(path, nil, unescape); handlers != nil {
- c.handlers = engine.allNoMethod
- serveError(c, http.StatusMethodNotAllowed, default405Body)
- return
- }
- }
- }
- c.handlers = engine.allNoRoute
- serveError(c, http.StatusNotFound, default404Body)
-}
-
-var mimePlain = []string{MIMEPlain}
-
-func serveError(c *Context, code int, defaultMessage []byte) {
- c.writermem.status = code
- c.Next()
- if c.writermem.Written() {
- return
- }
- if c.writermem.Status() == code {
- c.writermem.Header()["Content-Type"] = mimePlain
- c.Writer.Write(defaultMessage)
- return
- }
- c.writermem.WriteHeaderNow()
- return
-}
-
-func redirectTrailingSlash(c *Context) {
- req := c.Request
- path := req.URL.Path
- code := http.StatusMovedPermanently // Permanent redirect, request with GET method
- if req.Method != "GET" {
- code = http.StatusTemporaryRedirect
- }
-
- req.URL.Path = path + "/"
- if length := len(path); length > 1 && path[length-1] == '/' {
- req.URL.Path = path[:length-1]
- }
- debugPrint("redirecting request %d: %s --> %s", code, path, req.URL.String())
- http.Redirect(c.Writer, req, req.URL.String(), code)
- c.writermem.WriteHeaderNow()
-}
-
-func redirectFixedPath(c *Context, root *node, trailingSlash bool) bool {
- req := c.Request
- path := req.URL.Path
-
- if fixedPath, ok := root.findCaseInsensitivePath(cleanPath(path), trailingSlash); ok {
- code := http.StatusMovedPermanently // Permanent redirect, request with GET method
- if req.Method != "GET" {
- code = http.StatusTemporaryRedirect
- }
- req.URL.Path = string(fixedPath)
- debugPrint("redirecting request %d: %s --> %s", code, path, req.URL.String())
- http.Redirect(c.Writer, req, req.URL.String(), code)
- c.writermem.WriteHeaderNow()
- return true
- }
- return false
-}
diff --git a/vendor/github.com/gin-gonic/gin/json/json.go b/vendor/github.com/gin-gonic/gin/json/json.go
deleted file mode 100644
index aa76aa3..0000000
--- a/vendor/github.com/gin-gonic/gin/json/json.go
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2017 Bo-Yi Wu. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-// +build !jsoniter
-
-package json
-
-import "encoding/json"
-
-var (
- Marshal = json.Marshal
- MarshalIndent = json.MarshalIndent
- NewDecoder = json.NewDecoder
-)
diff --git a/vendor/github.com/gin-gonic/gin/json/jsoniter.go b/vendor/github.com/gin-gonic/gin/json/jsoniter.go
deleted file mode 100644
index ffe1424..0000000
--- a/vendor/github.com/gin-gonic/gin/json/jsoniter.go
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2017 Bo-Yi Wu. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-// +build jsoniter
-
-package json
-
-import "github.com/json-iterator/go"
-
-var (
- json = jsoniter.ConfigCompatibleWithStandardLibrary
- Marshal = json.Marshal
- MarshalIndent = json.MarshalIndent
- NewDecoder = json.NewDecoder
-)
diff --git a/vendor/github.com/gin-gonic/gin/logger.go b/vendor/github.com/gin-gonic/gin/logger.go
deleted file mode 100644
index 1a8df60..0000000
--- a/vendor/github.com/gin-gonic/gin/logger.go
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "fmt"
- "io"
- "net/http"
- "os"
- "time"
-
- "github.com/mattn/go-isatty"
-)
-
-var (
- green = string([]byte{27, 91, 57, 55, 59, 52, 50, 109})
- white = string([]byte{27, 91, 57, 48, 59, 52, 55, 109})
- yellow = string([]byte{27, 91, 57, 55, 59, 52, 51, 109})
- red = string([]byte{27, 91, 57, 55, 59, 52, 49, 109})
- blue = string([]byte{27, 91, 57, 55, 59, 52, 52, 109})
- magenta = string([]byte{27, 91, 57, 55, 59, 52, 53, 109})
- cyan = string([]byte{27, 91, 57, 55, 59, 52, 54, 109})
- reset = string([]byte{27, 91, 48, 109})
- disableColor = false
-)
-
-// DisableConsoleColor disables color output in the console.
-func DisableConsoleColor() {
- disableColor = true
-}
-
-// ErrorLogger returns a handlerfunc for any error type.
-func ErrorLogger() HandlerFunc {
- return ErrorLoggerT(ErrorTypeAny)
-}
-
-// ErrorLoggerT returns a handlerfunc for a given error type.
-func ErrorLoggerT(typ ErrorType) HandlerFunc {
- return func(c *Context) {
- c.Next()
- errors := c.Errors.ByType(typ)
- if len(errors) > 0 {
- c.JSON(-1, errors)
- }
- }
-}
-
-// Logger instances a Logger middleware that will write the logs to gin.DefaultWriter.
-// By default gin.DefaultWriter = os.Stdout.
-func Logger() HandlerFunc {
- return LoggerWithWriter(DefaultWriter)
-}
-
-// LoggerWithWriter instance a Logger middleware with the specified writter buffer.
-// Example: os.Stdout, a file opened in write mode, a socket...
-func LoggerWithWriter(out io.Writer, notlogged ...string) HandlerFunc {
- isTerm := true
-
- if w, ok := out.(*os.File); !ok ||
- (os.Getenv("TERM") == "dumb" || (!isatty.IsTerminal(w.Fd()) && !isatty.IsCygwinTerminal(w.Fd()))) ||
- disableColor {
- isTerm = false
- }
-
- var skip map[string]struct{}
-
- if length := len(notlogged); length > 0 {
- skip = make(map[string]struct{}, length)
-
- for _, path := range notlogged {
- skip[path] = struct{}{}
- }
- }
-
- return func(c *Context) {
- // Start timer
- start := time.Now()
- path := c.Request.URL.Path
- raw := c.Request.URL.RawQuery
-
- // Process request
- c.Next()
-
- // Log only when path is not being skipped
- if _, ok := skip[path]; !ok {
- // Stop timer
- end := time.Now()
- latency := end.Sub(start)
-
- clientIP := c.ClientIP()
- method := c.Request.Method
- statusCode := c.Writer.Status()
- var statusColor, methodColor, resetColor string
- if isTerm {
- statusColor = colorForStatus(statusCode)
- methodColor = colorForMethod(method)
- resetColor = reset
- }
- comment := c.Errors.ByType(ErrorTypePrivate).String()
-
- if raw != "" {
- path = path + "?" + raw
- }
-
- fmt.Fprintf(out, "[GIN] %v |%s %3d %s| %13v | %15s |%s %-7s %s %s\n%s",
- end.Format("2006/01/02 - 15:04:05"),
- statusColor, statusCode, resetColor,
- latency,
- clientIP,
- methodColor, method, resetColor,
- path,
- comment,
- )
- }
- }
-}
-
-func colorForStatus(code int) string {
- switch {
- case code >= http.StatusOK && code < http.StatusMultipleChoices:
- return green
- case code >= http.StatusMultipleChoices && code < http.StatusBadRequest:
- return white
- case code >= http.StatusBadRequest && code < http.StatusInternalServerError:
- return yellow
- default:
- return red
- }
-}
-
-func colorForMethod(method string) string {
- switch method {
- case "GET":
- return blue
- case "POST":
- return cyan
- case "PUT":
- return yellow
- case "DELETE":
- return red
- case "PATCH":
- return green
- case "HEAD":
- return magenta
- case "OPTIONS":
- return white
- default:
- return reset
- }
-}
diff --git a/vendor/github.com/gin-gonic/gin/mode.go b/vendor/github.com/gin-gonic/gin/mode.go
deleted file mode 100644
index 9df4e45..0000000
--- a/vendor/github.com/gin-gonic/gin/mode.go
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "io"
- "os"
-
- "github.com/gin-gonic/gin/binding"
-)
-
-const ENV_GIN_MODE = "GIN_MODE"
-
-const (
- DebugMode = "debug"
- ReleaseMode = "release"
- TestMode = "test"
-)
-const (
- debugCode = iota
- releaseCode
- testCode
-)
-
-// DefaultWriter is the default io.Writer used the Gin for debug output and
-// middleware output like Logger() or Recovery().
-// Note that both Logger and Recovery provides custom ways to configure their
-// output io.Writer.
-// To support coloring in Windows use:
-// import "github.com/mattn/go-colorable"
-// gin.DefaultWriter = colorable.NewColorableStdout()
-var DefaultWriter io.Writer = os.Stdout
-var DefaultErrorWriter io.Writer = os.Stderr
-
-var ginMode = debugCode
-var modeName = DebugMode
-
-func init() {
- mode := os.Getenv(ENV_GIN_MODE)
- SetMode(mode)
-}
-
-func SetMode(value string) {
- switch value {
- case DebugMode, "":
- ginMode = debugCode
- case ReleaseMode:
- ginMode = releaseCode
- case TestMode:
- ginMode = testCode
- default:
- panic("gin mode unknown: " + value)
- }
- if value == "" {
- value = DebugMode
- }
- modeName = value
-}
-
-func DisableBindValidation() {
- binding.Validator = nil
-}
-
-func EnableJsonDecoderUseNumber() {
- binding.EnableDecoderUseNumber = true
-}
-
-func Mode() string {
- return modeName
-}
diff --git a/vendor/github.com/gin-gonic/gin/path.go b/vendor/github.com/gin-gonic/gin/path.go
deleted file mode 100644
index d1f5962..0000000
--- a/vendor/github.com/gin-gonic/gin/path.go
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright 2013 Julien Schmidt. All rights reserved.
-// Based on the path package, Copyright 2009 The Go Authors.
-// Use of this source code is governed by a BSD-style license that can be found
-// at https://github.com/julienschmidt/httprouter/blob/master/LICENSE.
-
-package gin
-
-// cleanPath is the URL version of path.Clean, it returns a canonical URL path
-// for p, eliminating . and .. elements.
-//
-// The following rules are applied iteratively until no further processing can
-// be done:
-// 1. Replace multiple slashes with a single slash.
-// 2. Eliminate each . path name element (the current directory).
-// 3. Eliminate each inner .. path name element (the parent directory)
-// along with the non-.. element that precedes it.
-// 4. Eliminate .. elements that begin a rooted path:
-// that is, replace "/.." by "/" at the beginning of a path.
-//
-// If the result of this process is an empty string, "/" is returned.
-func cleanPath(p string) string {
- // Turn empty string into "/"
- if p == "" {
- return "/"
- }
-
- n := len(p)
- var buf []byte
-
- // Invariants:
- // reading from path; r is index of next byte to process.
- // writing to buf; w is index of next byte to write.
-
- // path must start with '/'
- r := 1
- w := 1
-
- if p[0] != '/' {
- r = 0
- buf = make([]byte, n+1)
- buf[0] = '/'
- }
-
- trailing := n > 1 && p[n-1] == '/'
-
- // A bit more clunky without a 'lazybuf' like the path package, but the loop
- // gets completely inlined (bufApp). So in contrast to the path package this
- // loop has no expensive function calls (except 1x make)
-
- for r < n {
- switch {
- case p[r] == '/':
- // empty path element, trailing slash is added after the end
- r++
-
- case p[r] == '.' && r+1 == n:
- trailing = true
- r++
-
- case p[r] == '.' && p[r+1] == '/':
- // . element
- r += 2
-
- case p[r] == '.' && p[r+1] == '.' && (r+2 == n || p[r+2] == '/'):
- // .. element: remove to last /
- r += 3
-
- if w > 1 {
- // can backtrack
- w--
-
- if buf == nil {
- for w > 1 && p[w] != '/' {
- w--
- }
- } else {
- for w > 1 && buf[w] != '/' {
- w--
- }
- }
- }
-
- default:
- // real path element.
- // add slash if needed
- if w > 1 {
- bufApp(&buf, p, w, '/')
- w++
- }
-
- // copy element
- for r < n && p[r] != '/' {
- bufApp(&buf, p, w, p[r])
- w++
- r++
- }
- }
- }
-
- // re-append trailing slash
- if trailing && w > 1 {
- bufApp(&buf, p, w, '/')
- w++
- }
-
- if buf == nil {
- return p[:w]
- }
- return string(buf[:w])
-}
-
-// internal helper to lazily create a buffer if necessary.
-func bufApp(buf *[]byte, s string, w int, c byte) {
- if *buf == nil {
- if s[w] == c {
- return
- }
-
- *buf = make([]byte, len(s))
- copy(*buf, s[:w])
- }
- (*buf)[w] = c
-}
diff --git a/vendor/github.com/gin-gonic/gin/recovery.go b/vendor/github.com/gin-gonic/gin/recovery.go
deleted file mode 100644
index 61c5bd5..0000000
--- a/vendor/github.com/gin-gonic/gin/recovery.go
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "bytes"
- "fmt"
- "io"
- "io/ioutil"
- "log"
- "net/http"
- "net/http/httputil"
- "runtime"
- "time"
-)
-
-var (
- dunno = []byte("???")
- centerDot = []byte("·")
- dot = []byte(".")
- slash = []byte("/")
-)
-
-// Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.
-func Recovery() HandlerFunc {
- return RecoveryWithWriter(DefaultErrorWriter)
-}
-
-// RecoveryWithWriter returns a middleware for a given writer that recovers from any panics and writes a 500 if there was one.
-func RecoveryWithWriter(out io.Writer) HandlerFunc {
- var logger *log.Logger
- if out != nil {
- logger = log.New(out, "\n\n\x1b[31m", log.LstdFlags)
- }
- return func(c *Context) {
- defer func() {
- if err := recover(); err != nil {
- if logger != nil {
- stack := stack(3)
- httprequest, _ := httputil.DumpRequest(c.Request, false)
- logger.Printf("[Recovery] %s panic recovered:\n%s\n%s\n%s%s", timeFormat(time.Now()), string(httprequest), err, stack, reset)
- }
- c.AbortWithStatus(http.StatusInternalServerError)
- }
- }()
- c.Next()
- }
-}
-
-// stack returns a nicely formatted stack frame, skipping skip frames.
-func stack(skip int) []byte {
- buf := new(bytes.Buffer) // the returned data
- // As we loop, we open files and read them. These variables record the currently
- // loaded file.
- var lines [][]byte
- var lastFile string
- for i := skip; ; i++ { // Skip the expected number of frames
- pc, file, line, ok := runtime.Caller(i)
- if !ok {
- break
- }
- // Print this much at least. If we can't find the source, it won't show.
- fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc)
- if file != lastFile {
- data, err := ioutil.ReadFile(file)
- if err != nil {
- continue
- }
- lines = bytes.Split(data, []byte{'\n'})
- lastFile = file
- }
- fmt.Fprintf(buf, "\t%s: %s\n", function(pc), source(lines, line))
- }
- return buf.Bytes()
-}
-
-// source returns a space-trimmed slice of the n'th line.
-func source(lines [][]byte, n int) []byte {
- n-- // in stack trace, lines are 1-indexed but our array is 0-indexed
- if n < 0 || n >= len(lines) {
- return dunno
- }
- return bytes.TrimSpace(lines[n])
-}
-
-// function returns, if possible, the name of the function containing the PC.
-func function(pc uintptr) []byte {
- fn := runtime.FuncForPC(pc)
- if fn == nil {
- return dunno
- }
- name := []byte(fn.Name())
- // The name includes the path name to the package, which is unnecessary
- // since the file name is already included. Plus, it has center dots.
- // That is, we see
- // runtime/debug.*T·ptrmethod
- // and want
- // *T.ptrmethod
- // Also the package path might contains dot (e.g. code.google.com/...),
- // so first eliminate the path prefix
- if lastslash := bytes.LastIndex(name, slash); lastslash >= 0 {
- name = name[lastslash+1:]
- }
- if period := bytes.Index(name, dot); period >= 0 {
- name = name[period+1:]
- }
- name = bytes.Replace(name, centerDot, dot, -1)
- return name
-}
-
-func timeFormat(t time.Time) string {
- var timeString = t.Format("2006/01/02 - 15:04:05")
- return timeString
-}
diff --git a/vendor/github.com/gin-gonic/gin/render/data.go b/vendor/github.com/gin-gonic/gin/render/data.go
deleted file mode 100644
index 3319491..0000000
--- a/vendor/github.com/gin-gonic/gin/render/data.go
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package render
-
-import "net/http"
-
-type Data struct {
- ContentType string
- Data []byte
-}
-
-// Render (Data) writes data with custom ContentType.
-func (r Data) Render(w http.ResponseWriter) (err error) {
- r.WriteContentType(w)
- _, err = w.Write(r.Data)
- return
-}
-
-func (r Data) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, []string{r.ContentType})
-}
diff --git a/vendor/github.com/gin-gonic/gin/render/html.go b/vendor/github.com/gin-gonic/gin/render/html.go
deleted file mode 100644
index 1e3be65..0000000
--- a/vendor/github.com/gin-gonic/gin/render/html.go
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package render
-
-import (
- "html/template"
- "net/http"
-)
-
-type Delims struct {
- Left string
- Right string
-}
-
-type HTMLRender interface {
- Instance(string, interface{}) Render
-}
-
-type HTMLProduction struct {
- Template *template.Template
- Delims Delims
-}
-
-type HTMLDebug struct {
- Files []string
- Glob string
- Delims Delims
- FuncMap template.FuncMap
-}
-
-type HTML struct {
- Template *template.Template
- Name string
- Data interface{}
-}
-
-var htmlContentType = []string{"text/html; charset=utf-8"}
-
-func (r HTMLProduction) Instance(name string, data interface{}) Render {
- return HTML{
- Template: r.Template,
- Name: name,
- Data: data,
- }
-}
-
-func (r HTMLDebug) Instance(name string, data interface{}) Render {
- return HTML{
- Template: r.loadTemplate(),
- Name: name,
- Data: data,
- }
-}
-func (r HTMLDebug) loadTemplate() *template.Template {
- if r.FuncMap == nil {
- r.FuncMap = template.FuncMap{}
- }
- if len(r.Files) > 0 {
- return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseFiles(r.Files...))
- }
- if r.Glob != "" {
- return template.Must(template.New("").Delims(r.Delims.Left, r.Delims.Right).Funcs(r.FuncMap).ParseGlob(r.Glob))
- }
- panic("the HTML debug render was created without files or glob pattern")
-}
-
-func (r HTML) Render(w http.ResponseWriter) error {
- r.WriteContentType(w)
-
- if r.Name == "" {
- return r.Template.Execute(w, r.Data)
- }
- return r.Template.ExecuteTemplate(w, r.Name, r.Data)
-}
-
-func (r HTML) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, htmlContentType)
-}
diff --git a/vendor/github.com/gin-gonic/gin/render/json.go b/vendor/github.com/gin-gonic/gin/render/json.go
deleted file mode 100644
index 6e5089a..0000000
--- a/vendor/github.com/gin-gonic/gin/render/json.go
+++ /dev/null
@@ -1,146 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package render
-
-import (
- "bytes"
- "fmt"
- "html/template"
- "net/http"
-
- "github.com/gin-gonic/gin/json"
-)
-
-type JSON struct {
- Data interface{}
-}
-
-type IndentedJSON struct {
- Data interface{}
-}
-
-type SecureJSON struct {
- Prefix string
- Data interface{}
-}
-
-type JsonpJSON struct {
- Callback string
- Data interface{}
-}
-
-type AsciiJSON struct {
- Data interface{}
-}
-
-type SecureJSONPrefix string
-
-var jsonContentType = []string{"application/json; charset=utf-8"}
-var jsonpContentType = []string{"application/javascript; charset=utf-8"}
-var jsonAsciiContentType = []string{"application/json"}
-
-func (r JSON) Render(w http.ResponseWriter) (err error) {
- if err = WriteJSON(w, r.Data); err != nil {
- panic(err)
- }
- return
-}
-
-func (r JSON) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, jsonContentType)
-}
-
-func WriteJSON(w http.ResponseWriter, obj interface{}) error {
- writeContentType(w, jsonContentType)
- jsonBytes, err := json.Marshal(obj)
- if err != nil {
- return err
- }
- w.Write(jsonBytes)
- return nil
-}
-
-func (r IndentedJSON) Render(w http.ResponseWriter) error {
- r.WriteContentType(w)
- jsonBytes, err := json.MarshalIndent(r.Data, "", " ")
- if err != nil {
- return err
- }
- w.Write(jsonBytes)
- return nil
-}
-
-func (r IndentedJSON) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, jsonContentType)
-}
-
-func (r SecureJSON) Render(w http.ResponseWriter) error {
- r.WriteContentType(w)
- jsonBytes, err := json.Marshal(r.Data)
- if err != nil {
- return err
- }
- // if the jsonBytes is array values
- if bytes.HasPrefix(jsonBytes, []byte("[")) && bytes.HasSuffix(jsonBytes, []byte("]")) {
- w.Write([]byte(r.Prefix))
- }
- w.Write(jsonBytes)
- return nil
-}
-
-func (r SecureJSON) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, jsonContentType)
-}
-
-func (r JsonpJSON) Render(w http.ResponseWriter) (err error) {
- r.WriteContentType(w)
- ret, err := json.Marshal(r.Data)
- if err != nil {
- return err
- }
-
- if r.Callback == "" {
- w.Write(ret)
- return nil
- }
-
- callback := template.JSEscapeString(r.Callback)
- w.Write([]byte(callback))
- w.Write([]byte("("))
- w.Write(ret)
- w.Write([]byte(")"))
-
- return nil
-}
-
-func (r JsonpJSON) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, jsonpContentType)
-}
-
-func (r AsciiJSON) Render(w http.ResponseWriter) (err error) {
- r.WriteContentType(w)
- ret, err := json.Marshal(r.Data)
- if err != nil {
- return err
- }
-
- var buffer bytes.Buffer
- for _, r := range string(ret) {
- cvt := ""
- if r < 128 {
- cvt = string(r)
- } else {
- cvt = fmt.Sprintf("\\u%04x", int64(r))
- }
- buffer.WriteString(cvt)
- }
-
- w.Write(buffer.Bytes())
- return nil
-}
-
-func (r AsciiJSON) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, jsonAsciiContentType)
-}
diff --git a/vendor/github.com/gin-gonic/gin/render/msgpack.go b/vendor/github.com/gin-gonic/gin/render/msgpack.go
deleted file mode 100644
index e6c13e5..0000000
--- a/vendor/github.com/gin-gonic/gin/render/msgpack.go
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package render
-
-import (
- "net/http"
-
- "github.com/ugorji/go/codec"
-)
-
-type MsgPack struct {
- Data interface{}
-}
-
-var msgpackContentType = []string{"application/msgpack; charset=utf-8"}
-
-func (r MsgPack) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, msgpackContentType)
-}
-
-func (r MsgPack) Render(w http.ResponseWriter) error {
- return WriteMsgPack(w, r.Data)
-}
-
-func WriteMsgPack(w http.ResponseWriter, obj interface{}) error {
- writeContentType(w, msgpackContentType)
- var h codec.Handle = new(codec.MsgpackHandle)
- return codec.NewEncoder(w, h).Encode(obj)
-}
diff --git a/vendor/github.com/gin-gonic/gin/render/reader.go b/vendor/github.com/gin-gonic/gin/render/reader.go
deleted file mode 100644
index be2132c..0000000
--- a/vendor/github.com/gin-gonic/gin/render/reader.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package render
-
-import (
- "io"
- "net/http"
- "strconv"
-)
-
-type Reader struct {
- ContentType string
- ContentLength int64
- Reader io.Reader
- Headers map[string]string
-}
-
-// Render (Reader) writes data with custom ContentType and headers.
-func (r Reader) Render(w http.ResponseWriter) (err error) {
- r.WriteContentType(w)
- r.Headers["Content-Length"] = strconv.FormatInt(r.ContentLength, 10)
- r.writeHeaders(w, r.Headers)
- _, err = io.Copy(w, r.Reader)
- return
-}
-
-func (r Reader) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, []string{r.ContentType})
-}
-
-func (r Reader) writeHeaders(w http.ResponseWriter, headers map[string]string) {
- header := w.Header()
- for k, v := range headers {
- if val := header[k]; len(val) == 0 {
- header[k] = []string{v}
- }
- }
-}
diff --git a/vendor/github.com/gin-gonic/gin/render/redirect.go b/vendor/github.com/gin-gonic/gin/render/redirect.go
deleted file mode 100644
index a0634f5..0000000
--- a/vendor/github.com/gin-gonic/gin/render/redirect.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package render
-
-import (
- "fmt"
- "net/http"
-)
-
-type Redirect struct {
- Code int
- Request *http.Request
- Location string
-}
-
-func (r Redirect) Render(w http.ResponseWriter) error {
- // todo(thinkerou): go1.6 not support StatusPermanentRedirect(308)
- // when we upgrade go version we can use http.StatusPermanentRedirect
- if (r.Code < 300 || r.Code > 308) && r.Code != 201 {
- panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))
- }
- http.Redirect(w, r.Request, r.Location, r.Code)
- return nil
-}
-
-func (r Redirect) WriteContentType(http.ResponseWriter) {}
diff --git a/vendor/github.com/gin-gonic/gin/render/render.go b/vendor/github.com/gin-gonic/gin/render/render.go
deleted file mode 100644
index 4ff1c7b..0000000
--- a/vendor/github.com/gin-gonic/gin/render/render.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package render
-
-import "net/http"
-
-type Render interface {
- Render(http.ResponseWriter) error
- WriteContentType(w http.ResponseWriter)
-}
-
-var (
- _ Render = JSON{}
- _ Render = IndentedJSON{}
- _ Render = SecureJSON{}
- _ Render = JsonpJSON{}
- _ Render = XML{}
- _ Render = String{}
- _ Render = Redirect{}
- _ Render = Data{}
- _ Render = HTML{}
- _ HTMLRender = HTMLDebug{}
- _ HTMLRender = HTMLProduction{}
- _ Render = YAML{}
- _ Render = MsgPack{}
- _ Render = Reader{}
- _ Render = AsciiJSON{}
-)
-
-func writeContentType(w http.ResponseWriter, value []string) {
- header := w.Header()
- if val := header["Content-Type"]; len(val) == 0 {
- header["Content-Type"] = value
- }
-}
diff --git a/vendor/github.com/gin-gonic/gin/render/text.go b/vendor/github.com/gin-gonic/gin/render/text.go
deleted file mode 100644
index 74cd26b..0000000
--- a/vendor/github.com/gin-gonic/gin/render/text.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package render
-
-import (
- "fmt"
- "io"
- "net/http"
-)
-
-type String struct {
- Format string
- Data []interface{}
-}
-
-var plainContentType = []string{"text/plain; charset=utf-8"}
-
-func (r String) Render(w http.ResponseWriter) error {
- WriteString(w, r.Format, r.Data)
- return nil
-}
-
-func (r String) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, plainContentType)
-}
-
-func WriteString(w http.ResponseWriter, format string, data []interface{}) {
- writeContentType(w, plainContentType)
- if len(data) > 0 {
- fmt.Fprintf(w, format, data...)
- } else {
- io.WriteString(w, format)
- }
-}
diff --git a/vendor/github.com/gin-gonic/gin/render/xml.go b/vendor/github.com/gin-gonic/gin/render/xml.go
deleted file mode 100644
index cff1ac3..0000000
--- a/vendor/github.com/gin-gonic/gin/render/xml.go
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package render
-
-import (
- "encoding/xml"
- "net/http"
-)
-
-type XML struct {
- Data interface{}
-}
-
-var xmlContentType = []string{"application/xml; charset=utf-8"}
-
-func (r XML) Render(w http.ResponseWriter) error {
- r.WriteContentType(w)
- return xml.NewEncoder(w).Encode(r.Data)
-}
-
-func (r XML) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, xmlContentType)
-}
diff --git a/vendor/github.com/gin-gonic/gin/render/yaml.go b/vendor/github.com/gin-gonic/gin/render/yaml.go
deleted file mode 100644
index 25d0ebd..0000000
--- a/vendor/github.com/gin-gonic/gin/render/yaml.go
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package render
-
-import (
- "net/http"
-
- "gopkg.in/yaml.v2"
-)
-
-type YAML struct {
- Data interface{}
-}
-
-var yamlContentType = []string{"application/x-yaml; charset=utf-8"}
-
-func (r YAML) Render(w http.ResponseWriter) error {
- r.WriteContentType(w)
-
- bytes, err := yaml.Marshal(r.Data)
- if err != nil {
- return err
- }
-
- w.Write(bytes)
- return nil
-}
-
-func (r YAML) WriteContentType(w http.ResponseWriter) {
- writeContentType(w, yamlContentType)
-}
diff --git a/vendor/github.com/gin-gonic/gin/response_writer.go b/vendor/github.com/gin-gonic/gin/response_writer.go
deleted file mode 100644
index 923b53f..0000000
--- a/vendor/github.com/gin-gonic/gin/response_writer.go
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "bufio"
- "io"
- "net"
- "net/http"
-)
-
-const (
- noWritten = -1
- defaultStatus = http.StatusOK
-)
-
-type responseWriterBase interface {
- http.ResponseWriter
- http.Hijacker
- http.Flusher
- http.CloseNotifier
-
- // Returns the HTTP response status code of the current request.
- Status() int
-
- // Returns the number of bytes already written into the response http body.
- // See Written()
- Size() int
-
- // Writes the string into the response body.
- WriteString(string) (int, error)
-
- // Returns true if the response body was already written.
- Written() bool
-
- // Forces to write the http header (status code + headers).
- WriteHeaderNow()
-}
-
-type responseWriter struct {
- http.ResponseWriter
- size int
- status int
-}
-
-var _ ResponseWriter = &responseWriter{}
-
-func (w *responseWriter) reset(writer http.ResponseWriter) {
- w.ResponseWriter = writer
- w.size = noWritten
- w.status = defaultStatus
-}
-
-func (w *responseWriter) WriteHeader(code int) {
- if code > 0 && w.status != code {
- if w.Written() {
- debugPrint("[WARNING] Headers were already written. Wanted to override status code %d with %d", w.status, code)
- }
- w.status = code
- }
-}
-
-func (w *responseWriter) WriteHeaderNow() {
- if !w.Written() {
- w.size = 0
- w.ResponseWriter.WriteHeader(w.status)
- }
-}
-
-func (w *responseWriter) Write(data []byte) (n int, err error) {
- w.WriteHeaderNow()
- n, err = w.ResponseWriter.Write(data)
- w.size += n
- return
-}
-
-func (w *responseWriter) WriteString(s string) (n int, err error) {
- w.WriteHeaderNow()
- n, err = io.WriteString(w.ResponseWriter, s)
- w.size += n
- return
-}
-
-func (w *responseWriter) Status() int {
- return w.status
-}
-
-func (w *responseWriter) Size() int {
- return w.size
-}
-
-func (w *responseWriter) Written() bool {
- return w.size != noWritten
-}
-
-// Hijack implements the http.Hijacker interface.
-func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
- if w.size < 0 {
- w.size = 0
- }
- return w.ResponseWriter.(http.Hijacker).Hijack()
-}
-
-// CloseNotify implements the http.CloseNotify interface.
-func (w *responseWriter) CloseNotify() <-chan bool {
- return w.ResponseWriter.(http.CloseNotifier).CloseNotify()
-}
-
-// Flush implements the http.Flush interface.
-func (w *responseWriter) Flush() {
- w.WriteHeaderNow()
- w.ResponseWriter.(http.Flusher).Flush()
-}
diff --git a/vendor/github.com/gin-gonic/gin/response_writer_1.7.go b/vendor/github.com/gin-gonic/gin/response_writer_1.7.go
deleted file mode 100644
index 801d196..0000000
--- a/vendor/github.com/gin-gonic/gin/response_writer_1.7.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// +build !go1.8
-
-// Copyright 2018 Gin Core Team. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-// ResponseWriter ...
-type ResponseWriter interface {
- responseWriterBase
-}
diff --git a/vendor/github.com/gin-gonic/gin/response_writer_1.8.go b/vendor/github.com/gin-gonic/gin/response_writer_1.8.go
deleted file mode 100644
index 527c003..0000000
--- a/vendor/github.com/gin-gonic/gin/response_writer_1.8.go
+++ /dev/null
@@ -1,25 +0,0 @@
-// +build go1.8
-
-// Copyright 2018 Gin Core Team. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "net/http"
-)
-
-// ResponseWriter ...
-type ResponseWriter interface {
- responseWriterBase
- // get the http.Pusher for server push
- Pusher() http.Pusher
-}
-
-func (w *responseWriter) Pusher() (pusher http.Pusher) {
- if pusher, ok := w.ResponseWriter.(http.Pusher); ok {
- return pusher
- }
- return nil
-}
diff --git a/vendor/github.com/gin-gonic/gin/routergroup.go b/vendor/github.com/gin-gonic/gin/routergroup.go
deleted file mode 100644
index 876a61b..0000000
--- a/vendor/github.com/gin-gonic/gin/routergroup.go
+++ /dev/null
@@ -1,213 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "net/http"
- "path"
- "regexp"
- "strings"
-)
-
-type IRouter interface {
- IRoutes
- Group(string, ...HandlerFunc) *RouterGroup
-}
-
-type IRoutes interface {
- Use(...HandlerFunc) IRoutes
-
- Handle(string, string, ...HandlerFunc) IRoutes
- Any(string, ...HandlerFunc) IRoutes
- GET(string, ...HandlerFunc) IRoutes
- POST(string, ...HandlerFunc) IRoutes
- DELETE(string, ...HandlerFunc) IRoutes
- PATCH(string, ...HandlerFunc) IRoutes
- PUT(string, ...HandlerFunc) IRoutes
- OPTIONS(string, ...HandlerFunc) IRoutes
- HEAD(string, ...HandlerFunc) IRoutes
-
- StaticFile(string, string) IRoutes
- Static(string, string) IRoutes
- StaticFS(string, http.FileSystem) IRoutes
-}
-
-// RouterGroup is used internally to configure router, a RouterGroup is associated with a prefix
-// and an array of handlers (middleware).
-type RouterGroup struct {
- Handlers HandlersChain
- basePath string
- engine *Engine
- root bool
-}
-
-var _ IRouter = &RouterGroup{}
-
-// Use adds middleware to the group, see example code in github.
-func (group *RouterGroup) Use(middleware ...HandlerFunc) IRoutes {
- group.Handlers = append(group.Handlers, middleware...)
- return group.returnObj()
-}
-
-// Group creates a new router group. You should add all the routes that have common middlwares or the same path prefix.
-// For example, all the routes that use a common middlware for authorization could be grouped.
-func (group *RouterGroup) Group(relativePath string, handlers ...HandlerFunc) *RouterGroup {
- return &RouterGroup{
- Handlers: group.combineHandlers(handlers),
- basePath: group.calculateAbsolutePath(relativePath),
- engine: group.engine,
- }
-}
-
-func (group *RouterGroup) BasePath() string {
- return group.basePath
-}
-
-func (group *RouterGroup) handle(httpMethod, relativePath string, handlers HandlersChain) IRoutes {
- absolutePath := group.calculateAbsolutePath(relativePath)
- handlers = group.combineHandlers(handlers)
- group.engine.addRoute(httpMethod, absolutePath, handlers)
- return group.returnObj()
-}
-
-// Handle registers a new request handle and middleware with the given path and method.
-// The last handler should be the real handler, the other ones should be middleware that can and should be shared among different routes.
-// See the example code in github.
-//
-// For GET, POST, PUT, PATCH and DELETE requests the respective shortcut
-// functions can be used.
-//
-// This function is intended for bulk loading and to allow the usage of less
-// frequently used, non-standardized or custom methods (e.g. for internal
-// communication with a proxy).
-func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes {
- if matches, err := regexp.MatchString("^[A-Z]+$", httpMethod); !matches || err != nil {
- panic("http method " + httpMethod + " is not valid")
- }
- return group.handle(httpMethod, relativePath, handlers)
-}
-
-// POST is a shortcut for router.Handle("POST", path, handle).
-func (group *RouterGroup) POST(relativePath string, handlers ...HandlerFunc) IRoutes {
- return group.handle("POST", relativePath, handlers)
-}
-
-// GET is a shortcut for router.Handle("GET", path, handle).
-func (group *RouterGroup) GET(relativePath string, handlers ...HandlerFunc) IRoutes {
- return group.handle("GET", relativePath, handlers)
-}
-
-// DELETE is a shortcut for router.Handle("DELETE", path, handle).
-func (group *RouterGroup) DELETE(relativePath string, handlers ...HandlerFunc) IRoutes {
- return group.handle("DELETE", relativePath, handlers)
-}
-
-// PATCH is a shortcut for router.Handle("PATCH", path, handle).
-func (group *RouterGroup) PATCH(relativePath string, handlers ...HandlerFunc) IRoutes {
- return group.handle("PATCH", relativePath, handlers)
-}
-
-// PUT is a shortcut for router.Handle("PUT", path, handle).
-func (group *RouterGroup) PUT(relativePath string, handlers ...HandlerFunc) IRoutes {
- return group.handle("PUT", relativePath, handlers)
-}
-
-// OPTIONS is a shortcut for router.Handle("OPTIONS", path, handle).
-func (group *RouterGroup) OPTIONS(relativePath string, handlers ...HandlerFunc) IRoutes {
- return group.handle("OPTIONS", relativePath, handlers)
-}
-
-// HEAD is a shortcut for router.Handle("HEAD", path, handle).
-func (group *RouterGroup) HEAD(relativePath string, handlers ...HandlerFunc) IRoutes {
- return group.handle("HEAD", relativePath, handlers)
-}
-
-// Any registers a route that matches all the HTTP methods.
-// GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, CONNECT, TRACE.
-func (group *RouterGroup) Any(relativePath string, handlers ...HandlerFunc) IRoutes {
- group.handle("GET", relativePath, handlers)
- group.handle("POST", relativePath, handlers)
- group.handle("PUT", relativePath, handlers)
- group.handle("PATCH", relativePath, handlers)
- group.handle("HEAD", relativePath, handlers)
- group.handle("OPTIONS", relativePath, handlers)
- group.handle("DELETE", relativePath, handlers)
- group.handle("CONNECT", relativePath, handlers)
- group.handle("TRACE", relativePath, handlers)
- return group.returnObj()
-}
-
-// StaticFile registers a single route in order to serve a single file of the local filesystem.
-// router.StaticFile("favicon.ico", "./resources/favicon.ico")
-func (group *RouterGroup) StaticFile(relativePath, filepath string) IRoutes {
- if strings.Contains(relativePath, ":") || strings.Contains(relativePath, "*") {
- panic("URL parameters can not be used when serving a static file")
- }
- handler := func(c *Context) {
- c.File(filepath)
- }
- group.GET(relativePath, handler)
- group.HEAD(relativePath, handler)
- return group.returnObj()
-}
-
-// Static serves files from the given file system root.
-// Internally a http.FileServer is used, therefore http.NotFound is used instead
-// of the Router's NotFound handler.
-// To use the operating system's file system implementation,
-// use :
-// router.Static("/static", "/var/www")
-func (group *RouterGroup) Static(relativePath, root string) IRoutes {
- return group.StaticFS(relativePath, Dir(root, false))
-}
-
-// StaticFS works just like `Static()` but a custom `http.FileSystem` can be used instead.
-// Gin by default user: gin.Dir()
-func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRoutes {
- if strings.Contains(relativePath, ":") || strings.Contains(relativePath, "*") {
- panic("URL parameters can not be used when serving a static folder")
- }
- handler := group.createStaticHandler(relativePath, fs)
- urlPattern := path.Join(relativePath, "/*filepath")
-
- // Register GET and HEAD handlers
- group.GET(urlPattern, handler)
- group.HEAD(urlPattern, handler)
- return group.returnObj()
-}
-
-func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem) HandlerFunc {
- absolutePath := group.calculateAbsolutePath(relativePath)
- fileServer := http.StripPrefix(absolutePath, http.FileServer(fs))
- _, nolisting := fs.(*onlyfilesFS)
- return func(c *Context) {
- if nolisting {
- c.Writer.WriteHeader(http.StatusNotFound)
- }
- fileServer.ServeHTTP(c.Writer, c.Request)
- }
-}
-
-func (group *RouterGroup) combineHandlers(handlers HandlersChain) HandlersChain {
- finalSize := len(group.Handlers) + len(handlers)
- if finalSize >= int(abortIndex) {
- panic("too many handlers")
- }
- mergedHandlers := make(HandlersChain, finalSize)
- copy(mergedHandlers, group.Handlers)
- copy(mergedHandlers[len(group.Handlers):], handlers)
- return mergedHandlers
-}
-
-func (group *RouterGroup) calculateAbsolutePath(relativePath string) string {
- return joinPaths(group.basePath, relativePath)
-}
-
-func (group *RouterGroup) returnObj() IRoutes {
- if group.root {
- return group.engine
- }
- return group
-}
diff --git a/vendor/github.com/gin-gonic/gin/test_helpers.go b/vendor/github.com/gin-gonic/gin/test_helpers.go
deleted file mode 100644
index 3a7a5dd..0000000
--- a/vendor/github.com/gin-gonic/gin/test_helpers.go
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import "net/http"
-
-// CreateTestContext returns a fresh engine and context for testing purposes
-func CreateTestContext(w http.ResponseWriter) (c *Context, r *Engine) {
- r = New()
- c = r.allocateContext()
- c.reset()
- c.writermem.reset(w)
- return
-}
diff --git a/vendor/github.com/gin-gonic/gin/tree.go b/vendor/github.com/gin-gonic/gin/tree.go
deleted file mode 100644
index b653066..0000000
--- a/vendor/github.com/gin-gonic/gin/tree.go
+++ /dev/null
@@ -1,620 +0,0 @@
-// Copyright 2013 Julien Schmidt. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be found
-// at https://github.com/julienschmidt/httprouter/blob/master/LICENSE
-
-package gin
-
-import (
- "net/url"
- "strings"
- "unicode"
-)
-
-// Param is a single URL parameter, consisting of a key and a value.
-type Param struct {
- Key string
- Value string
-}
-
-// Params is a Param-slice, as returned by the router.
-// The slice is ordered, the first URL parameter is also the first slice value.
-// It is therefore safe to read values by the index.
-type Params []Param
-
-// Get returns the value of the first Param which key matches the given name.
-// If no matching Param is found, an empty string is returned.
-func (ps Params) Get(name string) (string, bool) {
- for _, entry := range ps {
- if entry.Key == name {
- return entry.Value, true
- }
- }
- return "", false
-}
-
-// ByName returns the value of the first Param which key matches the given name.
-// If no matching Param is found, an empty string is returned.
-func (ps Params) ByName(name string) (va string) {
- va, _ = ps.Get(name)
- return
-}
-
-type methodTree struct {
- method string
- root *node
-}
-
-type methodTrees []methodTree
-
-func (trees methodTrees) get(method string) *node {
- for _, tree := range trees {
- if tree.method == method {
- return tree.root
- }
- }
- return nil
-}
-
-func min(a, b int) int {
- if a <= b {
- return a
- }
- return b
-}
-
-func countParams(path string) uint8 {
- var n uint
- for i := 0; i < len(path); i++ {
- if path[i] != ':' && path[i] != '*' {
- continue
- }
- n++
- }
- if n >= 255 {
- return 255
- }
- return uint8(n)
-}
-
-type nodeType uint8
-
-const (
- static nodeType = iota // default
- root
- param
- catchAll
-)
-
-type node struct {
- path string
- indices string
- children []*node
- handlers HandlersChain
- priority uint32
- nType nodeType
- maxParams uint8
- wildChild bool
-}
-
-// increments priority of the given child and reorders if necessary.
-func (n *node) incrementChildPrio(pos int) int {
- n.children[pos].priority++
- prio := n.children[pos].priority
-
- // adjust position (move to front)
- newPos := pos
- for newPos > 0 && n.children[newPos-1].priority < prio {
- // swap node positions
- n.children[newPos-1], n.children[newPos] = n.children[newPos], n.children[newPos-1]
-
- newPos--
- }
-
- // build new index char string
- if newPos != pos {
- n.indices = n.indices[:newPos] + // unchanged prefix, might be empty
- n.indices[pos:pos+1] + // the index char we move
- n.indices[newPos:pos] + n.indices[pos+1:] // rest without char at 'pos'
- }
-
- return newPos
-}
-
-// addRoute adds a node with the given handle to the path.
-// Not concurrency-safe!
-func (n *node) addRoute(path string, handlers HandlersChain) {
- fullPath := path
- n.priority++
- numParams := countParams(path)
-
- // non-empty tree
- if len(n.path) > 0 || len(n.children) > 0 {
- walk:
- for {
- // Update maxParams of the current node
- if numParams > n.maxParams {
- n.maxParams = numParams
- }
-
- // Find the longest common prefix.
- // This also implies that the common prefix contains no ':' or '*'
- // since the existing key can't contain those chars.
- i := 0
- max := min(len(path), len(n.path))
- for i < max && path[i] == n.path[i] {
- i++
- }
-
- // Split edge
- if i < len(n.path) {
- child := node{
- path: n.path[i:],
- wildChild: n.wildChild,
- indices: n.indices,
- children: n.children,
- handlers: n.handlers,
- priority: n.priority - 1,
- }
-
- // Update maxParams (max of all children)
- for i := range child.children {
- if child.children[i].maxParams > child.maxParams {
- child.maxParams = child.children[i].maxParams
- }
- }
-
- n.children = []*node{&child}
- // []byte for proper unicode char conversion, see #65
- n.indices = string([]byte{n.path[i]})
- n.path = path[:i]
- n.handlers = nil
- n.wildChild = false
- }
-
- // Make new node a child of this node
- if i < len(path) {
- path = path[i:]
-
- if n.wildChild {
- n = n.children[0]
- n.priority++
-
- // Update maxParams of the child node
- if numParams > n.maxParams {
- n.maxParams = numParams
- }
- numParams--
-
- // Check if the wildcard matches
- if len(path) >= len(n.path) && n.path == path[:len(n.path)] {
- // check for longer wildcard, e.g. :name and :names
- if len(n.path) >= len(path) || path[len(n.path)] == '/' {
- continue walk
- }
- }
-
- panic("path segment '" + path +
- "' conflicts with existing wildcard '" + n.path +
- "' in path '" + fullPath + "'")
- }
-
- c := path[0]
-
- // slash after param
- if n.nType == param && c == '/' && len(n.children) == 1 {
- n = n.children[0]
- n.priority++
- continue walk
- }
-
- // Check if a child with the next path byte exists
- for i := 0; i < len(n.indices); i++ {
- if c == n.indices[i] {
- i = n.incrementChildPrio(i)
- n = n.children[i]
- continue walk
- }
- }
-
- // Otherwise insert it
- if c != ':' && c != '*' {
- // []byte for proper unicode char conversion, see #65
- n.indices += string([]byte{c})
- child := &node{
- maxParams: numParams,
- }
- n.children = append(n.children, child)
- n.incrementChildPrio(len(n.indices) - 1)
- n = child
- }
- n.insertChild(numParams, path, fullPath, handlers)
- return
-
- } else if i == len(path) { // Make node a (in-path) leaf
- if n.handlers != nil {
- panic("handlers are already registered for path '" + fullPath + "'")
- }
- n.handlers = handlers
- }
- return
- }
- } else { // Empty tree
- n.insertChild(numParams, path, fullPath, handlers)
- n.nType = root
- }
-}
-
-func (n *node) insertChild(numParams uint8, path string, fullPath string, handlers HandlersChain) {
- var offset int // already handled bytes of the path
-
- // find prefix until first wildcard (beginning with ':' or '*')
- for i, max := 0, len(path); numParams > 0; i++ {
- c := path[i]
- if c != ':' && c != '*' {
- continue
- }
-
- // find wildcard end (either '/' or path end)
- end := i + 1
- for end < max && path[end] != '/' {
- switch path[end] {
- // the wildcard name must not contain ':' and '*'
- case ':', '*':
- panic("only one wildcard per path segment is allowed, has: '" +
- path[i:] + "' in path '" + fullPath + "'")
- default:
- end++
- }
- }
-
- // check if this Node existing children which would be
- // unreachable if we insert the wildcard here
- if len(n.children) > 0 {
- panic("wildcard route '" + path[i:end] +
- "' conflicts with existing children in path '" + fullPath + "'")
- }
-
- // check if the wildcard has a name
- if end-i < 2 {
- panic("wildcards must be named with a non-empty name in path '" + fullPath + "'")
- }
-
- if c == ':' { // param
- // split path at the beginning of the wildcard
- if i > 0 {
- n.path = path[offset:i]
- offset = i
- }
-
- child := &node{
- nType: param,
- maxParams: numParams,
- }
- n.children = []*node{child}
- n.wildChild = true
- n = child
- n.priority++
- numParams--
-
- // if the path doesn't end with the wildcard, then there
- // will be another non-wildcard subpath starting with '/'
- if end < max {
- n.path = path[offset:end]
- offset = end
-
- child := &node{
- maxParams: numParams,
- priority: 1,
- }
- n.children = []*node{child}
- n = child
- }
-
- } else { // catchAll
- if end != max || numParams > 1 {
- panic("catch-all routes are only allowed at the end of the path in path '" + fullPath + "'")
- }
-
- if len(n.path) > 0 && n.path[len(n.path)-1] == '/' {
- panic("catch-all conflicts with existing handle for the path segment root in path '" + fullPath + "'")
- }
-
- // currently fixed width 1 for '/'
- i--
- if path[i] != '/' {
- panic("no / before catch-all in path '" + fullPath + "'")
- }
-
- n.path = path[offset:i]
-
- // first node: catchAll node with empty path
- child := &node{
- wildChild: true,
- nType: catchAll,
- maxParams: 1,
- }
- n.children = []*node{child}
- n.indices = string(path[i])
- n = child
- n.priority++
-
- // second node: node holding the variable
- child = &node{
- path: path[i:],
- nType: catchAll,
- maxParams: 1,
- handlers: handlers,
- priority: 1,
- }
- n.children = []*node{child}
-
- return
- }
- }
-
- // insert remaining path part and handle to the leaf
- n.path = path[offset:]
- n.handlers = handlers
-}
-
-// getValue returns the handle registered with the given path (key). The values of
-// wildcards are saved to a map.
-// If no handle can be found, a TSR (trailing slash redirect) recommendation is
-// made if a handle exists with an extra (without the) trailing slash for the
-// given path.
-func (n *node) getValue(path string, po Params, unescape bool) (handlers HandlersChain, p Params, tsr bool) {
- p = po
-walk: // Outer loop for walking the tree
- for {
- if len(path) > len(n.path) {
- if path[:len(n.path)] == n.path {
- path = path[len(n.path):]
- // If this node does not have a wildcard (param or catchAll)
- // child, we can just look up the next child node and continue
- // to walk down the tree
- if !n.wildChild {
- c := path[0]
- for i := 0; i < len(n.indices); i++ {
- if c == n.indices[i] {
- n = n.children[i]
- continue walk
- }
- }
-
- // Nothing found.
- // We can recommend to redirect to the same URL without a
- // trailing slash if a leaf exists for that path.
- tsr = path == "/" && n.handlers != nil
- return
- }
-
- // handle wildcard child
- n = n.children[0]
- switch n.nType {
- case param:
- // find param end (either '/' or path end)
- end := 0
- for end < len(path) && path[end] != '/' {
- end++
- }
-
- // save param value
- if cap(p) < int(n.maxParams) {
- p = make(Params, 0, n.maxParams)
- }
- i := len(p)
- p = p[:i+1] // expand slice within preallocated capacity
- p[i].Key = n.path[1:]
- val := path[:end]
- if unescape {
- var err error
- if p[i].Value, err = url.QueryUnescape(val); err != nil {
- p[i].Value = val // fallback, in case of error
- }
- } else {
- p[i].Value = val
- }
-
- // we need to go deeper!
- if end < len(path) {
- if len(n.children) > 0 {
- path = path[end:]
- n = n.children[0]
- continue walk
- }
-
- // ... but we can't
- tsr = len(path) == end+1
- return
- }
-
- if handlers = n.handlers; handlers != nil {
- return
- }
- if len(n.children) == 1 {
- // No handle found. Check if a handle for this path + a
- // trailing slash exists for TSR recommendation
- n = n.children[0]
- tsr = n.path == "/" && n.handlers != nil
- }
-
- return
-
- case catchAll:
- // save param value
- if cap(p) < int(n.maxParams) {
- p = make(Params, 0, n.maxParams)
- }
- i := len(p)
- p = p[:i+1] // expand slice within preallocated capacity
- p[i].Key = n.path[2:]
- if unescape {
- var err error
- if p[i].Value, err = url.QueryUnescape(path); err != nil {
- p[i].Value = path // fallback, in case of error
- }
- } else {
- p[i].Value = path
- }
-
- handlers = n.handlers
- return
-
- default:
- panic("invalid node type")
- }
- }
- } else if path == n.path {
- // We should have reached the node containing the handle.
- // Check if this node has a handle registered.
- if handlers = n.handlers; handlers != nil {
- return
- }
-
- if path == "/" && n.wildChild && n.nType != root {
- tsr = true
- return
- }
-
- // No handle found. Check if a handle for this path + a
- // trailing slash exists for trailing slash recommendation
- for i := 0; i < len(n.indices); i++ {
- if n.indices[i] == '/' {
- n = n.children[i]
- tsr = (len(n.path) == 1 && n.handlers != nil) ||
- (n.nType == catchAll && n.children[0].handlers != nil)
- return
- }
- }
-
- return
- }
-
- // Nothing found. We can recommend to redirect to the same URL with an
- // extra trailing slash if a leaf exists for that path
- tsr = (path == "/") ||
- (len(n.path) == len(path)+1 && n.path[len(path)] == '/' &&
- path == n.path[:len(n.path)-1] && n.handlers != nil)
- return
- }
-}
-
-// findCaseInsensitivePath makes a case-insensitive lookup of the given path and tries to find a handler.
-// It can optionally also fix trailing slashes.
-// It returns the case-corrected path and a bool indicating whether the lookup
-// was successful.
-func (n *node) findCaseInsensitivePath(path string, fixTrailingSlash bool) (ciPath []byte, found bool) {
- ciPath = make([]byte, 0, len(path)+1) // preallocate enough memory
-
- // Outer loop for walking the tree
- for len(path) >= len(n.path) && strings.ToLower(path[:len(n.path)]) == strings.ToLower(n.path) {
- path = path[len(n.path):]
- ciPath = append(ciPath, n.path...)
-
- if len(path) > 0 {
- // If this node does not have a wildcard (param or catchAll) child,
- // we can just look up the next child node and continue to walk down
- // the tree
- if !n.wildChild {
- r := unicode.ToLower(rune(path[0]))
- for i, index := range n.indices {
- // must use recursive approach since both index and
- // ToLower(index) could exist. We must check both.
- if r == unicode.ToLower(index) {
- out, found := n.children[i].findCaseInsensitivePath(path, fixTrailingSlash)
- if found {
- return append(ciPath, out...), true
- }
- }
- }
-
- // Nothing found. We can recommend to redirect to the same URL
- // without a trailing slash if a leaf exists for that path
- found = fixTrailingSlash && path == "/" && n.handlers != nil
- return
- }
-
- n = n.children[0]
- switch n.nType {
- case param:
- // find param end (either '/' or path end)
- k := 0
- for k < len(path) && path[k] != '/' {
- k++
- }
-
- // add param value to case insensitive path
- ciPath = append(ciPath, path[:k]...)
-
- // we need to go deeper!
- if k < len(path) {
- if len(n.children) > 0 {
- path = path[k:]
- n = n.children[0]
- continue
- }
-
- // ... but we can't
- if fixTrailingSlash && len(path) == k+1 {
- return ciPath, true
- }
- return
- }
-
- if n.handlers != nil {
- return ciPath, true
- } else if fixTrailingSlash && len(n.children) == 1 {
- // No handle found. Check if a handle for this path + a
- // trailing slash exists
- n = n.children[0]
- if n.path == "/" && n.handlers != nil {
- return append(ciPath, '/'), true
- }
- }
- return
-
- case catchAll:
- return append(ciPath, path...), true
-
- default:
- panic("invalid node type")
- }
- } else {
- // We should have reached the node containing the handle.
- // Check if this node has a handle registered.
- if n.handlers != nil {
- return ciPath, true
- }
-
- // No handle found.
- // Try to fix the path by adding a trailing slash
- if fixTrailingSlash {
- for i := 0; i < len(n.indices); i++ {
- if n.indices[i] == '/' {
- n = n.children[i]
- if (len(n.path) == 1 && n.handlers != nil) ||
- (n.nType == catchAll && n.children[0].handlers != nil) {
- return append(ciPath, '/'), true
- }
- return
- }
- }
- }
- return
- }
- }
-
- // Nothing found.
- // Try to fix the path by adding / removing a trailing slash
- if fixTrailingSlash {
- if path == "/" {
- return ciPath, true
- }
- if len(path)+1 == len(n.path) && n.path[len(path)] == '/' &&
- strings.ToLower(path) == strings.ToLower(n.path[:len(path)]) &&
- n.handlers != nil {
- return append(ciPath, n.path...), true
- }
- }
- return
-}
diff --git a/vendor/github.com/gin-gonic/gin/utils.go b/vendor/github.com/gin-gonic/gin/utils.go
deleted file mode 100644
index bf32c77..0000000
--- a/vendor/github.com/gin-gonic/gin/utils.go
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
-// Use of this source code is governed by a MIT style
-// license that can be found in the LICENSE file.
-
-package gin
-
-import (
- "encoding/xml"
- "net/http"
- "os"
- "path"
- "reflect"
- "runtime"
- "strings"
-)
-
-const BindKey = "_gin-gonic/gin/bindkey"
-
-func Bind(val interface{}) HandlerFunc {
- value := reflect.ValueOf(val)
- if value.Kind() == reflect.Ptr {
- panic(`Bind struct can not be a pointer. Example:
- Use: gin.Bind(Struct{}) instead of gin.Bind(&Struct{})
-`)
- }
- typ := value.Type()
-
- return func(c *Context) {
- obj := reflect.New(typ).Interface()
- if c.Bind(obj) == nil {
- c.Set(BindKey, obj)
- }
- }
-}
-
-// WrapF is a helper function for wrapping http.HandlerFunc
-// Returns a Gin middleware
-func WrapF(f http.HandlerFunc) HandlerFunc {
- return func(c *Context) {
- f(c.Writer, c.Request)
- }
-}
-
-// WrapH is a helper function for wrapping http.Handler
-// Returns a Gin middleware
-func WrapH(h http.Handler) HandlerFunc {
- return func(c *Context) {
- h.ServeHTTP(c.Writer, c.Request)
- }
-}
-
-// H is a shortcut for map[string]interface{}
-type H map[string]interface{}
-
-// MarshalXML allows type H to be used with xml.Marshal.
-func (h H) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
- start.Name = xml.Name{
- Space: "",
- Local: "map",
- }
- if err := e.EncodeToken(start); err != nil {
- return err
- }
- for key, value := range h {
- elem := xml.StartElement{
- Name: xml.Name{Space: "", Local: key},
- Attr: []xml.Attr{},
- }
- if err := e.EncodeElement(value, elem); err != nil {
- return err
- }
- }
-
- return e.EncodeToken(xml.EndElement{Name: start.Name})
-}
-
-func assert1(guard bool, text string) {
- if !guard {
- panic(text)
- }
-}
-
-func filterFlags(content string) string {
- for i, char := range content {
- if char == ' ' || char == ';' {
- return content[:i]
- }
- }
- return content
-}
-
-func chooseData(custom, wildcard interface{}) interface{} {
- if custom == nil {
- if wildcard == nil {
- panic("negotiation config is invalid")
- }
- return wildcard
- }
- return custom
-}
-
-func parseAccept(acceptHeader string) []string {
- parts := strings.Split(acceptHeader, ",")
- out := make([]string, 0, len(parts))
- for _, part := range parts {
- if part = strings.TrimSpace(strings.Split(part, ";")[0]); part != "" {
- out = append(out, part)
- }
- }
- return out
-}
-
-func lastChar(str string) uint8 {
- if str == "" {
- panic("The length of the string can't be 0")
- }
- return str[len(str)-1]
-}
-
-func nameOfFunction(f interface{}) string {
- return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
-}
-
-func joinPaths(absolutePath, relativePath string) string {
- if relativePath == "" {
- return absolutePath
- }
-
- finalPath := path.Join(absolutePath, relativePath)
- appendSlash := lastChar(relativePath) == '/' && lastChar(finalPath) != '/'
- if appendSlash {
- return finalPath + "/"
- }
- return finalPath
-}
-
-func resolveAddress(addr []string) string {
- switch len(addr) {
- case 0:
- if port := os.Getenv("PORT"); port != "" {
- debugPrint("Environment variable PORT=\"%s\"", port)
- return ":" + port
- }
- debugPrint("Environment variable PORT is undefined. Using port :8080 by default")
- return ":8080"
- case 1:
- return addr[0]
- default:
- panic("too much parameters")
- }
-}
diff --git a/vendor/github.com/gin-gonic/gin/wercker.yml b/vendor/github.com/gin-gonic/gin/wercker.yml
deleted file mode 100644
index 3ab8084..0000000
--- a/vendor/github.com/gin-gonic/gin/wercker.yml
+++ /dev/null
@@ -1 +0,0 @@
-box: wercker/default
\ No newline at end of file
diff --git a/vendor/github.com/go-irc/irc/.gitignore b/vendor/github.com/go-irc/irc/.gitignore
deleted file mode 100644
index b64fa18..0000000
--- a/vendor/github.com/go-irc/irc/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*.cover
-*.test
-*.out
diff --git a/vendor/github.com/go-irc/irc/.gitmodules b/vendor/github.com/go-irc/irc/.gitmodules
deleted file mode 100644
index 8ed3899..0000000
--- a/vendor/github.com/go-irc/irc/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "testcases"]
- path = testcases
- url = https://github.com/go-irc/irc-parser-tests/
diff --git a/vendor/github.com/go-irc/irc/.travis.yml b/vendor/github.com/go-irc/irc/.travis.yml
deleted file mode 100644
index 494bd20..0000000
--- a/vendor/github.com/go-irc/irc/.travis.yml
+++ /dev/null
@@ -1,21 +0,0 @@
-language: go
-
-before_install:
- - go get github.com/axw/gocov/gocov
- - go get github.com/mattn/goveralls
- - go get golang.org/x/tools/cmd/cover
- # Grab all deps (should just be test deps)
- - go get -v -t ./...
- # Linting deps
- - go get github.com/alecthomas/gometalinter
- - gometalinter --install
- # Remove the go file from the test cases dir as it fails linting
- - rm ./testcases/*.go
-
-script:
- - gometalinter --fast ./... -D gas
- - go test -race -v ./...
- - go test -covermode=count -coverprofile=profile.cov
-
-after_script:
- - $HOME/gopath/bin/goveralls -coverprofile=profile.cov -service=travis-ci
diff --git a/vendor/github.com/go-irc/irc/LICENSE b/vendor/github.com/go-irc/irc/LICENSE
deleted file mode 100644
index 7e5e1ab..0000000
--- a/vendor/github.com/go-irc/irc/LICENSE
+++ /dev/null
@@ -1,18 +0,0 @@
-Copyright 2016 Kaleb Elwert
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/github.com/go-irc/irc/README.md b/vendor/github.com/go-irc/irc/README.md
deleted file mode 100644
index f2d755b..0000000
--- a/vendor/github.com/go-irc/irc/README.md
+++ /dev/null
@@ -1,104 +0,0 @@
-# go-irc
-
-[![GoDoc](https://img.shields.io/badge/doc-GoDoc-blue.svg)](https://godoc.org/github.com/go-irc/irc)
-[![Build Status](https://img.shields.io/travis/go-irc/irc.svg)](https://travis-ci.org/go-irc/irc)
-[![Coverage Status](https://img.shields.io/coveralls/go-irc/irc.svg)](https://coveralls.io/github/go-irc/irc?branch=master)
-
-This package was originally created to only handle message parsing,
-but has since been expanded to include a small abstraction around a
-connection and a simple client.
-
-This library is not designed to hide any of the IRC elements from
-you. If you just want to build a simple chat bot and don't want to
-deal with IRC in particular, there are a number of other libraries
-which provide a more full featured client if that's what you're
-looking for.
-
-This library is meant to stay as simple as possible so it can be a
-building block for other packages.
-
-This library aims for API compatibility whenever possible. New
-functions and other additions will most likely not result in a major
-version increase unless they break the API. This library aims to
-follow the semver recommendations mentioned on gopkg.in.
-
-Due to complications in how to support x/net/context vs the built-in context
-package, only go 1.7+ is officially supported.
-
-## Import Paths
-
-All development happens on the `master` branch and when features are
-considered stable enough, a new release will be tagged.
-
-As a result of this, there are multiple import locations.
-
-* `gopkg.in/irc.v2` should be used to develop against the commits
- tagged as stable
-* `github.com/go-irc/irc` should be used to develop against the master branch
-
-## Development
-
-In order to run the tests, make sure all submodules are up to date. If you are
-just using this library, these are not needed.
-
-## Example
-
-```go
-package main
-
-import (
- "log"
- "net"
-
- "github.com/belak/irc"
-)
-
-func main() {
- conn, err := net.Dial("tcp", "chat.freenode.net:6667")
- if err != nil {
- log.Fatalln(err)
- }
-
- config := irc.ClientConfig{
- Nick: "i_have_a_nick",
- Pass: "password",
- User: "username",
- Name: "Full Name",
- Handler: irc.HandlerFunc(func(c *irc.Client, m *irc.Message) {
- if m.Command == "001" {
- // 001 is a welcome event, so we join channels there
- c.Write("JOIN #bot-test-chan")
- } else if m.Command == "PRIVMSG" && m.FromChannel() {
- // Create a handler on all messages.
- c.WriteMessage(&irc.Message{
- Command: "PRIVMSG",
- Params: []string{
- m.Params[0],
- m.Trailing(),
- },
- })
- }
- }),
- }
-
- // Create the client
- client := irc.NewClient(conn, config)
- err = client.Run()
- if err != nil {
- log.Fatalln(err)
- }
-}
-```
-
-## Major Version Changes
-
-### v1
-
-Initial release
-
-### v2
-
-- CTCP messages will no longer be rewritten. The decision was made that this
- library should pass through all messages without mangling them.
-- Remove Message.FromChannel as this is not always accurate, while
- Client.FromChannel should always be accurate.
diff --git a/vendor/github.com/go-irc/irc/client.go b/vendor/github.com/go-irc/irc/client.go
deleted file mode 100644
index 999ebff..0000000
--- a/vendor/github.com/go-irc/irc/client.go
+++ /dev/null
@@ -1,331 +0,0 @@
-package irc
-
-import (
- "context"
- "errors"
- "fmt"
- "io"
- "sync"
- "time"
-)
-
-// ClientConfig is a structure used to configure a Client.
-type ClientConfig struct {
- // General connection information.
- Nick string
- Pass string
- User string
- Name string
-
- // Connection settings
- PingFrequency time.Duration
- PingTimeout time.Duration
-
- // SendLimit is how frequent messages can be sent. If this is zero,
- // there will be no limit.
- SendLimit time.Duration
-
- // SendBurst is the number of messages which can be sent in a burst.
- SendBurst int
-
- // Handler is used for message dispatching.
- Handler Handler
-}
-
-type cap struct {
- // Requested means that this cap was requested by the user
- Requested bool
-
- // Required will be true if this cap is non-optional
- Required bool
-
- // Enabled means that this cap was accepted by the server
- Enabled bool
-
- // Available means that the server supports this cap
- Available bool
-}
-
-// Client is a wrapper around Conn which is designed to make common operations
-// much simpler.
-type Client struct {
- *Conn
- config ClientConfig
-
- // Internal state
- currentNick string
- limiter chan struct{}
- incomingPongChan chan string
- errChan chan error
- caps map[string]cap
- remainingCapResponses int
- connected bool
-}
-
-// NewClient creates a client given an io stream and a client config.
-func NewClient(rw io.ReadWriter, config ClientConfig) *Client {
- c := &Client{
- Conn: NewConn(rw),
- config: config,
- errChan: make(chan error, 1),
- caps: make(map[string]cap),
- }
-
- // Replace the writer writeCallback with one of our own
- c.Conn.Writer.writeCallback = c.writeCallback
-
- return c
-}
-
-func (c *Client) writeCallback(w *Writer, line string) error {
- if c.limiter != nil {
- <-c.limiter
- }
-
- _, err := w.writer.Write([]byte(line + "\r\n"))
- if err != nil {
- c.sendError(err)
- }
- return err
-}
-
-// maybeStartLimiter will start a ticker which will limit how quickly messages
-// can be written to the connection if the SendLimit is set in the config.
-func (c *Client) maybeStartLimiter(wg *sync.WaitGroup, exiting chan struct{}) {
- if c.config.SendLimit == 0 {
- return
- }
-
- wg.Add(1)
-
- // If SendBurst is 0, this will be unbuffered, so keep that in mind.
- c.limiter = make(chan struct{}, c.config.SendBurst)
- limitTick := time.NewTicker(c.config.SendLimit)
-
- go func() {
- defer wg.Done()
-
- var done bool
- for !done {
- select {
- case <-limitTick.C:
- select {
- case c.limiter <- struct{}{}:
- default:
- }
- case <-exiting:
- done = true
- }
- }
-
- limitTick.Stop()
- close(c.limiter)
- c.limiter = nil
- }()
-}
-
-// maybeStartPingLoop will start a goroutine to send out PING messages at the
-// PingFrequency in the config if the frequency is not 0.
-func (c *Client) maybeStartPingLoop(wg *sync.WaitGroup, exiting chan struct{}) {
- if c.config.PingFrequency <= 0 {
- return
- }
-
- wg.Add(1)
-
- c.incomingPongChan = make(chan string, 5)
-
- go func() {
- defer wg.Done()
-
- pingHandlers := make(map[string]chan struct{})
- ticker := time.NewTicker(c.config.PingFrequency)
-
- defer ticker.Stop()
-
- for {
- select {
- case <-ticker.C:
- // Each time we get a tick, we send off a ping and start a
- // goroutine to handle the pong.
- timestamp := time.Now().Unix()
- pongChan := make(chan struct{}, 1)
- pingHandlers[fmt.Sprintf("%d", timestamp)] = pongChan
- wg.Add(1)
- go c.handlePing(timestamp, pongChan, wg, exiting)
- case data := <-c.incomingPongChan:
- // Make sure the pong gets routed to the correct
- // goroutine.
-
- c := pingHandlers[data]
- delete(pingHandlers, data)
-
- if c != nil {
- c <- struct{}{}
- }
- case <-exiting:
- return
- }
- }
- }()
-}
-
-func (c *Client) handlePing(timestamp int64, pongChan chan struct{}, wg *sync.WaitGroup, exiting chan struct{}) {
- defer wg.Done()
-
- c.Writef("PING :%d", timestamp)
-
- timer := time.NewTimer(c.config.PingTimeout)
- defer timer.Stop()
-
- select {
- case <-timer.C:
- c.sendError(errors.New("Ping Timeout"))
- case <-pongChan:
- return
- case <-exiting:
- return
- }
-}
-
-// maybeStartCapHandshake will run a CAP LS and all the relevant CAP REQ
-// commands if there are any CAPs requested.
-func (c *Client) maybeStartCapHandshake() {
- if len(c.caps) <= 0 {
- return
- }
-
- c.Write("CAP LS")
- c.remainingCapResponses = 1 // We count the CAP LS response as a normal response
- for key, cap := range c.caps {
- if cap.Requested {
- c.Writef("CAP REQ :%s", key)
- c.remainingCapResponses++
- }
- }
-}
-
-// CapRequest allows you to request IRCv3 capabilities from the server during
-// the handshake. The behavior is undefined if this is called before the
-// handshake completes so it is recommended that this be called before Run. If
-// the CAP is marked as required, the client will exit if that CAP could not be
-// negotiated during the handshake.
-func (c *Client) CapRequest(capName string, required bool) {
- cap := c.caps[capName]
- cap.Requested = true
- cap.Required = cap.Required || required
- c.caps[capName] = cap
-}
-
-// CapEnabled allows you to check if a CAP is enabled for this connection. Note
-// that it will not be populated until after the CAP handshake is done, so it is
-// recommended to wait to check this until after a message like 001.
-func (c *Client) CapEnabled(capName string) bool {
- return c.caps[capName].Enabled
-}
-
-// CapAvailable allows you to check if a CAP is available on this server. Note
-// that it will not be populated until after the CAP handshake is done, so it is
-// recommended to wait to check this until after a message like 001.
-func (c *Client) CapAvailable(capName string) bool {
- return c.caps[capName].Available
-}
-
-func (c *Client) sendError(err error) {
- select {
- case c.errChan <- err:
- default:
- }
-}
-
-func (c *Client) startReadLoop(wg *sync.WaitGroup) {
- wg.Add(1)
-
- go func() {
- defer wg.Done()
-
- for {
- m, err := c.ReadMessage()
- if err != nil {
- c.sendError(err)
- break
- }
-
- if f, ok := clientFilters[m.Command]; ok {
- f(c, m)
- }
-
- if c.config.Handler != nil {
- c.config.Handler.Handle(c, m)
- }
- }
-
- }()
-}
-
-// Run starts the main loop for this IRC connection. Note that it may break in
-// strange and unexpected ways if it is called again before the first connection
-// exits.
-func (c *Client) Run() error {
- return c.RunContext(context.TODO())
-}
-
-// RunContext is the same as Run but a context.Context can be passed in for
-// cancelation.
-func (c *Client) RunContext(ctx context.Context) error {
- // exiting is used by the main goroutine here to ensure any sub-goroutines
- // get closed when exiting.
- exiting := make(chan struct{})
- var wg sync.WaitGroup
-
- c.maybeStartLimiter(&wg, exiting)
- c.maybeStartPingLoop(&wg, exiting)
-
- c.currentNick = c.config.Nick
-
- if c.config.Pass != "" {
- c.Writef("PASS :%s", c.config.Pass)
- }
-
- c.maybeStartCapHandshake()
-
- // This feels wrong because it results in CAP LS, CAP REQ, NICK, USER, CAP
- // END, but it works and lets us keep the code a bit simpler.
- c.Writef("NICK :%s", c.config.Nick)
- c.Writef("USER %s 0.0.0.0 0.0.0.0 :%s", c.config.User, c.config.Name)
-
- // Now that the handshake is pretty much done, we can start listening for
- // messages.
- c.startReadLoop(&wg)
-
- // Wait for an error from any goroutine or for the context to time out, then
- // signal we're exiting and wait for the goroutines to exit.
- var err error
- select {
- case err = <-c.errChan:
- case <-ctx.Done():
- }
-
- close(exiting)
- wg.Wait()
-
- return err
-}
-
-// CurrentNick returns what the nick of the client is known to be at this point
-// in time.
-func (c *Client) CurrentNick() string {
- return c.currentNick
-}
-
-// FromChannel takes a Message representing a PRIVMSG and returns if that
-// message came from a channel or directly from a user.
-func (c *Client) FromChannel(m *Message) bool {
- if len(m.Params) < 1 {
- return false
- }
-
- // The first param is the target, so if this doesn't match the current nick,
- // the message came from a channel.
- return m.Params[0] != c.currentNick
-}
diff --git a/vendor/github.com/go-irc/irc/client_handlers.go b/vendor/github.com/go-irc/irc/client_handlers.go
deleted file mode 100644
index 3b5cd8d..0000000
--- a/vendor/github.com/go-irc/irc/client_handlers.go
+++ /dev/null
@@ -1,151 +0,0 @@
-package irc
-
-import (
- "fmt"
- "strings"
-)
-
-type clientFilter func(*Client, *Message)
-
-// clientFilters are pre-processing which happens for certain message
-// types. These were moved from below to keep the complexity of each
-// component down.
-var clientFilters = map[string]clientFilter{
- "001": handle001,
- "433": handle433,
- "437": handle437,
- "PING": handlePing,
- "PONG": handlePong,
- "NICK": handleNick,
- "CAP": handleCap,
-}
-
-// From rfc2812 section 5.1 (Command responses)
-//
-// 001 RPL_WELCOME
-// "Welcome to the Internet Relay Network
-// !@"
-func handle001(c *Client, m *Message) {
- c.currentNick = m.Params[0]
- c.connected = true
-}
-
-// From rfc2812 section 5.2 (Error Replies)
-//
-// 433 ERR_NICKNAMEINUSE
-// " :Nickname is already in use"
-//
-// - Returned when a NICK message is processed that results
-// in an attempt to change to a currently existing
-// nickname.
-func handle433(c *Client, m *Message) {
- // We only want to try and handle nick collisions during the initial
- // handshake.
- if c.connected {
- return
- }
- c.currentNick = c.currentNick + "_"
- c.Writef("NICK :%s", c.currentNick)
-}
-
-// From rfc2812 section 5.2 (Error Replies)
-//
-// 437 ERR_UNAVAILRESOURCE
-// " :Nick/channel is temporarily unavailable"
-//
-// - Returned by a server to a user trying to join a channel
-// currently blocked by the channel delay mechanism.
-//
-// - Returned by a server to a user trying to change nickname
-// when the desired nickname is blocked by the nick delay
-// mechanism.
-func handle437(c *Client, m *Message) {
- // We only want to try and handle nick collisions during the initial
- // handshake.
- if c.connected {
- return
- }
- c.currentNick = c.currentNick + "_"
- c.Writef("NICK :%s", c.currentNick)
-}
-
-func handlePing(c *Client, m *Message) {
- reply := m.Copy()
- reply.Command = "PONG"
- c.WriteMessage(reply)
-}
-
-func handlePong(c *Client, m *Message) {
- if c.incomingPongChan != nil {
- select {
- case c.incomingPongChan <- m.Trailing():
- default:
- // Note that this return isn't really needed, but it helps some code
- // coverage tools actually see this line.
- return
- }
- }
-}
-
-func handleNick(c *Client, m *Message) {
- if m.Prefix.Name == c.currentNick && len(m.Params) > 0 {
- c.currentNick = m.Params[0]
- }
-}
-
-var capFilters = map[string]clientFilter{
- "LS": handleCapLs,
- "ACK": handleCapAck,
- "NAK": handleCapNak,
-}
-
-func handleCap(c *Client, m *Message) {
- if c.remainingCapResponses <= 0 || len(m.Params) <= 2 {
- return
- }
-
- if filter, ok := capFilters[m.Params[1]]; ok {
- filter(c, m)
- }
-
- if c.remainingCapResponses <= 0 {
- for key, cap := range c.caps {
- if cap.Required && !cap.Enabled {
- c.sendError(fmt.Errorf("CAP %s requested but not accepted", key))
- return
- }
- }
-
- c.Write("CAP END")
- }
-}
-
-func handleCapLs(c *Client, m *Message) {
- for _, key := range strings.Split(m.Trailing(), " ") {
- cap := c.caps[key]
- cap.Available = true
- c.caps[key] = cap
- }
- c.remainingCapResponses--
-}
-
-func handleCapAck(c *Client, m *Message) {
- for _, key := range strings.Split(m.Trailing(), " ") {
- cap := c.caps[key]
- cap.Enabled = true
- c.caps[key] = cap
- }
- c.remainingCapResponses--
-}
-
-func handleCapNak(c *Client, m *Message) {
- // If we got a NAK and this REQ was required, we need to bail
- // with an error.
- for _, key := range strings.Split(m.Trailing(), " ") {
- if c.caps[key].Required {
- c.sendError(fmt.Errorf("CAP %s requested but was rejected", key))
- return
- }
- }
- c.remainingCapResponses--
-}
diff --git a/vendor/github.com/go-irc/irc/conn.go b/vendor/github.com/go-irc/irc/conn.go
deleted file mode 100644
index 7f9b68e..0000000
--- a/vendor/github.com/go-irc/irc/conn.go
+++ /dev/null
@@ -1,103 +0,0 @@
-package irc
-
-import (
- "bufio"
- "fmt"
- "io"
-)
-
-// Conn represents a simple IRC client. It embeds an irc.Reader and an
-// irc.Writer.
-type Conn struct {
- *Reader
- *Writer
-}
-
-// NewConn creates a new Conn
-func NewConn(rw io.ReadWriter) *Conn {
- return &Conn{
- NewReader(rw),
- NewWriter(rw),
- }
-}
-
-// Writer is the outgoing side of a connection.
-type Writer struct {
- // DebugCallback is called for each outgoing message. The name of this may
- // not be stable.
- DebugCallback func(line string)
-
- // Internal fields
- writer io.Writer
- writeCallback func(w *Writer, line string) error
-}
-
-func defaultWriteCallback(w *Writer, line string) error {
- _, err := w.writer.Write([]byte(line + "\r\n"))
- return err
-}
-
-// NewWriter creates an irc.Writer from an io.Writer.
-func NewWriter(w io.Writer) *Writer {
- return &Writer{nil, w, defaultWriteCallback}
-}
-
-// Write is a simple function which will write the given line to the
-// underlying connection.
-func (w *Writer) Write(line string) error {
- if w.DebugCallback != nil {
- w.DebugCallback(line)
- }
-
- return w.writeCallback(w, line)
-}
-
-// Writef is a wrapper around the connection's Write method and
-// fmt.Sprintf. Simply use it to send a message as you would normally
-// use fmt.Printf.
-func (w *Writer) Writef(format string, args ...interface{}) error {
- return w.Write(fmt.Sprintf(format, args...))
-}
-
-// WriteMessage writes the given message to the stream
-func (w *Writer) WriteMessage(m *Message) error {
- return w.Write(m.String())
-}
-
-// Reader is the incoming side of a connection. The data will be
-// buffered, so do not re-use the io.Reader used to create the
-// irc.Reader.
-type Reader struct {
- // DebugCallback is called for each incoming message. The name of this may
- // not be stable.
- DebugCallback func(string)
-
- // Internal fields
- reader *bufio.Reader
-}
-
-// NewReader creates an irc.Reader from an io.Reader. Note that once a reader is
-// passed into this function, you should no longer use it as it is being used
-// inside a bufio.Reader so you cannot rely on only the amount of data for a
-// Message being read when you call ReadMessage.
-func NewReader(r io.Reader) *Reader {
- return &Reader{
- nil,
- bufio.NewReader(r),
- }
-}
-
-// ReadMessage returns the next message from the stream or an error.
-func (r *Reader) ReadMessage() (*Message, error) {
- line, err := r.reader.ReadString('\n')
- if err != nil {
- return nil, err
- }
-
- if r.DebugCallback != nil {
- r.DebugCallback(line)
- }
-
- // Parse the message from our line
- return ParseMessage(line)
-}
diff --git a/vendor/github.com/go-irc/irc/handler.go b/vendor/github.com/go-irc/irc/handler.go
deleted file mode 100644
index 6a9fca7..0000000
--- a/vendor/github.com/go-irc/irc/handler.go
+++ /dev/null
@@ -1,16 +0,0 @@
-package irc
-
-// Handler is a simple interface meant for dispatching a message from
-// a Client connection.
-type Handler interface {
- Handle(*Client, *Message)
-}
-
-// HandlerFunc is a simple wrapper around a function which allows it
-// to be used as a Handler.
-type HandlerFunc func(*Client, *Message)
-
-// Handle calls f(c, m)
-func (f HandlerFunc) Handle(c *Client, m *Message) {
- f(c, m)
-}
diff --git a/vendor/github.com/go-irc/irc/parser.go b/vendor/github.com/go-irc/irc/parser.go
deleted file mode 100644
index 819de4d..0000000
--- a/vendor/github.com/go-irc/irc/parser.go
+++ /dev/null
@@ -1,394 +0,0 @@
-package irc
-
-import (
- "bytes"
- "errors"
- "strings"
-)
-
-var tagDecodeSlashMap = map[rune]rune{
- ':': ';',
- 's': ' ',
- '\\': '\\',
- 'r': '\r',
- 'n': '\n',
-}
-
-var tagEncodeMap = map[rune]string{
- ';': "\\:",
- ' ': "\\s",
- '\\': "\\\\",
- '\r': "\\r",
- '\n': "\\n",
-}
-
-var (
- // ErrZeroLengthMessage is returned when parsing if the input is
- // zero-length.
- ErrZeroLengthMessage = errors.New("irc: Cannot parse zero-length message")
-
- // ErrMissingDataAfterPrefix is returned when parsing if there is
- // no message data after the prefix.
- ErrMissingDataAfterPrefix = errors.New("irc: No message data after prefix")
-
- // ErrMissingDataAfterTags is returned when parsing if there is no
- // message data after the tags.
- ErrMissingDataAfterTags = errors.New("irc: No message data after tags")
-
- // ErrMissingCommand is returned when parsing if there is no
- // command in the parsed message.
- ErrMissingCommand = errors.New("irc: Missing message command")
-)
-
-// TagValue represents the value of a tag.
-type TagValue string
-
-// ParseTagValue parses a TagValue from the connection. If you need to
-// set a TagValue, you probably want to just set the string itself, so
-// it will be encoded properly.
-func ParseTagValue(v string) TagValue {
- ret := &bytes.Buffer{}
-
- input := bytes.NewBufferString(v)
-
- for {
- c, _, err := input.ReadRune()
- if err != nil {
- break
- }
-
- if c == '\\' {
- c2, _, err := input.ReadRune()
-
- // If we got a backslash then the end of the tag value, we should
- // just ignore the backslash.
- if err != nil {
- break
- }
-
- if replacement, ok := tagDecodeSlashMap[c2]; ok {
- ret.WriteRune(replacement)
- } else {
- ret.WriteRune(c2)
- }
- } else {
- ret.WriteRune(c)
- }
- }
-
- return TagValue(ret.String())
-}
-
-// Encode converts a TagValue to the format in the connection.
-func (v TagValue) Encode() string {
- ret := &bytes.Buffer{}
-
- for _, c := range v {
- if replacement, ok := tagEncodeMap[c]; ok {
- ret.WriteString(replacement)
- } else {
- ret.WriteRune(c)
- }
- }
-
- return ret.String()
-}
-
-// Tags represents the IRCv3 message tags.
-type Tags map[string]TagValue
-
-// ParseTags takes a tag string and parses it into a tag map. It will
-// always return a tag map, even if there are no valid tags.
-func ParseTags(line string) Tags {
- ret := Tags{}
-
- tags := strings.Split(line, ";")
- for _, tag := range tags {
- parts := strings.SplitN(tag, "=", 2)
- if len(parts) < 2 {
- ret[parts[0]] = ""
- continue
- }
-
- ret[parts[0]] = ParseTagValue(parts[1])
- }
-
- return ret
-}
-
-// GetTag is a convenience method to look up a tag in the map.
-func (t Tags) GetTag(key string) (string, bool) {
- ret, ok := t[key]
- return string(ret), ok
-}
-
-// Copy will create a new copy of all IRC tags attached to this
-// message.
-func (t Tags) Copy() Tags {
- ret := Tags{}
-
- for k, v := range t {
- ret[k] = v
- }
-
- return ret
-}
-
-// String ensures this is stringable
-func (t Tags) String() string {
- buf := &bytes.Buffer{}
-
- for k, v := range t {
- buf.WriteByte(';')
- buf.WriteString(k)
- if v != "" {
- buf.WriteByte('=')
- buf.WriteString(v.Encode())
- }
- }
-
- // We don't need the first byte because that's an extra ';'
- // character.
- buf.ReadByte()
-
- return buf.String()
-}
-
-// Prefix represents the prefix of a message, generally the user who sent it
-type Prefix struct {
- // Name will contain the nick of who sent the message, the
- // server who sent the message, or a blank string
- Name string
-
- // User will either contain the user who sent the message or a blank string
- User string
-
- // Host will either contain the host of who sent the message or a blank string
- Host string
-}
-
-// ParsePrefix takes an identity string and parses it into an
-// identity struct. It will always return an Prefix struct and never
-// nil.
-func ParsePrefix(line string) *Prefix {
- // Start by creating an Prefix with nothing but the host
- id := &Prefix{
- Name: line,
- }
-
- uh := strings.SplitN(id.Name, "@", 2)
- if len(uh) == 2 {
- id.Name, id.Host = uh[0], uh[1]
- }
-
- nu := strings.SplitN(id.Name, "!", 2)
- if len(nu) == 2 {
- id.Name, id.User = nu[0], nu[1]
- }
-
- return id
-}
-
-// Copy will create a new copy of an Prefix
-func (p *Prefix) Copy() *Prefix {
- if p == nil {
- return nil
- }
-
- newPrefix := &Prefix{}
-
- *newPrefix = *p
-
- return newPrefix
-}
-
-// String ensures this is stringable
-func (p *Prefix) String() string {
- buf := &bytes.Buffer{}
- buf.WriteString(p.Name)
-
- if p.User != "" {
- buf.WriteString("!")
- buf.WriteString(p.User)
- }
-
- if p.Host != "" {
- buf.WriteString("@")
- buf.WriteString(p.Host)
- }
-
- return buf.String()
-}
-
-// Message represents a line parsed from the server
-type Message struct {
- // Each message can have IRCv3 tags
- Tags
-
- // Each message can have a Prefix
- *Prefix
-
- // Command is which command is being called.
- Command string
-
- // Params are all the arguments for the command.
- Params []string
-}
-
-// MustParseMessage calls ParseMessage and either returns the message
-// or panics if an error is returned.
-func MustParseMessage(line string) *Message {
- m, err := ParseMessage(line)
- if err != nil {
- panic(err.Error())
- }
- return m
-}
-
-// ParseMessage takes a message string (usually a whole line) and
-// parses it into a Message struct. This will return nil in the case
-// of invalid messages.
-func ParseMessage(line string) (*Message, error) {
- // Trim the line and make sure we have data
- line = strings.TrimRight(line, "\r\n")
- if len(line) == 0 {
- return nil, ErrZeroLengthMessage
- }
-
- c := &Message{
- Tags: Tags{},
- Prefix: &Prefix{},
- }
-
- if line[0] == '@' {
- split := strings.SplitN(line, " ", 2)
- if len(split) < 2 {
- return nil, ErrMissingDataAfterTags
- }
-
- c.Tags = ParseTags(split[0][1:])
- line = split[1]
- }
-
- if line[0] == ':' {
- split := strings.SplitN(line, " ", 2)
- if len(split) < 2 {
- return nil, ErrMissingDataAfterPrefix
- }
-
- // Parse the identity, if there was one
- c.Prefix = ParsePrefix(split[0][1:])
- line = split[1]
- }
-
- // Split out the trailing then the rest of the args. Because
- // we expect there to be at least one result as an arg (the
- // command) we don't need to special case the trailing arg and
- // can just attempt a split on " :"
- split := strings.SplitN(line, " :", 2)
- c.Params = strings.FieldsFunc(split[0], func(r rune) bool {
- return r == ' '
- })
-
- // If there are no args, we need to bail because we need at
- // least the command.
- if len(c.Params) == 0 {
- return nil, ErrMissingCommand
- }
-
- // If we had a trailing arg, append it to the other args
- if len(split) == 2 {
- c.Params = append(c.Params, split[1])
- }
-
- // Because of how it's parsed, the Command will show up as the
- // first arg.
- c.Command = strings.ToUpper(c.Params[0])
- c.Params = c.Params[1:]
-
- // If there are no params, set it to nil, to make writing tests and other
- // things simpler.
- if len(c.Params) == 0 {
- c.Params = nil
- }
-
- return c, nil
-}
-
-// Trailing returns the last argument in the Message or an empty string
-// if there are no args
-func (m *Message) Trailing() string {
- if len(m.Params) < 1 {
- return ""
- }
-
- return m.Params[len(m.Params)-1]
-}
-
-// Copy will create a new copy of an message
-func (m *Message) Copy() *Message {
- // Create a new message
- newMessage := &Message{}
-
- // Copy stuff from the old message
- *newMessage = *m
-
- // Copy any IRcv3 tags
- newMessage.Tags = m.Tags.Copy()
-
- // Copy the Prefix
- newMessage.Prefix = m.Prefix.Copy()
-
- // Copy the Params slice
- newMessage.Params = append(make([]string, 0, len(m.Params)), m.Params...)
-
- // Similar to parsing, if Params is empty, set it to nil
- if len(newMessage.Params) == 0 {
- newMessage.Params = nil
- }
-
- return newMessage
-}
-
-// String ensures this is stringable
-func (m *Message) String() string {
- buf := &bytes.Buffer{}
-
- // Write any IRCv3 tags if they exist in the message
- if len(m.Tags) > 0 {
- buf.WriteByte('@')
- buf.WriteString(m.Tags.String())
- buf.WriteByte(' ')
- }
-
- // Add the prefix if we have one
- if m.Prefix != nil && m.Prefix.Name != "" {
- buf.WriteByte(':')
- buf.WriteString(m.Prefix.String())
- buf.WriteByte(' ')
- }
-
- // Add the command since we know we'll always have one
- buf.WriteString(m.Command)
-
- if len(m.Params) > 0 {
- args := m.Params[:len(m.Params)-1]
- trailing := m.Params[len(m.Params)-1]
-
- if len(args) > 0 {
- buf.WriteByte(' ')
- buf.WriteString(strings.Join(args, " "))
- }
-
- // If trailing is zero-length, contains a space or starts with
- // a : we need to actually specify that it's trailing.
- if len(trailing) == 0 || strings.ContainsRune(trailing, ' ') || trailing[0] == ':' {
- buf.WriteString(" :")
- } else {
- buf.WriteString(" ")
- }
- buf.WriteString(trailing)
- }
-
- return buf.String()
-}
diff --git a/vendor/github.com/go-irc/irc/utils.go b/vendor/github.com/go-irc/irc/utils.go
deleted file mode 100644
index 4633314..0000000
--- a/vendor/github.com/go-irc/irc/utils.go
+++ /dev/null
@@ -1,50 +0,0 @@
-package irc
-
-import (
- "bytes"
- "regexp"
-)
-
-var maskTranslations = map[byte]string{
- '?': ".",
- '*': ".*",
-}
-
-// MaskToRegex converts an irc mask to a go Regexp for more convenient
-// use. This should never return an error, but we have this here just
-// in case.
-func MaskToRegex(rawMask string) (*regexp.Regexp, error) {
- input := bytes.NewBufferString(rawMask)
-
- output := &bytes.Buffer{}
- output.WriteByte('^')
-
- for {
- c, err := input.ReadByte()
- if err != nil {
- break
- }
-
- if c == '\\' {
- c, err = input.ReadByte()
- if err != nil {
- output.WriteString(regexp.QuoteMeta("\\"))
- break
- }
-
- if c == '?' || c == '*' || c == '\\' {
- output.WriteString(regexp.QuoteMeta(string(c)))
- } else {
- output.WriteString(regexp.QuoteMeta("\\" + string(c)))
- }
- } else if trans, ok := maskTranslations[c]; ok {
- output.WriteString(trans)
- } else {
- output.WriteString(regexp.QuoteMeta(string(c)))
- }
- }
-
- output.WriteByte('$')
-
- return regexp.Compile(output.String())
-}
diff --git a/vendor/github.com/golang/protobuf/AUTHORS b/vendor/github.com/golang/protobuf/AUTHORS
deleted file mode 100644
index 15167cd..0000000
--- a/vendor/github.com/golang/protobuf/AUTHORS
+++ /dev/null
@@ -1,3 +0,0 @@
-# This source code refers to The Go Authors for copyright purposes.
-# The master list of authors is in the main Go distribution,
-# visible at http://tip.golang.org/AUTHORS.
diff --git a/vendor/github.com/golang/protobuf/CONTRIBUTORS b/vendor/github.com/golang/protobuf/CONTRIBUTORS
deleted file mode 100644
index 1c4577e..0000000
--- a/vendor/github.com/golang/protobuf/CONTRIBUTORS
+++ /dev/null
@@ -1,3 +0,0 @@
-# This source code was written by the Go contributors.
-# The master list of contributors is in the main Go distribution,
-# visible at http://tip.golang.org/CONTRIBUTORS.
diff --git a/vendor/github.com/golang/protobuf/LICENSE b/vendor/github.com/golang/protobuf/LICENSE
deleted file mode 100644
index 0f64693..0000000
--- a/vendor/github.com/golang/protobuf/LICENSE
+++ /dev/null
@@ -1,28 +0,0 @@
-Copyright 2010 The Go Authors. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
diff --git a/vendor/github.com/golang/protobuf/proto/clone.go b/vendor/github.com/golang/protobuf/proto/clone.go
deleted file mode 100644
index 3cd3249..0000000
--- a/vendor/github.com/golang/protobuf/proto/clone.go
+++ /dev/null
@@ -1,253 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2011 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// Protocol buffer deep copy and merge.
-// TODO: RawMessage.
-
-package proto
-
-import (
- "fmt"
- "log"
- "reflect"
- "strings"
-)
-
-// Clone returns a deep copy of a protocol buffer.
-func Clone(src Message) Message {
- in := reflect.ValueOf(src)
- if in.IsNil() {
- return src
- }
- out := reflect.New(in.Type().Elem())
- dst := out.Interface().(Message)
- Merge(dst, src)
- return dst
-}
-
-// Merger is the interface representing objects that can merge messages of the same type.
-type Merger interface {
- // Merge merges src into this message.
- // Required and optional fields that are set in src will be set to that value in dst.
- // Elements of repeated fields will be appended.
- //
- // Merge may panic if called with a different argument type than the receiver.
- Merge(src Message)
-}
-
-// generatedMerger is the custom merge method that generated protos will have.
-// We must add this method since a generate Merge method will conflict with
-// many existing protos that have a Merge data field already defined.
-type generatedMerger interface {
- XXX_Merge(src Message)
-}
-
-// Merge merges src into dst.
-// Required and optional fields that are set in src will be set to that value in dst.
-// Elements of repeated fields will be appended.
-// Merge panics if src and dst are not the same type, or if dst is nil.
-func Merge(dst, src Message) {
- if m, ok := dst.(Merger); ok {
- m.Merge(src)
- return
- }
-
- in := reflect.ValueOf(src)
- out := reflect.ValueOf(dst)
- if out.IsNil() {
- panic("proto: nil destination")
- }
- if in.Type() != out.Type() {
- panic(fmt.Sprintf("proto.Merge(%T, %T) type mismatch", dst, src))
- }
- if in.IsNil() {
- return // Merge from nil src is a noop
- }
- if m, ok := dst.(generatedMerger); ok {
- m.XXX_Merge(src)
- return
- }
- mergeStruct(out.Elem(), in.Elem())
-}
-
-func mergeStruct(out, in reflect.Value) {
- sprop := GetProperties(in.Type())
- for i := 0; i < in.NumField(); i++ {
- f := in.Type().Field(i)
- if strings.HasPrefix(f.Name, "XXX_") {
- continue
- }
- mergeAny(out.Field(i), in.Field(i), false, sprop.Prop[i])
- }
-
- if emIn, err := extendable(in.Addr().Interface()); err == nil {
- emOut, _ := extendable(out.Addr().Interface())
- mIn, muIn := emIn.extensionsRead()
- if mIn != nil {
- mOut := emOut.extensionsWrite()
- muIn.Lock()
- mergeExtension(mOut, mIn)
- muIn.Unlock()
- }
- }
-
- uf := in.FieldByName("XXX_unrecognized")
- if !uf.IsValid() {
- return
- }
- uin := uf.Bytes()
- if len(uin) > 0 {
- out.FieldByName("XXX_unrecognized").SetBytes(append([]byte(nil), uin...))
- }
-}
-
-// mergeAny performs a merge between two values of the same type.
-// viaPtr indicates whether the values were indirected through a pointer (implying proto2).
-// prop is set if this is a struct field (it may be nil).
-func mergeAny(out, in reflect.Value, viaPtr bool, prop *Properties) {
- if in.Type() == protoMessageType {
- if !in.IsNil() {
- if out.IsNil() {
- out.Set(reflect.ValueOf(Clone(in.Interface().(Message))))
- } else {
- Merge(out.Interface().(Message), in.Interface().(Message))
- }
- }
- return
- }
- switch in.Kind() {
- case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64,
- reflect.String, reflect.Uint32, reflect.Uint64:
- if !viaPtr && isProto3Zero(in) {
- return
- }
- out.Set(in)
- case reflect.Interface:
- // Probably a oneof field; copy non-nil values.
- if in.IsNil() {
- return
- }
- // Allocate destination if it is not set, or set to a different type.
- // Otherwise we will merge as normal.
- if out.IsNil() || out.Elem().Type() != in.Elem().Type() {
- out.Set(reflect.New(in.Elem().Elem().Type())) // interface -> *T -> T -> new(T)
- }
- mergeAny(out.Elem(), in.Elem(), false, nil)
- case reflect.Map:
- if in.Len() == 0 {
- return
- }
- if out.IsNil() {
- out.Set(reflect.MakeMap(in.Type()))
- }
- // For maps with value types of *T or []byte we need to deep copy each value.
- elemKind := in.Type().Elem().Kind()
- for _, key := range in.MapKeys() {
- var val reflect.Value
- switch elemKind {
- case reflect.Ptr:
- val = reflect.New(in.Type().Elem().Elem())
- mergeAny(val, in.MapIndex(key), false, nil)
- case reflect.Slice:
- val = in.MapIndex(key)
- val = reflect.ValueOf(append([]byte{}, val.Bytes()...))
- default:
- val = in.MapIndex(key)
- }
- out.SetMapIndex(key, val)
- }
- case reflect.Ptr:
- if in.IsNil() {
- return
- }
- if out.IsNil() {
- out.Set(reflect.New(in.Elem().Type()))
- }
- mergeAny(out.Elem(), in.Elem(), true, nil)
- case reflect.Slice:
- if in.IsNil() {
- return
- }
- if in.Type().Elem().Kind() == reflect.Uint8 {
- // []byte is a scalar bytes field, not a repeated field.
-
- // Edge case: if this is in a proto3 message, a zero length
- // bytes field is considered the zero value, and should not
- // be merged.
- if prop != nil && prop.proto3 && in.Len() == 0 {
- return
- }
-
- // Make a deep copy.
- // Append to []byte{} instead of []byte(nil) so that we never end up
- // with a nil result.
- out.SetBytes(append([]byte{}, in.Bytes()...))
- return
- }
- n := in.Len()
- if out.IsNil() {
- out.Set(reflect.MakeSlice(in.Type(), 0, n))
- }
- switch in.Type().Elem().Kind() {
- case reflect.Bool, reflect.Float32, reflect.Float64, reflect.Int32, reflect.Int64,
- reflect.String, reflect.Uint32, reflect.Uint64:
- out.Set(reflect.AppendSlice(out, in))
- default:
- for i := 0; i < n; i++ {
- x := reflect.Indirect(reflect.New(in.Type().Elem()))
- mergeAny(x, in.Index(i), false, nil)
- out.Set(reflect.Append(out, x))
- }
- }
- case reflect.Struct:
- mergeStruct(out, in)
- default:
- // unknown type, so not a protocol buffer
- log.Printf("proto: don't know how to copy %v", in)
- }
-}
-
-func mergeExtension(out, in map[int32]Extension) {
- for extNum, eIn := range in {
- eOut := Extension{desc: eIn.desc}
- if eIn.value != nil {
- v := reflect.New(reflect.TypeOf(eIn.value)).Elem()
- mergeAny(v, reflect.ValueOf(eIn.value), false, nil)
- eOut.value = v.Interface()
- }
- if eIn.enc != nil {
- eOut.enc = make([]byte, len(eIn.enc))
- copy(eOut.enc, eIn.enc)
- }
-
- out[extNum] = eOut
- }
-}
diff --git a/vendor/github.com/golang/protobuf/proto/decode.go b/vendor/github.com/golang/protobuf/proto/decode.go
deleted file mode 100644
index d9aa3c4..0000000
--- a/vendor/github.com/golang/protobuf/proto/decode.go
+++ /dev/null
@@ -1,428 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2010 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-/*
- * Routines for decoding protocol buffer data to construct in-memory representations.
- */
-
-import (
- "errors"
- "fmt"
- "io"
-)
-
-// errOverflow is returned when an integer is too large to be represented.
-var errOverflow = errors.New("proto: integer overflow")
-
-// ErrInternalBadWireType is returned by generated code when an incorrect
-// wire type is encountered. It does not get returned to user code.
-var ErrInternalBadWireType = errors.New("proto: internal error: bad wiretype for oneof")
-
-// DecodeVarint reads a varint-encoded integer from the slice.
-// It returns the integer and the number of bytes consumed, or
-// zero if there is not enough.
-// This is the format for the
-// int32, int64, uint32, uint64, bool, and enum
-// protocol buffer types.
-func DecodeVarint(buf []byte) (x uint64, n int) {
- for shift := uint(0); shift < 64; shift += 7 {
- if n >= len(buf) {
- return 0, 0
- }
- b := uint64(buf[n])
- n++
- x |= (b & 0x7F) << shift
- if (b & 0x80) == 0 {
- return x, n
- }
- }
-
- // The number is too large to represent in a 64-bit value.
- return 0, 0
-}
-
-func (p *Buffer) decodeVarintSlow() (x uint64, err error) {
- i := p.index
- l := len(p.buf)
-
- for shift := uint(0); shift < 64; shift += 7 {
- if i >= l {
- err = io.ErrUnexpectedEOF
- return
- }
- b := p.buf[i]
- i++
- x |= (uint64(b) & 0x7F) << shift
- if b < 0x80 {
- p.index = i
- return
- }
- }
-
- // The number is too large to represent in a 64-bit value.
- err = errOverflow
- return
-}
-
-// DecodeVarint reads a varint-encoded integer from the Buffer.
-// This is the format for the
-// int32, int64, uint32, uint64, bool, and enum
-// protocol buffer types.
-func (p *Buffer) DecodeVarint() (x uint64, err error) {
- i := p.index
- buf := p.buf
-
- if i >= len(buf) {
- return 0, io.ErrUnexpectedEOF
- } else if buf[i] < 0x80 {
- p.index++
- return uint64(buf[i]), nil
- } else if len(buf)-i < 10 {
- return p.decodeVarintSlow()
- }
-
- var b uint64
- // we already checked the first byte
- x = uint64(buf[i]) - 0x80
- i++
-
- b = uint64(buf[i])
- i++
- x += b << 7
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 7
-
- b = uint64(buf[i])
- i++
- x += b << 14
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 14
-
- b = uint64(buf[i])
- i++
- x += b << 21
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 21
-
- b = uint64(buf[i])
- i++
- x += b << 28
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 28
-
- b = uint64(buf[i])
- i++
- x += b << 35
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 35
-
- b = uint64(buf[i])
- i++
- x += b << 42
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 42
-
- b = uint64(buf[i])
- i++
- x += b << 49
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 49
-
- b = uint64(buf[i])
- i++
- x += b << 56
- if b&0x80 == 0 {
- goto done
- }
- x -= 0x80 << 56
-
- b = uint64(buf[i])
- i++
- x += b << 63
- if b&0x80 == 0 {
- goto done
- }
- // x -= 0x80 << 63 // Always zero.
-
- return 0, errOverflow
-
-done:
- p.index = i
- return x, nil
-}
-
-// DecodeFixed64 reads a 64-bit integer from the Buffer.
-// This is the format for the
-// fixed64, sfixed64, and double protocol buffer types.
-func (p *Buffer) DecodeFixed64() (x uint64, err error) {
- // x, err already 0
- i := p.index + 8
- if i < 0 || i > len(p.buf) {
- err = io.ErrUnexpectedEOF
- return
- }
- p.index = i
-
- x = uint64(p.buf[i-8])
- x |= uint64(p.buf[i-7]) << 8
- x |= uint64(p.buf[i-6]) << 16
- x |= uint64(p.buf[i-5]) << 24
- x |= uint64(p.buf[i-4]) << 32
- x |= uint64(p.buf[i-3]) << 40
- x |= uint64(p.buf[i-2]) << 48
- x |= uint64(p.buf[i-1]) << 56
- return
-}
-
-// DecodeFixed32 reads a 32-bit integer from the Buffer.
-// This is the format for the
-// fixed32, sfixed32, and float protocol buffer types.
-func (p *Buffer) DecodeFixed32() (x uint64, err error) {
- // x, err already 0
- i := p.index + 4
- if i < 0 || i > len(p.buf) {
- err = io.ErrUnexpectedEOF
- return
- }
- p.index = i
-
- x = uint64(p.buf[i-4])
- x |= uint64(p.buf[i-3]) << 8
- x |= uint64(p.buf[i-2]) << 16
- x |= uint64(p.buf[i-1]) << 24
- return
-}
-
-// DecodeZigzag64 reads a zigzag-encoded 64-bit integer
-// from the Buffer.
-// This is the format used for the sint64 protocol buffer type.
-func (p *Buffer) DecodeZigzag64() (x uint64, err error) {
- x, err = p.DecodeVarint()
- if err != nil {
- return
- }
- x = (x >> 1) ^ uint64((int64(x&1)<<63)>>63)
- return
-}
-
-// DecodeZigzag32 reads a zigzag-encoded 32-bit integer
-// from the Buffer.
-// This is the format used for the sint32 protocol buffer type.
-func (p *Buffer) DecodeZigzag32() (x uint64, err error) {
- x, err = p.DecodeVarint()
- if err != nil {
- return
- }
- x = uint64((uint32(x) >> 1) ^ uint32((int32(x&1)<<31)>>31))
- return
-}
-
-// DecodeRawBytes reads a count-delimited byte buffer from the Buffer.
-// This is the format used for the bytes protocol buffer
-// type and for embedded messages.
-func (p *Buffer) DecodeRawBytes(alloc bool) (buf []byte, err error) {
- n, err := p.DecodeVarint()
- if err != nil {
- return nil, err
- }
-
- nb := int(n)
- if nb < 0 {
- return nil, fmt.Errorf("proto: bad byte length %d", nb)
- }
- end := p.index + nb
- if end < p.index || end > len(p.buf) {
- return nil, io.ErrUnexpectedEOF
- }
-
- if !alloc {
- // todo: check if can get more uses of alloc=false
- buf = p.buf[p.index:end]
- p.index += nb
- return
- }
-
- buf = make([]byte, nb)
- copy(buf, p.buf[p.index:])
- p.index += nb
- return
-}
-
-// DecodeStringBytes reads an encoded string from the Buffer.
-// This is the format used for the proto2 string type.
-func (p *Buffer) DecodeStringBytes() (s string, err error) {
- buf, err := p.DecodeRawBytes(false)
- if err != nil {
- return
- }
- return string(buf), nil
-}
-
-// Unmarshaler is the interface representing objects that can
-// unmarshal themselves. The argument points to data that may be
-// overwritten, so implementations should not keep references to the
-// buffer.
-// Unmarshal implementations should not clear the receiver.
-// Any unmarshaled data should be merged into the receiver.
-// Callers of Unmarshal that do not want to retain existing data
-// should Reset the receiver before calling Unmarshal.
-type Unmarshaler interface {
- Unmarshal([]byte) error
-}
-
-// newUnmarshaler is the interface representing objects that can
-// unmarshal themselves. The semantics are identical to Unmarshaler.
-//
-// This exists to support protoc-gen-go generated messages.
-// The proto package will stop type-asserting to this interface in the future.
-//
-// DO NOT DEPEND ON THIS.
-type newUnmarshaler interface {
- XXX_Unmarshal([]byte) error
-}
-
-// Unmarshal parses the protocol buffer representation in buf and places the
-// decoded result in pb. If the struct underlying pb does not match
-// the data in buf, the results can be unpredictable.
-//
-// Unmarshal resets pb before starting to unmarshal, so any
-// existing data in pb is always removed. Use UnmarshalMerge
-// to preserve and append to existing data.
-func Unmarshal(buf []byte, pb Message) error {
- pb.Reset()
- if u, ok := pb.(newUnmarshaler); ok {
- return u.XXX_Unmarshal(buf)
- }
- if u, ok := pb.(Unmarshaler); ok {
- return u.Unmarshal(buf)
- }
- return NewBuffer(buf).Unmarshal(pb)
-}
-
-// UnmarshalMerge parses the protocol buffer representation in buf and
-// writes the decoded result to pb. If the struct underlying pb does not match
-// the data in buf, the results can be unpredictable.
-//
-// UnmarshalMerge merges into existing data in pb.
-// Most code should use Unmarshal instead.
-func UnmarshalMerge(buf []byte, pb Message) error {
- if u, ok := pb.(newUnmarshaler); ok {
- return u.XXX_Unmarshal(buf)
- }
- if u, ok := pb.(Unmarshaler); ok {
- // NOTE: The history of proto have unfortunately been inconsistent
- // whether Unmarshaler should or should not implicitly clear itself.
- // Some implementations do, most do not.
- // Thus, calling this here may or may not do what people want.
- //
- // See https://github.com/golang/protobuf/issues/424
- return u.Unmarshal(buf)
- }
- return NewBuffer(buf).Unmarshal(pb)
-}
-
-// DecodeMessage reads a count-delimited message from the Buffer.
-func (p *Buffer) DecodeMessage(pb Message) error {
- enc, err := p.DecodeRawBytes(false)
- if err != nil {
- return err
- }
- return NewBuffer(enc).Unmarshal(pb)
-}
-
-// DecodeGroup reads a tag-delimited group from the Buffer.
-// StartGroup tag is already consumed. This function consumes
-// EndGroup tag.
-func (p *Buffer) DecodeGroup(pb Message) error {
- b := p.buf[p.index:]
- x, y := findEndGroup(b)
- if x < 0 {
- return io.ErrUnexpectedEOF
- }
- err := Unmarshal(b[:x], pb)
- p.index += y
- return err
-}
-
-// Unmarshal parses the protocol buffer representation in the
-// Buffer and places the decoded result in pb. If the struct
-// underlying pb does not match the data in the buffer, the results can be
-// unpredictable.
-//
-// Unlike proto.Unmarshal, this does not reset pb before starting to unmarshal.
-func (p *Buffer) Unmarshal(pb Message) error {
- // If the object can unmarshal itself, let it.
- if u, ok := pb.(newUnmarshaler); ok {
- err := u.XXX_Unmarshal(p.buf[p.index:])
- p.index = len(p.buf)
- return err
- }
- if u, ok := pb.(Unmarshaler); ok {
- // NOTE: The history of proto have unfortunately been inconsistent
- // whether Unmarshaler should or should not implicitly clear itself.
- // Some implementations do, most do not.
- // Thus, calling this here may or may not do what people want.
- //
- // See https://github.com/golang/protobuf/issues/424
- err := u.Unmarshal(p.buf[p.index:])
- p.index = len(p.buf)
- return err
- }
-
- // Slow workaround for messages that aren't Unmarshalers.
- // This includes some hand-coded .pb.go files and
- // bootstrap protos.
- // TODO: fix all of those and then add Unmarshal to
- // the Message interface. Then:
- // The cast above and code below can be deleted.
- // The old unmarshaler can be deleted.
- // Clients can call Unmarshal directly (can already do that, actually).
- var info InternalMessageInfo
- err := info.Unmarshal(pb, p.buf[p.index:])
- p.index = len(p.buf)
- return err
-}
diff --git a/vendor/github.com/golang/protobuf/proto/discard.go b/vendor/github.com/golang/protobuf/proto/discard.go
deleted file mode 100644
index dea2617..0000000
--- a/vendor/github.com/golang/protobuf/proto/discard.go
+++ /dev/null
@@ -1,350 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2017 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-import (
- "fmt"
- "reflect"
- "strings"
- "sync"
- "sync/atomic"
-)
-
-type generatedDiscarder interface {
- XXX_DiscardUnknown()
-}
-
-// DiscardUnknown recursively discards all unknown fields from this message
-// and all embedded messages.
-//
-// When unmarshaling a message with unrecognized fields, the tags and values
-// of such fields are preserved in the Message. This allows a later call to
-// marshal to be able to produce a message that continues to have those
-// unrecognized fields. To avoid this, DiscardUnknown is used to
-// explicitly clear the unknown fields after unmarshaling.
-//
-// For proto2 messages, the unknown fields of message extensions are only
-// discarded from messages that have been accessed via GetExtension.
-func DiscardUnknown(m Message) {
- if m, ok := m.(generatedDiscarder); ok {
- m.XXX_DiscardUnknown()
- return
- }
- // TODO: Dynamically populate a InternalMessageInfo for legacy messages,
- // but the master branch has no implementation for InternalMessageInfo,
- // so it would be more work to replicate that approach.
- discardLegacy(m)
-}
-
-// DiscardUnknown recursively discards all unknown fields.
-func (a *InternalMessageInfo) DiscardUnknown(m Message) {
- di := atomicLoadDiscardInfo(&a.discard)
- if di == nil {
- di = getDiscardInfo(reflect.TypeOf(m).Elem())
- atomicStoreDiscardInfo(&a.discard, di)
- }
- di.discard(toPointer(&m))
-}
-
-type discardInfo struct {
- typ reflect.Type
-
- initialized int32 // 0: only typ is valid, 1: everything is valid
- lock sync.Mutex
-
- fields []discardFieldInfo
- unrecognized field
-}
-
-type discardFieldInfo struct {
- field field // Offset of field, guaranteed to be valid
- discard func(src pointer)
-}
-
-var (
- discardInfoMap = map[reflect.Type]*discardInfo{}
- discardInfoLock sync.Mutex
-)
-
-func getDiscardInfo(t reflect.Type) *discardInfo {
- discardInfoLock.Lock()
- defer discardInfoLock.Unlock()
- di := discardInfoMap[t]
- if di == nil {
- di = &discardInfo{typ: t}
- discardInfoMap[t] = di
- }
- return di
-}
-
-func (di *discardInfo) discard(src pointer) {
- if src.isNil() {
- return // Nothing to do.
- }
-
- if atomic.LoadInt32(&di.initialized) == 0 {
- di.computeDiscardInfo()
- }
-
- for _, fi := range di.fields {
- sfp := src.offset(fi.field)
- fi.discard(sfp)
- }
-
- // For proto2 messages, only discard unknown fields in message extensions
- // that have been accessed via GetExtension.
- if em, err := extendable(src.asPointerTo(di.typ).Interface()); err == nil {
- // Ignore lock since DiscardUnknown is not concurrency safe.
- emm, _ := em.extensionsRead()
- for _, mx := range emm {
- if m, ok := mx.value.(Message); ok {
- DiscardUnknown(m)
- }
- }
- }
-
- if di.unrecognized.IsValid() {
- *src.offset(di.unrecognized).toBytes() = nil
- }
-}
-
-func (di *discardInfo) computeDiscardInfo() {
- di.lock.Lock()
- defer di.lock.Unlock()
- if di.initialized != 0 {
- return
- }
- t := di.typ
- n := t.NumField()
-
- for i := 0; i < n; i++ {
- f := t.Field(i)
- if strings.HasPrefix(f.Name, "XXX_") {
- continue
- }
-
- dfi := discardFieldInfo{field: toField(&f)}
- tf := f.Type
-
- // Unwrap tf to get its most basic type.
- var isPointer, isSlice bool
- if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 {
- isSlice = true
- tf = tf.Elem()
- }
- if tf.Kind() == reflect.Ptr {
- isPointer = true
- tf = tf.Elem()
- }
- if isPointer && isSlice && tf.Kind() != reflect.Struct {
- panic(fmt.Sprintf("%v.%s cannot be a slice of pointers to primitive types", t, f.Name))
- }
-
- switch tf.Kind() {
- case reflect.Struct:
- switch {
- case !isPointer:
- panic(fmt.Sprintf("%v.%s cannot be a direct struct value", t, f.Name))
- case isSlice: // E.g., []*pb.T
- di := getDiscardInfo(tf)
- dfi.discard = func(src pointer) {
- sps := src.getPointerSlice()
- for _, sp := range sps {
- if !sp.isNil() {
- di.discard(sp)
- }
- }
- }
- default: // E.g., *pb.T
- di := getDiscardInfo(tf)
- dfi.discard = func(src pointer) {
- sp := src.getPointer()
- if !sp.isNil() {
- di.discard(sp)
- }
- }
- }
- case reflect.Map:
- switch {
- case isPointer || isSlice:
- panic(fmt.Sprintf("%v.%s cannot be a pointer to a map or a slice of map values", t, f.Name))
- default: // E.g., map[K]V
- if tf.Elem().Kind() == reflect.Ptr { // Proto struct (e.g., *T)
- dfi.discard = func(src pointer) {
- sm := src.asPointerTo(tf).Elem()
- if sm.Len() == 0 {
- return
- }
- for _, key := range sm.MapKeys() {
- val := sm.MapIndex(key)
- DiscardUnknown(val.Interface().(Message))
- }
- }
- } else {
- dfi.discard = func(pointer) {} // Noop
- }
- }
- case reflect.Interface:
- // Must be oneof field.
- switch {
- case isPointer || isSlice:
- panic(fmt.Sprintf("%v.%s cannot be a pointer to a interface or a slice of interface values", t, f.Name))
- default: // E.g., interface{}
- // TODO: Make this faster?
- dfi.discard = func(src pointer) {
- su := src.asPointerTo(tf).Elem()
- if !su.IsNil() {
- sv := su.Elem().Elem().Field(0)
- if sv.Kind() == reflect.Ptr && sv.IsNil() {
- return
- }
- switch sv.Type().Kind() {
- case reflect.Ptr: // Proto struct (e.g., *T)
- DiscardUnknown(sv.Interface().(Message))
- }
- }
- }
- }
- default:
- continue
- }
- di.fields = append(di.fields, dfi)
- }
-
- di.unrecognized = invalidField
- if f, ok := t.FieldByName("XXX_unrecognized"); ok {
- if f.Type != reflect.TypeOf([]byte{}) {
- panic("expected XXX_unrecognized to be of type []byte")
- }
- di.unrecognized = toField(&f)
- }
-
- atomic.StoreInt32(&di.initialized, 1)
-}
-
-func discardLegacy(m Message) {
- v := reflect.ValueOf(m)
- if v.Kind() != reflect.Ptr || v.IsNil() {
- return
- }
- v = v.Elem()
- if v.Kind() != reflect.Struct {
- return
- }
- t := v.Type()
-
- for i := 0; i < v.NumField(); i++ {
- f := t.Field(i)
- if strings.HasPrefix(f.Name, "XXX_") {
- continue
- }
- vf := v.Field(i)
- tf := f.Type
-
- // Unwrap tf to get its most basic type.
- var isPointer, isSlice bool
- if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 {
- isSlice = true
- tf = tf.Elem()
- }
- if tf.Kind() == reflect.Ptr {
- isPointer = true
- tf = tf.Elem()
- }
- if isPointer && isSlice && tf.Kind() != reflect.Struct {
- panic(fmt.Sprintf("%T.%s cannot be a slice of pointers to primitive types", m, f.Name))
- }
-
- switch tf.Kind() {
- case reflect.Struct:
- switch {
- case !isPointer:
- panic(fmt.Sprintf("%T.%s cannot be a direct struct value", m, f.Name))
- case isSlice: // E.g., []*pb.T
- for j := 0; j < vf.Len(); j++ {
- discardLegacy(vf.Index(j).Interface().(Message))
- }
- default: // E.g., *pb.T
- discardLegacy(vf.Interface().(Message))
- }
- case reflect.Map:
- switch {
- case isPointer || isSlice:
- panic(fmt.Sprintf("%T.%s cannot be a pointer to a map or a slice of map values", m, f.Name))
- default: // E.g., map[K]V
- tv := vf.Type().Elem()
- if tv.Kind() == reflect.Ptr && tv.Implements(protoMessageType) { // Proto struct (e.g., *T)
- for _, key := range vf.MapKeys() {
- val := vf.MapIndex(key)
- discardLegacy(val.Interface().(Message))
- }
- }
- }
- case reflect.Interface:
- // Must be oneof field.
- switch {
- case isPointer || isSlice:
- panic(fmt.Sprintf("%T.%s cannot be a pointer to a interface or a slice of interface values", m, f.Name))
- default: // E.g., test_proto.isCommunique_Union interface
- if !vf.IsNil() && f.Tag.Get("protobuf_oneof") != "" {
- vf = vf.Elem() // E.g., *test_proto.Communique_Msg
- if !vf.IsNil() {
- vf = vf.Elem() // E.g., test_proto.Communique_Msg
- vf = vf.Field(0) // E.g., Proto struct (e.g., *T) or primitive value
- if vf.Kind() == reflect.Ptr {
- discardLegacy(vf.Interface().(Message))
- }
- }
- }
- }
- }
- }
-
- if vf := v.FieldByName("XXX_unrecognized"); vf.IsValid() {
- if vf.Type() != reflect.TypeOf([]byte{}) {
- panic("expected XXX_unrecognized to be of type []byte")
- }
- vf.Set(reflect.ValueOf([]byte(nil)))
- }
-
- // For proto2 messages, only discard unknown fields in message extensions
- // that have been accessed via GetExtension.
- if em, err := extendable(m); err == nil {
- // Ignore lock since discardLegacy is not concurrency safe.
- emm, _ := em.extensionsRead()
- for _, mx := range emm {
- if m, ok := mx.value.(Message); ok {
- discardLegacy(m)
- }
- }
- }
-}
diff --git a/vendor/github.com/golang/protobuf/proto/encode.go b/vendor/github.com/golang/protobuf/proto/encode.go
deleted file mode 100644
index 3abfed2..0000000
--- a/vendor/github.com/golang/protobuf/proto/encode.go
+++ /dev/null
@@ -1,203 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2010 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-/*
- * Routines for encoding data into the wire format for protocol buffers.
- */
-
-import (
- "errors"
- "reflect"
-)
-
-var (
- // errRepeatedHasNil is the error returned if Marshal is called with
- // a struct with a repeated field containing a nil element.
- errRepeatedHasNil = errors.New("proto: repeated field has nil element")
-
- // errOneofHasNil is the error returned if Marshal is called with
- // a struct with a oneof field containing a nil element.
- errOneofHasNil = errors.New("proto: oneof field has nil value")
-
- // ErrNil is the error returned if Marshal is called with nil.
- ErrNil = errors.New("proto: Marshal called with nil")
-
- // ErrTooLarge is the error returned if Marshal is called with a
- // message that encodes to >2GB.
- ErrTooLarge = errors.New("proto: message encodes to over 2 GB")
-)
-
-// The fundamental encoders that put bytes on the wire.
-// Those that take integer types all accept uint64 and are
-// therefore of type valueEncoder.
-
-const maxVarintBytes = 10 // maximum length of a varint
-
-// EncodeVarint returns the varint encoding of x.
-// This is the format for the
-// int32, int64, uint32, uint64, bool, and enum
-// protocol buffer types.
-// Not used by the package itself, but helpful to clients
-// wishing to use the same encoding.
-func EncodeVarint(x uint64) []byte {
- var buf [maxVarintBytes]byte
- var n int
- for n = 0; x > 127; n++ {
- buf[n] = 0x80 | uint8(x&0x7F)
- x >>= 7
- }
- buf[n] = uint8(x)
- n++
- return buf[0:n]
-}
-
-// EncodeVarint writes a varint-encoded integer to the Buffer.
-// This is the format for the
-// int32, int64, uint32, uint64, bool, and enum
-// protocol buffer types.
-func (p *Buffer) EncodeVarint(x uint64) error {
- for x >= 1<<7 {
- p.buf = append(p.buf, uint8(x&0x7f|0x80))
- x >>= 7
- }
- p.buf = append(p.buf, uint8(x))
- return nil
-}
-
-// SizeVarint returns the varint encoding size of an integer.
-func SizeVarint(x uint64) int {
- switch {
- case x < 1<<7:
- return 1
- case x < 1<<14:
- return 2
- case x < 1<<21:
- return 3
- case x < 1<<28:
- return 4
- case x < 1<<35:
- return 5
- case x < 1<<42:
- return 6
- case x < 1<<49:
- return 7
- case x < 1<<56:
- return 8
- case x < 1<<63:
- return 9
- }
- return 10
-}
-
-// EncodeFixed64 writes a 64-bit integer to the Buffer.
-// This is the format for the
-// fixed64, sfixed64, and double protocol buffer types.
-func (p *Buffer) EncodeFixed64(x uint64) error {
- p.buf = append(p.buf,
- uint8(x),
- uint8(x>>8),
- uint8(x>>16),
- uint8(x>>24),
- uint8(x>>32),
- uint8(x>>40),
- uint8(x>>48),
- uint8(x>>56))
- return nil
-}
-
-// EncodeFixed32 writes a 32-bit integer to the Buffer.
-// This is the format for the
-// fixed32, sfixed32, and float protocol buffer types.
-func (p *Buffer) EncodeFixed32(x uint64) error {
- p.buf = append(p.buf,
- uint8(x),
- uint8(x>>8),
- uint8(x>>16),
- uint8(x>>24))
- return nil
-}
-
-// EncodeZigzag64 writes a zigzag-encoded 64-bit integer
-// to the Buffer.
-// This is the format used for the sint64 protocol buffer type.
-func (p *Buffer) EncodeZigzag64(x uint64) error {
- // use signed number to get arithmetic right shift.
- return p.EncodeVarint(uint64((x << 1) ^ uint64((int64(x) >> 63))))
-}
-
-// EncodeZigzag32 writes a zigzag-encoded 32-bit integer
-// to the Buffer.
-// This is the format used for the sint32 protocol buffer type.
-func (p *Buffer) EncodeZigzag32(x uint64) error {
- // use signed number to get arithmetic right shift.
- return p.EncodeVarint(uint64((uint32(x) << 1) ^ uint32((int32(x) >> 31))))
-}
-
-// EncodeRawBytes writes a count-delimited byte buffer to the Buffer.
-// This is the format used for the bytes protocol buffer
-// type and for embedded messages.
-func (p *Buffer) EncodeRawBytes(b []byte) error {
- p.EncodeVarint(uint64(len(b)))
- p.buf = append(p.buf, b...)
- return nil
-}
-
-// EncodeStringBytes writes an encoded string to the Buffer.
-// This is the format used for the proto2 string type.
-func (p *Buffer) EncodeStringBytes(s string) error {
- p.EncodeVarint(uint64(len(s)))
- p.buf = append(p.buf, s...)
- return nil
-}
-
-// Marshaler is the interface representing objects that can marshal themselves.
-type Marshaler interface {
- Marshal() ([]byte, error)
-}
-
-// EncodeMessage writes the protocol buffer to the Buffer,
-// prefixed by a varint-encoded length.
-func (p *Buffer) EncodeMessage(pb Message) error {
- siz := Size(pb)
- p.EncodeVarint(uint64(siz))
- return p.Marshal(pb)
-}
-
-// All protocol buffer fields are nillable, but be careful.
-func isNil(v reflect.Value) bool {
- switch v.Kind() {
- case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
- return v.IsNil()
- }
- return false
-}
diff --git a/vendor/github.com/golang/protobuf/proto/equal.go b/vendor/github.com/golang/protobuf/proto/equal.go
deleted file mode 100644
index d4db5a1..0000000
--- a/vendor/github.com/golang/protobuf/proto/equal.go
+++ /dev/null
@@ -1,300 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2011 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// Protocol buffer comparison.
-
-package proto
-
-import (
- "bytes"
- "log"
- "reflect"
- "strings"
-)
-
-/*
-Equal returns true iff protocol buffers a and b are equal.
-The arguments must both be pointers to protocol buffer structs.
-
-Equality is defined in this way:
- - Two messages are equal iff they are the same type,
- corresponding fields are equal, unknown field sets
- are equal, and extensions sets are equal.
- - Two set scalar fields are equal iff their values are equal.
- If the fields are of a floating-point type, remember that
- NaN != x for all x, including NaN. If the message is defined
- in a proto3 .proto file, fields are not "set"; specifically,
- zero length proto3 "bytes" fields are equal (nil == {}).
- - Two repeated fields are equal iff their lengths are the same,
- and their corresponding elements are equal. Note a "bytes" field,
- although represented by []byte, is not a repeated field and the
- rule for the scalar fields described above applies.
- - Two unset fields are equal.
- - Two unknown field sets are equal if their current
- encoded state is equal.
- - Two extension sets are equal iff they have corresponding
- elements that are pairwise equal.
- - Two map fields are equal iff their lengths are the same,
- and they contain the same set of elements. Zero-length map
- fields are equal.
- - Every other combination of things are not equal.
-
-The return value is undefined if a and b are not protocol buffers.
-*/
-func Equal(a, b Message) bool {
- if a == nil || b == nil {
- return a == b
- }
- v1, v2 := reflect.ValueOf(a), reflect.ValueOf(b)
- if v1.Type() != v2.Type() {
- return false
- }
- if v1.Kind() == reflect.Ptr {
- if v1.IsNil() {
- return v2.IsNil()
- }
- if v2.IsNil() {
- return false
- }
- v1, v2 = v1.Elem(), v2.Elem()
- }
- if v1.Kind() != reflect.Struct {
- return false
- }
- return equalStruct(v1, v2)
-}
-
-// v1 and v2 are known to have the same type.
-func equalStruct(v1, v2 reflect.Value) bool {
- sprop := GetProperties(v1.Type())
- for i := 0; i < v1.NumField(); i++ {
- f := v1.Type().Field(i)
- if strings.HasPrefix(f.Name, "XXX_") {
- continue
- }
- f1, f2 := v1.Field(i), v2.Field(i)
- if f.Type.Kind() == reflect.Ptr {
- if n1, n2 := f1.IsNil(), f2.IsNil(); n1 && n2 {
- // both unset
- continue
- } else if n1 != n2 {
- // set/unset mismatch
- return false
- }
- f1, f2 = f1.Elem(), f2.Elem()
- }
- if !equalAny(f1, f2, sprop.Prop[i]) {
- return false
- }
- }
-
- if em1 := v1.FieldByName("XXX_InternalExtensions"); em1.IsValid() {
- em2 := v2.FieldByName("XXX_InternalExtensions")
- if !equalExtensions(v1.Type(), em1.Interface().(XXX_InternalExtensions), em2.Interface().(XXX_InternalExtensions)) {
- return false
- }
- }
-
- if em1 := v1.FieldByName("XXX_extensions"); em1.IsValid() {
- em2 := v2.FieldByName("XXX_extensions")
- if !equalExtMap(v1.Type(), em1.Interface().(map[int32]Extension), em2.Interface().(map[int32]Extension)) {
- return false
- }
- }
-
- uf := v1.FieldByName("XXX_unrecognized")
- if !uf.IsValid() {
- return true
- }
-
- u1 := uf.Bytes()
- u2 := v2.FieldByName("XXX_unrecognized").Bytes()
- return bytes.Equal(u1, u2)
-}
-
-// v1 and v2 are known to have the same type.
-// prop may be nil.
-func equalAny(v1, v2 reflect.Value, prop *Properties) bool {
- if v1.Type() == protoMessageType {
- m1, _ := v1.Interface().(Message)
- m2, _ := v2.Interface().(Message)
- return Equal(m1, m2)
- }
- switch v1.Kind() {
- case reflect.Bool:
- return v1.Bool() == v2.Bool()
- case reflect.Float32, reflect.Float64:
- return v1.Float() == v2.Float()
- case reflect.Int32, reflect.Int64:
- return v1.Int() == v2.Int()
- case reflect.Interface:
- // Probably a oneof field; compare the inner values.
- n1, n2 := v1.IsNil(), v2.IsNil()
- if n1 || n2 {
- return n1 == n2
- }
- e1, e2 := v1.Elem(), v2.Elem()
- if e1.Type() != e2.Type() {
- return false
- }
- return equalAny(e1, e2, nil)
- case reflect.Map:
- if v1.Len() != v2.Len() {
- return false
- }
- for _, key := range v1.MapKeys() {
- val2 := v2.MapIndex(key)
- if !val2.IsValid() {
- // This key was not found in the second map.
- return false
- }
- if !equalAny(v1.MapIndex(key), val2, nil) {
- return false
- }
- }
- return true
- case reflect.Ptr:
- // Maps may have nil values in them, so check for nil.
- if v1.IsNil() && v2.IsNil() {
- return true
- }
- if v1.IsNil() != v2.IsNil() {
- return false
- }
- return equalAny(v1.Elem(), v2.Elem(), prop)
- case reflect.Slice:
- if v1.Type().Elem().Kind() == reflect.Uint8 {
- // short circuit: []byte
-
- // Edge case: if this is in a proto3 message, a zero length
- // bytes field is considered the zero value.
- if prop != nil && prop.proto3 && v1.Len() == 0 && v2.Len() == 0 {
- return true
- }
- if v1.IsNil() != v2.IsNil() {
- return false
- }
- return bytes.Equal(v1.Interface().([]byte), v2.Interface().([]byte))
- }
-
- if v1.Len() != v2.Len() {
- return false
- }
- for i := 0; i < v1.Len(); i++ {
- if !equalAny(v1.Index(i), v2.Index(i), prop) {
- return false
- }
- }
- return true
- case reflect.String:
- return v1.Interface().(string) == v2.Interface().(string)
- case reflect.Struct:
- return equalStruct(v1, v2)
- case reflect.Uint32, reflect.Uint64:
- return v1.Uint() == v2.Uint()
- }
-
- // unknown type, so not a protocol buffer
- log.Printf("proto: don't know how to compare %v", v1)
- return false
-}
-
-// base is the struct type that the extensions are based on.
-// x1 and x2 are InternalExtensions.
-func equalExtensions(base reflect.Type, x1, x2 XXX_InternalExtensions) bool {
- em1, _ := x1.extensionsRead()
- em2, _ := x2.extensionsRead()
- return equalExtMap(base, em1, em2)
-}
-
-func equalExtMap(base reflect.Type, em1, em2 map[int32]Extension) bool {
- if len(em1) != len(em2) {
- return false
- }
-
- for extNum, e1 := range em1 {
- e2, ok := em2[extNum]
- if !ok {
- return false
- }
-
- m1, m2 := e1.value, e2.value
-
- if m1 == nil && m2 == nil {
- // Both have only encoded form.
- if bytes.Equal(e1.enc, e2.enc) {
- continue
- }
- // The bytes are different, but the extensions might still be
- // equal. We need to decode them to compare.
- }
-
- if m1 != nil && m2 != nil {
- // Both are unencoded.
- if !equalAny(reflect.ValueOf(m1), reflect.ValueOf(m2), nil) {
- return false
- }
- continue
- }
-
- // At least one is encoded. To do a semantically correct comparison
- // we need to unmarshal them first.
- var desc *ExtensionDesc
- if m := extensionMaps[base]; m != nil {
- desc = m[extNum]
- }
- if desc == nil {
- // If both have only encoded form and the bytes are the same,
- // it is handled above. We get here when the bytes are different.
- // We don't know how to decode it, so just compare them as byte
- // slices.
- log.Printf("proto: don't know how to compare extension %d of %v", extNum, base)
- return false
- }
- var err error
- if m1 == nil {
- m1, err = decodeExtension(e1.enc, desc)
- }
- if m2 == nil && err == nil {
- m2, err = decodeExtension(e2.enc, desc)
- }
- if err != nil {
- // The encoded form is invalid.
- log.Printf("proto: badly encoded extension %d of %v: %v", extNum, base, err)
- return false
- }
- if !equalAny(reflect.ValueOf(m1), reflect.ValueOf(m2), nil) {
- return false
- }
- }
-
- return true
-}
diff --git a/vendor/github.com/golang/protobuf/proto/extensions.go b/vendor/github.com/golang/protobuf/proto/extensions.go
deleted file mode 100644
index 816a3b9..0000000
--- a/vendor/github.com/golang/protobuf/proto/extensions.go
+++ /dev/null
@@ -1,543 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2010 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-/*
- * Types and routines for supporting protocol buffer extensions.
- */
-
-import (
- "errors"
- "fmt"
- "io"
- "reflect"
- "strconv"
- "sync"
-)
-
-// ErrMissingExtension is the error returned by GetExtension if the named extension is not in the message.
-var ErrMissingExtension = errors.New("proto: missing extension")
-
-// ExtensionRange represents a range of message extensions for a protocol buffer.
-// Used in code generated by the protocol compiler.
-type ExtensionRange struct {
- Start, End int32 // both inclusive
-}
-
-// extendableProto is an interface implemented by any protocol buffer generated by the current
-// proto compiler that may be extended.
-type extendableProto interface {
- Message
- ExtensionRangeArray() []ExtensionRange
- extensionsWrite() map[int32]Extension
- extensionsRead() (map[int32]Extension, sync.Locker)
-}
-
-// extendableProtoV1 is an interface implemented by a protocol buffer generated by the previous
-// version of the proto compiler that may be extended.
-type extendableProtoV1 interface {
- Message
- ExtensionRangeArray() []ExtensionRange
- ExtensionMap() map[int32]Extension
-}
-
-// extensionAdapter is a wrapper around extendableProtoV1 that implements extendableProto.
-type extensionAdapter struct {
- extendableProtoV1
-}
-
-func (e extensionAdapter) extensionsWrite() map[int32]Extension {
- return e.ExtensionMap()
-}
-
-func (e extensionAdapter) extensionsRead() (map[int32]Extension, sync.Locker) {
- return e.ExtensionMap(), notLocker{}
-}
-
-// notLocker is a sync.Locker whose Lock and Unlock methods are nops.
-type notLocker struct{}
-
-func (n notLocker) Lock() {}
-func (n notLocker) Unlock() {}
-
-// extendable returns the extendableProto interface for the given generated proto message.
-// If the proto message has the old extension format, it returns a wrapper that implements
-// the extendableProto interface.
-func extendable(p interface{}) (extendableProto, error) {
- switch p := p.(type) {
- case extendableProto:
- if isNilPtr(p) {
- return nil, fmt.Errorf("proto: nil %T is not extendable", p)
- }
- return p, nil
- case extendableProtoV1:
- if isNilPtr(p) {
- return nil, fmt.Errorf("proto: nil %T is not extendable", p)
- }
- return extensionAdapter{p}, nil
- }
- // Don't allocate a specific error containing %T:
- // this is the hot path for Clone and MarshalText.
- return nil, errNotExtendable
-}
-
-var errNotExtendable = errors.New("proto: not an extendable proto.Message")
-
-func isNilPtr(x interface{}) bool {
- v := reflect.ValueOf(x)
- return v.Kind() == reflect.Ptr && v.IsNil()
-}
-
-// XXX_InternalExtensions is an internal representation of proto extensions.
-//
-// Each generated message struct type embeds an anonymous XXX_InternalExtensions field,
-// thus gaining the unexported 'extensions' method, which can be called only from the proto package.
-//
-// The methods of XXX_InternalExtensions are not concurrency safe in general,
-// but calls to logically read-only methods such as has and get may be executed concurrently.
-type XXX_InternalExtensions struct {
- // The struct must be indirect so that if a user inadvertently copies a
- // generated message and its embedded XXX_InternalExtensions, they
- // avoid the mayhem of a copied mutex.
- //
- // The mutex serializes all logically read-only operations to p.extensionMap.
- // It is up to the client to ensure that write operations to p.extensionMap are
- // mutually exclusive with other accesses.
- p *struct {
- mu sync.Mutex
- extensionMap map[int32]Extension
- }
-}
-
-// extensionsWrite returns the extension map, creating it on first use.
-func (e *XXX_InternalExtensions) extensionsWrite() map[int32]Extension {
- if e.p == nil {
- e.p = new(struct {
- mu sync.Mutex
- extensionMap map[int32]Extension
- })
- e.p.extensionMap = make(map[int32]Extension)
- }
- return e.p.extensionMap
-}
-
-// extensionsRead returns the extensions map for read-only use. It may be nil.
-// The caller must hold the returned mutex's lock when accessing Elements within the map.
-func (e *XXX_InternalExtensions) extensionsRead() (map[int32]Extension, sync.Locker) {
- if e.p == nil {
- return nil, nil
- }
- return e.p.extensionMap, &e.p.mu
-}
-
-// ExtensionDesc represents an extension specification.
-// Used in generated code from the protocol compiler.
-type ExtensionDesc struct {
- ExtendedType Message // nil pointer to the type that is being extended
- ExtensionType interface{} // nil pointer to the extension type
- Field int32 // field number
- Name string // fully-qualified name of extension, for text formatting
- Tag string // protobuf tag style
- Filename string // name of the file in which the extension is defined
-}
-
-func (ed *ExtensionDesc) repeated() bool {
- t := reflect.TypeOf(ed.ExtensionType)
- return t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8
-}
-
-// Extension represents an extension in a message.
-type Extension struct {
- // When an extension is stored in a message using SetExtension
- // only desc and value are set. When the message is marshaled
- // enc will be set to the encoded form of the message.
- //
- // When a message is unmarshaled and contains extensions, each
- // extension will have only enc set. When such an extension is
- // accessed using GetExtension (or GetExtensions) desc and value
- // will be set.
- desc *ExtensionDesc
- value interface{}
- enc []byte
-}
-
-// SetRawExtension is for testing only.
-func SetRawExtension(base Message, id int32, b []byte) {
- epb, err := extendable(base)
- if err != nil {
- return
- }
- extmap := epb.extensionsWrite()
- extmap[id] = Extension{enc: b}
-}
-
-// isExtensionField returns true iff the given field number is in an extension range.
-func isExtensionField(pb extendableProto, field int32) bool {
- for _, er := range pb.ExtensionRangeArray() {
- if er.Start <= field && field <= er.End {
- return true
- }
- }
- return false
-}
-
-// checkExtensionTypes checks that the given extension is valid for pb.
-func checkExtensionTypes(pb extendableProto, extension *ExtensionDesc) error {
- var pbi interface{} = pb
- // Check the extended type.
- if ea, ok := pbi.(extensionAdapter); ok {
- pbi = ea.extendableProtoV1
- }
- if a, b := reflect.TypeOf(pbi), reflect.TypeOf(extension.ExtendedType); a != b {
- return fmt.Errorf("proto: bad extended type; %v does not extend %v", b, a)
- }
- // Check the range.
- if !isExtensionField(pb, extension.Field) {
- return errors.New("proto: bad extension number; not in declared ranges")
- }
- return nil
-}
-
-// extPropKey is sufficient to uniquely identify an extension.
-type extPropKey struct {
- base reflect.Type
- field int32
-}
-
-var extProp = struct {
- sync.RWMutex
- m map[extPropKey]*Properties
-}{
- m: make(map[extPropKey]*Properties),
-}
-
-func extensionProperties(ed *ExtensionDesc) *Properties {
- key := extPropKey{base: reflect.TypeOf(ed.ExtendedType), field: ed.Field}
-
- extProp.RLock()
- if prop, ok := extProp.m[key]; ok {
- extProp.RUnlock()
- return prop
- }
- extProp.RUnlock()
-
- extProp.Lock()
- defer extProp.Unlock()
- // Check again.
- if prop, ok := extProp.m[key]; ok {
- return prop
- }
-
- prop := new(Properties)
- prop.Init(reflect.TypeOf(ed.ExtensionType), "unknown_name", ed.Tag, nil)
- extProp.m[key] = prop
- return prop
-}
-
-// HasExtension returns whether the given extension is present in pb.
-func HasExtension(pb Message, extension *ExtensionDesc) bool {
- // TODO: Check types, field numbers, etc.?
- epb, err := extendable(pb)
- if err != nil {
- return false
- }
- extmap, mu := epb.extensionsRead()
- if extmap == nil {
- return false
- }
- mu.Lock()
- _, ok := extmap[extension.Field]
- mu.Unlock()
- return ok
-}
-
-// ClearExtension removes the given extension from pb.
-func ClearExtension(pb Message, extension *ExtensionDesc) {
- epb, err := extendable(pb)
- if err != nil {
- return
- }
- // TODO: Check types, field numbers, etc.?
- extmap := epb.extensionsWrite()
- delete(extmap, extension.Field)
-}
-
-// GetExtension retrieves a proto2 extended field from pb.
-//
-// If the descriptor is type complete (i.e., ExtensionDesc.ExtensionType is non-nil),
-// then GetExtension parses the encoded field and returns a Go value of the specified type.
-// If the field is not present, then the default value is returned (if one is specified),
-// otherwise ErrMissingExtension is reported.
-//
-// If the descriptor is not type complete (i.e., ExtensionDesc.ExtensionType is nil),
-// then GetExtension returns the raw encoded bytes of the field extension.
-func GetExtension(pb Message, extension *ExtensionDesc) (interface{}, error) {
- epb, err := extendable(pb)
- if err != nil {
- return nil, err
- }
-
- if extension.ExtendedType != nil {
- // can only check type if this is a complete descriptor
- if err := checkExtensionTypes(epb, extension); err != nil {
- return nil, err
- }
- }
-
- emap, mu := epb.extensionsRead()
- if emap == nil {
- return defaultExtensionValue(extension)
- }
- mu.Lock()
- defer mu.Unlock()
- e, ok := emap[extension.Field]
- if !ok {
- // defaultExtensionValue returns the default value or
- // ErrMissingExtension if there is no default.
- return defaultExtensionValue(extension)
- }
-
- if e.value != nil {
- // Already decoded. Check the descriptor, though.
- if e.desc != extension {
- // This shouldn't happen. If it does, it means that
- // GetExtension was called twice with two different
- // descriptors with the same field number.
- return nil, errors.New("proto: descriptor conflict")
- }
- return e.value, nil
- }
-
- if extension.ExtensionType == nil {
- // incomplete descriptor
- return e.enc, nil
- }
-
- v, err := decodeExtension(e.enc, extension)
- if err != nil {
- return nil, err
- }
-
- // Remember the decoded version and drop the encoded version.
- // That way it is safe to mutate what we return.
- e.value = v
- e.desc = extension
- e.enc = nil
- emap[extension.Field] = e
- return e.value, nil
-}
-
-// defaultExtensionValue returns the default value for extension.
-// If no default for an extension is defined ErrMissingExtension is returned.
-func defaultExtensionValue(extension *ExtensionDesc) (interface{}, error) {
- if extension.ExtensionType == nil {
- // incomplete descriptor, so no default
- return nil, ErrMissingExtension
- }
-
- t := reflect.TypeOf(extension.ExtensionType)
- props := extensionProperties(extension)
-
- sf, _, err := fieldDefault(t, props)
- if err != nil {
- return nil, err
- }
-
- if sf == nil || sf.value == nil {
- // There is no default value.
- return nil, ErrMissingExtension
- }
-
- if t.Kind() != reflect.Ptr {
- // We do not need to return a Ptr, we can directly return sf.value.
- return sf.value, nil
- }
-
- // We need to return an interface{} that is a pointer to sf.value.
- value := reflect.New(t).Elem()
- value.Set(reflect.New(value.Type().Elem()))
- if sf.kind == reflect.Int32 {
- // We may have an int32 or an enum, but the underlying data is int32.
- // Since we can't set an int32 into a non int32 reflect.value directly
- // set it as a int32.
- value.Elem().SetInt(int64(sf.value.(int32)))
- } else {
- value.Elem().Set(reflect.ValueOf(sf.value))
- }
- return value.Interface(), nil
-}
-
-// decodeExtension decodes an extension encoded in b.
-func decodeExtension(b []byte, extension *ExtensionDesc) (interface{}, error) {
- t := reflect.TypeOf(extension.ExtensionType)
- unmarshal := typeUnmarshaler(t, extension.Tag)
-
- // t is a pointer to a struct, pointer to basic type or a slice.
- // Allocate space to store the pointer/slice.
- value := reflect.New(t).Elem()
-
- var err error
- for {
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- wire := int(x) & 7
-
- b, err = unmarshal(b, valToPointer(value.Addr()), wire)
- if err != nil {
- return nil, err
- }
-
- if len(b) == 0 {
- break
- }
- }
- return value.Interface(), nil
-}
-
-// GetExtensions returns a slice of the extensions present in pb that are also listed in es.
-// The returned slice has the same length as es; missing extensions will appear as nil elements.
-func GetExtensions(pb Message, es []*ExtensionDesc) (extensions []interface{}, err error) {
- epb, err := extendable(pb)
- if err != nil {
- return nil, err
- }
- extensions = make([]interface{}, len(es))
- for i, e := range es {
- extensions[i], err = GetExtension(epb, e)
- if err == ErrMissingExtension {
- err = nil
- }
- if err != nil {
- return
- }
- }
- return
-}
-
-// ExtensionDescs returns a new slice containing pb's extension descriptors, in undefined order.
-// For non-registered extensions, ExtensionDescs returns an incomplete descriptor containing
-// just the Field field, which defines the extension's field number.
-func ExtensionDescs(pb Message) ([]*ExtensionDesc, error) {
- epb, err := extendable(pb)
- if err != nil {
- return nil, err
- }
- registeredExtensions := RegisteredExtensions(pb)
-
- emap, mu := epb.extensionsRead()
- if emap == nil {
- return nil, nil
- }
- mu.Lock()
- defer mu.Unlock()
- extensions := make([]*ExtensionDesc, 0, len(emap))
- for extid, e := range emap {
- desc := e.desc
- if desc == nil {
- desc = registeredExtensions[extid]
- if desc == nil {
- desc = &ExtensionDesc{Field: extid}
- }
- }
-
- extensions = append(extensions, desc)
- }
- return extensions, nil
-}
-
-// SetExtension sets the specified extension of pb to the specified value.
-func SetExtension(pb Message, extension *ExtensionDesc, value interface{}) error {
- epb, err := extendable(pb)
- if err != nil {
- return err
- }
- if err := checkExtensionTypes(epb, extension); err != nil {
- return err
- }
- typ := reflect.TypeOf(extension.ExtensionType)
- if typ != reflect.TypeOf(value) {
- return errors.New("proto: bad extension value type")
- }
- // nil extension values need to be caught early, because the
- // encoder can't distinguish an ErrNil due to a nil extension
- // from an ErrNil due to a missing field. Extensions are
- // always optional, so the encoder would just swallow the error
- // and drop all the extensions from the encoded message.
- if reflect.ValueOf(value).IsNil() {
- return fmt.Errorf("proto: SetExtension called with nil value of type %T", value)
- }
-
- extmap := epb.extensionsWrite()
- extmap[extension.Field] = Extension{desc: extension, value: value}
- return nil
-}
-
-// ClearAllExtensions clears all extensions from pb.
-func ClearAllExtensions(pb Message) {
- epb, err := extendable(pb)
- if err != nil {
- return
- }
- m := epb.extensionsWrite()
- for k := range m {
- delete(m, k)
- }
-}
-
-// A global registry of extensions.
-// The generated code will register the generated descriptors by calling RegisterExtension.
-
-var extensionMaps = make(map[reflect.Type]map[int32]*ExtensionDesc)
-
-// RegisterExtension is called from the generated code.
-func RegisterExtension(desc *ExtensionDesc) {
- st := reflect.TypeOf(desc.ExtendedType).Elem()
- m := extensionMaps[st]
- if m == nil {
- m = make(map[int32]*ExtensionDesc)
- extensionMaps[st] = m
- }
- if _, ok := m[desc.Field]; ok {
- panic("proto: duplicate extension registered: " + st.String() + " " + strconv.Itoa(int(desc.Field)))
- }
- m[desc.Field] = desc
-}
-
-// RegisteredExtensions returns a map of the registered extensions of a
-// protocol buffer struct, indexed by the extension number.
-// The argument pb should be a nil pointer to the struct type.
-func RegisteredExtensions(pb Message) map[int32]*ExtensionDesc {
- return extensionMaps[reflect.TypeOf(pb).Elem()]
-}
diff --git a/vendor/github.com/golang/protobuf/proto/lib.go b/vendor/github.com/golang/protobuf/proto/lib.go
deleted file mode 100644
index 75565cc..0000000
--- a/vendor/github.com/golang/protobuf/proto/lib.go
+++ /dev/null
@@ -1,979 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2010 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-/*
-Package proto converts data structures to and from the wire format of
-protocol buffers. It works in concert with the Go source code generated
-for .proto files by the protocol compiler.
-
-A summary of the properties of the protocol buffer interface
-for a protocol buffer variable v:
-
- - Names are turned from camel_case to CamelCase for export.
- - There are no methods on v to set fields; just treat
- them as structure fields.
- - There are getters that return a field's value if set,
- and return the field's default value if unset.
- The getters work even if the receiver is a nil message.
- - The zero value for a struct is its correct initialization state.
- All desired fields must be set before marshaling.
- - A Reset() method will restore a protobuf struct to its zero state.
- - Non-repeated fields are pointers to the values; nil means unset.
- That is, optional or required field int32 f becomes F *int32.
- - Repeated fields are slices.
- - Helper functions are available to aid the setting of fields.
- msg.Foo = proto.String("hello") // set field
- - Constants are defined to hold the default values of all fields that
- have them. They have the form Default_StructName_FieldName.
- Because the getter methods handle defaulted values,
- direct use of these constants should be rare.
- - Enums are given type names and maps from names to values.
- Enum values are prefixed by the enclosing message's name, or by the
- enum's type name if it is a top-level enum. Enum types have a String
- method, and a Enum method to assist in message construction.
- - Nested messages, groups and enums have type names prefixed with the name of
- the surrounding message type.
- - Extensions are given descriptor names that start with E_,
- followed by an underscore-delimited list of the nested messages
- that contain it (if any) followed by the CamelCased name of the
- extension field itself. HasExtension, ClearExtension, GetExtension
- and SetExtension are functions for manipulating extensions.
- - Oneof field sets are given a single field in their message,
- with distinguished wrapper types for each possible field value.
- - Marshal and Unmarshal are functions to encode and decode the wire format.
-
-When the .proto file specifies `syntax="proto3"`, there are some differences:
-
- - Non-repeated fields of non-message type are values instead of pointers.
- - Enum types do not get an Enum method.
-
-The simplest way to describe this is to see an example.
-Given file test.proto, containing
-
- package example;
-
- enum FOO { X = 17; }
-
- message Test {
- required string label = 1;
- optional int32 type = 2 [default=77];
- repeated int64 reps = 3;
- optional group OptionalGroup = 4 {
- required string RequiredField = 5;
- }
- oneof union {
- int32 number = 6;
- string name = 7;
- }
- }
-
-The resulting file, test.pb.go, is:
-
- package example
-
- import proto "github.com/golang/protobuf/proto"
- import math "math"
-
- type FOO int32
- const (
- FOO_X FOO = 17
- )
- var FOO_name = map[int32]string{
- 17: "X",
- }
- var FOO_value = map[string]int32{
- "X": 17,
- }
-
- func (x FOO) Enum() *FOO {
- p := new(FOO)
- *p = x
- return p
- }
- func (x FOO) String() string {
- return proto.EnumName(FOO_name, int32(x))
- }
- func (x *FOO) UnmarshalJSON(data []byte) error {
- value, err := proto.UnmarshalJSONEnum(FOO_value, data)
- if err != nil {
- return err
- }
- *x = FOO(value)
- return nil
- }
-
- type Test struct {
- Label *string `protobuf:"bytes,1,req,name=label" json:"label,omitempty"`
- Type *int32 `protobuf:"varint,2,opt,name=type,def=77" json:"type,omitempty"`
- Reps []int64 `protobuf:"varint,3,rep,name=reps" json:"reps,omitempty"`
- Optionalgroup *Test_OptionalGroup `protobuf:"group,4,opt,name=OptionalGroup" json:"optionalgroup,omitempty"`
- // Types that are valid to be assigned to Union:
- // *Test_Number
- // *Test_Name
- Union isTest_Union `protobuf_oneof:"union"`
- XXX_unrecognized []byte `json:"-"`
- }
- func (m *Test) Reset() { *m = Test{} }
- func (m *Test) String() string { return proto.CompactTextString(m) }
- func (*Test) ProtoMessage() {}
-
- type isTest_Union interface {
- isTest_Union()
- }
-
- type Test_Number struct {
- Number int32 `protobuf:"varint,6,opt,name=number"`
- }
- type Test_Name struct {
- Name string `protobuf:"bytes,7,opt,name=name"`
- }
-
- func (*Test_Number) isTest_Union() {}
- func (*Test_Name) isTest_Union() {}
-
- func (m *Test) GetUnion() isTest_Union {
- if m != nil {
- return m.Union
- }
- return nil
- }
- const Default_Test_Type int32 = 77
-
- func (m *Test) GetLabel() string {
- if m != nil && m.Label != nil {
- return *m.Label
- }
- return ""
- }
-
- func (m *Test) GetType() int32 {
- if m != nil && m.Type != nil {
- return *m.Type
- }
- return Default_Test_Type
- }
-
- func (m *Test) GetOptionalgroup() *Test_OptionalGroup {
- if m != nil {
- return m.Optionalgroup
- }
- return nil
- }
-
- type Test_OptionalGroup struct {
- RequiredField *string `protobuf:"bytes,5,req" json:"RequiredField,omitempty"`
- }
- func (m *Test_OptionalGroup) Reset() { *m = Test_OptionalGroup{} }
- func (m *Test_OptionalGroup) String() string { return proto.CompactTextString(m) }
-
- func (m *Test_OptionalGroup) GetRequiredField() string {
- if m != nil && m.RequiredField != nil {
- return *m.RequiredField
- }
- return ""
- }
-
- func (m *Test) GetNumber() int32 {
- if x, ok := m.GetUnion().(*Test_Number); ok {
- return x.Number
- }
- return 0
- }
-
- func (m *Test) GetName() string {
- if x, ok := m.GetUnion().(*Test_Name); ok {
- return x.Name
- }
- return ""
- }
-
- func init() {
- proto.RegisterEnum("example.FOO", FOO_name, FOO_value)
- }
-
-To create and play with a Test object:
-
- package main
-
- import (
- "log"
-
- "github.com/golang/protobuf/proto"
- pb "./example.pb"
- )
-
- func main() {
- test := &pb.Test{
- Label: proto.String("hello"),
- Type: proto.Int32(17),
- Reps: []int64{1, 2, 3},
- Optionalgroup: &pb.Test_OptionalGroup{
- RequiredField: proto.String("good bye"),
- },
- Union: &pb.Test_Name{"fred"},
- }
- data, err := proto.Marshal(test)
- if err != nil {
- log.Fatal("marshaling error: ", err)
- }
- newTest := &pb.Test{}
- err = proto.Unmarshal(data, newTest)
- if err != nil {
- log.Fatal("unmarshaling error: ", err)
- }
- // Now test and newTest contain the same data.
- if test.GetLabel() != newTest.GetLabel() {
- log.Fatalf("data mismatch %q != %q", test.GetLabel(), newTest.GetLabel())
- }
- // Use a type switch to determine which oneof was set.
- switch u := test.Union.(type) {
- case *pb.Test_Number: // u.Number contains the number.
- case *pb.Test_Name: // u.Name contains the string.
- }
- // etc.
- }
-*/
-package proto
-
-import (
- "encoding/json"
- "fmt"
- "log"
- "reflect"
- "sort"
- "strconv"
- "sync"
-)
-
-// RequiredNotSetError is an error type returned by either Marshal or Unmarshal.
-// Marshal reports this when a required field is not initialized.
-// Unmarshal reports this when a required field is missing from the wire data.
-type RequiredNotSetError struct{ field string }
-
-func (e *RequiredNotSetError) Error() string {
- if e.field == "" {
- return fmt.Sprintf("proto: required field not set")
- }
- return fmt.Sprintf("proto: required field %q not set", e.field)
-}
-func (e *RequiredNotSetError) RequiredNotSet() bool {
- return true
-}
-
-type invalidUTF8Error struct{ field string }
-
-func (e *invalidUTF8Error) Error() string {
- if e.field == "" {
- return "proto: invalid UTF-8 detected"
- }
- return fmt.Sprintf("proto: field %q contains invalid UTF-8", e.field)
-}
-func (e *invalidUTF8Error) InvalidUTF8() bool {
- return true
-}
-
-// errInvalidUTF8 is a sentinel error to identify fields with invalid UTF-8.
-// This error should not be exposed to the external API as such errors should
-// be recreated with the field information.
-var errInvalidUTF8 = &invalidUTF8Error{}
-
-// isNonFatal reports whether the error is either a RequiredNotSet error
-// or a InvalidUTF8 error.
-func isNonFatal(err error) bool {
- if re, ok := err.(interface{ RequiredNotSet() bool }); ok && re.RequiredNotSet() {
- return true
- }
- if re, ok := err.(interface{ InvalidUTF8() bool }); ok && re.InvalidUTF8() {
- return true
- }
- return false
-}
-
-type nonFatal struct{ E error }
-
-// Merge merges err into nf and reports whether it was successful.
-// Otherwise it returns false for any fatal non-nil errors.
-func (nf *nonFatal) Merge(err error) (ok bool) {
- if err == nil {
- return true // not an error
- }
- if !isNonFatal(err) {
- return false // fatal error
- }
- if nf.E == nil {
- nf.E = err // store first instance of non-fatal error
- }
- return true
-}
-
-// Message is implemented by generated protocol buffer messages.
-type Message interface {
- Reset()
- String() string
- ProtoMessage()
-}
-
-// Stats records allocation details about the protocol buffer encoders
-// and decoders. Useful for tuning the library itself.
-type Stats struct {
- Emalloc uint64 // mallocs in encode
- Dmalloc uint64 // mallocs in decode
- Encode uint64 // number of encodes
- Decode uint64 // number of decodes
- Chit uint64 // number of cache hits
- Cmiss uint64 // number of cache misses
- Size uint64 // number of sizes
-}
-
-// Set to true to enable stats collection.
-const collectStats = false
-
-var stats Stats
-
-// GetStats returns a copy of the global Stats structure.
-func GetStats() Stats { return stats }
-
-// A Buffer is a buffer manager for marshaling and unmarshaling
-// protocol buffers. It may be reused between invocations to
-// reduce memory usage. It is not necessary to use a Buffer;
-// the global functions Marshal and Unmarshal create a
-// temporary Buffer and are fine for most applications.
-type Buffer struct {
- buf []byte // encode/decode byte stream
- index int // read point
-
- deterministic bool
-}
-
-// NewBuffer allocates a new Buffer and initializes its internal data to
-// the contents of the argument slice.
-func NewBuffer(e []byte) *Buffer {
- return &Buffer{buf: e}
-}
-
-// Reset resets the Buffer, ready for marshaling a new protocol buffer.
-func (p *Buffer) Reset() {
- p.buf = p.buf[0:0] // for reading/writing
- p.index = 0 // for reading
-}
-
-// SetBuf replaces the internal buffer with the slice,
-// ready for unmarshaling the contents of the slice.
-func (p *Buffer) SetBuf(s []byte) {
- p.buf = s
- p.index = 0
-}
-
-// Bytes returns the contents of the Buffer.
-func (p *Buffer) Bytes() []byte { return p.buf }
-
-// SetDeterministic sets whether to use deterministic serialization.
-//
-// Deterministic serialization guarantees that for a given binary, equal
-// messages will always be serialized to the same bytes. This implies:
-//
-// - Repeated serialization of a message will return the same bytes.
-// - Different processes of the same binary (which may be executing on
-// different machines) will serialize equal messages to the same bytes.
-//
-// Note that the deterministic serialization is NOT canonical across
-// languages. It is not guaranteed to remain stable over time. It is unstable
-// across different builds with schema changes due to unknown fields.
-// Users who need canonical serialization (e.g., persistent storage in a
-// canonical form, fingerprinting, etc.) should define their own
-// canonicalization specification and implement their own serializer rather
-// than relying on this API.
-//
-// If deterministic serialization is requested, map entries will be sorted
-// by keys in lexographical order. This is an implementation detail and
-// subject to change.
-func (p *Buffer) SetDeterministic(deterministic bool) {
- p.deterministic = deterministic
-}
-
-/*
- * Helper routines for simplifying the creation of optional fields of basic type.
- */
-
-// Bool is a helper routine that allocates a new bool value
-// to store v and returns a pointer to it.
-func Bool(v bool) *bool {
- return &v
-}
-
-// Int32 is a helper routine that allocates a new int32 value
-// to store v and returns a pointer to it.
-func Int32(v int32) *int32 {
- return &v
-}
-
-// Int is a helper routine that allocates a new int32 value
-// to store v and returns a pointer to it, but unlike Int32
-// its argument value is an int.
-func Int(v int) *int32 {
- p := new(int32)
- *p = int32(v)
- return p
-}
-
-// Int64 is a helper routine that allocates a new int64 value
-// to store v and returns a pointer to it.
-func Int64(v int64) *int64 {
- return &v
-}
-
-// Float32 is a helper routine that allocates a new float32 value
-// to store v and returns a pointer to it.
-func Float32(v float32) *float32 {
- return &v
-}
-
-// Float64 is a helper routine that allocates a new float64 value
-// to store v and returns a pointer to it.
-func Float64(v float64) *float64 {
- return &v
-}
-
-// Uint32 is a helper routine that allocates a new uint32 value
-// to store v and returns a pointer to it.
-func Uint32(v uint32) *uint32 {
- return &v
-}
-
-// Uint64 is a helper routine that allocates a new uint64 value
-// to store v and returns a pointer to it.
-func Uint64(v uint64) *uint64 {
- return &v
-}
-
-// String is a helper routine that allocates a new string value
-// to store v and returns a pointer to it.
-func String(v string) *string {
- return &v
-}
-
-// EnumName is a helper function to simplify printing protocol buffer enums
-// by name. Given an enum map and a value, it returns a useful string.
-func EnumName(m map[int32]string, v int32) string {
- s, ok := m[v]
- if ok {
- return s
- }
- return strconv.Itoa(int(v))
-}
-
-// UnmarshalJSONEnum is a helper function to simplify recovering enum int values
-// from their JSON-encoded representation. Given a map from the enum's symbolic
-// names to its int values, and a byte buffer containing the JSON-encoded
-// value, it returns an int32 that can be cast to the enum type by the caller.
-//
-// The function can deal with both JSON representations, numeric and symbolic.
-func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
- if data[0] == '"' {
- // New style: enums are strings.
- var repr string
- if err := json.Unmarshal(data, &repr); err != nil {
- return -1, err
- }
- val, ok := m[repr]
- if !ok {
- return 0, fmt.Errorf("unrecognized enum %s value %q", enumName, repr)
- }
- return val, nil
- }
- // Old style: enums are ints.
- var val int32
- if err := json.Unmarshal(data, &val); err != nil {
- return 0, fmt.Errorf("cannot unmarshal %#q into enum %s", data, enumName)
- }
- return val, nil
-}
-
-// DebugPrint dumps the encoded data in b in a debugging format with a header
-// including the string s. Used in testing but made available for general debugging.
-func (p *Buffer) DebugPrint(s string, b []byte) {
- var u uint64
-
- obuf := p.buf
- index := p.index
- p.buf = b
- p.index = 0
- depth := 0
-
- fmt.Printf("\n--- %s ---\n", s)
-
-out:
- for {
- for i := 0; i < depth; i++ {
- fmt.Print(" ")
- }
-
- index := p.index
- if index == len(p.buf) {
- break
- }
-
- op, err := p.DecodeVarint()
- if err != nil {
- fmt.Printf("%3d: fetching op err %v\n", index, err)
- break out
- }
- tag := op >> 3
- wire := op & 7
-
- switch wire {
- default:
- fmt.Printf("%3d: t=%3d unknown wire=%d\n",
- index, tag, wire)
- break out
-
- case WireBytes:
- var r []byte
-
- r, err = p.DecodeRawBytes(false)
- if err != nil {
- break out
- }
- fmt.Printf("%3d: t=%3d bytes [%d]", index, tag, len(r))
- if len(r) <= 6 {
- for i := 0; i < len(r); i++ {
- fmt.Printf(" %.2x", r[i])
- }
- } else {
- for i := 0; i < 3; i++ {
- fmt.Printf(" %.2x", r[i])
- }
- fmt.Printf(" ..")
- for i := len(r) - 3; i < len(r); i++ {
- fmt.Printf(" %.2x", r[i])
- }
- }
- fmt.Printf("\n")
-
- case WireFixed32:
- u, err = p.DecodeFixed32()
- if err != nil {
- fmt.Printf("%3d: t=%3d fix32 err %v\n", index, tag, err)
- break out
- }
- fmt.Printf("%3d: t=%3d fix32 %d\n", index, tag, u)
-
- case WireFixed64:
- u, err = p.DecodeFixed64()
- if err != nil {
- fmt.Printf("%3d: t=%3d fix64 err %v\n", index, tag, err)
- break out
- }
- fmt.Printf("%3d: t=%3d fix64 %d\n", index, tag, u)
-
- case WireVarint:
- u, err = p.DecodeVarint()
- if err != nil {
- fmt.Printf("%3d: t=%3d varint err %v\n", index, tag, err)
- break out
- }
- fmt.Printf("%3d: t=%3d varint %d\n", index, tag, u)
-
- case WireStartGroup:
- fmt.Printf("%3d: t=%3d start\n", index, tag)
- depth++
-
- case WireEndGroup:
- depth--
- fmt.Printf("%3d: t=%3d end\n", index, tag)
- }
- }
-
- if depth != 0 {
- fmt.Printf("%3d: start-end not balanced %d\n", p.index, depth)
- }
- fmt.Printf("\n")
-
- p.buf = obuf
- p.index = index
-}
-
-// SetDefaults sets unset protocol buffer fields to their default values.
-// It only modifies fields that are both unset and have defined defaults.
-// It recursively sets default values in any non-nil sub-messages.
-func SetDefaults(pb Message) {
- setDefaults(reflect.ValueOf(pb), true, false)
-}
-
-// v is a pointer to a struct.
-func setDefaults(v reflect.Value, recur, zeros bool) {
- v = v.Elem()
-
- defaultMu.RLock()
- dm, ok := defaults[v.Type()]
- defaultMu.RUnlock()
- if !ok {
- dm = buildDefaultMessage(v.Type())
- defaultMu.Lock()
- defaults[v.Type()] = dm
- defaultMu.Unlock()
- }
-
- for _, sf := range dm.scalars {
- f := v.Field(sf.index)
- if !f.IsNil() {
- // field already set
- continue
- }
- dv := sf.value
- if dv == nil && !zeros {
- // no explicit default, and don't want to set zeros
- continue
- }
- fptr := f.Addr().Interface() // **T
- // TODO: Consider batching the allocations we do here.
- switch sf.kind {
- case reflect.Bool:
- b := new(bool)
- if dv != nil {
- *b = dv.(bool)
- }
- *(fptr.(**bool)) = b
- case reflect.Float32:
- f := new(float32)
- if dv != nil {
- *f = dv.(float32)
- }
- *(fptr.(**float32)) = f
- case reflect.Float64:
- f := new(float64)
- if dv != nil {
- *f = dv.(float64)
- }
- *(fptr.(**float64)) = f
- case reflect.Int32:
- // might be an enum
- if ft := f.Type(); ft != int32PtrType {
- // enum
- f.Set(reflect.New(ft.Elem()))
- if dv != nil {
- f.Elem().SetInt(int64(dv.(int32)))
- }
- } else {
- // int32 field
- i := new(int32)
- if dv != nil {
- *i = dv.(int32)
- }
- *(fptr.(**int32)) = i
- }
- case reflect.Int64:
- i := new(int64)
- if dv != nil {
- *i = dv.(int64)
- }
- *(fptr.(**int64)) = i
- case reflect.String:
- s := new(string)
- if dv != nil {
- *s = dv.(string)
- }
- *(fptr.(**string)) = s
- case reflect.Uint8:
- // exceptional case: []byte
- var b []byte
- if dv != nil {
- db := dv.([]byte)
- b = make([]byte, len(db))
- copy(b, db)
- } else {
- b = []byte{}
- }
- *(fptr.(*[]byte)) = b
- case reflect.Uint32:
- u := new(uint32)
- if dv != nil {
- *u = dv.(uint32)
- }
- *(fptr.(**uint32)) = u
- case reflect.Uint64:
- u := new(uint64)
- if dv != nil {
- *u = dv.(uint64)
- }
- *(fptr.(**uint64)) = u
- default:
- log.Printf("proto: can't set default for field %v (sf.kind=%v)", f, sf.kind)
- }
- }
-
- for _, ni := range dm.nested {
- f := v.Field(ni)
- // f is *T or []*T or map[T]*T
- switch f.Kind() {
- case reflect.Ptr:
- if f.IsNil() {
- continue
- }
- setDefaults(f, recur, zeros)
-
- case reflect.Slice:
- for i := 0; i < f.Len(); i++ {
- e := f.Index(i)
- if e.IsNil() {
- continue
- }
- setDefaults(e, recur, zeros)
- }
-
- case reflect.Map:
- for _, k := range f.MapKeys() {
- e := f.MapIndex(k)
- if e.IsNil() {
- continue
- }
- setDefaults(e, recur, zeros)
- }
- }
- }
-}
-
-var (
- // defaults maps a protocol buffer struct type to a slice of the fields,
- // with its scalar fields set to their proto-declared non-zero default values.
- defaultMu sync.RWMutex
- defaults = make(map[reflect.Type]defaultMessage)
-
- int32PtrType = reflect.TypeOf((*int32)(nil))
-)
-
-// defaultMessage represents information about the default values of a message.
-type defaultMessage struct {
- scalars []scalarField
- nested []int // struct field index of nested messages
-}
-
-type scalarField struct {
- index int // struct field index
- kind reflect.Kind // element type (the T in *T or []T)
- value interface{} // the proto-declared default value, or nil
-}
-
-// t is a struct type.
-func buildDefaultMessage(t reflect.Type) (dm defaultMessage) {
- sprop := GetProperties(t)
- for _, prop := range sprop.Prop {
- fi, ok := sprop.decoderTags.get(prop.Tag)
- if !ok {
- // XXX_unrecognized
- continue
- }
- ft := t.Field(fi).Type
-
- sf, nested, err := fieldDefault(ft, prop)
- switch {
- case err != nil:
- log.Print(err)
- case nested:
- dm.nested = append(dm.nested, fi)
- case sf != nil:
- sf.index = fi
- dm.scalars = append(dm.scalars, *sf)
- }
- }
-
- return dm
-}
-
-// fieldDefault returns the scalarField for field type ft.
-// sf will be nil if the field can not have a default.
-// nestedMessage will be true if this is a nested message.
-// Note that sf.index is not set on return.
-func fieldDefault(ft reflect.Type, prop *Properties) (sf *scalarField, nestedMessage bool, err error) {
- var canHaveDefault bool
- switch ft.Kind() {
- case reflect.Ptr:
- if ft.Elem().Kind() == reflect.Struct {
- nestedMessage = true
- } else {
- canHaveDefault = true // proto2 scalar field
- }
-
- case reflect.Slice:
- switch ft.Elem().Kind() {
- case reflect.Ptr:
- nestedMessage = true // repeated message
- case reflect.Uint8:
- canHaveDefault = true // bytes field
- }
-
- case reflect.Map:
- if ft.Elem().Kind() == reflect.Ptr {
- nestedMessage = true // map with message values
- }
- }
-
- if !canHaveDefault {
- if nestedMessage {
- return nil, true, nil
- }
- return nil, false, nil
- }
-
- // We now know that ft is a pointer or slice.
- sf = &scalarField{kind: ft.Elem().Kind()}
-
- // scalar fields without defaults
- if !prop.HasDefault {
- return sf, false, nil
- }
-
- // a scalar field: either *T or []byte
- switch ft.Elem().Kind() {
- case reflect.Bool:
- x, err := strconv.ParseBool(prop.Default)
- if err != nil {
- return nil, false, fmt.Errorf("proto: bad default bool %q: %v", prop.Default, err)
- }
- sf.value = x
- case reflect.Float32:
- x, err := strconv.ParseFloat(prop.Default, 32)
- if err != nil {
- return nil, false, fmt.Errorf("proto: bad default float32 %q: %v", prop.Default, err)
- }
- sf.value = float32(x)
- case reflect.Float64:
- x, err := strconv.ParseFloat(prop.Default, 64)
- if err != nil {
- return nil, false, fmt.Errorf("proto: bad default float64 %q: %v", prop.Default, err)
- }
- sf.value = x
- case reflect.Int32:
- x, err := strconv.ParseInt(prop.Default, 10, 32)
- if err != nil {
- return nil, false, fmt.Errorf("proto: bad default int32 %q: %v", prop.Default, err)
- }
- sf.value = int32(x)
- case reflect.Int64:
- x, err := strconv.ParseInt(prop.Default, 10, 64)
- if err != nil {
- return nil, false, fmt.Errorf("proto: bad default int64 %q: %v", prop.Default, err)
- }
- sf.value = x
- case reflect.String:
- sf.value = prop.Default
- case reflect.Uint8:
- // []byte (not *uint8)
- sf.value = []byte(prop.Default)
- case reflect.Uint32:
- x, err := strconv.ParseUint(prop.Default, 10, 32)
- if err != nil {
- return nil, false, fmt.Errorf("proto: bad default uint32 %q: %v", prop.Default, err)
- }
- sf.value = uint32(x)
- case reflect.Uint64:
- x, err := strconv.ParseUint(prop.Default, 10, 64)
- if err != nil {
- return nil, false, fmt.Errorf("proto: bad default uint64 %q: %v", prop.Default, err)
- }
- sf.value = x
- default:
- return nil, false, fmt.Errorf("proto: unhandled def kind %v", ft.Elem().Kind())
- }
-
- return sf, false, nil
-}
-
-// mapKeys returns a sort.Interface to be used for sorting the map keys.
-// Map fields may have key types of non-float scalars, strings and enums.
-func mapKeys(vs []reflect.Value) sort.Interface {
- s := mapKeySorter{vs: vs}
-
- // Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps.
- if len(vs) == 0 {
- return s
- }
- switch vs[0].Kind() {
- case reflect.Int32, reflect.Int64:
- s.less = func(a, b reflect.Value) bool { return a.Int() < b.Int() }
- case reflect.Uint32, reflect.Uint64:
- s.less = func(a, b reflect.Value) bool { return a.Uint() < b.Uint() }
- case reflect.Bool:
- s.less = func(a, b reflect.Value) bool { return !a.Bool() && b.Bool() } // false < true
- case reflect.String:
- s.less = func(a, b reflect.Value) bool { return a.String() < b.String() }
- default:
- panic(fmt.Sprintf("unsupported map key type: %v", vs[0].Kind()))
- }
-
- return s
-}
-
-type mapKeySorter struct {
- vs []reflect.Value
- less func(a, b reflect.Value) bool
-}
-
-func (s mapKeySorter) Len() int { return len(s.vs) }
-func (s mapKeySorter) Swap(i, j int) { s.vs[i], s.vs[j] = s.vs[j], s.vs[i] }
-func (s mapKeySorter) Less(i, j int) bool {
- return s.less(s.vs[i], s.vs[j])
-}
-
-// isProto3Zero reports whether v is a zero proto3 value.
-func isProto3Zero(v reflect.Value) bool {
- switch v.Kind() {
- case reflect.Bool:
- return !v.Bool()
- case reflect.Int32, reflect.Int64:
- return v.Int() == 0
- case reflect.Uint32, reflect.Uint64:
- return v.Uint() == 0
- case reflect.Float32, reflect.Float64:
- return v.Float() == 0
- case reflect.String:
- return v.String() == ""
- }
- return false
-}
-
-// ProtoPackageIsVersion2 is referenced from generated protocol buffer files
-// to assert that that code is compatible with this version of the proto package.
-const ProtoPackageIsVersion2 = true
-
-// ProtoPackageIsVersion1 is referenced from generated protocol buffer files
-// to assert that that code is compatible with this version of the proto package.
-const ProtoPackageIsVersion1 = true
-
-// InternalMessageInfo is a type used internally by generated .pb.go files.
-// This type is not intended to be used by non-generated code.
-// This type is not subject to any compatibility guarantee.
-type InternalMessageInfo struct {
- marshal *marshalInfo
- unmarshal *unmarshalInfo
- merge *mergeInfo
- discard *discardInfo
-}
diff --git a/vendor/github.com/golang/protobuf/proto/message_set.go b/vendor/github.com/golang/protobuf/proto/message_set.go
deleted file mode 100644
index 3b6ca41..0000000
--- a/vendor/github.com/golang/protobuf/proto/message_set.go
+++ /dev/null
@@ -1,314 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2010 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-/*
- * Support for message sets.
- */
-
-import (
- "bytes"
- "encoding/json"
- "errors"
- "fmt"
- "reflect"
- "sort"
- "sync"
-)
-
-// errNoMessageTypeID occurs when a protocol buffer does not have a message type ID.
-// A message type ID is required for storing a protocol buffer in a message set.
-var errNoMessageTypeID = errors.New("proto does not have a message type ID")
-
-// The first two types (_MessageSet_Item and messageSet)
-// model what the protocol compiler produces for the following protocol message:
-// message MessageSet {
-// repeated group Item = 1 {
-// required int32 type_id = 2;
-// required string message = 3;
-// };
-// }
-// That is the MessageSet wire format. We can't use a proto to generate these
-// because that would introduce a circular dependency between it and this package.
-
-type _MessageSet_Item struct {
- TypeId *int32 `protobuf:"varint,2,req,name=type_id"`
- Message []byte `protobuf:"bytes,3,req,name=message"`
-}
-
-type messageSet struct {
- Item []*_MessageSet_Item `protobuf:"group,1,rep"`
- XXX_unrecognized []byte
- // TODO: caching?
-}
-
-// Make sure messageSet is a Message.
-var _ Message = (*messageSet)(nil)
-
-// messageTypeIder is an interface satisfied by a protocol buffer type
-// that may be stored in a MessageSet.
-type messageTypeIder interface {
- MessageTypeId() int32
-}
-
-func (ms *messageSet) find(pb Message) *_MessageSet_Item {
- mti, ok := pb.(messageTypeIder)
- if !ok {
- return nil
- }
- id := mti.MessageTypeId()
- for _, item := range ms.Item {
- if *item.TypeId == id {
- return item
- }
- }
- return nil
-}
-
-func (ms *messageSet) Has(pb Message) bool {
- return ms.find(pb) != nil
-}
-
-func (ms *messageSet) Unmarshal(pb Message) error {
- if item := ms.find(pb); item != nil {
- return Unmarshal(item.Message, pb)
- }
- if _, ok := pb.(messageTypeIder); !ok {
- return errNoMessageTypeID
- }
- return nil // TODO: return error instead?
-}
-
-func (ms *messageSet) Marshal(pb Message) error {
- msg, err := Marshal(pb)
- if err != nil {
- return err
- }
- if item := ms.find(pb); item != nil {
- // reuse existing item
- item.Message = msg
- return nil
- }
-
- mti, ok := pb.(messageTypeIder)
- if !ok {
- return errNoMessageTypeID
- }
-
- mtid := mti.MessageTypeId()
- ms.Item = append(ms.Item, &_MessageSet_Item{
- TypeId: &mtid,
- Message: msg,
- })
- return nil
-}
-
-func (ms *messageSet) Reset() { *ms = messageSet{} }
-func (ms *messageSet) String() string { return CompactTextString(ms) }
-func (*messageSet) ProtoMessage() {}
-
-// Support for the message_set_wire_format message option.
-
-func skipVarint(buf []byte) []byte {
- i := 0
- for ; buf[i]&0x80 != 0; i++ {
- }
- return buf[i+1:]
-}
-
-// MarshalMessageSet encodes the extension map represented by m in the message set wire format.
-// It is called by generated Marshal methods on protocol buffer messages with the message_set_wire_format option.
-func MarshalMessageSet(exts interface{}) ([]byte, error) {
- return marshalMessageSet(exts, false)
-}
-
-// marshaMessageSet implements above function, with the opt to turn on / off deterministic during Marshal.
-func marshalMessageSet(exts interface{}, deterministic bool) ([]byte, error) {
- switch exts := exts.(type) {
- case *XXX_InternalExtensions:
- var u marshalInfo
- siz := u.sizeMessageSet(exts)
- b := make([]byte, 0, siz)
- return u.appendMessageSet(b, exts, deterministic)
-
- case map[int32]Extension:
- // This is an old-style extension map.
- // Wrap it in a new-style XXX_InternalExtensions.
- ie := XXX_InternalExtensions{
- p: &struct {
- mu sync.Mutex
- extensionMap map[int32]Extension
- }{
- extensionMap: exts,
- },
- }
-
- var u marshalInfo
- siz := u.sizeMessageSet(&ie)
- b := make([]byte, 0, siz)
- return u.appendMessageSet(b, &ie, deterministic)
-
- default:
- return nil, errors.New("proto: not an extension map")
- }
-}
-
-// UnmarshalMessageSet decodes the extension map encoded in buf in the message set wire format.
-// It is called by Unmarshal methods on protocol buffer messages with the message_set_wire_format option.
-func UnmarshalMessageSet(buf []byte, exts interface{}) error {
- var m map[int32]Extension
- switch exts := exts.(type) {
- case *XXX_InternalExtensions:
- m = exts.extensionsWrite()
- case map[int32]Extension:
- m = exts
- default:
- return errors.New("proto: not an extension map")
- }
-
- ms := new(messageSet)
- if err := Unmarshal(buf, ms); err != nil {
- return err
- }
- for _, item := range ms.Item {
- id := *item.TypeId
- msg := item.Message
-
- // Restore wire type and field number varint, plus length varint.
- // Be careful to preserve duplicate items.
- b := EncodeVarint(uint64(id)<<3 | WireBytes)
- if ext, ok := m[id]; ok {
- // Existing data; rip off the tag and length varint
- // so we join the new data correctly.
- // We can assume that ext.enc is set because we are unmarshaling.
- o := ext.enc[len(b):] // skip wire type and field number
- _, n := DecodeVarint(o) // calculate length of length varint
- o = o[n:] // skip length varint
- msg = append(o, msg...) // join old data and new data
- }
- b = append(b, EncodeVarint(uint64(len(msg)))...)
- b = append(b, msg...)
-
- m[id] = Extension{enc: b}
- }
- return nil
-}
-
-// MarshalMessageSetJSON encodes the extension map represented by m in JSON format.
-// It is called by generated MarshalJSON methods on protocol buffer messages with the message_set_wire_format option.
-func MarshalMessageSetJSON(exts interface{}) ([]byte, error) {
- var m map[int32]Extension
- switch exts := exts.(type) {
- case *XXX_InternalExtensions:
- var mu sync.Locker
- m, mu = exts.extensionsRead()
- if m != nil {
- // Keep the extensions map locked until we're done marshaling to prevent
- // races between marshaling and unmarshaling the lazily-{en,de}coded
- // values.
- mu.Lock()
- defer mu.Unlock()
- }
- case map[int32]Extension:
- m = exts
- default:
- return nil, errors.New("proto: not an extension map")
- }
- var b bytes.Buffer
- b.WriteByte('{')
-
- // Process the map in key order for deterministic output.
- ids := make([]int32, 0, len(m))
- for id := range m {
- ids = append(ids, id)
- }
- sort.Sort(int32Slice(ids)) // int32Slice defined in text.go
-
- for i, id := range ids {
- ext := m[id]
- msd, ok := messageSetMap[id]
- if !ok {
- // Unknown type; we can't render it, so skip it.
- continue
- }
-
- if i > 0 && b.Len() > 1 {
- b.WriteByte(',')
- }
-
- fmt.Fprintf(&b, `"[%s]":`, msd.name)
-
- x := ext.value
- if x == nil {
- x = reflect.New(msd.t.Elem()).Interface()
- if err := Unmarshal(ext.enc, x.(Message)); err != nil {
- return nil, err
- }
- }
- d, err := json.Marshal(x)
- if err != nil {
- return nil, err
- }
- b.Write(d)
- }
- b.WriteByte('}')
- return b.Bytes(), nil
-}
-
-// UnmarshalMessageSetJSON decodes the extension map encoded in buf in JSON format.
-// It is called by generated UnmarshalJSON methods on protocol buffer messages with the message_set_wire_format option.
-func UnmarshalMessageSetJSON(buf []byte, exts interface{}) error {
- // Common-case fast path.
- if len(buf) == 0 || bytes.Equal(buf, []byte("{}")) {
- return nil
- }
-
- // This is fairly tricky, and it's not clear that it is needed.
- return errors.New("TODO: UnmarshalMessageSetJSON not yet implemented")
-}
-
-// A global registry of types that can be used in a MessageSet.
-
-var messageSetMap = make(map[int32]messageSetDesc)
-
-type messageSetDesc struct {
- t reflect.Type // pointer to struct
- name string
-}
-
-// RegisterMessageSetType is called from the generated code.
-func RegisterMessageSetType(m Message, fieldNum int32, name string) {
- messageSetMap[fieldNum] = messageSetDesc{
- t: reflect.TypeOf(m),
- name: name,
- }
-}
diff --git a/vendor/github.com/golang/protobuf/proto/pointer_reflect.go b/vendor/github.com/golang/protobuf/proto/pointer_reflect.go
deleted file mode 100644
index b6cad90..0000000
--- a/vendor/github.com/golang/protobuf/proto/pointer_reflect.go
+++ /dev/null
@@ -1,357 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2012 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// +build purego appengine js
-
-// This file contains an implementation of proto field accesses using package reflect.
-// It is slower than the code in pointer_unsafe.go but it avoids package unsafe and can
-// be used on App Engine.
-
-package proto
-
-import (
- "reflect"
- "sync"
-)
-
-const unsafeAllowed = false
-
-// A field identifies a field in a struct, accessible from a pointer.
-// In this implementation, a field is identified by the sequence of field indices
-// passed to reflect's FieldByIndex.
-type field []int
-
-// toField returns a field equivalent to the given reflect field.
-func toField(f *reflect.StructField) field {
- return f.Index
-}
-
-// invalidField is an invalid field identifier.
-var invalidField = field(nil)
-
-// zeroField is a noop when calling pointer.offset.
-var zeroField = field([]int{})
-
-// IsValid reports whether the field identifier is valid.
-func (f field) IsValid() bool { return f != nil }
-
-// The pointer type is for the table-driven decoder.
-// The implementation here uses a reflect.Value of pointer type to
-// create a generic pointer. In pointer_unsafe.go we use unsafe
-// instead of reflect to implement the same (but faster) interface.
-type pointer struct {
- v reflect.Value
-}
-
-// toPointer converts an interface of pointer type to a pointer
-// that points to the same target.
-func toPointer(i *Message) pointer {
- return pointer{v: reflect.ValueOf(*i)}
-}
-
-// toAddrPointer converts an interface to a pointer that points to
-// the interface data.
-func toAddrPointer(i *interface{}, isptr bool) pointer {
- v := reflect.ValueOf(*i)
- u := reflect.New(v.Type())
- u.Elem().Set(v)
- return pointer{v: u}
-}
-
-// valToPointer converts v to a pointer. v must be of pointer type.
-func valToPointer(v reflect.Value) pointer {
- return pointer{v: v}
-}
-
-// offset converts from a pointer to a structure to a pointer to
-// one of its fields.
-func (p pointer) offset(f field) pointer {
- return pointer{v: p.v.Elem().FieldByIndex(f).Addr()}
-}
-
-func (p pointer) isNil() bool {
- return p.v.IsNil()
-}
-
-// grow updates the slice s in place to make it one element longer.
-// s must be addressable.
-// Returns the (addressable) new element.
-func grow(s reflect.Value) reflect.Value {
- n, m := s.Len(), s.Cap()
- if n < m {
- s.SetLen(n + 1)
- } else {
- s.Set(reflect.Append(s, reflect.Zero(s.Type().Elem())))
- }
- return s.Index(n)
-}
-
-func (p pointer) toInt64() *int64 {
- return p.v.Interface().(*int64)
-}
-func (p pointer) toInt64Ptr() **int64 {
- return p.v.Interface().(**int64)
-}
-func (p pointer) toInt64Slice() *[]int64 {
- return p.v.Interface().(*[]int64)
-}
-
-var int32ptr = reflect.TypeOf((*int32)(nil))
-
-func (p pointer) toInt32() *int32 {
- return p.v.Convert(int32ptr).Interface().(*int32)
-}
-
-// The toInt32Ptr/Slice methods don't work because of enums.
-// Instead, we must use set/get methods for the int32ptr/slice case.
-/*
- func (p pointer) toInt32Ptr() **int32 {
- return p.v.Interface().(**int32)
-}
- func (p pointer) toInt32Slice() *[]int32 {
- return p.v.Interface().(*[]int32)
-}
-*/
-func (p pointer) getInt32Ptr() *int32 {
- if p.v.Type().Elem().Elem() == reflect.TypeOf(int32(0)) {
- // raw int32 type
- return p.v.Elem().Interface().(*int32)
- }
- // an enum
- return p.v.Elem().Convert(int32PtrType).Interface().(*int32)
-}
-func (p pointer) setInt32Ptr(v int32) {
- // Allocate value in a *int32. Possibly convert that to a *enum.
- // Then assign it to a **int32 or **enum.
- // Note: we can convert *int32 to *enum, but we can't convert
- // **int32 to **enum!
- p.v.Elem().Set(reflect.ValueOf(&v).Convert(p.v.Type().Elem()))
-}
-
-// getInt32Slice copies []int32 from p as a new slice.
-// This behavior differs from the implementation in pointer_unsafe.go.
-func (p pointer) getInt32Slice() []int32 {
- if p.v.Type().Elem().Elem() == reflect.TypeOf(int32(0)) {
- // raw int32 type
- return p.v.Elem().Interface().([]int32)
- }
- // an enum
- // Allocate a []int32, then assign []enum's values into it.
- // Note: we can't convert []enum to []int32.
- slice := p.v.Elem()
- s := make([]int32, slice.Len())
- for i := 0; i < slice.Len(); i++ {
- s[i] = int32(slice.Index(i).Int())
- }
- return s
-}
-
-// setInt32Slice copies []int32 into p as a new slice.
-// This behavior differs from the implementation in pointer_unsafe.go.
-func (p pointer) setInt32Slice(v []int32) {
- if p.v.Type().Elem().Elem() == reflect.TypeOf(int32(0)) {
- // raw int32 type
- p.v.Elem().Set(reflect.ValueOf(v))
- return
- }
- // an enum
- // Allocate a []enum, then assign []int32's values into it.
- // Note: we can't convert []enum to []int32.
- slice := reflect.MakeSlice(p.v.Type().Elem(), len(v), cap(v))
- for i, x := range v {
- slice.Index(i).SetInt(int64(x))
- }
- p.v.Elem().Set(slice)
-}
-func (p pointer) appendInt32Slice(v int32) {
- grow(p.v.Elem()).SetInt(int64(v))
-}
-
-func (p pointer) toUint64() *uint64 {
- return p.v.Interface().(*uint64)
-}
-func (p pointer) toUint64Ptr() **uint64 {
- return p.v.Interface().(**uint64)
-}
-func (p pointer) toUint64Slice() *[]uint64 {
- return p.v.Interface().(*[]uint64)
-}
-func (p pointer) toUint32() *uint32 {
- return p.v.Interface().(*uint32)
-}
-func (p pointer) toUint32Ptr() **uint32 {
- return p.v.Interface().(**uint32)
-}
-func (p pointer) toUint32Slice() *[]uint32 {
- return p.v.Interface().(*[]uint32)
-}
-func (p pointer) toBool() *bool {
- return p.v.Interface().(*bool)
-}
-func (p pointer) toBoolPtr() **bool {
- return p.v.Interface().(**bool)
-}
-func (p pointer) toBoolSlice() *[]bool {
- return p.v.Interface().(*[]bool)
-}
-func (p pointer) toFloat64() *float64 {
- return p.v.Interface().(*float64)
-}
-func (p pointer) toFloat64Ptr() **float64 {
- return p.v.Interface().(**float64)
-}
-func (p pointer) toFloat64Slice() *[]float64 {
- return p.v.Interface().(*[]float64)
-}
-func (p pointer) toFloat32() *float32 {
- return p.v.Interface().(*float32)
-}
-func (p pointer) toFloat32Ptr() **float32 {
- return p.v.Interface().(**float32)
-}
-func (p pointer) toFloat32Slice() *[]float32 {
- return p.v.Interface().(*[]float32)
-}
-func (p pointer) toString() *string {
- return p.v.Interface().(*string)
-}
-func (p pointer) toStringPtr() **string {
- return p.v.Interface().(**string)
-}
-func (p pointer) toStringSlice() *[]string {
- return p.v.Interface().(*[]string)
-}
-func (p pointer) toBytes() *[]byte {
- return p.v.Interface().(*[]byte)
-}
-func (p pointer) toBytesSlice() *[][]byte {
- return p.v.Interface().(*[][]byte)
-}
-func (p pointer) toExtensions() *XXX_InternalExtensions {
- return p.v.Interface().(*XXX_InternalExtensions)
-}
-func (p pointer) toOldExtensions() *map[int32]Extension {
- return p.v.Interface().(*map[int32]Extension)
-}
-func (p pointer) getPointer() pointer {
- return pointer{v: p.v.Elem()}
-}
-func (p pointer) setPointer(q pointer) {
- p.v.Elem().Set(q.v)
-}
-func (p pointer) appendPointer(q pointer) {
- grow(p.v.Elem()).Set(q.v)
-}
-
-// getPointerSlice copies []*T from p as a new []pointer.
-// This behavior differs from the implementation in pointer_unsafe.go.
-func (p pointer) getPointerSlice() []pointer {
- if p.v.IsNil() {
- return nil
- }
- n := p.v.Elem().Len()
- s := make([]pointer, n)
- for i := 0; i < n; i++ {
- s[i] = pointer{v: p.v.Elem().Index(i)}
- }
- return s
-}
-
-// setPointerSlice copies []pointer into p as a new []*T.
-// This behavior differs from the implementation in pointer_unsafe.go.
-func (p pointer) setPointerSlice(v []pointer) {
- if v == nil {
- p.v.Elem().Set(reflect.New(p.v.Elem().Type()).Elem())
- return
- }
- s := reflect.MakeSlice(p.v.Elem().Type(), 0, len(v))
- for _, p := range v {
- s = reflect.Append(s, p.v)
- }
- p.v.Elem().Set(s)
-}
-
-// getInterfacePointer returns a pointer that points to the
-// interface data of the interface pointed by p.
-func (p pointer) getInterfacePointer() pointer {
- if p.v.Elem().IsNil() {
- return pointer{v: p.v.Elem()}
- }
- return pointer{v: p.v.Elem().Elem().Elem().Field(0).Addr()} // *interface -> interface -> *struct -> struct
-}
-
-func (p pointer) asPointerTo(t reflect.Type) reflect.Value {
- // TODO: check that p.v.Type().Elem() == t?
- return p.v
-}
-
-func atomicLoadUnmarshalInfo(p **unmarshalInfo) *unmarshalInfo {
- atomicLock.Lock()
- defer atomicLock.Unlock()
- return *p
-}
-func atomicStoreUnmarshalInfo(p **unmarshalInfo, v *unmarshalInfo) {
- atomicLock.Lock()
- defer atomicLock.Unlock()
- *p = v
-}
-func atomicLoadMarshalInfo(p **marshalInfo) *marshalInfo {
- atomicLock.Lock()
- defer atomicLock.Unlock()
- return *p
-}
-func atomicStoreMarshalInfo(p **marshalInfo, v *marshalInfo) {
- atomicLock.Lock()
- defer atomicLock.Unlock()
- *p = v
-}
-func atomicLoadMergeInfo(p **mergeInfo) *mergeInfo {
- atomicLock.Lock()
- defer atomicLock.Unlock()
- return *p
-}
-func atomicStoreMergeInfo(p **mergeInfo, v *mergeInfo) {
- atomicLock.Lock()
- defer atomicLock.Unlock()
- *p = v
-}
-func atomicLoadDiscardInfo(p **discardInfo) *discardInfo {
- atomicLock.Lock()
- defer atomicLock.Unlock()
- return *p
-}
-func atomicStoreDiscardInfo(p **discardInfo, v *discardInfo) {
- atomicLock.Lock()
- defer atomicLock.Unlock()
- *p = v
-}
-
-var atomicLock sync.Mutex
diff --git a/vendor/github.com/golang/protobuf/proto/pointer_unsafe.go b/vendor/github.com/golang/protobuf/proto/pointer_unsafe.go
deleted file mode 100644
index d55a335..0000000
--- a/vendor/github.com/golang/protobuf/proto/pointer_unsafe.go
+++ /dev/null
@@ -1,308 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2012 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-// +build !purego,!appengine,!js
-
-// This file contains the implementation of the proto field accesses using package unsafe.
-
-package proto
-
-import (
- "reflect"
- "sync/atomic"
- "unsafe"
-)
-
-const unsafeAllowed = true
-
-// A field identifies a field in a struct, accessible from a pointer.
-// In this implementation, a field is identified by its byte offset from the start of the struct.
-type field uintptr
-
-// toField returns a field equivalent to the given reflect field.
-func toField(f *reflect.StructField) field {
- return field(f.Offset)
-}
-
-// invalidField is an invalid field identifier.
-const invalidField = ^field(0)
-
-// zeroField is a noop when calling pointer.offset.
-const zeroField = field(0)
-
-// IsValid reports whether the field identifier is valid.
-func (f field) IsValid() bool {
- return f != invalidField
-}
-
-// The pointer type below is for the new table-driven encoder/decoder.
-// The implementation here uses unsafe.Pointer to create a generic pointer.
-// In pointer_reflect.go we use reflect instead of unsafe to implement
-// the same (but slower) interface.
-type pointer struct {
- p unsafe.Pointer
-}
-
-// size of pointer
-var ptrSize = unsafe.Sizeof(uintptr(0))
-
-// toPointer converts an interface of pointer type to a pointer
-// that points to the same target.
-func toPointer(i *Message) pointer {
- // Super-tricky - read pointer out of data word of interface value.
- // Saves ~25ns over the equivalent:
- // return valToPointer(reflect.ValueOf(*i))
- return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
-}
-
-// toAddrPointer converts an interface to a pointer that points to
-// the interface data.
-func toAddrPointer(i *interface{}, isptr bool) pointer {
- // Super-tricky - read or get the address of data word of interface value.
- if isptr {
- // The interface is of pointer type, thus it is a direct interface.
- // The data word is the pointer data itself. We take its address.
- return pointer{p: unsafe.Pointer(uintptr(unsafe.Pointer(i)) + ptrSize)}
- }
- // The interface is not of pointer type. The data word is the pointer
- // to the data.
- return pointer{p: (*[2]unsafe.Pointer)(unsafe.Pointer(i))[1]}
-}
-
-// valToPointer converts v to a pointer. v must be of pointer type.
-func valToPointer(v reflect.Value) pointer {
- return pointer{p: unsafe.Pointer(v.Pointer())}
-}
-
-// offset converts from a pointer to a structure to a pointer to
-// one of its fields.
-func (p pointer) offset(f field) pointer {
- // For safety, we should panic if !f.IsValid, however calling panic causes
- // this to no longer be inlineable, which is a serious performance cost.
- /*
- if !f.IsValid() {
- panic("invalid field")
- }
- */
- return pointer{p: unsafe.Pointer(uintptr(p.p) + uintptr(f))}
-}
-
-func (p pointer) isNil() bool {
- return p.p == nil
-}
-
-func (p pointer) toInt64() *int64 {
- return (*int64)(p.p)
-}
-func (p pointer) toInt64Ptr() **int64 {
- return (**int64)(p.p)
-}
-func (p pointer) toInt64Slice() *[]int64 {
- return (*[]int64)(p.p)
-}
-func (p pointer) toInt32() *int32 {
- return (*int32)(p.p)
-}
-
-// See pointer_reflect.go for why toInt32Ptr/Slice doesn't exist.
-/*
- func (p pointer) toInt32Ptr() **int32 {
- return (**int32)(p.p)
- }
- func (p pointer) toInt32Slice() *[]int32 {
- return (*[]int32)(p.p)
- }
-*/
-func (p pointer) getInt32Ptr() *int32 {
- return *(**int32)(p.p)
-}
-func (p pointer) setInt32Ptr(v int32) {
- *(**int32)(p.p) = &v
-}
-
-// getInt32Slice loads a []int32 from p.
-// The value returned is aliased with the original slice.
-// This behavior differs from the implementation in pointer_reflect.go.
-func (p pointer) getInt32Slice() []int32 {
- return *(*[]int32)(p.p)
-}
-
-// setInt32Slice stores a []int32 to p.
-// The value set is aliased with the input slice.
-// This behavior differs from the implementation in pointer_reflect.go.
-func (p pointer) setInt32Slice(v []int32) {
- *(*[]int32)(p.p) = v
-}
-
-// TODO: Can we get rid of appendInt32Slice and use setInt32Slice instead?
-func (p pointer) appendInt32Slice(v int32) {
- s := (*[]int32)(p.p)
- *s = append(*s, v)
-}
-
-func (p pointer) toUint64() *uint64 {
- return (*uint64)(p.p)
-}
-func (p pointer) toUint64Ptr() **uint64 {
- return (**uint64)(p.p)
-}
-func (p pointer) toUint64Slice() *[]uint64 {
- return (*[]uint64)(p.p)
-}
-func (p pointer) toUint32() *uint32 {
- return (*uint32)(p.p)
-}
-func (p pointer) toUint32Ptr() **uint32 {
- return (**uint32)(p.p)
-}
-func (p pointer) toUint32Slice() *[]uint32 {
- return (*[]uint32)(p.p)
-}
-func (p pointer) toBool() *bool {
- return (*bool)(p.p)
-}
-func (p pointer) toBoolPtr() **bool {
- return (**bool)(p.p)
-}
-func (p pointer) toBoolSlice() *[]bool {
- return (*[]bool)(p.p)
-}
-func (p pointer) toFloat64() *float64 {
- return (*float64)(p.p)
-}
-func (p pointer) toFloat64Ptr() **float64 {
- return (**float64)(p.p)
-}
-func (p pointer) toFloat64Slice() *[]float64 {
- return (*[]float64)(p.p)
-}
-func (p pointer) toFloat32() *float32 {
- return (*float32)(p.p)
-}
-func (p pointer) toFloat32Ptr() **float32 {
- return (**float32)(p.p)
-}
-func (p pointer) toFloat32Slice() *[]float32 {
- return (*[]float32)(p.p)
-}
-func (p pointer) toString() *string {
- return (*string)(p.p)
-}
-func (p pointer) toStringPtr() **string {
- return (**string)(p.p)
-}
-func (p pointer) toStringSlice() *[]string {
- return (*[]string)(p.p)
-}
-func (p pointer) toBytes() *[]byte {
- return (*[]byte)(p.p)
-}
-func (p pointer) toBytesSlice() *[][]byte {
- return (*[][]byte)(p.p)
-}
-func (p pointer) toExtensions() *XXX_InternalExtensions {
- return (*XXX_InternalExtensions)(p.p)
-}
-func (p pointer) toOldExtensions() *map[int32]Extension {
- return (*map[int32]Extension)(p.p)
-}
-
-// getPointerSlice loads []*T from p as a []pointer.
-// The value returned is aliased with the original slice.
-// This behavior differs from the implementation in pointer_reflect.go.
-func (p pointer) getPointerSlice() []pointer {
- // Super-tricky - p should point to a []*T where T is a
- // message type. We load it as []pointer.
- return *(*[]pointer)(p.p)
-}
-
-// setPointerSlice stores []pointer into p as a []*T.
-// The value set is aliased with the input slice.
-// This behavior differs from the implementation in pointer_reflect.go.
-func (p pointer) setPointerSlice(v []pointer) {
- // Super-tricky - p should point to a []*T where T is a
- // message type. We store it as []pointer.
- *(*[]pointer)(p.p) = v
-}
-
-// getPointer loads the pointer at p and returns it.
-func (p pointer) getPointer() pointer {
- return pointer{p: *(*unsafe.Pointer)(p.p)}
-}
-
-// setPointer stores the pointer q at p.
-func (p pointer) setPointer(q pointer) {
- *(*unsafe.Pointer)(p.p) = q.p
-}
-
-// append q to the slice pointed to by p.
-func (p pointer) appendPointer(q pointer) {
- s := (*[]unsafe.Pointer)(p.p)
- *s = append(*s, q.p)
-}
-
-// getInterfacePointer returns a pointer that points to the
-// interface data of the interface pointed by p.
-func (p pointer) getInterfacePointer() pointer {
- // Super-tricky - read pointer out of data word of interface value.
- return pointer{p: (*(*[2]unsafe.Pointer)(p.p))[1]}
-}
-
-// asPointerTo returns a reflect.Value that is a pointer to an
-// object of type t stored at p.
-func (p pointer) asPointerTo(t reflect.Type) reflect.Value {
- return reflect.NewAt(t, p.p)
-}
-
-func atomicLoadUnmarshalInfo(p **unmarshalInfo) *unmarshalInfo {
- return (*unmarshalInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
-}
-func atomicStoreUnmarshalInfo(p **unmarshalInfo, v *unmarshalInfo) {
- atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
-}
-func atomicLoadMarshalInfo(p **marshalInfo) *marshalInfo {
- return (*marshalInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
-}
-func atomicStoreMarshalInfo(p **marshalInfo, v *marshalInfo) {
- atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
-}
-func atomicLoadMergeInfo(p **mergeInfo) *mergeInfo {
- return (*mergeInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
-}
-func atomicStoreMergeInfo(p **mergeInfo, v *mergeInfo) {
- atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
-}
-func atomicLoadDiscardInfo(p **discardInfo) *discardInfo {
- return (*discardInfo)(atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(p))))
-}
-func atomicStoreDiscardInfo(p **discardInfo, v *discardInfo) {
- atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(p)), unsafe.Pointer(v))
-}
diff --git a/vendor/github.com/golang/protobuf/proto/properties.go b/vendor/github.com/golang/protobuf/proto/properties.go
deleted file mode 100644
index 50b99b8..0000000
--- a/vendor/github.com/golang/protobuf/proto/properties.go
+++ /dev/null
@@ -1,544 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2010 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-/*
- * Routines for encoding data into the wire format for protocol buffers.
- */
-
-import (
- "fmt"
- "log"
- "os"
- "reflect"
- "sort"
- "strconv"
- "strings"
- "sync"
-)
-
-const debug bool = false
-
-// Constants that identify the encoding of a value on the wire.
-const (
- WireVarint = 0
- WireFixed64 = 1
- WireBytes = 2
- WireStartGroup = 3
- WireEndGroup = 4
- WireFixed32 = 5
-)
-
-// tagMap is an optimization over map[int]int for typical protocol buffer
-// use-cases. Encoded protocol buffers are often in tag order with small tag
-// numbers.
-type tagMap struct {
- fastTags []int
- slowTags map[int]int
-}
-
-// tagMapFastLimit is the upper bound on the tag number that will be stored in
-// the tagMap slice rather than its map.
-const tagMapFastLimit = 1024
-
-func (p *tagMap) get(t int) (int, bool) {
- if t > 0 && t < tagMapFastLimit {
- if t >= len(p.fastTags) {
- return 0, false
- }
- fi := p.fastTags[t]
- return fi, fi >= 0
- }
- fi, ok := p.slowTags[t]
- return fi, ok
-}
-
-func (p *tagMap) put(t int, fi int) {
- if t > 0 && t < tagMapFastLimit {
- for len(p.fastTags) < t+1 {
- p.fastTags = append(p.fastTags, -1)
- }
- p.fastTags[t] = fi
- return
- }
- if p.slowTags == nil {
- p.slowTags = make(map[int]int)
- }
- p.slowTags[t] = fi
-}
-
-// StructProperties represents properties for all the fields of a struct.
-// decoderTags and decoderOrigNames should only be used by the decoder.
-type StructProperties struct {
- Prop []*Properties // properties for each field
- reqCount int // required count
- decoderTags tagMap // map from proto tag to struct field number
- decoderOrigNames map[string]int // map from original name to struct field number
- order []int // list of struct field numbers in tag order
-
- // OneofTypes contains information about the oneof fields in this message.
- // It is keyed by the original name of a field.
- OneofTypes map[string]*OneofProperties
-}
-
-// OneofProperties represents information about a specific field in a oneof.
-type OneofProperties struct {
- Type reflect.Type // pointer to generated struct type for this oneof field
- Field int // struct field number of the containing oneof in the message
- Prop *Properties
-}
-
-// Implement the sorting interface so we can sort the fields in tag order, as recommended by the spec.
-// See encode.go, (*Buffer).enc_struct.
-
-func (sp *StructProperties) Len() int { return len(sp.order) }
-func (sp *StructProperties) Less(i, j int) bool {
- return sp.Prop[sp.order[i]].Tag < sp.Prop[sp.order[j]].Tag
-}
-func (sp *StructProperties) Swap(i, j int) { sp.order[i], sp.order[j] = sp.order[j], sp.order[i] }
-
-// Properties represents the protocol-specific behavior of a single struct field.
-type Properties struct {
- Name string // name of the field, for error messages
- OrigName string // original name before protocol compiler (always set)
- JSONName string // name to use for JSON; determined by protoc
- Wire string
- WireType int
- Tag int
- Required bool
- Optional bool
- Repeated bool
- Packed bool // relevant for repeated primitives only
- Enum string // set for enum types only
- proto3 bool // whether this is known to be a proto3 field
- oneof bool // whether this is a oneof field
-
- Default string // default value
- HasDefault bool // whether an explicit default was provided
-
- stype reflect.Type // set for struct types only
- sprop *StructProperties // set for struct types only
-
- mtype reflect.Type // set for map types only
- MapKeyProp *Properties // set for map types only
- MapValProp *Properties // set for map types only
-}
-
-// String formats the properties in the protobuf struct field tag style.
-func (p *Properties) String() string {
- s := p.Wire
- s += ","
- s += strconv.Itoa(p.Tag)
- if p.Required {
- s += ",req"
- }
- if p.Optional {
- s += ",opt"
- }
- if p.Repeated {
- s += ",rep"
- }
- if p.Packed {
- s += ",packed"
- }
- s += ",name=" + p.OrigName
- if p.JSONName != p.OrigName {
- s += ",json=" + p.JSONName
- }
- if p.proto3 {
- s += ",proto3"
- }
- if p.oneof {
- s += ",oneof"
- }
- if len(p.Enum) > 0 {
- s += ",enum=" + p.Enum
- }
- if p.HasDefault {
- s += ",def=" + p.Default
- }
- return s
-}
-
-// Parse populates p by parsing a string in the protobuf struct field tag style.
-func (p *Properties) Parse(s string) {
- // "bytes,49,opt,name=foo,def=hello!"
- fields := strings.Split(s, ",") // breaks def=, but handled below.
- if len(fields) < 2 {
- fmt.Fprintf(os.Stderr, "proto: tag has too few fields: %q\n", s)
- return
- }
-
- p.Wire = fields[0]
- switch p.Wire {
- case "varint":
- p.WireType = WireVarint
- case "fixed32":
- p.WireType = WireFixed32
- case "fixed64":
- p.WireType = WireFixed64
- case "zigzag32":
- p.WireType = WireVarint
- case "zigzag64":
- p.WireType = WireVarint
- case "bytes", "group":
- p.WireType = WireBytes
- // no numeric converter for non-numeric types
- default:
- fmt.Fprintf(os.Stderr, "proto: tag has unknown wire type: %q\n", s)
- return
- }
-
- var err error
- p.Tag, err = strconv.Atoi(fields[1])
- if err != nil {
- return
- }
-
-outer:
- for i := 2; i < len(fields); i++ {
- f := fields[i]
- switch {
- case f == "req":
- p.Required = true
- case f == "opt":
- p.Optional = true
- case f == "rep":
- p.Repeated = true
- case f == "packed":
- p.Packed = true
- case strings.HasPrefix(f, "name="):
- p.OrigName = f[5:]
- case strings.HasPrefix(f, "json="):
- p.JSONName = f[5:]
- case strings.HasPrefix(f, "enum="):
- p.Enum = f[5:]
- case f == "proto3":
- p.proto3 = true
- case f == "oneof":
- p.oneof = true
- case strings.HasPrefix(f, "def="):
- p.HasDefault = true
- p.Default = f[4:] // rest of string
- if i+1 < len(fields) {
- // Commas aren't escaped, and def is always last.
- p.Default += "," + strings.Join(fields[i+1:], ",")
- break outer
- }
- }
- }
-}
-
-var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem()
-
-// setFieldProps initializes the field properties for submessages and maps.
-func (p *Properties) setFieldProps(typ reflect.Type, f *reflect.StructField, lockGetProp bool) {
- switch t1 := typ; t1.Kind() {
- case reflect.Ptr:
- if t1.Elem().Kind() == reflect.Struct {
- p.stype = t1.Elem()
- }
-
- case reflect.Slice:
- if t2 := t1.Elem(); t2.Kind() == reflect.Ptr && t2.Elem().Kind() == reflect.Struct {
- p.stype = t2.Elem()
- }
-
- case reflect.Map:
- p.mtype = t1
- p.MapKeyProp = &Properties{}
- p.MapKeyProp.init(reflect.PtrTo(p.mtype.Key()), "Key", f.Tag.Get("protobuf_key"), nil, lockGetProp)
- p.MapValProp = &Properties{}
- vtype := p.mtype.Elem()
- if vtype.Kind() != reflect.Ptr && vtype.Kind() != reflect.Slice {
- // The value type is not a message (*T) or bytes ([]byte),
- // so we need encoders for the pointer to this type.
- vtype = reflect.PtrTo(vtype)
- }
- p.MapValProp.init(vtype, "Value", f.Tag.Get("protobuf_val"), nil, lockGetProp)
- }
-
- if p.stype != nil {
- if lockGetProp {
- p.sprop = GetProperties(p.stype)
- } else {
- p.sprop = getPropertiesLocked(p.stype)
- }
- }
-}
-
-var (
- marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
-)
-
-// Init populates the properties from a protocol buffer struct tag.
-func (p *Properties) Init(typ reflect.Type, name, tag string, f *reflect.StructField) {
- p.init(typ, name, tag, f, true)
-}
-
-func (p *Properties) init(typ reflect.Type, name, tag string, f *reflect.StructField, lockGetProp bool) {
- // "bytes,49,opt,def=hello!"
- p.Name = name
- p.OrigName = name
- if tag == "" {
- return
- }
- p.Parse(tag)
- p.setFieldProps(typ, f, lockGetProp)
-}
-
-var (
- propertiesMu sync.RWMutex
- propertiesMap = make(map[reflect.Type]*StructProperties)
-)
-
-// GetProperties returns the list of properties for the type represented by t.
-// t must represent a generated struct type of a protocol message.
-func GetProperties(t reflect.Type) *StructProperties {
- if t.Kind() != reflect.Struct {
- panic("proto: type must have kind struct")
- }
-
- // Most calls to GetProperties in a long-running program will be
- // retrieving details for types we have seen before.
- propertiesMu.RLock()
- sprop, ok := propertiesMap[t]
- propertiesMu.RUnlock()
- if ok {
- if collectStats {
- stats.Chit++
- }
- return sprop
- }
-
- propertiesMu.Lock()
- sprop = getPropertiesLocked(t)
- propertiesMu.Unlock()
- return sprop
-}
-
-// getPropertiesLocked requires that propertiesMu is held.
-func getPropertiesLocked(t reflect.Type) *StructProperties {
- if prop, ok := propertiesMap[t]; ok {
- if collectStats {
- stats.Chit++
- }
- return prop
- }
- if collectStats {
- stats.Cmiss++
- }
-
- prop := new(StructProperties)
- // in case of recursive protos, fill this in now.
- propertiesMap[t] = prop
-
- // build properties
- prop.Prop = make([]*Properties, t.NumField())
- prop.order = make([]int, t.NumField())
-
- for i := 0; i < t.NumField(); i++ {
- f := t.Field(i)
- p := new(Properties)
- name := f.Name
- p.init(f.Type, name, f.Tag.Get("protobuf"), &f, false)
-
- oneof := f.Tag.Get("protobuf_oneof") // special case
- if oneof != "" {
- // Oneof fields don't use the traditional protobuf tag.
- p.OrigName = oneof
- }
- prop.Prop[i] = p
- prop.order[i] = i
- if debug {
- print(i, " ", f.Name, " ", t.String(), " ")
- if p.Tag > 0 {
- print(p.String())
- }
- print("\n")
- }
- }
-
- // Re-order prop.order.
- sort.Sort(prop)
-
- type oneofMessage interface {
- XXX_OneofFuncs() (func(Message, *Buffer) error, func(Message, int, int, *Buffer) (bool, error), func(Message) int, []interface{})
- }
- if om, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(oneofMessage); ok {
- var oots []interface{}
- _, _, _, oots = om.XXX_OneofFuncs()
-
- // Interpret oneof metadata.
- prop.OneofTypes = make(map[string]*OneofProperties)
- for _, oot := range oots {
- oop := &OneofProperties{
- Type: reflect.ValueOf(oot).Type(), // *T
- Prop: new(Properties),
- }
- sft := oop.Type.Elem().Field(0)
- oop.Prop.Name = sft.Name
- oop.Prop.Parse(sft.Tag.Get("protobuf"))
- // There will be exactly one interface field that
- // this new value is assignable to.
- for i := 0; i < t.NumField(); i++ {
- f := t.Field(i)
- if f.Type.Kind() != reflect.Interface {
- continue
- }
- if !oop.Type.AssignableTo(f.Type) {
- continue
- }
- oop.Field = i
- break
- }
- prop.OneofTypes[oop.Prop.OrigName] = oop
- }
- }
-
- // build required counts
- // build tags
- reqCount := 0
- prop.decoderOrigNames = make(map[string]int)
- for i, p := range prop.Prop {
- if strings.HasPrefix(p.Name, "XXX_") {
- // Internal fields should not appear in tags/origNames maps.
- // They are handled specially when encoding and decoding.
- continue
- }
- if p.Required {
- reqCount++
- }
- prop.decoderTags.put(p.Tag, i)
- prop.decoderOrigNames[p.OrigName] = i
- }
- prop.reqCount = reqCount
-
- return prop
-}
-
-// A global registry of enum types.
-// The generated code will register the generated maps by calling RegisterEnum.
-
-var enumValueMaps = make(map[string]map[string]int32)
-
-// RegisterEnum is called from the generated code to install the enum descriptor
-// maps into the global table to aid parsing text format protocol buffers.
-func RegisterEnum(typeName string, unusedNameMap map[int32]string, valueMap map[string]int32) {
- if _, ok := enumValueMaps[typeName]; ok {
- panic("proto: duplicate enum registered: " + typeName)
- }
- enumValueMaps[typeName] = valueMap
-}
-
-// EnumValueMap returns the mapping from names to integers of the
-// enum type enumType, or a nil if not found.
-func EnumValueMap(enumType string) map[string]int32 {
- return enumValueMaps[enumType]
-}
-
-// A registry of all linked message types.
-// The string is a fully-qualified proto name ("pkg.Message").
-var (
- protoTypedNils = make(map[string]Message) // a map from proto names to typed nil pointers
- protoMapTypes = make(map[string]reflect.Type) // a map from proto names to map types
- revProtoTypes = make(map[reflect.Type]string)
-)
-
-// RegisterType is called from generated code and maps from the fully qualified
-// proto name to the type (pointer to struct) of the protocol buffer.
-func RegisterType(x Message, name string) {
- if _, ok := protoTypedNils[name]; ok {
- // TODO: Some day, make this a panic.
- log.Printf("proto: duplicate proto type registered: %s", name)
- return
- }
- t := reflect.TypeOf(x)
- if v := reflect.ValueOf(x); v.Kind() == reflect.Ptr && v.Pointer() == 0 {
- // Generated code always calls RegisterType with nil x.
- // This check is just for extra safety.
- protoTypedNils[name] = x
- } else {
- protoTypedNils[name] = reflect.Zero(t).Interface().(Message)
- }
- revProtoTypes[t] = name
-}
-
-// RegisterMapType is called from generated code and maps from the fully qualified
-// proto name to the native map type of the proto map definition.
-func RegisterMapType(x interface{}, name string) {
- if reflect.TypeOf(x).Kind() != reflect.Map {
- panic(fmt.Sprintf("RegisterMapType(%T, %q); want map", x, name))
- }
- if _, ok := protoMapTypes[name]; ok {
- log.Printf("proto: duplicate proto type registered: %s", name)
- return
- }
- t := reflect.TypeOf(x)
- protoMapTypes[name] = t
- revProtoTypes[t] = name
-}
-
-// MessageName returns the fully-qualified proto name for the given message type.
-func MessageName(x Message) string {
- type xname interface {
- XXX_MessageName() string
- }
- if m, ok := x.(xname); ok {
- return m.XXX_MessageName()
- }
- return revProtoTypes[reflect.TypeOf(x)]
-}
-
-// MessageType returns the message type (pointer to struct) for a named message.
-// The type is not guaranteed to implement proto.Message if the name refers to a
-// map entry.
-func MessageType(name string) reflect.Type {
- if t, ok := protoTypedNils[name]; ok {
- return reflect.TypeOf(t)
- }
- return protoMapTypes[name]
-}
-
-// A registry of all linked proto files.
-var (
- protoFiles = make(map[string][]byte) // file name => fileDescriptor
-)
-
-// RegisterFile is called from generated code and maps from the
-// full file name of a .proto file to its compressed FileDescriptorProto.
-func RegisterFile(filename string, fileDescriptor []byte) {
- protoFiles[filename] = fileDescriptor
-}
-
-// FileDescriptor returns the compressed FileDescriptorProto for a .proto file.
-func FileDescriptor(filename string) []byte { return protoFiles[filename] }
diff --git a/vendor/github.com/golang/protobuf/proto/table_marshal.go b/vendor/github.com/golang/protobuf/proto/table_marshal.go
deleted file mode 100644
index b167944..0000000
--- a/vendor/github.com/golang/protobuf/proto/table_marshal.go
+++ /dev/null
@@ -1,2767 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2016 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-import (
- "errors"
- "fmt"
- "math"
- "reflect"
- "sort"
- "strconv"
- "strings"
- "sync"
- "sync/atomic"
- "unicode/utf8"
-)
-
-// a sizer takes a pointer to a field and the size of its tag, computes the size of
-// the encoded data.
-type sizer func(pointer, int) int
-
-// a marshaler takes a byte slice, a pointer to a field, and its tag (in wire format),
-// marshals the field to the end of the slice, returns the slice and error (if any).
-type marshaler func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error)
-
-// marshalInfo is the information used for marshaling a message.
-type marshalInfo struct {
- typ reflect.Type
- fields []*marshalFieldInfo
- unrecognized field // offset of XXX_unrecognized
- extensions field // offset of XXX_InternalExtensions
- v1extensions field // offset of XXX_extensions
- sizecache field // offset of XXX_sizecache
- initialized int32 // 0 -- only typ is set, 1 -- fully initialized
- messageset bool // uses message set wire format
- hasmarshaler bool // has custom marshaler
- sync.RWMutex // protect extElems map, also for initialization
- extElems map[int32]*marshalElemInfo // info of extension elements
-}
-
-// marshalFieldInfo is the information used for marshaling a field of a message.
-type marshalFieldInfo struct {
- field field
- wiretag uint64 // tag in wire format
- tagsize int // size of tag in wire format
- sizer sizer
- marshaler marshaler
- isPointer bool
- required bool // field is required
- name string // name of the field, for error reporting
- oneofElems map[reflect.Type]*marshalElemInfo // info of oneof elements
-}
-
-// marshalElemInfo is the information used for marshaling an extension or oneof element.
-type marshalElemInfo struct {
- wiretag uint64 // tag in wire format
- tagsize int // size of tag in wire format
- sizer sizer
- marshaler marshaler
- isptr bool // elem is pointer typed, thus interface of this type is a direct interface (extension only)
-}
-
-var (
- marshalInfoMap = map[reflect.Type]*marshalInfo{}
- marshalInfoLock sync.Mutex
-)
-
-// getMarshalInfo returns the information to marshal a given type of message.
-// The info it returns may not necessarily initialized.
-// t is the type of the message (NOT the pointer to it).
-func getMarshalInfo(t reflect.Type) *marshalInfo {
- marshalInfoLock.Lock()
- u, ok := marshalInfoMap[t]
- if !ok {
- u = &marshalInfo{typ: t}
- marshalInfoMap[t] = u
- }
- marshalInfoLock.Unlock()
- return u
-}
-
-// Size is the entry point from generated code,
-// and should be ONLY called by generated code.
-// It computes the size of encoded data of msg.
-// a is a pointer to a place to store cached marshal info.
-func (a *InternalMessageInfo) Size(msg Message) int {
- u := getMessageMarshalInfo(msg, a)
- ptr := toPointer(&msg)
- if ptr.isNil() {
- // We get here if msg is a typed nil ((*SomeMessage)(nil)),
- // so it satisfies the interface, and msg == nil wouldn't
- // catch it. We don't want crash in this case.
- return 0
- }
- return u.size(ptr)
-}
-
-// Marshal is the entry point from generated code,
-// and should be ONLY called by generated code.
-// It marshals msg to the end of b.
-// a is a pointer to a place to store cached marshal info.
-func (a *InternalMessageInfo) Marshal(b []byte, msg Message, deterministic bool) ([]byte, error) {
- u := getMessageMarshalInfo(msg, a)
- ptr := toPointer(&msg)
- if ptr.isNil() {
- // We get here if msg is a typed nil ((*SomeMessage)(nil)),
- // so it satisfies the interface, and msg == nil wouldn't
- // catch it. We don't want crash in this case.
- return b, ErrNil
- }
- return u.marshal(b, ptr, deterministic)
-}
-
-func getMessageMarshalInfo(msg interface{}, a *InternalMessageInfo) *marshalInfo {
- // u := a.marshal, but atomically.
- // We use an atomic here to ensure memory consistency.
- u := atomicLoadMarshalInfo(&a.marshal)
- if u == nil {
- // Get marshal information from type of message.
- t := reflect.ValueOf(msg).Type()
- if t.Kind() != reflect.Ptr {
- panic(fmt.Sprintf("cannot handle non-pointer message type %v", t))
- }
- u = getMarshalInfo(t.Elem())
- // Store it in the cache for later users.
- // a.marshal = u, but atomically.
- atomicStoreMarshalInfo(&a.marshal, u)
- }
- return u
-}
-
-// size is the main function to compute the size of the encoded data of a message.
-// ptr is the pointer to the message.
-func (u *marshalInfo) size(ptr pointer) int {
- if atomic.LoadInt32(&u.initialized) == 0 {
- u.computeMarshalInfo()
- }
-
- // If the message can marshal itself, let it do it, for compatibility.
- // NOTE: This is not efficient.
- if u.hasmarshaler {
- m := ptr.asPointerTo(u.typ).Interface().(Marshaler)
- b, _ := m.Marshal()
- return len(b)
- }
-
- n := 0
- for _, f := range u.fields {
- if f.isPointer && ptr.offset(f.field).getPointer().isNil() {
- // nil pointer always marshals to nothing
- continue
- }
- n += f.sizer(ptr.offset(f.field), f.tagsize)
- }
- if u.extensions.IsValid() {
- e := ptr.offset(u.extensions).toExtensions()
- if u.messageset {
- n += u.sizeMessageSet(e)
- } else {
- n += u.sizeExtensions(e)
- }
- }
- if u.v1extensions.IsValid() {
- m := *ptr.offset(u.v1extensions).toOldExtensions()
- n += u.sizeV1Extensions(m)
- }
- if u.unrecognized.IsValid() {
- s := *ptr.offset(u.unrecognized).toBytes()
- n += len(s)
- }
- // cache the result for use in marshal
- if u.sizecache.IsValid() {
- atomic.StoreInt32(ptr.offset(u.sizecache).toInt32(), int32(n))
- }
- return n
-}
-
-// cachedsize gets the size from cache. If there is no cache (i.e. message is not generated),
-// fall back to compute the size.
-func (u *marshalInfo) cachedsize(ptr pointer) int {
- if u.sizecache.IsValid() {
- return int(atomic.LoadInt32(ptr.offset(u.sizecache).toInt32()))
- }
- return u.size(ptr)
-}
-
-// marshal is the main function to marshal a message. It takes a byte slice and appends
-// the encoded data to the end of the slice, returns the slice and error (if any).
-// ptr is the pointer to the message.
-// If deterministic is true, map is marshaled in deterministic order.
-func (u *marshalInfo) marshal(b []byte, ptr pointer, deterministic bool) ([]byte, error) {
- if atomic.LoadInt32(&u.initialized) == 0 {
- u.computeMarshalInfo()
- }
-
- // If the message can marshal itself, let it do it, for compatibility.
- // NOTE: This is not efficient.
- if u.hasmarshaler {
- m := ptr.asPointerTo(u.typ).Interface().(Marshaler)
- b1, err := m.Marshal()
- b = append(b, b1...)
- return b, err
- }
-
- var err, errLater error
- // The old marshaler encodes extensions at beginning.
- if u.extensions.IsValid() {
- e := ptr.offset(u.extensions).toExtensions()
- if u.messageset {
- b, err = u.appendMessageSet(b, e, deterministic)
- } else {
- b, err = u.appendExtensions(b, e, deterministic)
- }
- if err != nil {
- return b, err
- }
- }
- if u.v1extensions.IsValid() {
- m := *ptr.offset(u.v1extensions).toOldExtensions()
- b, err = u.appendV1Extensions(b, m, deterministic)
- if err != nil {
- return b, err
- }
- }
- for _, f := range u.fields {
- if f.required {
- if ptr.offset(f.field).getPointer().isNil() {
- // Required field is not set.
- // We record the error but keep going, to give a complete marshaling.
- if errLater == nil {
- errLater = &RequiredNotSetError{f.name}
- }
- continue
- }
- }
- if f.isPointer && ptr.offset(f.field).getPointer().isNil() {
- // nil pointer always marshals to nothing
- continue
- }
- b, err = f.marshaler(b, ptr.offset(f.field), f.wiretag, deterministic)
- if err != nil {
- if err1, ok := err.(*RequiredNotSetError); ok {
- // Required field in submessage is not set.
- // We record the error but keep going, to give a complete marshaling.
- if errLater == nil {
- errLater = &RequiredNotSetError{f.name + "." + err1.field}
- }
- continue
- }
- if err == errRepeatedHasNil {
- err = errors.New("proto: repeated field " + f.name + " has nil element")
- }
- if err == errInvalidUTF8 {
- if errLater == nil {
- fullName := revProtoTypes[reflect.PtrTo(u.typ)] + "." + f.name
- errLater = &invalidUTF8Error{fullName}
- }
- continue
- }
- return b, err
- }
- }
- if u.unrecognized.IsValid() {
- s := *ptr.offset(u.unrecognized).toBytes()
- b = append(b, s...)
- }
- return b, errLater
-}
-
-// computeMarshalInfo initializes the marshal info.
-func (u *marshalInfo) computeMarshalInfo() {
- u.Lock()
- defer u.Unlock()
- if u.initialized != 0 { // non-atomic read is ok as it is protected by the lock
- return
- }
-
- t := u.typ
- u.unrecognized = invalidField
- u.extensions = invalidField
- u.v1extensions = invalidField
- u.sizecache = invalidField
-
- // If the message can marshal itself, let it do it, for compatibility.
- // NOTE: This is not efficient.
- if reflect.PtrTo(t).Implements(marshalerType) {
- u.hasmarshaler = true
- atomic.StoreInt32(&u.initialized, 1)
- return
- }
-
- // get oneof implementers
- var oneofImplementers []interface{}
- if m, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(oneofMessage); ok {
- _, _, _, oneofImplementers = m.XXX_OneofFuncs()
- }
-
- n := t.NumField()
-
- // deal with XXX fields first
- for i := 0; i < t.NumField(); i++ {
- f := t.Field(i)
- if !strings.HasPrefix(f.Name, "XXX_") {
- continue
- }
- switch f.Name {
- case "XXX_sizecache":
- u.sizecache = toField(&f)
- case "XXX_unrecognized":
- u.unrecognized = toField(&f)
- case "XXX_InternalExtensions":
- u.extensions = toField(&f)
- u.messageset = f.Tag.Get("protobuf_messageset") == "1"
- case "XXX_extensions":
- u.v1extensions = toField(&f)
- case "XXX_NoUnkeyedLiteral":
- // nothing to do
- default:
- panic("unknown XXX field: " + f.Name)
- }
- n--
- }
-
- // normal fields
- fields := make([]marshalFieldInfo, n) // batch allocation
- u.fields = make([]*marshalFieldInfo, 0, n)
- for i, j := 0, 0; i < t.NumField(); i++ {
- f := t.Field(i)
-
- if strings.HasPrefix(f.Name, "XXX_") {
- continue
- }
- field := &fields[j]
- j++
- field.name = f.Name
- u.fields = append(u.fields, field)
- if f.Tag.Get("protobuf_oneof") != "" {
- field.computeOneofFieldInfo(&f, oneofImplementers)
- continue
- }
- if f.Tag.Get("protobuf") == "" {
- // field has no tag (not in generated message), ignore it
- u.fields = u.fields[:len(u.fields)-1]
- j--
- continue
- }
- field.computeMarshalFieldInfo(&f)
- }
-
- // fields are marshaled in tag order on the wire.
- sort.Sort(byTag(u.fields))
-
- atomic.StoreInt32(&u.initialized, 1)
-}
-
-// helper for sorting fields by tag
-type byTag []*marshalFieldInfo
-
-func (a byTag) Len() int { return len(a) }
-func (a byTag) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
-func (a byTag) Less(i, j int) bool { return a[i].wiretag < a[j].wiretag }
-
-// getExtElemInfo returns the information to marshal an extension element.
-// The info it returns is initialized.
-func (u *marshalInfo) getExtElemInfo(desc *ExtensionDesc) *marshalElemInfo {
- // get from cache first
- u.RLock()
- e, ok := u.extElems[desc.Field]
- u.RUnlock()
- if ok {
- return e
- }
-
- t := reflect.TypeOf(desc.ExtensionType) // pointer or slice to basic type or struct
- tags := strings.Split(desc.Tag, ",")
- tag, err := strconv.Atoi(tags[1])
- if err != nil {
- panic("tag is not an integer")
- }
- wt := wiretype(tags[0])
- sizer, marshaler := typeMarshaler(t, tags, false, false)
- e = &marshalElemInfo{
- wiretag: uint64(tag)<<3 | wt,
- tagsize: SizeVarint(uint64(tag) << 3),
- sizer: sizer,
- marshaler: marshaler,
- isptr: t.Kind() == reflect.Ptr,
- }
-
- // update cache
- u.Lock()
- if u.extElems == nil {
- u.extElems = make(map[int32]*marshalElemInfo)
- }
- u.extElems[desc.Field] = e
- u.Unlock()
- return e
-}
-
-// computeMarshalFieldInfo fills up the information to marshal a field.
-func (fi *marshalFieldInfo) computeMarshalFieldInfo(f *reflect.StructField) {
- // parse protobuf tag of the field.
- // tag has format of "bytes,49,opt,name=foo,def=hello!"
- tags := strings.Split(f.Tag.Get("protobuf"), ",")
- if tags[0] == "" {
- return
- }
- tag, err := strconv.Atoi(tags[1])
- if err != nil {
- panic("tag is not an integer")
- }
- wt := wiretype(tags[0])
- if tags[2] == "req" {
- fi.required = true
- }
- fi.setTag(f, tag, wt)
- fi.setMarshaler(f, tags)
-}
-
-func (fi *marshalFieldInfo) computeOneofFieldInfo(f *reflect.StructField, oneofImplementers []interface{}) {
- fi.field = toField(f)
- fi.wiretag = 1<<31 - 1 // Use a large tag number, make oneofs sorted at the end. This tag will not appear on the wire.
- fi.isPointer = true
- fi.sizer, fi.marshaler = makeOneOfMarshaler(fi, f)
- fi.oneofElems = make(map[reflect.Type]*marshalElemInfo)
-
- ityp := f.Type // interface type
- for _, o := range oneofImplementers {
- t := reflect.TypeOf(o)
- if !t.Implements(ityp) {
- continue
- }
- sf := t.Elem().Field(0) // oneof implementer is a struct with a single field
- tags := strings.Split(sf.Tag.Get("protobuf"), ",")
- tag, err := strconv.Atoi(tags[1])
- if err != nil {
- panic("tag is not an integer")
- }
- wt := wiretype(tags[0])
- sizer, marshaler := typeMarshaler(sf.Type, tags, false, true) // oneof should not omit any zero value
- fi.oneofElems[t.Elem()] = &marshalElemInfo{
- wiretag: uint64(tag)<<3 | wt,
- tagsize: SizeVarint(uint64(tag) << 3),
- sizer: sizer,
- marshaler: marshaler,
- }
- }
-}
-
-type oneofMessage interface {
- XXX_OneofFuncs() (func(Message, *Buffer) error, func(Message, int, int, *Buffer) (bool, error), func(Message) int, []interface{})
-}
-
-// wiretype returns the wire encoding of the type.
-func wiretype(encoding string) uint64 {
- switch encoding {
- case "fixed32":
- return WireFixed32
- case "fixed64":
- return WireFixed64
- case "varint", "zigzag32", "zigzag64":
- return WireVarint
- case "bytes":
- return WireBytes
- case "group":
- return WireStartGroup
- }
- panic("unknown wire type " + encoding)
-}
-
-// setTag fills up the tag (in wire format) and its size in the info of a field.
-func (fi *marshalFieldInfo) setTag(f *reflect.StructField, tag int, wt uint64) {
- fi.field = toField(f)
- fi.wiretag = uint64(tag)<<3 | wt
- fi.tagsize = SizeVarint(uint64(tag) << 3)
-}
-
-// setMarshaler fills up the sizer and marshaler in the info of a field.
-func (fi *marshalFieldInfo) setMarshaler(f *reflect.StructField, tags []string) {
- switch f.Type.Kind() {
- case reflect.Map:
- // map field
- fi.isPointer = true
- fi.sizer, fi.marshaler = makeMapMarshaler(f)
- return
- case reflect.Ptr, reflect.Slice:
- fi.isPointer = true
- }
- fi.sizer, fi.marshaler = typeMarshaler(f.Type, tags, true, false)
-}
-
-// typeMarshaler returns the sizer and marshaler of a given field.
-// t is the type of the field.
-// tags is the generated "protobuf" tag of the field.
-// If nozero is true, zero value is not marshaled to the wire.
-// If oneof is true, it is a oneof field.
-func typeMarshaler(t reflect.Type, tags []string, nozero, oneof bool) (sizer, marshaler) {
- encoding := tags[0]
-
- pointer := false
- slice := false
- if t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8 {
- slice = true
- t = t.Elem()
- }
- if t.Kind() == reflect.Ptr {
- pointer = true
- t = t.Elem()
- }
-
- packed := false
- proto3 := false
- validateUTF8 := true
- for i := 2; i < len(tags); i++ {
- if tags[i] == "packed" {
- packed = true
- }
- if tags[i] == "proto3" {
- proto3 = true
- }
- }
- validateUTF8 = validateUTF8 && proto3
-
- switch t.Kind() {
- case reflect.Bool:
- if pointer {
- return sizeBoolPtr, appendBoolPtr
- }
- if slice {
- if packed {
- return sizeBoolPackedSlice, appendBoolPackedSlice
- }
- return sizeBoolSlice, appendBoolSlice
- }
- if nozero {
- return sizeBoolValueNoZero, appendBoolValueNoZero
- }
- return sizeBoolValue, appendBoolValue
- case reflect.Uint32:
- switch encoding {
- case "fixed32":
- if pointer {
- return sizeFixed32Ptr, appendFixed32Ptr
- }
- if slice {
- if packed {
- return sizeFixed32PackedSlice, appendFixed32PackedSlice
- }
- return sizeFixed32Slice, appendFixed32Slice
- }
- if nozero {
- return sizeFixed32ValueNoZero, appendFixed32ValueNoZero
- }
- return sizeFixed32Value, appendFixed32Value
- case "varint":
- if pointer {
- return sizeVarint32Ptr, appendVarint32Ptr
- }
- if slice {
- if packed {
- return sizeVarint32PackedSlice, appendVarint32PackedSlice
- }
- return sizeVarint32Slice, appendVarint32Slice
- }
- if nozero {
- return sizeVarint32ValueNoZero, appendVarint32ValueNoZero
- }
- return sizeVarint32Value, appendVarint32Value
- }
- case reflect.Int32:
- switch encoding {
- case "fixed32":
- if pointer {
- return sizeFixedS32Ptr, appendFixedS32Ptr
- }
- if slice {
- if packed {
- return sizeFixedS32PackedSlice, appendFixedS32PackedSlice
- }
- return sizeFixedS32Slice, appendFixedS32Slice
- }
- if nozero {
- return sizeFixedS32ValueNoZero, appendFixedS32ValueNoZero
- }
- return sizeFixedS32Value, appendFixedS32Value
- case "varint":
- if pointer {
- return sizeVarintS32Ptr, appendVarintS32Ptr
- }
- if slice {
- if packed {
- return sizeVarintS32PackedSlice, appendVarintS32PackedSlice
- }
- return sizeVarintS32Slice, appendVarintS32Slice
- }
- if nozero {
- return sizeVarintS32ValueNoZero, appendVarintS32ValueNoZero
- }
- return sizeVarintS32Value, appendVarintS32Value
- case "zigzag32":
- if pointer {
- return sizeZigzag32Ptr, appendZigzag32Ptr
- }
- if slice {
- if packed {
- return sizeZigzag32PackedSlice, appendZigzag32PackedSlice
- }
- return sizeZigzag32Slice, appendZigzag32Slice
- }
- if nozero {
- return sizeZigzag32ValueNoZero, appendZigzag32ValueNoZero
- }
- return sizeZigzag32Value, appendZigzag32Value
- }
- case reflect.Uint64:
- switch encoding {
- case "fixed64":
- if pointer {
- return sizeFixed64Ptr, appendFixed64Ptr
- }
- if slice {
- if packed {
- return sizeFixed64PackedSlice, appendFixed64PackedSlice
- }
- return sizeFixed64Slice, appendFixed64Slice
- }
- if nozero {
- return sizeFixed64ValueNoZero, appendFixed64ValueNoZero
- }
- return sizeFixed64Value, appendFixed64Value
- case "varint":
- if pointer {
- return sizeVarint64Ptr, appendVarint64Ptr
- }
- if slice {
- if packed {
- return sizeVarint64PackedSlice, appendVarint64PackedSlice
- }
- return sizeVarint64Slice, appendVarint64Slice
- }
- if nozero {
- return sizeVarint64ValueNoZero, appendVarint64ValueNoZero
- }
- return sizeVarint64Value, appendVarint64Value
- }
- case reflect.Int64:
- switch encoding {
- case "fixed64":
- if pointer {
- return sizeFixedS64Ptr, appendFixedS64Ptr
- }
- if slice {
- if packed {
- return sizeFixedS64PackedSlice, appendFixedS64PackedSlice
- }
- return sizeFixedS64Slice, appendFixedS64Slice
- }
- if nozero {
- return sizeFixedS64ValueNoZero, appendFixedS64ValueNoZero
- }
- return sizeFixedS64Value, appendFixedS64Value
- case "varint":
- if pointer {
- return sizeVarintS64Ptr, appendVarintS64Ptr
- }
- if slice {
- if packed {
- return sizeVarintS64PackedSlice, appendVarintS64PackedSlice
- }
- return sizeVarintS64Slice, appendVarintS64Slice
- }
- if nozero {
- return sizeVarintS64ValueNoZero, appendVarintS64ValueNoZero
- }
- return sizeVarintS64Value, appendVarintS64Value
- case "zigzag64":
- if pointer {
- return sizeZigzag64Ptr, appendZigzag64Ptr
- }
- if slice {
- if packed {
- return sizeZigzag64PackedSlice, appendZigzag64PackedSlice
- }
- return sizeZigzag64Slice, appendZigzag64Slice
- }
- if nozero {
- return sizeZigzag64ValueNoZero, appendZigzag64ValueNoZero
- }
- return sizeZigzag64Value, appendZigzag64Value
- }
- case reflect.Float32:
- if pointer {
- return sizeFloat32Ptr, appendFloat32Ptr
- }
- if slice {
- if packed {
- return sizeFloat32PackedSlice, appendFloat32PackedSlice
- }
- return sizeFloat32Slice, appendFloat32Slice
- }
- if nozero {
- return sizeFloat32ValueNoZero, appendFloat32ValueNoZero
- }
- return sizeFloat32Value, appendFloat32Value
- case reflect.Float64:
- if pointer {
- return sizeFloat64Ptr, appendFloat64Ptr
- }
- if slice {
- if packed {
- return sizeFloat64PackedSlice, appendFloat64PackedSlice
- }
- return sizeFloat64Slice, appendFloat64Slice
- }
- if nozero {
- return sizeFloat64ValueNoZero, appendFloat64ValueNoZero
- }
- return sizeFloat64Value, appendFloat64Value
- case reflect.String:
- if validateUTF8 {
- if pointer {
- return sizeStringPtr, appendUTF8StringPtr
- }
- if slice {
- return sizeStringSlice, appendUTF8StringSlice
- }
- if nozero {
- return sizeStringValueNoZero, appendUTF8StringValueNoZero
- }
- return sizeStringValue, appendUTF8StringValue
- }
- if pointer {
- return sizeStringPtr, appendStringPtr
- }
- if slice {
- return sizeStringSlice, appendStringSlice
- }
- if nozero {
- return sizeStringValueNoZero, appendStringValueNoZero
- }
- return sizeStringValue, appendStringValue
- case reflect.Slice:
- if slice {
- return sizeBytesSlice, appendBytesSlice
- }
- if oneof {
- // Oneof bytes field may also have "proto3" tag.
- // We want to marshal it as a oneof field. Do this
- // check before the proto3 check.
- return sizeBytesOneof, appendBytesOneof
- }
- if proto3 {
- return sizeBytes3, appendBytes3
- }
- return sizeBytes, appendBytes
- case reflect.Struct:
- switch encoding {
- case "group":
- if slice {
- return makeGroupSliceMarshaler(getMarshalInfo(t))
- }
- return makeGroupMarshaler(getMarshalInfo(t))
- case "bytes":
- if slice {
- return makeMessageSliceMarshaler(getMarshalInfo(t))
- }
- return makeMessageMarshaler(getMarshalInfo(t))
- }
- }
- panic(fmt.Sprintf("unknown or mismatched type: type: %v, wire type: %v", t, encoding))
-}
-
-// Below are functions to size/marshal a specific type of a field.
-// They are stored in the field's info, and called by function pointers.
-// They have type sizer or marshaler.
-
-func sizeFixed32Value(_ pointer, tagsize int) int {
- return 4 + tagsize
-}
-func sizeFixed32ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toUint32()
- if v == 0 {
- return 0
- }
- return 4 + tagsize
-}
-func sizeFixed32Ptr(ptr pointer, tagsize int) int {
- p := *ptr.toUint32Ptr()
- if p == nil {
- return 0
- }
- return 4 + tagsize
-}
-func sizeFixed32Slice(ptr pointer, tagsize int) int {
- s := *ptr.toUint32Slice()
- return (4 + tagsize) * len(s)
-}
-func sizeFixed32PackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toUint32Slice()
- if len(s) == 0 {
- return 0
- }
- return 4*len(s) + SizeVarint(uint64(4*len(s))) + tagsize
-}
-func sizeFixedS32Value(_ pointer, tagsize int) int {
- return 4 + tagsize
-}
-func sizeFixedS32ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toInt32()
- if v == 0 {
- return 0
- }
- return 4 + tagsize
-}
-func sizeFixedS32Ptr(ptr pointer, tagsize int) int {
- p := ptr.getInt32Ptr()
- if p == nil {
- return 0
- }
- return 4 + tagsize
-}
-func sizeFixedS32Slice(ptr pointer, tagsize int) int {
- s := ptr.getInt32Slice()
- return (4 + tagsize) * len(s)
-}
-func sizeFixedS32PackedSlice(ptr pointer, tagsize int) int {
- s := ptr.getInt32Slice()
- if len(s) == 0 {
- return 0
- }
- return 4*len(s) + SizeVarint(uint64(4*len(s))) + tagsize
-}
-func sizeFloat32Value(_ pointer, tagsize int) int {
- return 4 + tagsize
-}
-func sizeFloat32ValueNoZero(ptr pointer, tagsize int) int {
- v := math.Float32bits(*ptr.toFloat32())
- if v == 0 {
- return 0
- }
- return 4 + tagsize
-}
-func sizeFloat32Ptr(ptr pointer, tagsize int) int {
- p := *ptr.toFloat32Ptr()
- if p == nil {
- return 0
- }
- return 4 + tagsize
-}
-func sizeFloat32Slice(ptr pointer, tagsize int) int {
- s := *ptr.toFloat32Slice()
- return (4 + tagsize) * len(s)
-}
-func sizeFloat32PackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toFloat32Slice()
- if len(s) == 0 {
- return 0
- }
- return 4*len(s) + SizeVarint(uint64(4*len(s))) + tagsize
-}
-func sizeFixed64Value(_ pointer, tagsize int) int {
- return 8 + tagsize
-}
-func sizeFixed64ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toUint64()
- if v == 0 {
- return 0
- }
- return 8 + tagsize
-}
-func sizeFixed64Ptr(ptr pointer, tagsize int) int {
- p := *ptr.toUint64Ptr()
- if p == nil {
- return 0
- }
- return 8 + tagsize
-}
-func sizeFixed64Slice(ptr pointer, tagsize int) int {
- s := *ptr.toUint64Slice()
- return (8 + tagsize) * len(s)
-}
-func sizeFixed64PackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toUint64Slice()
- if len(s) == 0 {
- return 0
- }
- return 8*len(s) + SizeVarint(uint64(8*len(s))) + tagsize
-}
-func sizeFixedS64Value(_ pointer, tagsize int) int {
- return 8 + tagsize
-}
-func sizeFixedS64ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toInt64()
- if v == 0 {
- return 0
- }
- return 8 + tagsize
-}
-func sizeFixedS64Ptr(ptr pointer, tagsize int) int {
- p := *ptr.toInt64Ptr()
- if p == nil {
- return 0
- }
- return 8 + tagsize
-}
-func sizeFixedS64Slice(ptr pointer, tagsize int) int {
- s := *ptr.toInt64Slice()
- return (8 + tagsize) * len(s)
-}
-func sizeFixedS64PackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toInt64Slice()
- if len(s) == 0 {
- return 0
- }
- return 8*len(s) + SizeVarint(uint64(8*len(s))) + tagsize
-}
-func sizeFloat64Value(_ pointer, tagsize int) int {
- return 8 + tagsize
-}
-func sizeFloat64ValueNoZero(ptr pointer, tagsize int) int {
- v := math.Float64bits(*ptr.toFloat64())
- if v == 0 {
- return 0
- }
- return 8 + tagsize
-}
-func sizeFloat64Ptr(ptr pointer, tagsize int) int {
- p := *ptr.toFloat64Ptr()
- if p == nil {
- return 0
- }
- return 8 + tagsize
-}
-func sizeFloat64Slice(ptr pointer, tagsize int) int {
- s := *ptr.toFloat64Slice()
- return (8 + tagsize) * len(s)
-}
-func sizeFloat64PackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toFloat64Slice()
- if len(s) == 0 {
- return 0
- }
- return 8*len(s) + SizeVarint(uint64(8*len(s))) + tagsize
-}
-func sizeVarint32Value(ptr pointer, tagsize int) int {
- v := *ptr.toUint32()
- return SizeVarint(uint64(v)) + tagsize
-}
-func sizeVarint32ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toUint32()
- if v == 0 {
- return 0
- }
- return SizeVarint(uint64(v)) + tagsize
-}
-func sizeVarint32Ptr(ptr pointer, tagsize int) int {
- p := *ptr.toUint32Ptr()
- if p == nil {
- return 0
- }
- return SizeVarint(uint64(*p)) + tagsize
-}
-func sizeVarint32Slice(ptr pointer, tagsize int) int {
- s := *ptr.toUint32Slice()
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v)) + tagsize
- }
- return n
-}
-func sizeVarint32PackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toUint32Slice()
- if len(s) == 0 {
- return 0
- }
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v))
- }
- return n + SizeVarint(uint64(n)) + tagsize
-}
-func sizeVarintS32Value(ptr pointer, tagsize int) int {
- v := *ptr.toInt32()
- return SizeVarint(uint64(v)) + tagsize
-}
-func sizeVarintS32ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toInt32()
- if v == 0 {
- return 0
- }
- return SizeVarint(uint64(v)) + tagsize
-}
-func sizeVarintS32Ptr(ptr pointer, tagsize int) int {
- p := ptr.getInt32Ptr()
- if p == nil {
- return 0
- }
- return SizeVarint(uint64(*p)) + tagsize
-}
-func sizeVarintS32Slice(ptr pointer, tagsize int) int {
- s := ptr.getInt32Slice()
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v)) + tagsize
- }
- return n
-}
-func sizeVarintS32PackedSlice(ptr pointer, tagsize int) int {
- s := ptr.getInt32Slice()
- if len(s) == 0 {
- return 0
- }
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v))
- }
- return n + SizeVarint(uint64(n)) + tagsize
-}
-func sizeVarint64Value(ptr pointer, tagsize int) int {
- v := *ptr.toUint64()
- return SizeVarint(v) + tagsize
-}
-func sizeVarint64ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toUint64()
- if v == 0 {
- return 0
- }
- return SizeVarint(v) + tagsize
-}
-func sizeVarint64Ptr(ptr pointer, tagsize int) int {
- p := *ptr.toUint64Ptr()
- if p == nil {
- return 0
- }
- return SizeVarint(*p) + tagsize
-}
-func sizeVarint64Slice(ptr pointer, tagsize int) int {
- s := *ptr.toUint64Slice()
- n := 0
- for _, v := range s {
- n += SizeVarint(v) + tagsize
- }
- return n
-}
-func sizeVarint64PackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toUint64Slice()
- if len(s) == 0 {
- return 0
- }
- n := 0
- for _, v := range s {
- n += SizeVarint(v)
- }
- return n + SizeVarint(uint64(n)) + tagsize
-}
-func sizeVarintS64Value(ptr pointer, tagsize int) int {
- v := *ptr.toInt64()
- return SizeVarint(uint64(v)) + tagsize
-}
-func sizeVarintS64ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toInt64()
- if v == 0 {
- return 0
- }
- return SizeVarint(uint64(v)) + tagsize
-}
-func sizeVarintS64Ptr(ptr pointer, tagsize int) int {
- p := *ptr.toInt64Ptr()
- if p == nil {
- return 0
- }
- return SizeVarint(uint64(*p)) + tagsize
-}
-func sizeVarintS64Slice(ptr pointer, tagsize int) int {
- s := *ptr.toInt64Slice()
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v)) + tagsize
- }
- return n
-}
-func sizeVarintS64PackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toInt64Slice()
- if len(s) == 0 {
- return 0
- }
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v))
- }
- return n + SizeVarint(uint64(n)) + tagsize
-}
-func sizeZigzag32Value(ptr pointer, tagsize int) int {
- v := *ptr.toInt32()
- return SizeVarint(uint64((uint32(v)<<1)^uint32((int32(v)>>31)))) + tagsize
-}
-func sizeZigzag32ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toInt32()
- if v == 0 {
- return 0
- }
- return SizeVarint(uint64((uint32(v)<<1)^uint32((int32(v)>>31)))) + tagsize
-}
-func sizeZigzag32Ptr(ptr pointer, tagsize int) int {
- p := ptr.getInt32Ptr()
- if p == nil {
- return 0
- }
- v := *p
- return SizeVarint(uint64((uint32(v)<<1)^uint32((int32(v)>>31)))) + tagsize
-}
-func sizeZigzag32Slice(ptr pointer, tagsize int) int {
- s := ptr.getInt32Slice()
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64((uint32(v)<<1)^uint32((int32(v)>>31)))) + tagsize
- }
- return n
-}
-func sizeZigzag32PackedSlice(ptr pointer, tagsize int) int {
- s := ptr.getInt32Slice()
- if len(s) == 0 {
- return 0
- }
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64((uint32(v) << 1) ^ uint32((int32(v) >> 31))))
- }
- return n + SizeVarint(uint64(n)) + tagsize
-}
-func sizeZigzag64Value(ptr pointer, tagsize int) int {
- v := *ptr.toInt64()
- return SizeVarint(uint64(v<<1)^uint64((int64(v)>>63))) + tagsize
-}
-func sizeZigzag64ValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toInt64()
- if v == 0 {
- return 0
- }
- return SizeVarint(uint64(v<<1)^uint64((int64(v)>>63))) + tagsize
-}
-func sizeZigzag64Ptr(ptr pointer, tagsize int) int {
- p := *ptr.toInt64Ptr()
- if p == nil {
- return 0
- }
- v := *p
- return SizeVarint(uint64(v<<1)^uint64((int64(v)>>63))) + tagsize
-}
-func sizeZigzag64Slice(ptr pointer, tagsize int) int {
- s := *ptr.toInt64Slice()
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v<<1)^uint64((int64(v)>>63))) + tagsize
- }
- return n
-}
-func sizeZigzag64PackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toInt64Slice()
- if len(s) == 0 {
- return 0
- }
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v<<1) ^ uint64((int64(v) >> 63)))
- }
- return n + SizeVarint(uint64(n)) + tagsize
-}
-func sizeBoolValue(_ pointer, tagsize int) int {
- return 1 + tagsize
-}
-func sizeBoolValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toBool()
- if !v {
- return 0
- }
- return 1 + tagsize
-}
-func sizeBoolPtr(ptr pointer, tagsize int) int {
- p := *ptr.toBoolPtr()
- if p == nil {
- return 0
- }
- return 1 + tagsize
-}
-func sizeBoolSlice(ptr pointer, tagsize int) int {
- s := *ptr.toBoolSlice()
- return (1 + tagsize) * len(s)
-}
-func sizeBoolPackedSlice(ptr pointer, tagsize int) int {
- s := *ptr.toBoolSlice()
- if len(s) == 0 {
- return 0
- }
- return len(s) + SizeVarint(uint64(len(s))) + tagsize
-}
-func sizeStringValue(ptr pointer, tagsize int) int {
- v := *ptr.toString()
- return len(v) + SizeVarint(uint64(len(v))) + tagsize
-}
-func sizeStringValueNoZero(ptr pointer, tagsize int) int {
- v := *ptr.toString()
- if v == "" {
- return 0
- }
- return len(v) + SizeVarint(uint64(len(v))) + tagsize
-}
-func sizeStringPtr(ptr pointer, tagsize int) int {
- p := *ptr.toStringPtr()
- if p == nil {
- return 0
- }
- v := *p
- return len(v) + SizeVarint(uint64(len(v))) + tagsize
-}
-func sizeStringSlice(ptr pointer, tagsize int) int {
- s := *ptr.toStringSlice()
- n := 0
- for _, v := range s {
- n += len(v) + SizeVarint(uint64(len(v))) + tagsize
- }
- return n
-}
-func sizeBytes(ptr pointer, tagsize int) int {
- v := *ptr.toBytes()
- if v == nil {
- return 0
- }
- return len(v) + SizeVarint(uint64(len(v))) + tagsize
-}
-func sizeBytes3(ptr pointer, tagsize int) int {
- v := *ptr.toBytes()
- if len(v) == 0 {
- return 0
- }
- return len(v) + SizeVarint(uint64(len(v))) + tagsize
-}
-func sizeBytesOneof(ptr pointer, tagsize int) int {
- v := *ptr.toBytes()
- return len(v) + SizeVarint(uint64(len(v))) + tagsize
-}
-func sizeBytesSlice(ptr pointer, tagsize int) int {
- s := *ptr.toBytesSlice()
- n := 0
- for _, v := range s {
- n += len(v) + SizeVarint(uint64(len(v))) + tagsize
- }
- return n
-}
-
-// appendFixed32 appends an encoded fixed32 to b.
-func appendFixed32(b []byte, v uint32) []byte {
- b = append(b,
- byte(v),
- byte(v>>8),
- byte(v>>16),
- byte(v>>24))
- return b
-}
-
-// appendFixed64 appends an encoded fixed64 to b.
-func appendFixed64(b []byte, v uint64) []byte {
- b = append(b,
- byte(v),
- byte(v>>8),
- byte(v>>16),
- byte(v>>24),
- byte(v>>32),
- byte(v>>40),
- byte(v>>48),
- byte(v>>56))
- return b
-}
-
-// appendVarint appends an encoded varint to b.
-func appendVarint(b []byte, v uint64) []byte {
- // TODO: make 1-byte (maybe 2-byte) case inline-able, once we
- // have non-leaf inliner.
- switch {
- case v < 1<<7:
- b = append(b, byte(v))
- case v < 1<<14:
- b = append(b,
- byte(v&0x7f|0x80),
- byte(v>>7))
- case v < 1<<21:
- b = append(b,
- byte(v&0x7f|0x80),
- byte((v>>7)&0x7f|0x80),
- byte(v>>14))
- case v < 1<<28:
- b = append(b,
- byte(v&0x7f|0x80),
- byte((v>>7)&0x7f|0x80),
- byte((v>>14)&0x7f|0x80),
- byte(v>>21))
- case v < 1<<35:
- b = append(b,
- byte(v&0x7f|0x80),
- byte((v>>7)&0x7f|0x80),
- byte((v>>14)&0x7f|0x80),
- byte((v>>21)&0x7f|0x80),
- byte(v>>28))
- case v < 1<<42:
- b = append(b,
- byte(v&0x7f|0x80),
- byte((v>>7)&0x7f|0x80),
- byte((v>>14)&0x7f|0x80),
- byte((v>>21)&0x7f|0x80),
- byte((v>>28)&0x7f|0x80),
- byte(v>>35))
- case v < 1<<49:
- b = append(b,
- byte(v&0x7f|0x80),
- byte((v>>7)&0x7f|0x80),
- byte((v>>14)&0x7f|0x80),
- byte((v>>21)&0x7f|0x80),
- byte((v>>28)&0x7f|0x80),
- byte((v>>35)&0x7f|0x80),
- byte(v>>42))
- case v < 1<<56:
- b = append(b,
- byte(v&0x7f|0x80),
- byte((v>>7)&0x7f|0x80),
- byte((v>>14)&0x7f|0x80),
- byte((v>>21)&0x7f|0x80),
- byte((v>>28)&0x7f|0x80),
- byte((v>>35)&0x7f|0x80),
- byte((v>>42)&0x7f|0x80),
- byte(v>>49))
- case v < 1<<63:
- b = append(b,
- byte(v&0x7f|0x80),
- byte((v>>7)&0x7f|0x80),
- byte((v>>14)&0x7f|0x80),
- byte((v>>21)&0x7f|0x80),
- byte((v>>28)&0x7f|0x80),
- byte((v>>35)&0x7f|0x80),
- byte((v>>42)&0x7f|0x80),
- byte((v>>49)&0x7f|0x80),
- byte(v>>56))
- default:
- b = append(b,
- byte(v&0x7f|0x80),
- byte((v>>7)&0x7f|0x80),
- byte((v>>14)&0x7f|0x80),
- byte((v>>21)&0x7f|0x80),
- byte((v>>28)&0x7f|0x80),
- byte((v>>35)&0x7f|0x80),
- byte((v>>42)&0x7f|0x80),
- byte((v>>49)&0x7f|0x80),
- byte((v>>56)&0x7f|0x80),
- 1)
- }
- return b
-}
-
-func appendFixed32Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toUint32()
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, v)
- return b, nil
-}
-func appendFixed32ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toUint32()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, v)
- return b, nil
-}
-func appendFixed32Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toUint32Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, *p)
- return b, nil
-}
-func appendFixed32Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toUint32Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, v)
- }
- return b, nil
-}
-func appendFixed32PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toUint32Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- b = appendVarint(b, uint64(4*len(s)))
- for _, v := range s {
- b = appendFixed32(b, v)
- }
- return b, nil
-}
-func appendFixedS32Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt32()
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, uint32(v))
- return b, nil
-}
-func appendFixedS32ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt32()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, uint32(v))
- return b, nil
-}
-func appendFixedS32Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := ptr.getInt32Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, uint32(*p))
- return b, nil
-}
-func appendFixedS32Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := ptr.getInt32Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, uint32(v))
- }
- return b, nil
-}
-func appendFixedS32PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := ptr.getInt32Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- b = appendVarint(b, uint64(4*len(s)))
- for _, v := range s {
- b = appendFixed32(b, uint32(v))
- }
- return b, nil
-}
-func appendFloat32Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := math.Float32bits(*ptr.toFloat32())
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, v)
- return b, nil
-}
-func appendFloat32ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := math.Float32bits(*ptr.toFloat32())
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, v)
- return b, nil
-}
-func appendFloat32Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toFloat32Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, math.Float32bits(*p))
- return b, nil
-}
-func appendFloat32Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toFloat32Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendFixed32(b, math.Float32bits(v))
- }
- return b, nil
-}
-func appendFloat32PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toFloat32Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- b = appendVarint(b, uint64(4*len(s)))
- for _, v := range s {
- b = appendFixed32(b, math.Float32bits(v))
- }
- return b, nil
-}
-func appendFixed64Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toUint64()
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, v)
- return b, nil
-}
-func appendFixed64ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toUint64()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, v)
- return b, nil
-}
-func appendFixed64Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toUint64Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, *p)
- return b, nil
-}
-func appendFixed64Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toUint64Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, v)
- }
- return b, nil
-}
-func appendFixed64PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toUint64Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- b = appendVarint(b, uint64(8*len(s)))
- for _, v := range s {
- b = appendFixed64(b, v)
- }
- return b, nil
-}
-func appendFixedS64Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt64()
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, uint64(v))
- return b, nil
-}
-func appendFixedS64ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt64()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, uint64(v))
- return b, nil
-}
-func appendFixedS64Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toInt64Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, uint64(*p))
- return b, nil
-}
-func appendFixedS64Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toInt64Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, uint64(v))
- }
- return b, nil
-}
-func appendFixedS64PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toInt64Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- b = appendVarint(b, uint64(8*len(s)))
- for _, v := range s {
- b = appendFixed64(b, uint64(v))
- }
- return b, nil
-}
-func appendFloat64Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := math.Float64bits(*ptr.toFloat64())
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, v)
- return b, nil
-}
-func appendFloat64ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := math.Float64bits(*ptr.toFloat64())
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, v)
- return b, nil
-}
-func appendFloat64Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toFloat64Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, math.Float64bits(*p))
- return b, nil
-}
-func appendFloat64Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toFloat64Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendFixed64(b, math.Float64bits(v))
- }
- return b, nil
-}
-func appendFloat64PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toFloat64Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- b = appendVarint(b, uint64(8*len(s)))
- for _, v := range s {
- b = appendFixed64(b, math.Float64bits(v))
- }
- return b, nil
-}
-func appendVarint32Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toUint32()
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v))
- return b, nil
-}
-func appendVarint32ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toUint32()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v))
- return b, nil
-}
-func appendVarint32Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toUint32Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(*p))
- return b, nil
-}
-func appendVarint32Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toUint32Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v))
- }
- return b, nil
-}
-func appendVarint32PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toUint32Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- // compute size
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v))
- }
- b = appendVarint(b, uint64(n))
- for _, v := range s {
- b = appendVarint(b, uint64(v))
- }
- return b, nil
-}
-func appendVarintS32Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt32()
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v))
- return b, nil
-}
-func appendVarintS32ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt32()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v))
- return b, nil
-}
-func appendVarintS32Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := ptr.getInt32Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(*p))
- return b, nil
-}
-func appendVarintS32Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := ptr.getInt32Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v))
- }
- return b, nil
-}
-func appendVarintS32PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := ptr.getInt32Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- // compute size
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v))
- }
- b = appendVarint(b, uint64(n))
- for _, v := range s {
- b = appendVarint(b, uint64(v))
- }
- return b, nil
-}
-func appendVarint64Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toUint64()
- b = appendVarint(b, wiretag)
- b = appendVarint(b, v)
- return b, nil
-}
-func appendVarint64ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toUint64()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, v)
- return b, nil
-}
-func appendVarint64Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toUint64Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, *p)
- return b, nil
-}
-func appendVarint64Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toUint64Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendVarint(b, v)
- }
- return b, nil
-}
-func appendVarint64PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toUint64Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- // compute size
- n := 0
- for _, v := range s {
- n += SizeVarint(v)
- }
- b = appendVarint(b, uint64(n))
- for _, v := range s {
- b = appendVarint(b, v)
- }
- return b, nil
-}
-func appendVarintS64Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt64()
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v))
- return b, nil
-}
-func appendVarintS64ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt64()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v))
- return b, nil
-}
-func appendVarintS64Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toInt64Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(*p))
- return b, nil
-}
-func appendVarintS64Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toInt64Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v))
- }
- return b, nil
-}
-func appendVarintS64PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toInt64Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- // compute size
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v))
- }
- b = appendVarint(b, uint64(n))
- for _, v := range s {
- b = appendVarint(b, uint64(v))
- }
- return b, nil
-}
-func appendZigzag32Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt32()
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64((uint32(v)<<1)^uint32((int32(v)>>31))))
- return b, nil
-}
-func appendZigzag32ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt32()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64((uint32(v)<<1)^uint32((int32(v)>>31))))
- return b, nil
-}
-func appendZigzag32Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := ptr.getInt32Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- v := *p
- b = appendVarint(b, uint64((uint32(v)<<1)^uint32((int32(v)>>31))))
- return b, nil
-}
-func appendZigzag32Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := ptr.getInt32Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64((uint32(v)<<1)^uint32((int32(v)>>31))))
- }
- return b, nil
-}
-func appendZigzag32PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := ptr.getInt32Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- // compute size
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64((uint32(v) << 1) ^ uint32((int32(v) >> 31))))
- }
- b = appendVarint(b, uint64(n))
- for _, v := range s {
- b = appendVarint(b, uint64((uint32(v)<<1)^uint32((int32(v)>>31))))
- }
- return b, nil
-}
-func appendZigzag64Value(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt64()
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v<<1)^uint64((int64(v)>>63)))
- return b, nil
-}
-func appendZigzag64ValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toInt64()
- if v == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v<<1)^uint64((int64(v)>>63)))
- return b, nil
-}
-func appendZigzag64Ptr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toInt64Ptr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- v := *p
- b = appendVarint(b, uint64(v<<1)^uint64((int64(v)>>63)))
- return b, nil
-}
-func appendZigzag64Slice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toInt64Slice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(v<<1)^uint64((int64(v)>>63)))
- }
- return b, nil
-}
-func appendZigzag64PackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toInt64Slice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- // compute size
- n := 0
- for _, v := range s {
- n += SizeVarint(uint64(v<<1) ^ uint64((int64(v) >> 63)))
- }
- b = appendVarint(b, uint64(n))
- for _, v := range s {
- b = appendVarint(b, uint64(v<<1)^uint64((int64(v)>>63)))
- }
- return b, nil
-}
-func appendBoolValue(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toBool()
- b = appendVarint(b, wiretag)
- if v {
- b = append(b, 1)
- } else {
- b = append(b, 0)
- }
- return b, nil
-}
-func appendBoolValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toBool()
- if !v {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = append(b, 1)
- return b, nil
-}
-
-func appendBoolPtr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toBoolPtr()
- if p == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- if *p {
- b = append(b, 1)
- } else {
- b = append(b, 0)
- }
- return b, nil
-}
-func appendBoolSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toBoolSlice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- if v {
- b = append(b, 1)
- } else {
- b = append(b, 0)
- }
- }
- return b, nil
-}
-func appendBoolPackedSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toBoolSlice()
- if len(s) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag&^7|WireBytes)
- b = appendVarint(b, uint64(len(s)))
- for _, v := range s {
- if v {
- b = append(b, 1)
- } else {
- b = append(b, 0)
- }
- }
- return b, nil
-}
-func appendStringValue(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toString()
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- return b, nil
-}
-func appendStringValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toString()
- if v == "" {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- return b, nil
-}
-func appendStringPtr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- p := *ptr.toStringPtr()
- if p == nil {
- return b, nil
- }
- v := *p
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- return b, nil
-}
-func appendStringSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toStringSlice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- }
- return b, nil
-}
-func appendUTF8StringValue(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- var invalidUTF8 bool
- v := *ptr.toString()
- if !utf8.ValidString(v) {
- invalidUTF8 = true
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- if invalidUTF8 {
- return b, errInvalidUTF8
- }
- return b, nil
-}
-func appendUTF8StringValueNoZero(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- var invalidUTF8 bool
- v := *ptr.toString()
- if v == "" {
- return b, nil
- }
- if !utf8.ValidString(v) {
- invalidUTF8 = true
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- if invalidUTF8 {
- return b, errInvalidUTF8
- }
- return b, nil
-}
-func appendUTF8StringPtr(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- var invalidUTF8 bool
- p := *ptr.toStringPtr()
- if p == nil {
- return b, nil
- }
- v := *p
- if !utf8.ValidString(v) {
- invalidUTF8 = true
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- if invalidUTF8 {
- return b, errInvalidUTF8
- }
- return b, nil
-}
-func appendUTF8StringSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- var invalidUTF8 bool
- s := *ptr.toStringSlice()
- for _, v := range s {
- if !utf8.ValidString(v) {
- invalidUTF8 = true
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- }
- if invalidUTF8 {
- return b, errInvalidUTF8
- }
- return b, nil
-}
-func appendBytes(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toBytes()
- if v == nil {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- return b, nil
-}
-func appendBytes3(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toBytes()
- if len(v) == 0 {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- return b, nil
-}
-func appendBytesOneof(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- v := *ptr.toBytes()
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- return b, nil
-}
-func appendBytesSlice(b []byte, ptr pointer, wiretag uint64, _ bool) ([]byte, error) {
- s := *ptr.toBytesSlice()
- for _, v := range s {
- b = appendVarint(b, wiretag)
- b = appendVarint(b, uint64(len(v)))
- b = append(b, v...)
- }
- return b, nil
-}
-
-// makeGroupMarshaler returns the sizer and marshaler for a group.
-// u is the marshal info of the underlying message.
-func makeGroupMarshaler(u *marshalInfo) (sizer, marshaler) {
- return func(ptr pointer, tagsize int) int {
- p := ptr.getPointer()
- if p.isNil() {
- return 0
- }
- return u.size(p) + 2*tagsize
- },
- func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
- p := ptr.getPointer()
- if p.isNil() {
- return b, nil
- }
- var err error
- b = appendVarint(b, wiretag) // start group
- b, err = u.marshal(b, p, deterministic)
- b = appendVarint(b, wiretag+(WireEndGroup-WireStartGroup)) // end group
- return b, err
- }
-}
-
-// makeGroupSliceMarshaler returns the sizer and marshaler for a group slice.
-// u is the marshal info of the underlying message.
-func makeGroupSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
- return func(ptr pointer, tagsize int) int {
- s := ptr.getPointerSlice()
- n := 0
- for _, v := range s {
- if v.isNil() {
- continue
- }
- n += u.size(v) + 2*tagsize
- }
- return n
- },
- func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
- s := ptr.getPointerSlice()
- var err error
- var nerr nonFatal
- for _, v := range s {
- if v.isNil() {
- return b, errRepeatedHasNil
- }
- b = appendVarint(b, wiretag) // start group
- b, err = u.marshal(b, v, deterministic)
- b = appendVarint(b, wiretag+(WireEndGroup-WireStartGroup)) // end group
- if !nerr.Merge(err) {
- if err == ErrNil {
- err = errRepeatedHasNil
- }
- return b, err
- }
- }
- return b, nerr.E
- }
-}
-
-// makeMessageMarshaler returns the sizer and marshaler for a message field.
-// u is the marshal info of the message.
-func makeMessageMarshaler(u *marshalInfo) (sizer, marshaler) {
- return func(ptr pointer, tagsize int) int {
- p := ptr.getPointer()
- if p.isNil() {
- return 0
- }
- siz := u.size(p)
- return siz + SizeVarint(uint64(siz)) + tagsize
- },
- func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
- p := ptr.getPointer()
- if p.isNil() {
- return b, nil
- }
- b = appendVarint(b, wiretag)
- siz := u.cachedsize(p)
- b = appendVarint(b, uint64(siz))
- return u.marshal(b, p, deterministic)
- }
-}
-
-// makeMessageSliceMarshaler returns the sizer and marshaler for a message slice.
-// u is the marshal info of the message.
-func makeMessageSliceMarshaler(u *marshalInfo) (sizer, marshaler) {
- return func(ptr pointer, tagsize int) int {
- s := ptr.getPointerSlice()
- n := 0
- for _, v := range s {
- if v.isNil() {
- continue
- }
- siz := u.size(v)
- n += siz + SizeVarint(uint64(siz)) + tagsize
- }
- return n
- },
- func(b []byte, ptr pointer, wiretag uint64, deterministic bool) ([]byte, error) {
- s := ptr.getPointerSlice()
- var err error
- var nerr nonFatal
- for _, v := range s {
- if v.isNil() {
- return b, errRepeatedHasNil
- }
- b = appendVarint(b, wiretag)
- siz := u.cachedsize(v)
- b = appendVarint(b, uint64(siz))
- b, err = u.marshal(b, v, deterministic)
-
- if !nerr.Merge(err) {
- if err == ErrNil {
- err = errRepeatedHasNil
- }
- return b, err
- }
- }
- return b, nerr.E
- }
-}
-
-// makeMapMarshaler returns the sizer and marshaler for a map field.
-// f is the pointer to the reflect data structure of the field.
-func makeMapMarshaler(f *reflect.StructField) (sizer, marshaler) {
- // figure out key and value type
- t := f.Type
- keyType := t.Key()
- valType := t.Elem()
- keyTags := strings.Split(f.Tag.Get("protobuf_key"), ",")
- valTags := strings.Split(f.Tag.Get("protobuf_val"), ",")
- keySizer, keyMarshaler := typeMarshaler(keyType, keyTags, false, false) // don't omit zero value in map
- valSizer, valMarshaler := typeMarshaler(valType, valTags, false, false) // don't omit zero value in map
- keyWireTag := 1<<3 | wiretype(keyTags[0])
- valWireTag := 2<<3 | wiretype(valTags[0])
-
- // We create an interface to get the addresses of the map key and value.
- // If value is pointer-typed, the interface is a direct interface, the
- // idata itself is the value. Otherwise, the idata is the pointer to the
- // value.
- // Key cannot be pointer-typed.
- valIsPtr := valType.Kind() == reflect.Ptr
-
- // If value is a message with nested maps, calling
- // valSizer in marshal may be quadratic. We should use
- // cached version in marshal (but not in size).
- // If value is not message type, we don't have size cache,
- // but it cannot be nested either. Just use valSizer.
- valCachedSizer := valSizer
- if valIsPtr && valType.Elem().Kind() == reflect.Struct {
- u := getMarshalInfo(valType.Elem())
- valCachedSizer = func(ptr pointer, tagsize int) int {
- // Same as message sizer, but use cache.
- p := ptr.getPointer()
- if p.isNil() {
- return 0
- }
- siz := u.cachedsize(p)
- return siz + SizeVarint(uint64(siz)) + tagsize
- }
- }
- return func(ptr pointer, tagsize int) int {
- m := ptr.asPointerTo(t).Elem() // the map
- n := 0
- for _, k := range m.MapKeys() {
- ki := k.Interface()
- vi := m.MapIndex(k).Interface()
- kaddr := toAddrPointer(&ki, false) // pointer to key
- vaddr := toAddrPointer(&vi, valIsPtr) // pointer to value
- siz := keySizer(kaddr, 1) + valSizer(vaddr, 1) // tag of key = 1 (size=1), tag of val = 2 (size=1)
- n += siz + SizeVarint(uint64(siz)) + tagsize
- }
- return n
- },
- func(b []byte, ptr pointer, tag uint64, deterministic bool) ([]byte, error) {
- m := ptr.asPointerTo(t).Elem() // the map
- var err error
- keys := m.MapKeys()
- if len(keys) > 1 && deterministic {
- sort.Sort(mapKeys(keys))
- }
-
- var nerr nonFatal
- for _, k := range keys {
- ki := k.Interface()
- vi := m.MapIndex(k).Interface()
- kaddr := toAddrPointer(&ki, false) // pointer to key
- vaddr := toAddrPointer(&vi, valIsPtr) // pointer to value
- b = appendVarint(b, tag)
- siz := keySizer(kaddr, 1) + valCachedSizer(vaddr, 1) // tag of key = 1 (size=1), tag of val = 2 (size=1)
- b = appendVarint(b, uint64(siz))
- b, err = keyMarshaler(b, kaddr, keyWireTag, deterministic)
- if !nerr.Merge(err) {
- return b, err
- }
- b, err = valMarshaler(b, vaddr, valWireTag, deterministic)
- if err != ErrNil && !nerr.Merge(err) { // allow nil value in map
- return b, err
- }
- }
- return b, nerr.E
- }
-}
-
-// makeOneOfMarshaler returns the sizer and marshaler for a oneof field.
-// fi is the marshal info of the field.
-// f is the pointer to the reflect data structure of the field.
-func makeOneOfMarshaler(fi *marshalFieldInfo, f *reflect.StructField) (sizer, marshaler) {
- // Oneof field is an interface. We need to get the actual data type on the fly.
- t := f.Type
- return func(ptr pointer, _ int) int {
- p := ptr.getInterfacePointer()
- if p.isNil() {
- return 0
- }
- v := ptr.asPointerTo(t).Elem().Elem().Elem() // *interface -> interface -> *struct -> struct
- telem := v.Type()
- e := fi.oneofElems[telem]
- return e.sizer(p, e.tagsize)
- },
- func(b []byte, ptr pointer, _ uint64, deterministic bool) ([]byte, error) {
- p := ptr.getInterfacePointer()
- if p.isNil() {
- return b, nil
- }
- v := ptr.asPointerTo(t).Elem().Elem().Elem() // *interface -> interface -> *struct -> struct
- telem := v.Type()
- if telem.Field(0).Type.Kind() == reflect.Ptr && p.getPointer().isNil() {
- return b, errOneofHasNil
- }
- e := fi.oneofElems[telem]
- return e.marshaler(b, p, e.wiretag, deterministic)
- }
-}
-
-// sizeExtensions computes the size of encoded data for a XXX_InternalExtensions field.
-func (u *marshalInfo) sizeExtensions(ext *XXX_InternalExtensions) int {
- m, mu := ext.extensionsRead()
- if m == nil {
- return 0
- }
- mu.Lock()
-
- n := 0
- for _, e := range m {
- if e.value == nil || e.desc == nil {
- // Extension is only in its encoded form.
- n += len(e.enc)
- continue
- }
-
- // We don't skip extensions that have an encoded form set,
- // because the extension value may have been mutated after
- // the last time this function was called.
- ei := u.getExtElemInfo(e.desc)
- v := e.value
- p := toAddrPointer(&v, ei.isptr)
- n += ei.sizer(p, ei.tagsize)
- }
- mu.Unlock()
- return n
-}
-
-// appendExtensions marshals a XXX_InternalExtensions field to the end of byte slice b.
-func (u *marshalInfo) appendExtensions(b []byte, ext *XXX_InternalExtensions, deterministic bool) ([]byte, error) {
- m, mu := ext.extensionsRead()
- if m == nil {
- return b, nil
- }
- mu.Lock()
- defer mu.Unlock()
-
- var err error
- var nerr nonFatal
-
- // Fast-path for common cases: zero or one extensions.
- // Don't bother sorting the keys.
- if len(m) <= 1 {
- for _, e := range m {
- if e.value == nil || e.desc == nil {
- // Extension is only in its encoded form.
- b = append(b, e.enc...)
- continue
- }
-
- // We don't skip extensions that have an encoded form set,
- // because the extension value may have been mutated after
- // the last time this function was called.
-
- ei := u.getExtElemInfo(e.desc)
- v := e.value
- p := toAddrPointer(&v, ei.isptr)
- b, err = ei.marshaler(b, p, ei.wiretag, deterministic)
- if !nerr.Merge(err) {
- return b, err
- }
- }
- return b, nerr.E
- }
-
- // Sort the keys to provide a deterministic encoding.
- // Not sure this is required, but the old code does it.
- keys := make([]int, 0, len(m))
- for k := range m {
- keys = append(keys, int(k))
- }
- sort.Ints(keys)
-
- for _, k := range keys {
- e := m[int32(k)]
- if e.value == nil || e.desc == nil {
- // Extension is only in its encoded form.
- b = append(b, e.enc...)
- continue
- }
-
- // We don't skip extensions that have an encoded form set,
- // because the extension value may have been mutated after
- // the last time this function was called.
-
- ei := u.getExtElemInfo(e.desc)
- v := e.value
- p := toAddrPointer(&v, ei.isptr)
- b, err = ei.marshaler(b, p, ei.wiretag, deterministic)
- if !nerr.Merge(err) {
- return b, err
- }
- }
- return b, nerr.E
-}
-
-// message set format is:
-// message MessageSet {
-// repeated group Item = 1 {
-// required int32 type_id = 2;
-// required string message = 3;
-// };
-// }
-
-// sizeMessageSet computes the size of encoded data for a XXX_InternalExtensions field
-// in message set format (above).
-func (u *marshalInfo) sizeMessageSet(ext *XXX_InternalExtensions) int {
- m, mu := ext.extensionsRead()
- if m == nil {
- return 0
- }
- mu.Lock()
-
- n := 0
- for id, e := range m {
- n += 2 // start group, end group. tag = 1 (size=1)
- n += SizeVarint(uint64(id)) + 1 // type_id, tag = 2 (size=1)
-
- if e.value == nil || e.desc == nil {
- // Extension is only in its encoded form.
- msgWithLen := skipVarint(e.enc) // skip old tag, but leave the length varint
- siz := len(msgWithLen)
- n += siz + 1 // message, tag = 3 (size=1)
- continue
- }
-
- // We don't skip extensions that have an encoded form set,
- // because the extension value may have been mutated after
- // the last time this function was called.
-
- ei := u.getExtElemInfo(e.desc)
- v := e.value
- p := toAddrPointer(&v, ei.isptr)
- n += ei.sizer(p, 1) // message, tag = 3 (size=1)
- }
- mu.Unlock()
- return n
-}
-
-// appendMessageSet marshals a XXX_InternalExtensions field in message set format (above)
-// to the end of byte slice b.
-func (u *marshalInfo) appendMessageSet(b []byte, ext *XXX_InternalExtensions, deterministic bool) ([]byte, error) {
- m, mu := ext.extensionsRead()
- if m == nil {
- return b, nil
- }
- mu.Lock()
- defer mu.Unlock()
-
- var err error
- var nerr nonFatal
-
- // Fast-path for common cases: zero or one extensions.
- // Don't bother sorting the keys.
- if len(m) <= 1 {
- for id, e := range m {
- b = append(b, 1<<3|WireStartGroup)
- b = append(b, 2<<3|WireVarint)
- b = appendVarint(b, uint64(id))
-
- if e.value == nil || e.desc == nil {
- // Extension is only in its encoded form.
- msgWithLen := skipVarint(e.enc) // skip old tag, but leave the length varint
- b = append(b, 3<<3|WireBytes)
- b = append(b, msgWithLen...)
- b = append(b, 1<<3|WireEndGroup)
- continue
- }
-
- // We don't skip extensions that have an encoded form set,
- // because the extension value may have been mutated after
- // the last time this function was called.
-
- ei := u.getExtElemInfo(e.desc)
- v := e.value
- p := toAddrPointer(&v, ei.isptr)
- b, err = ei.marshaler(b, p, 3<<3|WireBytes, deterministic)
- if !nerr.Merge(err) {
- return b, err
- }
- b = append(b, 1<<3|WireEndGroup)
- }
- return b, nerr.E
- }
-
- // Sort the keys to provide a deterministic encoding.
- keys := make([]int, 0, len(m))
- for k := range m {
- keys = append(keys, int(k))
- }
- sort.Ints(keys)
-
- for _, id := range keys {
- e := m[int32(id)]
- b = append(b, 1<<3|WireStartGroup)
- b = append(b, 2<<3|WireVarint)
- b = appendVarint(b, uint64(id))
-
- if e.value == nil || e.desc == nil {
- // Extension is only in its encoded form.
- msgWithLen := skipVarint(e.enc) // skip old tag, but leave the length varint
- b = append(b, 3<<3|WireBytes)
- b = append(b, msgWithLen...)
- b = append(b, 1<<3|WireEndGroup)
- continue
- }
-
- // We don't skip extensions that have an encoded form set,
- // because the extension value may have been mutated after
- // the last time this function was called.
-
- ei := u.getExtElemInfo(e.desc)
- v := e.value
- p := toAddrPointer(&v, ei.isptr)
- b, err = ei.marshaler(b, p, 3<<3|WireBytes, deterministic)
- b = append(b, 1<<3|WireEndGroup)
- if !nerr.Merge(err) {
- return b, err
- }
- }
- return b, nerr.E
-}
-
-// sizeV1Extensions computes the size of encoded data for a V1-API extension field.
-func (u *marshalInfo) sizeV1Extensions(m map[int32]Extension) int {
- if m == nil {
- return 0
- }
-
- n := 0
- for _, e := range m {
- if e.value == nil || e.desc == nil {
- // Extension is only in its encoded form.
- n += len(e.enc)
- continue
- }
-
- // We don't skip extensions that have an encoded form set,
- // because the extension value may have been mutated after
- // the last time this function was called.
-
- ei := u.getExtElemInfo(e.desc)
- v := e.value
- p := toAddrPointer(&v, ei.isptr)
- n += ei.sizer(p, ei.tagsize)
- }
- return n
-}
-
-// appendV1Extensions marshals a V1-API extension field to the end of byte slice b.
-func (u *marshalInfo) appendV1Extensions(b []byte, m map[int32]Extension, deterministic bool) ([]byte, error) {
- if m == nil {
- return b, nil
- }
-
- // Sort the keys to provide a deterministic encoding.
- keys := make([]int, 0, len(m))
- for k := range m {
- keys = append(keys, int(k))
- }
- sort.Ints(keys)
-
- var err error
- var nerr nonFatal
- for _, k := range keys {
- e := m[int32(k)]
- if e.value == nil || e.desc == nil {
- // Extension is only in its encoded form.
- b = append(b, e.enc...)
- continue
- }
-
- // We don't skip extensions that have an encoded form set,
- // because the extension value may have been mutated after
- // the last time this function was called.
-
- ei := u.getExtElemInfo(e.desc)
- v := e.value
- p := toAddrPointer(&v, ei.isptr)
- b, err = ei.marshaler(b, p, ei.wiretag, deterministic)
- if !nerr.Merge(err) {
- return b, err
- }
- }
- return b, nerr.E
-}
-
-// newMarshaler is the interface representing objects that can marshal themselves.
-//
-// This exists to support protoc-gen-go generated messages.
-// The proto package will stop type-asserting to this interface in the future.
-//
-// DO NOT DEPEND ON THIS.
-type newMarshaler interface {
- XXX_Size() int
- XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
-}
-
-// Size returns the encoded size of a protocol buffer message.
-// This is the main entry point.
-func Size(pb Message) int {
- if m, ok := pb.(newMarshaler); ok {
- return m.XXX_Size()
- }
- if m, ok := pb.(Marshaler); ok {
- // If the message can marshal itself, let it do it, for compatibility.
- // NOTE: This is not efficient.
- b, _ := m.Marshal()
- return len(b)
- }
- // in case somehow we didn't generate the wrapper
- if pb == nil {
- return 0
- }
- var info InternalMessageInfo
- return info.Size(pb)
-}
-
-// Marshal takes a protocol buffer message
-// and encodes it into the wire format, returning the data.
-// This is the main entry point.
-func Marshal(pb Message) ([]byte, error) {
- if m, ok := pb.(newMarshaler); ok {
- siz := m.XXX_Size()
- b := make([]byte, 0, siz)
- return m.XXX_Marshal(b, false)
- }
- if m, ok := pb.(Marshaler); ok {
- // If the message can marshal itself, let it do it, for compatibility.
- // NOTE: This is not efficient.
- return m.Marshal()
- }
- // in case somehow we didn't generate the wrapper
- if pb == nil {
- return nil, ErrNil
- }
- var info InternalMessageInfo
- siz := info.Size(pb)
- b := make([]byte, 0, siz)
- return info.Marshal(b, pb, false)
-}
-
-// Marshal takes a protocol buffer message
-// and encodes it into the wire format, writing the result to the
-// Buffer.
-// This is an alternative entry point. It is not necessary to use
-// a Buffer for most applications.
-func (p *Buffer) Marshal(pb Message) error {
- var err error
- if m, ok := pb.(newMarshaler); ok {
- siz := m.XXX_Size()
- p.grow(siz) // make sure buf has enough capacity
- p.buf, err = m.XXX_Marshal(p.buf, p.deterministic)
- return err
- }
- if m, ok := pb.(Marshaler); ok {
- // If the message can marshal itself, let it do it, for compatibility.
- // NOTE: This is not efficient.
- b, err := m.Marshal()
- p.buf = append(p.buf, b...)
- return err
- }
- // in case somehow we didn't generate the wrapper
- if pb == nil {
- return ErrNil
- }
- var info InternalMessageInfo
- siz := info.Size(pb)
- p.grow(siz) // make sure buf has enough capacity
- p.buf, err = info.Marshal(p.buf, pb, p.deterministic)
- return err
-}
-
-// grow grows the buffer's capacity, if necessary, to guarantee space for
-// another n bytes. After grow(n), at least n bytes can be written to the
-// buffer without another allocation.
-func (p *Buffer) grow(n int) {
- need := len(p.buf) + n
- if need <= cap(p.buf) {
- return
- }
- newCap := len(p.buf) * 2
- if newCap < need {
- newCap = need
- }
- p.buf = append(make([]byte, 0, newCap), p.buf...)
-}
diff --git a/vendor/github.com/golang/protobuf/proto/table_merge.go b/vendor/github.com/golang/protobuf/proto/table_merge.go
deleted file mode 100644
index 5525def..0000000
--- a/vendor/github.com/golang/protobuf/proto/table_merge.go
+++ /dev/null
@@ -1,654 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2016 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-import (
- "fmt"
- "reflect"
- "strings"
- "sync"
- "sync/atomic"
-)
-
-// Merge merges the src message into dst.
-// This assumes that dst and src of the same type and are non-nil.
-func (a *InternalMessageInfo) Merge(dst, src Message) {
- mi := atomicLoadMergeInfo(&a.merge)
- if mi == nil {
- mi = getMergeInfo(reflect.TypeOf(dst).Elem())
- atomicStoreMergeInfo(&a.merge, mi)
- }
- mi.merge(toPointer(&dst), toPointer(&src))
-}
-
-type mergeInfo struct {
- typ reflect.Type
-
- initialized int32 // 0: only typ is valid, 1: everything is valid
- lock sync.Mutex
-
- fields []mergeFieldInfo
- unrecognized field // Offset of XXX_unrecognized
-}
-
-type mergeFieldInfo struct {
- field field // Offset of field, guaranteed to be valid
-
- // isPointer reports whether the value in the field is a pointer.
- // This is true for the following situations:
- // * Pointer to struct
- // * Pointer to basic type (proto2 only)
- // * Slice (first value in slice header is a pointer)
- // * String (first value in string header is a pointer)
- isPointer bool
-
- // basicWidth reports the width of the field assuming that it is directly
- // embedded in the struct (as is the case for basic types in proto3).
- // The possible values are:
- // 0: invalid
- // 1: bool
- // 4: int32, uint32, float32
- // 8: int64, uint64, float64
- basicWidth int
-
- // Where dst and src are pointers to the types being merged.
- merge func(dst, src pointer)
-}
-
-var (
- mergeInfoMap = map[reflect.Type]*mergeInfo{}
- mergeInfoLock sync.Mutex
-)
-
-func getMergeInfo(t reflect.Type) *mergeInfo {
- mergeInfoLock.Lock()
- defer mergeInfoLock.Unlock()
- mi := mergeInfoMap[t]
- if mi == nil {
- mi = &mergeInfo{typ: t}
- mergeInfoMap[t] = mi
- }
- return mi
-}
-
-// merge merges src into dst assuming they are both of type *mi.typ.
-func (mi *mergeInfo) merge(dst, src pointer) {
- if dst.isNil() {
- panic("proto: nil destination")
- }
- if src.isNil() {
- return // Nothing to do.
- }
-
- if atomic.LoadInt32(&mi.initialized) == 0 {
- mi.computeMergeInfo()
- }
-
- for _, fi := range mi.fields {
- sfp := src.offset(fi.field)
-
- // As an optimization, we can avoid the merge function call cost
- // if we know for sure that the source will have no effect
- // by checking if it is the zero value.
- if unsafeAllowed {
- if fi.isPointer && sfp.getPointer().isNil() { // Could be slice or string
- continue
- }
- if fi.basicWidth > 0 {
- switch {
- case fi.basicWidth == 1 && !*sfp.toBool():
- continue
- case fi.basicWidth == 4 && *sfp.toUint32() == 0:
- continue
- case fi.basicWidth == 8 && *sfp.toUint64() == 0:
- continue
- }
- }
- }
-
- dfp := dst.offset(fi.field)
- fi.merge(dfp, sfp)
- }
-
- // TODO: Make this faster?
- out := dst.asPointerTo(mi.typ).Elem()
- in := src.asPointerTo(mi.typ).Elem()
- if emIn, err := extendable(in.Addr().Interface()); err == nil {
- emOut, _ := extendable(out.Addr().Interface())
- mIn, muIn := emIn.extensionsRead()
- if mIn != nil {
- mOut := emOut.extensionsWrite()
- muIn.Lock()
- mergeExtension(mOut, mIn)
- muIn.Unlock()
- }
- }
-
- if mi.unrecognized.IsValid() {
- if b := *src.offset(mi.unrecognized).toBytes(); len(b) > 0 {
- *dst.offset(mi.unrecognized).toBytes() = append([]byte(nil), b...)
- }
- }
-}
-
-func (mi *mergeInfo) computeMergeInfo() {
- mi.lock.Lock()
- defer mi.lock.Unlock()
- if mi.initialized != 0 {
- return
- }
- t := mi.typ
- n := t.NumField()
-
- props := GetProperties(t)
- for i := 0; i < n; i++ {
- f := t.Field(i)
- if strings.HasPrefix(f.Name, "XXX_") {
- continue
- }
-
- mfi := mergeFieldInfo{field: toField(&f)}
- tf := f.Type
-
- // As an optimization, we can avoid the merge function call cost
- // if we know for sure that the source will have no effect
- // by checking if it is the zero value.
- if unsafeAllowed {
- switch tf.Kind() {
- case reflect.Ptr, reflect.Slice, reflect.String:
- // As a special case, we assume slices and strings are pointers
- // since we know that the first field in the SliceSlice or
- // StringHeader is a data pointer.
- mfi.isPointer = true
- case reflect.Bool:
- mfi.basicWidth = 1
- case reflect.Int32, reflect.Uint32, reflect.Float32:
- mfi.basicWidth = 4
- case reflect.Int64, reflect.Uint64, reflect.Float64:
- mfi.basicWidth = 8
- }
- }
-
- // Unwrap tf to get at its most basic type.
- var isPointer, isSlice bool
- if tf.Kind() == reflect.Slice && tf.Elem().Kind() != reflect.Uint8 {
- isSlice = true
- tf = tf.Elem()
- }
- if tf.Kind() == reflect.Ptr {
- isPointer = true
- tf = tf.Elem()
- }
- if isPointer && isSlice && tf.Kind() != reflect.Struct {
- panic("both pointer and slice for basic type in " + tf.Name())
- }
-
- switch tf.Kind() {
- case reflect.Int32:
- switch {
- case isSlice: // E.g., []int32
- mfi.merge = func(dst, src pointer) {
- // NOTE: toInt32Slice is not defined (see pointer_reflect.go).
- /*
- sfsp := src.toInt32Slice()
- if *sfsp != nil {
- dfsp := dst.toInt32Slice()
- *dfsp = append(*dfsp, *sfsp...)
- if *dfsp == nil {
- *dfsp = []int64{}
- }
- }
- */
- sfs := src.getInt32Slice()
- if sfs != nil {
- dfs := dst.getInt32Slice()
- dfs = append(dfs, sfs...)
- if dfs == nil {
- dfs = []int32{}
- }
- dst.setInt32Slice(dfs)
- }
- }
- case isPointer: // E.g., *int32
- mfi.merge = func(dst, src pointer) {
- // NOTE: toInt32Ptr is not defined (see pointer_reflect.go).
- /*
- sfpp := src.toInt32Ptr()
- if *sfpp != nil {
- dfpp := dst.toInt32Ptr()
- if *dfpp == nil {
- *dfpp = Int32(**sfpp)
- } else {
- **dfpp = **sfpp
- }
- }
- */
- sfp := src.getInt32Ptr()
- if sfp != nil {
- dfp := dst.getInt32Ptr()
- if dfp == nil {
- dst.setInt32Ptr(*sfp)
- } else {
- *dfp = *sfp
- }
- }
- }
- default: // E.g., int32
- mfi.merge = func(dst, src pointer) {
- if v := *src.toInt32(); v != 0 {
- *dst.toInt32() = v
- }
- }
- }
- case reflect.Int64:
- switch {
- case isSlice: // E.g., []int64
- mfi.merge = func(dst, src pointer) {
- sfsp := src.toInt64Slice()
- if *sfsp != nil {
- dfsp := dst.toInt64Slice()
- *dfsp = append(*dfsp, *sfsp...)
- if *dfsp == nil {
- *dfsp = []int64{}
- }
- }
- }
- case isPointer: // E.g., *int64
- mfi.merge = func(dst, src pointer) {
- sfpp := src.toInt64Ptr()
- if *sfpp != nil {
- dfpp := dst.toInt64Ptr()
- if *dfpp == nil {
- *dfpp = Int64(**sfpp)
- } else {
- **dfpp = **sfpp
- }
- }
- }
- default: // E.g., int64
- mfi.merge = func(dst, src pointer) {
- if v := *src.toInt64(); v != 0 {
- *dst.toInt64() = v
- }
- }
- }
- case reflect.Uint32:
- switch {
- case isSlice: // E.g., []uint32
- mfi.merge = func(dst, src pointer) {
- sfsp := src.toUint32Slice()
- if *sfsp != nil {
- dfsp := dst.toUint32Slice()
- *dfsp = append(*dfsp, *sfsp...)
- if *dfsp == nil {
- *dfsp = []uint32{}
- }
- }
- }
- case isPointer: // E.g., *uint32
- mfi.merge = func(dst, src pointer) {
- sfpp := src.toUint32Ptr()
- if *sfpp != nil {
- dfpp := dst.toUint32Ptr()
- if *dfpp == nil {
- *dfpp = Uint32(**sfpp)
- } else {
- **dfpp = **sfpp
- }
- }
- }
- default: // E.g., uint32
- mfi.merge = func(dst, src pointer) {
- if v := *src.toUint32(); v != 0 {
- *dst.toUint32() = v
- }
- }
- }
- case reflect.Uint64:
- switch {
- case isSlice: // E.g., []uint64
- mfi.merge = func(dst, src pointer) {
- sfsp := src.toUint64Slice()
- if *sfsp != nil {
- dfsp := dst.toUint64Slice()
- *dfsp = append(*dfsp, *sfsp...)
- if *dfsp == nil {
- *dfsp = []uint64{}
- }
- }
- }
- case isPointer: // E.g., *uint64
- mfi.merge = func(dst, src pointer) {
- sfpp := src.toUint64Ptr()
- if *sfpp != nil {
- dfpp := dst.toUint64Ptr()
- if *dfpp == nil {
- *dfpp = Uint64(**sfpp)
- } else {
- **dfpp = **sfpp
- }
- }
- }
- default: // E.g., uint64
- mfi.merge = func(dst, src pointer) {
- if v := *src.toUint64(); v != 0 {
- *dst.toUint64() = v
- }
- }
- }
- case reflect.Float32:
- switch {
- case isSlice: // E.g., []float32
- mfi.merge = func(dst, src pointer) {
- sfsp := src.toFloat32Slice()
- if *sfsp != nil {
- dfsp := dst.toFloat32Slice()
- *dfsp = append(*dfsp, *sfsp...)
- if *dfsp == nil {
- *dfsp = []float32{}
- }
- }
- }
- case isPointer: // E.g., *float32
- mfi.merge = func(dst, src pointer) {
- sfpp := src.toFloat32Ptr()
- if *sfpp != nil {
- dfpp := dst.toFloat32Ptr()
- if *dfpp == nil {
- *dfpp = Float32(**sfpp)
- } else {
- **dfpp = **sfpp
- }
- }
- }
- default: // E.g., float32
- mfi.merge = func(dst, src pointer) {
- if v := *src.toFloat32(); v != 0 {
- *dst.toFloat32() = v
- }
- }
- }
- case reflect.Float64:
- switch {
- case isSlice: // E.g., []float64
- mfi.merge = func(dst, src pointer) {
- sfsp := src.toFloat64Slice()
- if *sfsp != nil {
- dfsp := dst.toFloat64Slice()
- *dfsp = append(*dfsp, *sfsp...)
- if *dfsp == nil {
- *dfsp = []float64{}
- }
- }
- }
- case isPointer: // E.g., *float64
- mfi.merge = func(dst, src pointer) {
- sfpp := src.toFloat64Ptr()
- if *sfpp != nil {
- dfpp := dst.toFloat64Ptr()
- if *dfpp == nil {
- *dfpp = Float64(**sfpp)
- } else {
- **dfpp = **sfpp
- }
- }
- }
- default: // E.g., float64
- mfi.merge = func(dst, src pointer) {
- if v := *src.toFloat64(); v != 0 {
- *dst.toFloat64() = v
- }
- }
- }
- case reflect.Bool:
- switch {
- case isSlice: // E.g., []bool
- mfi.merge = func(dst, src pointer) {
- sfsp := src.toBoolSlice()
- if *sfsp != nil {
- dfsp := dst.toBoolSlice()
- *dfsp = append(*dfsp, *sfsp...)
- if *dfsp == nil {
- *dfsp = []bool{}
- }
- }
- }
- case isPointer: // E.g., *bool
- mfi.merge = func(dst, src pointer) {
- sfpp := src.toBoolPtr()
- if *sfpp != nil {
- dfpp := dst.toBoolPtr()
- if *dfpp == nil {
- *dfpp = Bool(**sfpp)
- } else {
- **dfpp = **sfpp
- }
- }
- }
- default: // E.g., bool
- mfi.merge = func(dst, src pointer) {
- if v := *src.toBool(); v {
- *dst.toBool() = v
- }
- }
- }
- case reflect.String:
- switch {
- case isSlice: // E.g., []string
- mfi.merge = func(dst, src pointer) {
- sfsp := src.toStringSlice()
- if *sfsp != nil {
- dfsp := dst.toStringSlice()
- *dfsp = append(*dfsp, *sfsp...)
- if *dfsp == nil {
- *dfsp = []string{}
- }
- }
- }
- case isPointer: // E.g., *string
- mfi.merge = func(dst, src pointer) {
- sfpp := src.toStringPtr()
- if *sfpp != nil {
- dfpp := dst.toStringPtr()
- if *dfpp == nil {
- *dfpp = String(**sfpp)
- } else {
- **dfpp = **sfpp
- }
- }
- }
- default: // E.g., string
- mfi.merge = func(dst, src pointer) {
- if v := *src.toString(); v != "" {
- *dst.toString() = v
- }
- }
- }
- case reflect.Slice:
- isProto3 := props.Prop[i].proto3
- switch {
- case isPointer:
- panic("bad pointer in byte slice case in " + tf.Name())
- case tf.Elem().Kind() != reflect.Uint8:
- panic("bad element kind in byte slice case in " + tf.Name())
- case isSlice: // E.g., [][]byte
- mfi.merge = func(dst, src pointer) {
- sbsp := src.toBytesSlice()
- if *sbsp != nil {
- dbsp := dst.toBytesSlice()
- for _, sb := range *sbsp {
- if sb == nil {
- *dbsp = append(*dbsp, nil)
- } else {
- *dbsp = append(*dbsp, append([]byte{}, sb...))
- }
- }
- if *dbsp == nil {
- *dbsp = [][]byte{}
- }
- }
- }
- default: // E.g., []byte
- mfi.merge = func(dst, src pointer) {
- sbp := src.toBytes()
- if *sbp != nil {
- dbp := dst.toBytes()
- if !isProto3 || len(*sbp) > 0 {
- *dbp = append([]byte{}, *sbp...)
- }
- }
- }
- }
- case reflect.Struct:
- switch {
- case !isPointer:
- panic(fmt.Sprintf("message field %s without pointer", tf))
- case isSlice: // E.g., []*pb.T
- mi := getMergeInfo(tf)
- mfi.merge = func(dst, src pointer) {
- sps := src.getPointerSlice()
- if sps != nil {
- dps := dst.getPointerSlice()
- for _, sp := range sps {
- var dp pointer
- if !sp.isNil() {
- dp = valToPointer(reflect.New(tf))
- mi.merge(dp, sp)
- }
- dps = append(dps, dp)
- }
- if dps == nil {
- dps = []pointer{}
- }
- dst.setPointerSlice(dps)
- }
- }
- default: // E.g., *pb.T
- mi := getMergeInfo(tf)
- mfi.merge = func(dst, src pointer) {
- sp := src.getPointer()
- if !sp.isNil() {
- dp := dst.getPointer()
- if dp.isNil() {
- dp = valToPointer(reflect.New(tf))
- dst.setPointer(dp)
- }
- mi.merge(dp, sp)
- }
- }
- }
- case reflect.Map:
- switch {
- case isPointer || isSlice:
- panic("bad pointer or slice in map case in " + tf.Name())
- default: // E.g., map[K]V
- mfi.merge = func(dst, src pointer) {
- sm := src.asPointerTo(tf).Elem()
- if sm.Len() == 0 {
- return
- }
- dm := dst.asPointerTo(tf).Elem()
- if dm.IsNil() {
- dm.Set(reflect.MakeMap(tf))
- }
-
- switch tf.Elem().Kind() {
- case reflect.Ptr: // Proto struct (e.g., *T)
- for _, key := range sm.MapKeys() {
- val := sm.MapIndex(key)
- val = reflect.ValueOf(Clone(val.Interface().(Message)))
- dm.SetMapIndex(key, val)
- }
- case reflect.Slice: // E.g. Bytes type (e.g., []byte)
- for _, key := range sm.MapKeys() {
- val := sm.MapIndex(key)
- val = reflect.ValueOf(append([]byte{}, val.Bytes()...))
- dm.SetMapIndex(key, val)
- }
- default: // Basic type (e.g., string)
- for _, key := range sm.MapKeys() {
- val := sm.MapIndex(key)
- dm.SetMapIndex(key, val)
- }
- }
- }
- }
- case reflect.Interface:
- // Must be oneof field.
- switch {
- case isPointer || isSlice:
- panic("bad pointer or slice in interface case in " + tf.Name())
- default: // E.g., interface{}
- // TODO: Make this faster?
- mfi.merge = func(dst, src pointer) {
- su := src.asPointerTo(tf).Elem()
- if !su.IsNil() {
- du := dst.asPointerTo(tf).Elem()
- typ := su.Elem().Type()
- if du.IsNil() || du.Elem().Type() != typ {
- du.Set(reflect.New(typ.Elem())) // Initialize interface if empty
- }
- sv := su.Elem().Elem().Field(0)
- if sv.Kind() == reflect.Ptr && sv.IsNil() {
- return
- }
- dv := du.Elem().Elem().Field(0)
- if dv.Kind() == reflect.Ptr && dv.IsNil() {
- dv.Set(reflect.New(sv.Type().Elem())) // Initialize proto message if empty
- }
- switch sv.Type().Kind() {
- case reflect.Ptr: // Proto struct (e.g., *T)
- Merge(dv.Interface().(Message), sv.Interface().(Message))
- case reflect.Slice: // E.g. Bytes type (e.g., []byte)
- dv.Set(reflect.ValueOf(append([]byte{}, sv.Bytes()...)))
- default: // Basic type (e.g., string)
- dv.Set(sv)
- }
- }
- }
- }
- default:
- panic(fmt.Sprintf("merger not found for type:%s", tf))
- }
- mi.fields = append(mi.fields, mfi)
- }
-
- mi.unrecognized = invalidField
- if f, ok := t.FieldByName("XXX_unrecognized"); ok {
- if f.Type != reflect.TypeOf([]byte{}) {
- panic("expected XXX_unrecognized to be of type []byte")
- }
- mi.unrecognized = toField(&f)
- }
-
- atomic.StoreInt32(&mi.initialized, 1)
-}
diff --git a/vendor/github.com/golang/protobuf/proto/table_unmarshal.go b/vendor/github.com/golang/protobuf/proto/table_unmarshal.go
deleted file mode 100644
index ebf1caa..0000000
--- a/vendor/github.com/golang/protobuf/proto/table_unmarshal.go
+++ /dev/null
@@ -1,2051 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2016 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-import (
- "errors"
- "fmt"
- "io"
- "math"
- "reflect"
- "strconv"
- "strings"
- "sync"
- "sync/atomic"
- "unicode/utf8"
-)
-
-// Unmarshal is the entry point from the generated .pb.go files.
-// This function is not intended to be used by non-generated code.
-// This function is not subject to any compatibility guarantee.
-// msg contains a pointer to a protocol buffer struct.
-// b is the data to be unmarshaled into the protocol buffer.
-// a is a pointer to a place to store cached unmarshal information.
-func (a *InternalMessageInfo) Unmarshal(msg Message, b []byte) error {
- // Load the unmarshal information for this message type.
- // The atomic load ensures memory consistency.
- u := atomicLoadUnmarshalInfo(&a.unmarshal)
- if u == nil {
- // Slow path: find unmarshal info for msg, update a with it.
- u = getUnmarshalInfo(reflect.TypeOf(msg).Elem())
- atomicStoreUnmarshalInfo(&a.unmarshal, u)
- }
- // Then do the unmarshaling.
- err := u.unmarshal(toPointer(&msg), b)
- return err
-}
-
-type unmarshalInfo struct {
- typ reflect.Type // type of the protobuf struct
-
- // 0 = only typ field is initialized
- // 1 = completely initialized
- initialized int32
- lock sync.Mutex // prevents double initialization
- dense []unmarshalFieldInfo // fields indexed by tag #
- sparse map[uint64]unmarshalFieldInfo // fields indexed by tag #
- reqFields []string // names of required fields
- reqMask uint64 // 1< 0 {
- // Read tag and wire type.
- // Special case 1 and 2 byte varints.
- var x uint64
- if b[0] < 128 {
- x = uint64(b[0])
- b = b[1:]
- } else if len(b) >= 2 && b[1] < 128 {
- x = uint64(b[0]&0x7f) + uint64(b[1])<<7
- b = b[2:]
- } else {
- var n int
- x, n = decodeVarint(b)
- if n == 0 {
- return io.ErrUnexpectedEOF
- }
- b = b[n:]
- }
- tag := x >> 3
- wire := int(x) & 7
-
- // Dispatch on the tag to one of the unmarshal* functions below.
- var f unmarshalFieldInfo
- if tag < uint64(len(u.dense)) {
- f = u.dense[tag]
- } else {
- f = u.sparse[tag]
- }
- if fn := f.unmarshal; fn != nil {
- var err error
- b, err = fn(b, m.offset(f.field), wire)
- if err == nil {
- reqMask |= f.reqMask
- continue
- }
- if r, ok := err.(*RequiredNotSetError); ok {
- // Remember this error, but keep parsing. We need to produce
- // a full parse even if a required field is missing.
- if errLater == nil {
- errLater = r
- }
- reqMask |= f.reqMask
- continue
- }
- if err != errInternalBadWireType {
- if err == errInvalidUTF8 {
- if errLater == nil {
- fullName := revProtoTypes[reflect.PtrTo(u.typ)] + "." + f.name
- errLater = &invalidUTF8Error{fullName}
- }
- continue
- }
- return err
- }
- // Fragments with bad wire type are treated as unknown fields.
- }
-
- // Unknown tag.
- if !u.unrecognized.IsValid() {
- // Don't keep unrecognized data; just skip it.
- var err error
- b, err = skipField(b, wire)
- if err != nil {
- return err
- }
- continue
- }
- // Keep unrecognized data around.
- // maybe in extensions, maybe in the unrecognized field.
- z := m.offset(u.unrecognized).toBytes()
- var emap map[int32]Extension
- var e Extension
- for _, r := range u.extensionRanges {
- if uint64(r.Start) <= tag && tag <= uint64(r.End) {
- if u.extensions.IsValid() {
- mp := m.offset(u.extensions).toExtensions()
- emap = mp.extensionsWrite()
- e = emap[int32(tag)]
- z = &e.enc
- break
- }
- if u.oldExtensions.IsValid() {
- p := m.offset(u.oldExtensions).toOldExtensions()
- emap = *p
- if emap == nil {
- emap = map[int32]Extension{}
- *p = emap
- }
- e = emap[int32(tag)]
- z = &e.enc
- break
- }
- panic("no extensions field available")
- }
- }
-
- // Use wire type to skip data.
- var err error
- b0 := b
- b, err = skipField(b, wire)
- if err != nil {
- return err
- }
- *z = encodeVarint(*z, tag<<3|uint64(wire))
- *z = append(*z, b0[:len(b0)-len(b)]...)
-
- if emap != nil {
- emap[int32(tag)] = e
- }
- }
- if reqMask != u.reqMask && errLater == nil {
- // A required field of this message is missing.
- for _, n := range u.reqFields {
- if reqMask&1 == 0 {
- errLater = &RequiredNotSetError{n}
- }
- reqMask >>= 1
- }
- }
- return errLater
-}
-
-// computeUnmarshalInfo fills in u with information for use
-// in unmarshaling protocol buffers of type u.typ.
-func (u *unmarshalInfo) computeUnmarshalInfo() {
- u.lock.Lock()
- defer u.lock.Unlock()
- if u.initialized != 0 {
- return
- }
- t := u.typ
- n := t.NumField()
-
- // Set up the "not found" value for the unrecognized byte buffer.
- // This is the default for proto3.
- u.unrecognized = invalidField
- u.extensions = invalidField
- u.oldExtensions = invalidField
-
- // List of the generated type and offset for each oneof field.
- type oneofField struct {
- ityp reflect.Type // interface type of oneof field
- field field // offset in containing message
- }
- var oneofFields []oneofField
-
- for i := 0; i < n; i++ {
- f := t.Field(i)
- if f.Name == "XXX_unrecognized" {
- // The byte slice used to hold unrecognized input is special.
- if f.Type != reflect.TypeOf(([]byte)(nil)) {
- panic("bad type for XXX_unrecognized field: " + f.Type.Name())
- }
- u.unrecognized = toField(&f)
- continue
- }
- if f.Name == "XXX_InternalExtensions" {
- // Ditto here.
- if f.Type != reflect.TypeOf(XXX_InternalExtensions{}) {
- panic("bad type for XXX_InternalExtensions field: " + f.Type.Name())
- }
- u.extensions = toField(&f)
- if f.Tag.Get("protobuf_messageset") == "1" {
- u.isMessageSet = true
- }
- continue
- }
- if f.Name == "XXX_extensions" {
- // An older form of the extensions field.
- if f.Type != reflect.TypeOf((map[int32]Extension)(nil)) {
- panic("bad type for XXX_extensions field: " + f.Type.Name())
- }
- u.oldExtensions = toField(&f)
- continue
- }
- if f.Name == "XXX_NoUnkeyedLiteral" || f.Name == "XXX_sizecache" {
- continue
- }
-
- oneof := f.Tag.Get("protobuf_oneof")
- if oneof != "" {
- oneofFields = append(oneofFields, oneofField{f.Type, toField(&f)})
- // The rest of oneof processing happens below.
- continue
- }
-
- tags := f.Tag.Get("protobuf")
- tagArray := strings.Split(tags, ",")
- if len(tagArray) < 2 {
- panic("protobuf tag not enough fields in " + t.Name() + "." + f.Name + ": " + tags)
- }
- tag, err := strconv.Atoi(tagArray[1])
- if err != nil {
- panic("protobuf tag field not an integer: " + tagArray[1])
- }
-
- name := ""
- for _, tag := range tagArray[3:] {
- if strings.HasPrefix(tag, "name=") {
- name = tag[5:]
- }
- }
-
- // Extract unmarshaling function from the field (its type and tags).
- unmarshal := fieldUnmarshaler(&f)
-
- // Required field?
- var reqMask uint64
- if tagArray[2] == "req" {
- bit := len(u.reqFields)
- u.reqFields = append(u.reqFields, name)
- reqMask = uint64(1) << uint(bit)
- // TODO: if we have more than 64 required fields, we end up
- // not verifying that all required fields are present.
- // Fix this, perhaps using a count of required fields?
- }
-
- // Store the info in the correct slot in the message.
- u.setTag(tag, toField(&f), unmarshal, reqMask, name)
- }
-
- // Find any types associated with oneof fields.
- // TODO: XXX_OneofFuncs returns more info than we need. Get rid of some of it?
- fn := reflect.Zero(reflect.PtrTo(t)).MethodByName("XXX_OneofFuncs")
- if fn.IsValid() {
- res := fn.Call(nil)[3] // last return value from XXX_OneofFuncs: []interface{}
- for i := res.Len() - 1; i >= 0; i-- {
- v := res.Index(i) // interface{}
- tptr := reflect.ValueOf(v.Interface()).Type() // *Msg_X
- typ := tptr.Elem() // Msg_X
-
- f := typ.Field(0) // oneof implementers have one field
- baseUnmarshal := fieldUnmarshaler(&f)
- tags := strings.Split(f.Tag.Get("protobuf"), ",")
- fieldNum, err := strconv.Atoi(tags[1])
- if err != nil {
- panic("protobuf tag field not an integer: " + tags[1])
- }
- var name string
- for _, tag := range tags {
- if strings.HasPrefix(tag, "name=") {
- name = strings.TrimPrefix(tag, "name=")
- break
- }
- }
-
- // Find the oneof field that this struct implements.
- // Might take O(n^2) to process all of the oneofs, but who cares.
- for _, of := range oneofFields {
- if tptr.Implements(of.ityp) {
- // We have found the corresponding interface for this struct.
- // That lets us know where this struct should be stored
- // when we encounter it during unmarshaling.
- unmarshal := makeUnmarshalOneof(typ, of.ityp, baseUnmarshal)
- u.setTag(fieldNum, of.field, unmarshal, 0, name)
- }
- }
- }
- }
-
- // Get extension ranges, if any.
- fn = reflect.Zero(reflect.PtrTo(t)).MethodByName("ExtensionRangeArray")
- if fn.IsValid() {
- if !u.extensions.IsValid() && !u.oldExtensions.IsValid() {
- panic("a message with extensions, but no extensions field in " + t.Name())
- }
- u.extensionRanges = fn.Call(nil)[0].Interface().([]ExtensionRange)
- }
-
- // Explicitly disallow tag 0. This will ensure we flag an error
- // when decoding a buffer of all zeros. Without this code, we
- // would decode and skip an all-zero buffer of even length.
- // [0 0] is [tag=0/wiretype=varint varint-encoded-0].
- u.setTag(0, zeroField, func(b []byte, f pointer, w int) ([]byte, error) {
- return nil, fmt.Errorf("proto: %s: illegal tag 0 (wire type %d)", t, w)
- }, 0, "")
-
- // Set mask for required field check.
- u.reqMask = uint64(1)<= 0 && (tag < 16 || tag < 2*n) { // TODO: what are the right numbers here?
- for len(u.dense) <= tag {
- u.dense = append(u.dense, unmarshalFieldInfo{})
- }
- u.dense[tag] = i
- return
- }
- if u.sparse == nil {
- u.sparse = map[uint64]unmarshalFieldInfo{}
- }
- u.sparse[uint64(tag)] = i
-}
-
-// fieldUnmarshaler returns an unmarshaler for the given field.
-func fieldUnmarshaler(f *reflect.StructField) unmarshaler {
- if f.Type.Kind() == reflect.Map {
- return makeUnmarshalMap(f)
- }
- return typeUnmarshaler(f.Type, f.Tag.Get("protobuf"))
-}
-
-// typeUnmarshaler returns an unmarshaler for the given field type / field tag pair.
-func typeUnmarshaler(t reflect.Type, tags string) unmarshaler {
- tagArray := strings.Split(tags, ",")
- encoding := tagArray[0]
- name := "unknown"
- proto3 := false
- validateUTF8 := true
- for _, tag := range tagArray[3:] {
- if strings.HasPrefix(tag, "name=") {
- name = tag[5:]
- }
- if tag == "proto3" {
- proto3 = true
- }
- }
- validateUTF8 = validateUTF8 && proto3
-
- // Figure out packaging (pointer, slice, or both)
- slice := false
- pointer := false
- if t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8 {
- slice = true
- t = t.Elem()
- }
- if t.Kind() == reflect.Ptr {
- pointer = true
- t = t.Elem()
- }
-
- // We'll never have both pointer and slice for basic types.
- if pointer && slice && t.Kind() != reflect.Struct {
- panic("both pointer and slice for basic type in " + t.Name())
- }
-
- switch t.Kind() {
- case reflect.Bool:
- if pointer {
- return unmarshalBoolPtr
- }
- if slice {
- return unmarshalBoolSlice
- }
- return unmarshalBoolValue
- case reflect.Int32:
- switch encoding {
- case "fixed32":
- if pointer {
- return unmarshalFixedS32Ptr
- }
- if slice {
- return unmarshalFixedS32Slice
- }
- return unmarshalFixedS32Value
- case "varint":
- // this could be int32 or enum
- if pointer {
- return unmarshalInt32Ptr
- }
- if slice {
- return unmarshalInt32Slice
- }
- return unmarshalInt32Value
- case "zigzag32":
- if pointer {
- return unmarshalSint32Ptr
- }
- if slice {
- return unmarshalSint32Slice
- }
- return unmarshalSint32Value
- }
- case reflect.Int64:
- switch encoding {
- case "fixed64":
- if pointer {
- return unmarshalFixedS64Ptr
- }
- if slice {
- return unmarshalFixedS64Slice
- }
- return unmarshalFixedS64Value
- case "varint":
- if pointer {
- return unmarshalInt64Ptr
- }
- if slice {
- return unmarshalInt64Slice
- }
- return unmarshalInt64Value
- case "zigzag64":
- if pointer {
- return unmarshalSint64Ptr
- }
- if slice {
- return unmarshalSint64Slice
- }
- return unmarshalSint64Value
- }
- case reflect.Uint32:
- switch encoding {
- case "fixed32":
- if pointer {
- return unmarshalFixed32Ptr
- }
- if slice {
- return unmarshalFixed32Slice
- }
- return unmarshalFixed32Value
- case "varint":
- if pointer {
- return unmarshalUint32Ptr
- }
- if slice {
- return unmarshalUint32Slice
- }
- return unmarshalUint32Value
- }
- case reflect.Uint64:
- switch encoding {
- case "fixed64":
- if pointer {
- return unmarshalFixed64Ptr
- }
- if slice {
- return unmarshalFixed64Slice
- }
- return unmarshalFixed64Value
- case "varint":
- if pointer {
- return unmarshalUint64Ptr
- }
- if slice {
- return unmarshalUint64Slice
- }
- return unmarshalUint64Value
- }
- case reflect.Float32:
- if pointer {
- return unmarshalFloat32Ptr
- }
- if slice {
- return unmarshalFloat32Slice
- }
- return unmarshalFloat32Value
- case reflect.Float64:
- if pointer {
- return unmarshalFloat64Ptr
- }
- if slice {
- return unmarshalFloat64Slice
- }
- return unmarshalFloat64Value
- case reflect.Map:
- panic("map type in typeUnmarshaler in " + t.Name())
- case reflect.Slice:
- if pointer {
- panic("bad pointer in slice case in " + t.Name())
- }
- if slice {
- return unmarshalBytesSlice
- }
- return unmarshalBytesValue
- case reflect.String:
- if validateUTF8 {
- if pointer {
- return unmarshalUTF8StringPtr
- }
- if slice {
- return unmarshalUTF8StringSlice
- }
- return unmarshalUTF8StringValue
- }
- if pointer {
- return unmarshalStringPtr
- }
- if slice {
- return unmarshalStringSlice
- }
- return unmarshalStringValue
- case reflect.Struct:
- // message or group field
- if !pointer {
- panic(fmt.Sprintf("message/group field %s:%s without pointer", t, encoding))
- }
- switch encoding {
- case "bytes":
- if slice {
- return makeUnmarshalMessageSlicePtr(getUnmarshalInfo(t), name)
- }
- return makeUnmarshalMessagePtr(getUnmarshalInfo(t), name)
- case "group":
- if slice {
- return makeUnmarshalGroupSlicePtr(getUnmarshalInfo(t), name)
- }
- return makeUnmarshalGroupPtr(getUnmarshalInfo(t), name)
- }
- }
- panic(fmt.Sprintf("unmarshaler not found type:%s encoding:%s", t, encoding))
-}
-
-// Below are all the unmarshalers for individual fields of various types.
-
-func unmarshalInt64Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int64(x)
- *f.toInt64() = v
- return b, nil
-}
-
-func unmarshalInt64Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int64(x)
- *f.toInt64Ptr() = &v
- return b, nil
-}
-
-func unmarshalInt64Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- x, n = decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int64(x)
- s := f.toInt64Slice()
- *s = append(*s, v)
- }
- return res, nil
- }
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int64(x)
- s := f.toInt64Slice()
- *s = append(*s, v)
- return b, nil
-}
-
-func unmarshalSint64Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int64(x>>1) ^ int64(x)<<63>>63
- *f.toInt64() = v
- return b, nil
-}
-
-func unmarshalSint64Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int64(x>>1) ^ int64(x)<<63>>63
- *f.toInt64Ptr() = &v
- return b, nil
-}
-
-func unmarshalSint64Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- x, n = decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int64(x>>1) ^ int64(x)<<63>>63
- s := f.toInt64Slice()
- *s = append(*s, v)
- }
- return res, nil
- }
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int64(x>>1) ^ int64(x)<<63>>63
- s := f.toInt64Slice()
- *s = append(*s, v)
- return b, nil
-}
-
-func unmarshalUint64Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := uint64(x)
- *f.toUint64() = v
- return b, nil
-}
-
-func unmarshalUint64Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := uint64(x)
- *f.toUint64Ptr() = &v
- return b, nil
-}
-
-func unmarshalUint64Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- x, n = decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := uint64(x)
- s := f.toUint64Slice()
- *s = append(*s, v)
- }
- return res, nil
- }
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := uint64(x)
- s := f.toUint64Slice()
- *s = append(*s, v)
- return b, nil
-}
-
-func unmarshalInt32Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int32(x)
- *f.toInt32() = v
- return b, nil
-}
-
-func unmarshalInt32Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int32(x)
- f.setInt32Ptr(v)
- return b, nil
-}
-
-func unmarshalInt32Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- x, n = decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int32(x)
- f.appendInt32Slice(v)
- }
- return res, nil
- }
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int32(x)
- f.appendInt32Slice(v)
- return b, nil
-}
-
-func unmarshalSint32Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int32(x>>1) ^ int32(x)<<31>>31
- *f.toInt32() = v
- return b, nil
-}
-
-func unmarshalSint32Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int32(x>>1) ^ int32(x)<<31>>31
- f.setInt32Ptr(v)
- return b, nil
-}
-
-func unmarshalSint32Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- x, n = decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int32(x>>1) ^ int32(x)<<31>>31
- f.appendInt32Slice(v)
- }
- return res, nil
- }
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := int32(x>>1) ^ int32(x)<<31>>31
- f.appendInt32Slice(v)
- return b, nil
-}
-
-func unmarshalUint32Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := uint32(x)
- *f.toUint32() = v
- return b, nil
-}
-
-func unmarshalUint32Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := uint32(x)
- *f.toUint32Ptr() = &v
- return b, nil
-}
-
-func unmarshalUint32Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- x, n = decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := uint32(x)
- s := f.toUint32Slice()
- *s = append(*s, v)
- }
- return res, nil
- }
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- v := uint32(x)
- s := f.toUint32Slice()
- *s = append(*s, v)
- return b, nil
-}
-
-func unmarshalFixed64Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed64 {
- return b, errInternalBadWireType
- }
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
- *f.toUint64() = v
- return b[8:], nil
-}
-
-func unmarshalFixed64Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed64 {
- return b, errInternalBadWireType
- }
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
- *f.toUint64Ptr() = &v
- return b[8:], nil
-}
-
-func unmarshalFixed64Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
- s := f.toUint64Slice()
- *s = append(*s, v)
- b = b[8:]
- }
- return res, nil
- }
- if w != WireFixed64 {
- return b, errInternalBadWireType
- }
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56
- s := f.toUint64Slice()
- *s = append(*s, v)
- return b[8:], nil
-}
-
-func unmarshalFixedS64Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed64 {
- return b, errInternalBadWireType
- }
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56
- *f.toInt64() = v
- return b[8:], nil
-}
-
-func unmarshalFixedS64Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed64 {
- return b, errInternalBadWireType
- }
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56
- *f.toInt64Ptr() = &v
- return b[8:], nil
-}
-
-func unmarshalFixedS64Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56
- s := f.toInt64Slice()
- *s = append(*s, v)
- b = b[8:]
- }
- return res, nil
- }
- if w != WireFixed64 {
- return b, errInternalBadWireType
- }
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56
- s := f.toInt64Slice()
- *s = append(*s, v)
- return b[8:], nil
-}
-
-func unmarshalFixed32Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed32 {
- return b, errInternalBadWireType
- }
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
- *f.toUint32() = v
- return b[4:], nil
-}
-
-func unmarshalFixed32Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed32 {
- return b, errInternalBadWireType
- }
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
- *f.toUint32Ptr() = &v
- return b[4:], nil
-}
-
-func unmarshalFixed32Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
- s := f.toUint32Slice()
- *s = append(*s, v)
- b = b[4:]
- }
- return res, nil
- }
- if w != WireFixed32 {
- return b, errInternalBadWireType
- }
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
- s := f.toUint32Slice()
- *s = append(*s, v)
- return b[4:], nil
-}
-
-func unmarshalFixedS32Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed32 {
- return b, errInternalBadWireType
- }
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24
- *f.toInt32() = v
- return b[4:], nil
-}
-
-func unmarshalFixedS32Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed32 {
- return b, errInternalBadWireType
- }
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24
- f.setInt32Ptr(v)
- return b[4:], nil
-}
-
-func unmarshalFixedS32Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24
- f.appendInt32Slice(v)
- b = b[4:]
- }
- return res, nil
- }
- if w != WireFixed32 {
- return b, errInternalBadWireType
- }
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24
- f.appendInt32Slice(v)
- return b[4:], nil
-}
-
-func unmarshalBoolValue(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- // Note: any length varint is allowed, even though any sane
- // encoder will use one byte.
- // See https://github.com/golang/protobuf/issues/76
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- // TODO: check if x>1? Tests seem to indicate no.
- v := x != 0
- *f.toBool() = v
- return b[n:], nil
-}
-
-func unmarshalBoolPtr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- v := x != 0
- *f.toBoolPtr() = &v
- return b[n:], nil
-}
-
-func unmarshalBoolSlice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- x, n = decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- v := x != 0
- s := f.toBoolSlice()
- *s = append(*s, v)
- b = b[n:]
- }
- return res, nil
- }
- if w != WireVarint {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- v := x != 0
- s := f.toBoolSlice()
- *s = append(*s, v)
- return b[n:], nil
-}
-
-func unmarshalFloat64Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed64 {
- return b, errInternalBadWireType
- }
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := math.Float64frombits(uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56)
- *f.toFloat64() = v
- return b[8:], nil
-}
-
-func unmarshalFloat64Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed64 {
- return b, errInternalBadWireType
- }
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := math.Float64frombits(uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56)
- *f.toFloat64Ptr() = &v
- return b[8:], nil
-}
-
-func unmarshalFloat64Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := math.Float64frombits(uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56)
- s := f.toFloat64Slice()
- *s = append(*s, v)
- b = b[8:]
- }
- return res, nil
- }
- if w != WireFixed64 {
- return b, errInternalBadWireType
- }
- if len(b) < 8 {
- return nil, io.ErrUnexpectedEOF
- }
- v := math.Float64frombits(uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56)
- s := f.toFloat64Slice()
- *s = append(*s, v)
- return b[8:], nil
-}
-
-func unmarshalFloat32Value(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed32 {
- return b, errInternalBadWireType
- }
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := math.Float32frombits(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
- *f.toFloat32() = v
- return b[4:], nil
-}
-
-func unmarshalFloat32Ptr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireFixed32 {
- return b, errInternalBadWireType
- }
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := math.Float32frombits(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
- *f.toFloat32Ptr() = &v
- return b[4:], nil
-}
-
-func unmarshalFloat32Slice(b []byte, f pointer, w int) ([]byte, error) {
- if w == WireBytes { // packed
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- res := b[x:]
- b = b[:x]
- for len(b) > 0 {
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := math.Float32frombits(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
- s := f.toFloat32Slice()
- *s = append(*s, v)
- b = b[4:]
- }
- return res, nil
- }
- if w != WireFixed32 {
- return b, errInternalBadWireType
- }
- if len(b) < 4 {
- return nil, io.ErrUnexpectedEOF
- }
- v := math.Float32frombits(uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24)
- s := f.toFloat32Slice()
- *s = append(*s, v)
- return b[4:], nil
-}
-
-func unmarshalStringValue(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- v := string(b[:x])
- *f.toString() = v
- return b[x:], nil
-}
-
-func unmarshalStringPtr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- v := string(b[:x])
- *f.toStringPtr() = &v
- return b[x:], nil
-}
-
-func unmarshalStringSlice(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- v := string(b[:x])
- s := f.toStringSlice()
- *s = append(*s, v)
- return b[x:], nil
-}
-
-func unmarshalUTF8StringValue(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- v := string(b[:x])
- *f.toString() = v
- if !utf8.ValidString(v) {
- return b[x:], errInvalidUTF8
- }
- return b[x:], nil
-}
-
-func unmarshalUTF8StringPtr(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- v := string(b[:x])
- *f.toStringPtr() = &v
- if !utf8.ValidString(v) {
- return b[x:], errInvalidUTF8
- }
- return b[x:], nil
-}
-
-func unmarshalUTF8StringSlice(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- v := string(b[:x])
- s := f.toStringSlice()
- *s = append(*s, v)
- if !utf8.ValidString(v) {
- return b[x:], errInvalidUTF8
- }
- return b[x:], nil
-}
-
-var emptyBuf [0]byte
-
-func unmarshalBytesValue(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- // The use of append here is a trick which avoids the zeroing
- // that would be required if we used a make/copy pair.
- // We append to emptyBuf instead of nil because we want
- // a non-nil result even when the length is 0.
- v := append(emptyBuf[:], b[:x]...)
- *f.toBytes() = v
- return b[x:], nil
-}
-
-func unmarshalBytesSlice(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- v := append(emptyBuf[:], b[:x]...)
- s := f.toBytesSlice()
- *s = append(*s, v)
- return b[x:], nil
-}
-
-func makeUnmarshalMessagePtr(sub *unmarshalInfo, name string) unmarshaler {
- return func(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- // First read the message field to see if something is there.
- // The semantics of multiple submessages are weird. Instead of
- // the last one winning (as it is for all other fields), multiple
- // submessages are merged.
- v := f.getPointer()
- if v.isNil() {
- v = valToPointer(reflect.New(sub.typ))
- f.setPointer(v)
- }
- err := sub.unmarshal(v, b[:x])
- if err != nil {
- if r, ok := err.(*RequiredNotSetError); ok {
- r.field = name + "." + r.field
- } else {
- return nil, err
- }
- }
- return b[x:], err
- }
-}
-
-func makeUnmarshalMessageSlicePtr(sub *unmarshalInfo, name string) unmarshaler {
- return func(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireBytes {
- return b, errInternalBadWireType
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- v := valToPointer(reflect.New(sub.typ))
- err := sub.unmarshal(v, b[:x])
- if err != nil {
- if r, ok := err.(*RequiredNotSetError); ok {
- r.field = name + "." + r.field
- } else {
- return nil, err
- }
- }
- f.appendPointer(v)
- return b[x:], err
- }
-}
-
-func makeUnmarshalGroupPtr(sub *unmarshalInfo, name string) unmarshaler {
- return func(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireStartGroup {
- return b, errInternalBadWireType
- }
- x, y := findEndGroup(b)
- if x < 0 {
- return nil, io.ErrUnexpectedEOF
- }
- v := f.getPointer()
- if v.isNil() {
- v = valToPointer(reflect.New(sub.typ))
- f.setPointer(v)
- }
- err := sub.unmarshal(v, b[:x])
- if err != nil {
- if r, ok := err.(*RequiredNotSetError); ok {
- r.field = name + "." + r.field
- } else {
- return nil, err
- }
- }
- return b[y:], err
- }
-}
-
-func makeUnmarshalGroupSlicePtr(sub *unmarshalInfo, name string) unmarshaler {
- return func(b []byte, f pointer, w int) ([]byte, error) {
- if w != WireStartGroup {
- return b, errInternalBadWireType
- }
- x, y := findEndGroup(b)
- if x < 0 {
- return nil, io.ErrUnexpectedEOF
- }
- v := valToPointer(reflect.New(sub.typ))
- err := sub.unmarshal(v, b[:x])
- if err != nil {
- if r, ok := err.(*RequiredNotSetError); ok {
- r.field = name + "." + r.field
- } else {
- return nil, err
- }
- }
- f.appendPointer(v)
- return b[y:], err
- }
-}
-
-func makeUnmarshalMap(f *reflect.StructField) unmarshaler {
- t := f.Type
- kt := t.Key()
- vt := t.Elem()
- unmarshalKey := typeUnmarshaler(kt, f.Tag.Get("protobuf_key"))
- unmarshalVal := typeUnmarshaler(vt, f.Tag.Get("protobuf_val"))
- return func(b []byte, f pointer, w int) ([]byte, error) {
- // The map entry is a submessage. Figure out how big it is.
- if w != WireBytes {
- return nil, fmt.Errorf("proto: bad wiretype for map field: got %d want %d", w, WireBytes)
- }
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- b = b[n:]
- if x > uint64(len(b)) {
- return nil, io.ErrUnexpectedEOF
- }
- r := b[x:] // unused data to return
- b = b[:x] // data for map entry
-
- // Note: we could use #keys * #values ~= 200 functions
- // to do map decoding without reflection. Probably not worth it.
- // Maps will be somewhat slow. Oh well.
-
- // Read key and value from data.
- var nerr nonFatal
- k := reflect.New(kt)
- v := reflect.New(vt)
- for len(b) > 0 {
- x, n := decodeVarint(b)
- if n == 0 {
- return nil, io.ErrUnexpectedEOF
- }
- wire := int(x) & 7
- b = b[n:]
-
- var err error
- switch x >> 3 {
- case 1:
- b, err = unmarshalKey(b, valToPointer(k), wire)
- case 2:
- b, err = unmarshalVal(b, valToPointer(v), wire)
- default:
- err = errInternalBadWireType // skip unknown tag
- }
-
- if nerr.Merge(err) {
- continue
- }
- if err != errInternalBadWireType {
- return nil, err
- }
-
- // Skip past unknown fields.
- b, err = skipField(b, wire)
- if err != nil {
- return nil, err
- }
- }
-
- // Get map, allocate if needed.
- m := f.asPointerTo(t).Elem() // an addressable map[K]T
- if m.IsNil() {
- m.Set(reflect.MakeMap(t))
- }
-
- // Insert into map.
- m.SetMapIndex(k.Elem(), v.Elem())
-
- return r, nerr.E
- }
-}
-
-// makeUnmarshalOneof makes an unmarshaler for oneof fields.
-// for:
-// message Msg {
-// oneof F {
-// int64 X = 1;
-// float64 Y = 2;
-// }
-// }
-// typ is the type of the concrete entry for a oneof case (e.g. Msg_X).
-// ityp is the interface type of the oneof field (e.g. isMsg_F).
-// unmarshal is the unmarshaler for the base type of the oneof case (e.g. int64).
-// Note that this function will be called once for each case in the oneof.
-func makeUnmarshalOneof(typ, ityp reflect.Type, unmarshal unmarshaler) unmarshaler {
- sf := typ.Field(0)
- field0 := toField(&sf)
- return func(b []byte, f pointer, w int) ([]byte, error) {
- // Allocate holder for value.
- v := reflect.New(typ)
-
- // Unmarshal data into holder.
- // We unmarshal into the first field of the holder object.
- var err error
- var nerr nonFatal
- b, err = unmarshal(b, valToPointer(v).offset(field0), w)
- if !nerr.Merge(err) {
- return nil, err
- }
-
- // Write pointer to holder into target field.
- f.asPointerTo(ityp).Elem().Set(v)
-
- return b, nerr.E
- }
-}
-
-// Error used by decode internally.
-var errInternalBadWireType = errors.New("proto: internal error: bad wiretype")
-
-// skipField skips past a field of type wire and returns the remaining bytes.
-func skipField(b []byte, wire int) ([]byte, error) {
- switch wire {
- case WireVarint:
- _, k := decodeVarint(b)
- if k == 0 {
- return b, io.ErrUnexpectedEOF
- }
- b = b[k:]
- case WireFixed32:
- if len(b) < 4 {
- return b, io.ErrUnexpectedEOF
- }
- b = b[4:]
- case WireFixed64:
- if len(b) < 8 {
- return b, io.ErrUnexpectedEOF
- }
- b = b[8:]
- case WireBytes:
- m, k := decodeVarint(b)
- if k == 0 || uint64(len(b)-k) < m {
- return b, io.ErrUnexpectedEOF
- }
- b = b[uint64(k)+m:]
- case WireStartGroup:
- _, i := findEndGroup(b)
- if i == -1 {
- return b, io.ErrUnexpectedEOF
- }
- b = b[i:]
- default:
- return b, fmt.Errorf("proto: can't skip unknown wire type %d", wire)
- }
- return b, nil
-}
-
-// findEndGroup finds the index of the next EndGroup tag.
-// Groups may be nested, so the "next" EndGroup tag is the first
-// unpaired EndGroup.
-// findEndGroup returns the indexes of the start and end of the EndGroup tag.
-// Returns (-1,-1) if it can't find one.
-func findEndGroup(b []byte) (int, int) {
- depth := 1
- i := 0
- for {
- x, n := decodeVarint(b[i:])
- if n == 0 {
- return -1, -1
- }
- j := i
- i += n
- switch x & 7 {
- case WireVarint:
- _, k := decodeVarint(b[i:])
- if k == 0 {
- return -1, -1
- }
- i += k
- case WireFixed32:
- if len(b)-4 < i {
- return -1, -1
- }
- i += 4
- case WireFixed64:
- if len(b)-8 < i {
- return -1, -1
- }
- i += 8
- case WireBytes:
- m, k := decodeVarint(b[i:])
- if k == 0 {
- return -1, -1
- }
- i += k
- if uint64(len(b)-i) < m {
- return -1, -1
- }
- i += int(m)
- case WireStartGroup:
- depth++
- case WireEndGroup:
- depth--
- if depth == 0 {
- return j, i
- }
- default:
- return -1, -1
- }
- }
-}
-
-// encodeVarint appends a varint-encoded integer to b and returns the result.
-func encodeVarint(b []byte, x uint64) []byte {
- for x >= 1<<7 {
- b = append(b, byte(x&0x7f|0x80))
- x >>= 7
- }
- return append(b, byte(x))
-}
-
-// decodeVarint reads a varint-encoded integer from b.
-// Returns the decoded integer and the number of bytes read.
-// If there is an error, it returns 0,0.
-func decodeVarint(b []byte) (uint64, int) {
- var x, y uint64
- if len(b) <= 0 {
- goto bad
- }
- x = uint64(b[0])
- if x < 0x80 {
- return x, 1
- }
- x -= 0x80
-
- if len(b) <= 1 {
- goto bad
- }
- y = uint64(b[1])
- x += y << 7
- if y < 0x80 {
- return x, 2
- }
- x -= 0x80 << 7
-
- if len(b) <= 2 {
- goto bad
- }
- y = uint64(b[2])
- x += y << 14
- if y < 0x80 {
- return x, 3
- }
- x -= 0x80 << 14
-
- if len(b) <= 3 {
- goto bad
- }
- y = uint64(b[3])
- x += y << 21
- if y < 0x80 {
- return x, 4
- }
- x -= 0x80 << 21
-
- if len(b) <= 4 {
- goto bad
- }
- y = uint64(b[4])
- x += y << 28
- if y < 0x80 {
- return x, 5
- }
- x -= 0x80 << 28
-
- if len(b) <= 5 {
- goto bad
- }
- y = uint64(b[5])
- x += y << 35
- if y < 0x80 {
- return x, 6
- }
- x -= 0x80 << 35
-
- if len(b) <= 6 {
- goto bad
- }
- y = uint64(b[6])
- x += y << 42
- if y < 0x80 {
- return x, 7
- }
- x -= 0x80 << 42
-
- if len(b) <= 7 {
- goto bad
- }
- y = uint64(b[7])
- x += y << 49
- if y < 0x80 {
- return x, 8
- }
- x -= 0x80 << 49
-
- if len(b) <= 8 {
- goto bad
- }
- y = uint64(b[8])
- x += y << 56
- if y < 0x80 {
- return x, 9
- }
- x -= 0x80 << 56
-
- if len(b) <= 9 {
- goto bad
- }
- y = uint64(b[9])
- x += y << 63
- if y < 2 {
- return x, 10
- }
-
-bad:
- return 0, 0
-}
diff --git a/vendor/github.com/golang/protobuf/proto/text.go b/vendor/github.com/golang/protobuf/proto/text.go
deleted file mode 100644
index 1aaee72..0000000
--- a/vendor/github.com/golang/protobuf/proto/text.go
+++ /dev/null
@@ -1,843 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2010 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-// Functions for writing the text protocol buffer format.
-
-import (
- "bufio"
- "bytes"
- "encoding"
- "errors"
- "fmt"
- "io"
- "log"
- "math"
- "reflect"
- "sort"
- "strings"
-)
-
-var (
- newline = []byte("\n")
- spaces = []byte(" ")
- endBraceNewline = []byte("}\n")
- backslashN = []byte{'\\', 'n'}
- backslashR = []byte{'\\', 'r'}
- backslashT = []byte{'\\', 't'}
- backslashDQ = []byte{'\\', '"'}
- backslashBS = []byte{'\\', '\\'}
- posInf = []byte("inf")
- negInf = []byte("-inf")
- nan = []byte("nan")
-)
-
-type writer interface {
- io.Writer
- WriteByte(byte) error
-}
-
-// textWriter is an io.Writer that tracks its indentation level.
-type textWriter struct {
- ind int
- complete bool // if the current position is a complete line
- compact bool // whether to write out as a one-liner
- w writer
-}
-
-func (w *textWriter) WriteString(s string) (n int, err error) {
- if !strings.Contains(s, "\n") {
- if !w.compact && w.complete {
- w.writeIndent()
- }
- w.complete = false
- return io.WriteString(w.w, s)
- }
- // WriteString is typically called without newlines, so this
- // codepath and its copy are rare. We copy to avoid
- // duplicating all of Write's logic here.
- return w.Write([]byte(s))
-}
-
-func (w *textWriter) Write(p []byte) (n int, err error) {
- newlines := bytes.Count(p, newline)
- if newlines == 0 {
- if !w.compact && w.complete {
- w.writeIndent()
- }
- n, err = w.w.Write(p)
- w.complete = false
- return n, err
- }
-
- frags := bytes.SplitN(p, newline, newlines+1)
- if w.compact {
- for i, frag := range frags {
- if i > 0 {
- if err := w.w.WriteByte(' '); err != nil {
- return n, err
- }
- n++
- }
- nn, err := w.w.Write(frag)
- n += nn
- if err != nil {
- return n, err
- }
- }
- return n, nil
- }
-
- for i, frag := range frags {
- if w.complete {
- w.writeIndent()
- }
- nn, err := w.w.Write(frag)
- n += nn
- if err != nil {
- return n, err
- }
- if i+1 < len(frags) {
- if err := w.w.WriteByte('\n'); err != nil {
- return n, err
- }
- n++
- }
- }
- w.complete = len(frags[len(frags)-1]) == 0
- return n, nil
-}
-
-func (w *textWriter) WriteByte(c byte) error {
- if w.compact && c == '\n' {
- c = ' '
- }
- if !w.compact && w.complete {
- w.writeIndent()
- }
- err := w.w.WriteByte(c)
- w.complete = c == '\n'
- return err
-}
-
-func (w *textWriter) indent() { w.ind++ }
-
-func (w *textWriter) unindent() {
- if w.ind == 0 {
- log.Print("proto: textWriter unindented too far")
- return
- }
- w.ind--
-}
-
-func writeName(w *textWriter, props *Properties) error {
- if _, err := w.WriteString(props.OrigName); err != nil {
- return err
- }
- if props.Wire != "group" {
- return w.WriteByte(':')
- }
- return nil
-}
-
-func requiresQuotes(u string) bool {
- // When type URL contains any characters except [0-9A-Za-z./\-]*, it must be quoted.
- for _, ch := range u {
- switch {
- case ch == '.' || ch == '/' || ch == '_':
- continue
- case '0' <= ch && ch <= '9':
- continue
- case 'A' <= ch && ch <= 'Z':
- continue
- case 'a' <= ch && ch <= 'z':
- continue
- default:
- return true
- }
- }
- return false
-}
-
-// isAny reports whether sv is a google.protobuf.Any message
-func isAny(sv reflect.Value) bool {
- type wkt interface {
- XXX_WellKnownType() string
- }
- t, ok := sv.Addr().Interface().(wkt)
- return ok && t.XXX_WellKnownType() == "Any"
-}
-
-// writeProto3Any writes an expanded google.protobuf.Any message.
-//
-// It returns (false, nil) if sv value can't be unmarshaled (e.g. because
-// required messages are not linked in).
-//
-// It returns (true, error) when sv was written in expanded format or an error
-// was encountered.
-func (tm *TextMarshaler) writeProto3Any(w *textWriter, sv reflect.Value) (bool, error) {
- turl := sv.FieldByName("TypeUrl")
- val := sv.FieldByName("Value")
- if !turl.IsValid() || !val.IsValid() {
- return true, errors.New("proto: invalid google.protobuf.Any message")
- }
-
- b, ok := val.Interface().([]byte)
- if !ok {
- return true, errors.New("proto: invalid google.protobuf.Any message")
- }
-
- parts := strings.Split(turl.String(), "/")
- mt := MessageType(parts[len(parts)-1])
- if mt == nil {
- return false, nil
- }
- m := reflect.New(mt.Elem())
- if err := Unmarshal(b, m.Interface().(Message)); err != nil {
- return false, nil
- }
- w.Write([]byte("["))
- u := turl.String()
- if requiresQuotes(u) {
- writeString(w, u)
- } else {
- w.Write([]byte(u))
- }
- if w.compact {
- w.Write([]byte("]:<"))
- } else {
- w.Write([]byte("]: <\n"))
- w.ind++
- }
- if err := tm.writeStruct(w, m.Elem()); err != nil {
- return true, err
- }
- if w.compact {
- w.Write([]byte("> "))
- } else {
- w.ind--
- w.Write([]byte(">\n"))
- }
- return true, nil
-}
-
-func (tm *TextMarshaler) writeStruct(w *textWriter, sv reflect.Value) error {
- if tm.ExpandAny && isAny(sv) {
- if canExpand, err := tm.writeProto3Any(w, sv); canExpand {
- return err
- }
- }
- st := sv.Type()
- sprops := GetProperties(st)
- for i := 0; i < sv.NumField(); i++ {
- fv := sv.Field(i)
- props := sprops.Prop[i]
- name := st.Field(i).Name
-
- if name == "XXX_NoUnkeyedLiteral" {
- continue
- }
-
- if strings.HasPrefix(name, "XXX_") {
- // There are two XXX_ fields:
- // XXX_unrecognized []byte
- // XXX_extensions map[int32]proto.Extension
- // The first is handled here;
- // the second is handled at the bottom of this function.
- if name == "XXX_unrecognized" && !fv.IsNil() {
- if err := writeUnknownStruct(w, fv.Interface().([]byte)); err != nil {
- return err
- }
- }
- continue
- }
- if fv.Kind() == reflect.Ptr && fv.IsNil() {
- // Field not filled in. This could be an optional field or
- // a required field that wasn't filled in. Either way, there
- // isn't anything we can show for it.
- continue
- }
- if fv.Kind() == reflect.Slice && fv.IsNil() {
- // Repeated field that is empty, or a bytes field that is unused.
- continue
- }
-
- if props.Repeated && fv.Kind() == reflect.Slice {
- // Repeated field.
- for j := 0; j < fv.Len(); j++ {
- if err := writeName(w, props); err != nil {
- return err
- }
- if !w.compact {
- if err := w.WriteByte(' '); err != nil {
- return err
- }
- }
- v := fv.Index(j)
- if v.Kind() == reflect.Ptr && v.IsNil() {
- // A nil message in a repeated field is not valid,
- // but we can handle that more gracefully than panicking.
- if _, err := w.Write([]byte("\n")); err != nil {
- return err
- }
- continue
- }
- if err := tm.writeAny(w, v, props); err != nil {
- return err
- }
- if err := w.WriteByte('\n'); err != nil {
- return err
- }
- }
- continue
- }
- if fv.Kind() == reflect.Map {
- // Map fields are rendered as a repeated struct with key/value fields.
- keys := fv.MapKeys()
- sort.Sort(mapKeys(keys))
- for _, key := range keys {
- val := fv.MapIndex(key)
- if err := writeName(w, props); err != nil {
- return err
- }
- if !w.compact {
- if err := w.WriteByte(' '); err != nil {
- return err
- }
- }
- // open struct
- if err := w.WriteByte('<'); err != nil {
- return err
- }
- if !w.compact {
- if err := w.WriteByte('\n'); err != nil {
- return err
- }
- }
- w.indent()
- // key
- if _, err := w.WriteString("key:"); err != nil {
- return err
- }
- if !w.compact {
- if err := w.WriteByte(' '); err != nil {
- return err
- }
- }
- if err := tm.writeAny(w, key, props.MapKeyProp); err != nil {
- return err
- }
- if err := w.WriteByte('\n'); err != nil {
- return err
- }
- // nil values aren't legal, but we can avoid panicking because of them.
- if val.Kind() != reflect.Ptr || !val.IsNil() {
- // value
- if _, err := w.WriteString("value:"); err != nil {
- return err
- }
- if !w.compact {
- if err := w.WriteByte(' '); err != nil {
- return err
- }
- }
- if err := tm.writeAny(w, val, props.MapValProp); err != nil {
- return err
- }
- if err := w.WriteByte('\n'); err != nil {
- return err
- }
- }
- // close struct
- w.unindent()
- if err := w.WriteByte('>'); err != nil {
- return err
- }
- if err := w.WriteByte('\n'); err != nil {
- return err
- }
- }
- continue
- }
- if props.proto3 && fv.Kind() == reflect.Slice && fv.Len() == 0 {
- // empty bytes field
- continue
- }
- if fv.Kind() != reflect.Ptr && fv.Kind() != reflect.Slice {
- // proto3 non-repeated scalar field; skip if zero value
- if isProto3Zero(fv) {
- continue
- }
- }
-
- if fv.Kind() == reflect.Interface {
- // Check if it is a oneof.
- if st.Field(i).Tag.Get("protobuf_oneof") != "" {
- // fv is nil, or holds a pointer to generated struct.
- // That generated struct has exactly one field,
- // which has a protobuf struct tag.
- if fv.IsNil() {
- continue
- }
- inner := fv.Elem().Elem() // interface -> *T -> T
- tag := inner.Type().Field(0).Tag.Get("protobuf")
- props = new(Properties) // Overwrite the outer props var, but not its pointee.
- props.Parse(tag)
- // Write the value in the oneof, not the oneof itself.
- fv = inner.Field(0)
-
- // Special case to cope with malformed messages gracefully:
- // If the value in the oneof is a nil pointer, don't panic
- // in writeAny.
- if fv.Kind() == reflect.Ptr && fv.IsNil() {
- // Use errors.New so writeAny won't render quotes.
- msg := errors.New("/* nil */")
- fv = reflect.ValueOf(&msg).Elem()
- }
- }
- }
-
- if err := writeName(w, props); err != nil {
- return err
- }
- if !w.compact {
- if err := w.WriteByte(' '); err != nil {
- return err
- }
- }
-
- // Enums have a String method, so writeAny will work fine.
- if err := tm.writeAny(w, fv, props); err != nil {
- return err
- }
-
- if err := w.WriteByte('\n'); err != nil {
- return err
- }
- }
-
- // Extensions (the XXX_extensions field).
- pv := sv.Addr()
- if _, err := extendable(pv.Interface()); err == nil {
- if err := tm.writeExtensions(w, pv); err != nil {
- return err
- }
- }
-
- return nil
-}
-
-// writeAny writes an arbitrary field.
-func (tm *TextMarshaler) writeAny(w *textWriter, v reflect.Value, props *Properties) error {
- v = reflect.Indirect(v)
-
- // Floats have special cases.
- if v.Kind() == reflect.Float32 || v.Kind() == reflect.Float64 {
- x := v.Float()
- var b []byte
- switch {
- case math.IsInf(x, 1):
- b = posInf
- case math.IsInf(x, -1):
- b = negInf
- case math.IsNaN(x):
- b = nan
- }
- if b != nil {
- _, err := w.Write(b)
- return err
- }
- // Other values are handled below.
- }
-
- // We don't attempt to serialise every possible value type; only those
- // that can occur in protocol buffers.
- switch v.Kind() {
- case reflect.Slice:
- // Should only be a []byte; repeated fields are handled in writeStruct.
- if err := writeString(w, string(v.Bytes())); err != nil {
- return err
- }
- case reflect.String:
- if err := writeString(w, v.String()); err != nil {
- return err
- }
- case reflect.Struct:
- // Required/optional group/message.
- var bra, ket byte = '<', '>'
- if props != nil && props.Wire == "group" {
- bra, ket = '{', '}'
- }
- if err := w.WriteByte(bra); err != nil {
- return err
- }
- if !w.compact {
- if err := w.WriteByte('\n'); err != nil {
- return err
- }
- }
- w.indent()
- if v.CanAddr() {
- // Calling v.Interface on a struct causes the reflect package to
- // copy the entire struct. This is racy with the new Marshaler
- // since we atomically update the XXX_sizecache.
- //
- // Thus, we retrieve a pointer to the struct if possible to avoid
- // a race since v.Interface on the pointer doesn't copy the struct.
- //
- // If v is not addressable, then we are not worried about a race
- // since it implies that the binary Marshaler cannot possibly be
- // mutating this value.
- v = v.Addr()
- }
- if etm, ok := v.Interface().(encoding.TextMarshaler); ok {
- text, err := etm.MarshalText()
- if err != nil {
- return err
- }
- if _, err = w.Write(text); err != nil {
- return err
- }
- } else {
- if v.Kind() == reflect.Ptr {
- v = v.Elem()
- }
- if err := tm.writeStruct(w, v); err != nil {
- return err
- }
- }
- w.unindent()
- if err := w.WriteByte(ket); err != nil {
- return err
- }
- default:
- _, err := fmt.Fprint(w, v.Interface())
- return err
- }
- return nil
-}
-
-// equivalent to C's isprint.
-func isprint(c byte) bool {
- return c >= 0x20 && c < 0x7f
-}
-
-// writeString writes a string in the protocol buffer text format.
-// It is similar to strconv.Quote except we don't use Go escape sequences,
-// we treat the string as a byte sequence, and we use octal escapes.
-// These differences are to maintain interoperability with the other
-// languages' implementations of the text format.
-func writeString(w *textWriter, s string) error {
- // use WriteByte here to get any needed indent
- if err := w.WriteByte('"'); err != nil {
- return err
- }
- // Loop over the bytes, not the runes.
- for i := 0; i < len(s); i++ {
- var err error
- // Divergence from C++: we don't escape apostrophes.
- // There's no need to escape them, and the C++ parser
- // copes with a naked apostrophe.
- switch c := s[i]; c {
- case '\n':
- _, err = w.w.Write(backslashN)
- case '\r':
- _, err = w.w.Write(backslashR)
- case '\t':
- _, err = w.w.Write(backslashT)
- case '"':
- _, err = w.w.Write(backslashDQ)
- case '\\':
- _, err = w.w.Write(backslashBS)
- default:
- if isprint(c) {
- err = w.w.WriteByte(c)
- } else {
- _, err = fmt.Fprintf(w.w, "\\%03o", c)
- }
- }
- if err != nil {
- return err
- }
- }
- return w.WriteByte('"')
-}
-
-func writeUnknownStruct(w *textWriter, data []byte) (err error) {
- if !w.compact {
- if _, err := fmt.Fprintf(w, "/* %d unknown bytes */\n", len(data)); err != nil {
- return err
- }
- }
- b := NewBuffer(data)
- for b.index < len(b.buf) {
- x, err := b.DecodeVarint()
- if err != nil {
- _, err := fmt.Fprintf(w, "/* %v */\n", err)
- return err
- }
- wire, tag := x&7, x>>3
- if wire == WireEndGroup {
- w.unindent()
- if _, err := w.Write(endBraceNewline); err != nil {
- return err
- }
- continue
- }
- if _, err := fmt.Fprint(w, tag); err != nil {
- return err
- }
- if wire != WireStartGroup {
- if err := w.WriteByte(':'); err != nil {
- return err
- }
- }
- if !w.compact || wire == WireStartGroup {
- if err := w.WriteByte(' '); err != nil {
- return err
- }
- }
- switch wire {
- case WireBytes:
- buf, e := b.DecodeRawBytes(false)
- if e == nil {
- _, err = fmt.Fprintf(w, "%q", buf)
- } else {
- _, err = fmt.Fprintf(w, "/* %v */", e)
- }
- case WireFixed32:
- x, err = b.DecodeFixed32()
- err = writeUnknownInt(w, x, err)
- case WireFixed64:
- x, err = b.DecodeFixed64()
- err = writeUnknownInt(w, x, err)
- case WireStartGroup:
- err = w.WriteByte('{')
- w.indent()
- case WireVarint:
- x, err = b.DecodeVarint()
- err = writeUnknownInt(w, x, err)
- default:
- _, err = fmt.Fprintf(w, "/* unknown wire type %d */", wire)
- }
- if err != nil {
- return err
- }
- if err = w.WriteByte('\n'); err != nil {
- return err
- }
- }
- return nil
-}
-
-func writeUnknownInt(w *textWriter, x uint64, err error) error {
- if err == nil {
- _, err = fmt.Fprint(w, x)
- } else {
- _, err = fmt.Fprintf(w, "/* %v */", err)
- }
- return err
-}
-
-type int32Slice []int32
-
-func (s int32Slice) Len() int { return len(s) }
-func (s int32Slice) Less(i, j int) bool { return s[i] < s[j] }
-func (s int32Slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
-
-// writeExtensions writes all the extensions in pv.
-// pv is assumed to be a pointer to a protocol message struct that is extendable.
-func (tm *TextMarshaler) writeExtensions(w *textWriter, pv reflect.Value) error {
- emap := extensionMaps[pv.Type().Elem()]
- ep, _ := extendable(pv.Interface())
-
- // Order the extensions by ID.
- // This isn't strictly necessary, but it will give us
- // canonical output, which will also make testing easier.
- m, mu := ep.extensionsRead()
- if m == nil {
- return nil
- }
- mu.Lock()
- ids := make([]int32, 0, len(m))
- for id := range m {
- ids = append(ids, id)
- }
- sort.Sort(int32Slice(ids))
- mu.Unlock()
-
- for _, extNum := range ids {
- ext := m[extNum]
- var desc *ExtensionDesc
- if emap != nil {
- desc = emap[extNum]
- }
- if desc == nil {
- // Unknown extension.
- if err := writeUnknownStruct(w, ext.enc); err != nil {
- return err
- }
- continue
- }
-
- pb, err := GetExtension(ep, desc)
- if err != nil {
- return fmt.Errorf("failed getting extension: %v", err)
- }
-
- // Repeated extensions will appear as a slice.
- if !desc.repeated() {
- if err := tm.writeExtension(w, desc.Name, pb); err != nil {
- return err
- }
- } else {
- v := reflect.ValueOf(pb)
- for i := 0; i < v.Len(); i++ {
- if err := tm.writeExtension(w, desc.Name, v.Index(i).Interface()); err != nil {
- return err
- }
- }
- }
- }
- return nil
-}
-
-func (tm *TextMarshaler) writeExtension(w *textWriter, name string, pb interface{}) error {
- if _, err := fmt.Fprintf(w, "[%s]:", name); err != nil {
- return err
- }
- if !w.compact {
- if err := w.WriteByte(' '); err != nil {
- return err
- }
- }
- if err := tm.writeAny(w, reflect.ValueOf(pb), nil); err != nil {
- return err
- }
- if err := w.WriteByte('\n'); err != nil {
- return err
- }
- return nil
-}
-
-func (w *textWriter) writeIndent() {
- if !w.complete {
- return
- }
- remain := w.ind * 2
- for remain > 0 {
- n := remain
- if n > len(spaces) {
- n = len(spaces)
- }
- w.w.Write(spaces[:n])
- remain -= n
- }
- w.complete = false
-}
-
-// TextMarshaler is a configurable text format marshaler.
-type TextMarshaler struct {
- Compact bool // use compact text format (one line).
- ExpandAny bool // expand google.protobuf.Any messages of known types
-}
-
-// Marshal writes a given protocol buffer in text format.
-// The only errors returned are from w.
-func (tm *TextMarshaler) Marshal(w io.Writer, pb Message) error {
- val := reflect.ValueOf(pb)
- if pb == nil || val.IsNil() {
- w.Write([]byte(""))
- return nil
- }
- var bw *bufio.Writer
- ww, ok := w.(writer)
- if !ok {
- bw = bufio.NewWriter(w)
- ww = bw
- }
- aw := &textWriter{
- w: ww,
- complete: true,
- compact: tm.Compact,
- }
-
- if etm, ok := pb.(encoding.TextMarshaler); ok {
- text, err := etm.MarshalText()
- if err != nil {
- return err
- }
- if _, err = aw.Write(text); err != nil {
- return err
- }
- if bw != nil {
- return bw.Flush()
- }
- return nil
- }
- // Dereference the received pointer so we don't have outer < and >.
- v := reflect.Indirect(val)
- if err := tm.writeStruct(aw, v); err != nil {
- return err
- }
- if bw != nil {
- return bw.Flush()
- }
- return nil
-}
-
-// Text is the same as Marshal, but returns the string directly.
-func (tm *TextMarshaler) Text(pb Message) string {
- var buf bytes.Buffer
- tm.Marshal(&buf, pb)
- return buf.String()
-}
-
-var (
- defaultTextMarshaler = TextMarshaler{}
- compactTextMarshaler = TextMarshaler{Compact: true}
-)
-
-// TODO: consider removing some of the Marshal functions below.
-
-// MarshalText writes a given protocol buffer in text format.
-// The only errors returned are from w.
-func MarshalText(w io.Writer, pb Message) error { return defaultTextMarshaler.Marshal(w, pb) }
-
-// MarshalTextString is the same as MarshalText, but returns the string directly.
-func MarshalTextString(pb Message) string { return defaultTextMarshaler.Text(pb) }
-
-// CompactText writes a given protocol buffer in compact text format (one line).
-func CompactText(w io.Writer, pb Message) error { return compactTextMarshaler.Marshal(w, pb) }
-
-// CompactTextString is the same as CompactText, but returns the string directly.
-func CompactTextString(pb Message) string { return compactTextMarshaler.Text(pb) }
diff --git a/vendor/github.com/golang/protobuf/proto/text_parser.go b/vendor/github.com/golang/protobuf/proto/text_parser.go
deleted file mode 100644
index bb55a3a..0000000
--- a/vendor/github.com/golang/protobuf/proto/text_parser.go
+++ /dev/null
@@ -1,880 +0,0 @@
-// Go support for Protocol Buffers - Google's data interchange format
-//
-// Copyright 2010 The Go Authors. All rights reserved.
-// https://github.com/golang/protobuf
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-package proto
-
-// Functions for parsing the Text protocol buffer format.
-// TODO: message sets.
-
-import (
- "encoding"
- "errors"
- "fmt"
- "reflect"
- "strconv"
- "strings"
- "unicode/utf8"
-)
-
-// Error string emitted when deserializing Any and fields are already set
-const anyRepeatedlyUnpacked = "Any message unpacked multiple times, or %q already set"
-
-type ParseError struct {
- Message string
- Line int // 1-based line number
- Offset int // 0-based byte offset from start of input
-}
-
-func (p *ParseError) Error() string {
- if p.Line == 1 {
- // show offset only for first line
- return fmt.Sprintf("line 1.%d: %v", p.Offset, p.Message)
- }
- return fmt.Sprintf("line %d: %v", p.Line, p.Message)
-}
-
-type token struct {
- value string
- err *ParseError
- line int // line number
- offset int // byte number from start of input, not start of line
- unquoted string // the unquoted version of value, if it was a quoted string
-}
-
-func (t *token) String() string {
- if t.err == nil {
- return fmt.Sprintf("%q (line=%d, offset=%d)", t.value, t.line, t.offset)
- }
- return fmt.Sprintf("parse error: %v", t.err)
-}
-
-type textParser struct {
- s string // remaining input
- done bool // whether the parsing is finished (success or error)
- backed bool // whether back() was called
- offset, line int
- cur token
-}
-
-func newTextParser(s string) *textParser {
- p := new(textParser)
- p.s = s
- p.line = 1
- p.cur.line = 1
- return p
-}
-
-func (p *textParser) errorf(format string, a ...interface{}) *ParseError {
- pe := &ParseError{fmt.Sprintf(format, a...), p.cur.line, p.cur.offset}
- p.cur.err = pe
- p.done = true
- return pe
-}
-
-// Numbers and identifiers are matched by [-+._A-Za-z0-9]
-func isIdentOrNumberChar(c byte) bool {
- switch {
- case 'A' <= c && c <= 'Z', 'a' <= c && c <= 'z':
- return true
- case '0' <= c && c <= '9':
- return true
- }
- switch c {
- case '-', '+', '.', '_':
- return true
- }
- return false
-}
-
-func isWhitespace(c byte) bool {
- switch c {
- case ' ', '\t', '\n', '\r':
- return true
- }
- return false
-}
-
-func isQuote(c byte) bool {
- switch c {
- case '"', '\'':
- return true
- }
- return false
-}
-
-func (p *textParser) skipWhitespace() {
- i := 0
- for i < len(p.s) && (isWhitespace(p.s[i]) || p.s[i] == '#') {
- if p.s[i] == '#' {
- // comment; skip to end of line or input
- for i < len(p.s) && p.s[i] != '\n' {
- i++
- }
- if i == len(p.s) {
- break
- }
- }
- if p.s[i] == '\n' {
- p.line++
- }
- i++
- }
- p.offset += i
- p.s = p.s[i:len(p.s)]
- if len(p.s) == 0 {
- p.done = true
- }
-}
-
-func (p *textParser) advance() {
- // Skip whitespace
- p.skipWhitespace()
- if p.done {
- return
- }
-
- // Start of non-whitespace
- p.cur.err = nil
- p.cur.offset, p.cur.line = p.offset, p.line
- p.cur.unquoted = ""
- switch p.s[0] {
- case '<', '>', '{', '}', ':', '[', ']', ';', ',', '/':
- // Single symbol
- p.cur.value, p.s = p.s[0:1], p.s[1:len(p.s)]
- case '"', '\'':
- // Quoted string
- i := 1
- for i < len(p.s) && p.s[i] != p.s[0] && p.s[i] != '\n' {
- if p.s[i] == '\\' && i+1 < len(p.s) {
- // skip escaped char
- i++
- }
- i++
- }
- if i >= len(p.s) || p.s[i] != p.s[0] {
- p.errorf("unmatched quote")
- return
- }
- unq, err := unquoteC(p.s[1:i], rune(p.s[0]))
- if err != nil {
- p.errorf("invalid quoted string %s: %v", p.s[0:i+1], err)
- return
- }
- p.cur.value, p.s = p.s[0:i+1], p.s[i+1:len(p.s)]
- p.cur.unquoted = unq
- default:
- i := 0
- for i < len(p.s) && isIdentOrNumberChar(p.s[i]) {
- i++
- }
- if i == 0 {
- p.errorf("unexpected byte %#x", p.s[0])
- return
- }
- p.cur.value, p.s = p.s[0:i], p.s[i:len(p.s)]
- }
- p.offset += len(p.cur.value)
-}
-
-var (
- errBadUTF8 = errors.New("proto: bad UTF-8")
-)
-
-func unquoteC(s string, quote rune) (string, error) {
- // This is based on C++'s tokenizer.cc.
- // Despite its name, this is *not* parsing C syntax.
- // For instance, "\0" is an invalid quoted string.
-
- // Avoid allocation in trivial cases.
- simple := true
- for _, r := range s {
- if r == '\\' || r == quote {
- simple = false
- break
- }
- }
- if simple {
- return s, nil
- }
-
- buf := make([]byte, 0, 3*len(s)/2)
- for len(s) > 0 {
- r, n := utf8.DecodeRuneInString(s)
- if r == utf8.RuneError && n == 1 {
- return "", errBadUTF8
- }
- s = s[n:]
- if r != '\\' {
- if r < utf8.RuneSelf {
- buf = append(buf, byte(r))
- } else {
- buf = append(buf, string(r)...)
- }
- continue
- }
-
- ch, tail, err := unescape(s)
- if err != nil {
- return "", err
- }
- buf = append(buf, ch...)
- s = tail
- }
- return string(buf), nil
-}
-
-func unescape(s string) (ch string, tail string, err error) {
- r, n := utf8.DecodeRuneInString(s)
- if r == utf8.RuneError && n == 1 {
- return "", "", errBadUTF8
- }
- s = s[n:]
- switch r {
- case 'a':
- return "\a", s, nil
- case 'b':
- return "\b", s, nil
- case 'f':
- return "\f", s, nil
- case 'n':
- return "\n", s, nil
- case 'r':
- return "\r", s, nil
- case 't':
- return "\t", s, nil
- case 'v':
- return "\v", s, nil
- case '?':
- return "?", s, nil // trigraph workaround
- case '\'', '"', '\\':
- return string(r), s, nil
- case '0', '1', '2', '3', '4', '5', '6', '7':
- if len(s) < 2 {
- return "", "", fmt.Errorf(`\%c requires 2 following digits`, r)
- }
- ss := string(r) + s[:2]
- s = s[2:]
- i, err := strconv.ParseUint(ss, 8, 8)
- if err != nil {
- return "", "", fmt.Errorf(`\%s contains non-octal digits`, ss)
- }
- return string([]byte{byte(i)}), s, nil
- case 'x', 'X', 'u', 'U':
- var n int
- switch r {
- case 'x', 'X':
- n = 2
- case 'u':
- n = 4
- case 'U':
- n = 8
- }
- if len(s) < n {
- return "", "", fmt.Errorf(`\%c requires %d following digits`, r, n)
- }
- ss := s[:n]
- s = s[n:]
- i, err := strconv.ParseUint(ss, 16, 64)
- if err != nil {
- return "", "", fmt.Errorf(`\%c%s contains non-hexadecimal digits`, r, ss)
- }
- if r == 'x' || r == 'X' {
- return string([]byte{byte(i)}), s, nil
- }
- if i > utf8.MaxRune {
- return "", "", fmt.Errorf(`\%c%s is not a valid Unicode code point`, r, ss)
- }
- return string(i), s, nil
- }
- return "", "", fmt.Errorf(`unknown escape \%c`, r)
-}
-
-// Back off the parser by one token. Can only be done between calls to next().
-// It makes the next advance() a no-op.
-func (p *textParser) back() { p.backed = true }
-
-// Advances the parser and returns the new current token.
-func (p *textParser) next() *token {
- if p.backed || p.done {
- p.backed = false
- return &p.cur
- }
- p.advance()
- if p.done {
- p.cur.value = ""
- } else if len(p.cur.value) > 0 && isQuote(p.cur.value[0]) {
- // Look for multiple quoted strings separated by whitespace,
- // and concatenate them.
- cat := p.cur
- for {
- p.skipWhitespace()
- if p.done || !isQuote(p.s[0]) {
- break
- }
- p.advance()
- if p.cur.err != nil {
- return &p.cur
- }
- cat.value += " " + p.cur.value
- cat.unquoted += p.cur.unquoted
- }
- p.done = false // parser may have seen EOF, but we want to return cat
- p.cur = cat
- }
- return &p.cur
-}
-
-func (p *textParser) consumeToken(s string) error {
- tok := p.next()
- if tok.err != nil {
- return tok.err
- }
- if tok.value != s {
- p.back()
- return p.errorf("expected %q, found %q", s, tok.value)
- }
- return nil
-}
-
-// Return a RequiredNotSetError indicating which required field was not set.
-func (p *textParser) missingRequiredFieldError(sv reflect.Value) *RequiredNotSetError {
- st := sv.Type()
- sprops := GetProperties(st)
- for i := 0; i < st.NumField(); i++ {
- if !isNil(sv.Field(i)) {
- continue
- }
-
- props := sprops.Prop[i]
- if props.Required {
- return &RequiredNotSetError{fmt.Sprintf("%v.%v", st, props.OrigName)}
- }
- }
- return &RequiredNotSetError{fmt.Sprintf("%v.", st)} // should not happen
-}
-
-// Returns the index in the struct for the named field, as well as the parsed tag properties.
-func structFieldByName(sprops *StructProperties, name string) (int, *Properties, bool) {
- i, ok := sprops.decoderOrigNames[name]
- if ok {
- return i, sprops.Prop[i], true
- }
- return -1, nil, false
-}
-
-// Consume a ':' from the input stream (if the next token is a colon),
-// returning an error if a colon is needed but not present.
-func (p *textParser) checkForColon(props *Properties, typ reflect.Type) *ParseError {
- tok := p.next()
- if tok.err != nil {
- return tok.err
- }
- if tok.value != ":" {
- // Colon is optional when the field is a group or message.
- needColon := true
- switch props.Wire {
- case "group":
- needColon = false
- case "bytes":
- // A "bytes" field is either a message, a string, or a repeated field;
- // those three become *T, *string and []T respectively, so we can check for
- // this field being a pointer to a non-string.
- if typ.Kind() == reflect.Ptr {
- // *T or *string
- if typ.Elem().Kind() == reflect.String {
- break
- }
- } else if typ.Kind() == reflect.Slice {
- // []T or []*T
- if typ.Elem().Kind() != reflect.Ptr {
- break
- }
- } else if typ.Kind() == reflect.String {
- // The proto3 exception is for a string field,
- // which requires a colon.
- break
- }
- needColon = false
- }
- if needColon {
- return p.errorf("expected ':', found %q", tok.value)
- }
- p.back()
- }
- return nil
-}
-
-func (p *textParser) readStruct(sv reflect.Value, terminator string) error {
- st := sv.Type()
- sprops := GetProperties(st)
- reqCount := sprops.reqCount
- var reqFieldErr error
- fieldSet := make(map[string]bool)
- // A struct is a sequence of "name: value", terminated by one of
- // '>' or '}', or the end of the input. A name may also be
- // "[extension]" or "[type/url]".
- //
- // The whole struct can also be an expanded Any message, like:
- // [type/url] < ... struct contents ... >
- for {
- tok := p.next()
- if tok.err != nil {
- return tok.err
- }
- if tok.value == terminator {
- break
- }
- if tok.value == "[" {
- // Looks like an extension or an Any.
- //
- // TODO: Check whether we need to handle
- // namespace rooted names (e.g. ".something.Foo").
- extName, err := p.consumeExtName()
- if err != nil {
- return err
- }
-
- if s := strings.LastIndex(extName, "/"); s >= 0 {
- // If it contains a slash, it's an Any type URL.
- messageName := extName[s+1:]
- mt := MessageType(messageName)
- if mt == nil {
- return p.errorf("unrecognized message %q in google.protobuf.Any", messageName)
- }
- tok = p.next()
- if tok.err != nil {
- return tok.err
- }
- // consume an optional colon
- if tok.value == ":" {
- tok = p.next()
- if tok.err != nil {
- return tok.err
- }
- }
- var terminator string
- switch tok.value {
- case "<":
- terminator = ">"
- case "{":
- terminator = "}"
- default:
- return p.errorf("expected '{' or '<', found %q", tok.value)
- }
- v := reflect.New(mt.Elem())
- if pe := p.readStruct(v.Elem(), terminator); pe != nil {
- return pe
- }
- b, err := Marshal(v.Interface().(Message))
- if err != nil {
- return p.errorf("failed to marshal message of type %q: %v", messageName, err)
- }
- if fieldSet["type_url"] {
- return p.errorf(anyRepeatedlyUnpacked, "type_url")
- }
- if fieldSet["value"] {
- return p.errorf(anyRepeatedlyUnpacked, "value")
- }
- sv.FieldByName("TypeUrl").SetString(extName)
- sv.FieldByName("Value").SetBytes(b)
- fieldSet["type_url"] = true
- fieldSet["value"] = true
- continue
- }
-
- var desc *ExtensionDesc
- // This could be faster, but it's functional.
- // TODO: Do something smarter than a linear scan.
- for _, d := range RegisteredExtensions(reflect.New(st).Interface().(Message)) {
- if d.Name == extName {
- desc = d
- break
- }
- }
- if desc == nil {
- return p.errorf("unrecognized extension %q", extName)
- }
-
- props := &Properties{}
- props.Parse(desc.Tag)
-
- typ := reflect.TypeOf(desc.ExtensionType)
- if err := p.checkForColon(props, typ); err != nil {
- return err
- }
-
- rep := desc.repeated()
-
- // Read the extension structure, and set it in
- // the value we're constructing.
- var ext reflect.Value
- if !rep {
- ext = reflect.New(typ).Elem()
- } else {
- ext = reflect.New(typ.Elem()).Elem()
- }
- if err := p.readAny(ext, props); err != nil {
- if _, ok := err.(*RequiredNotSetError); !ok {
- return err
- }
- reqFieldErr = err
- }
- ep := sv.Addr().Interface().(Message)
- if !rep {
- SetExtension(ep, desc, ext.Interface())
- } else {
- old, err := GetExtension(ep, desc)
- var sl reflect.Value
- if err == nil {
- sl = reflect.ValueOf(old) // existing slice
- } else {
- sl = reflect.MakeSlice(typ, 0, 1)
- }
- sl = reflect.Append(sl, ext)
- SetExtension(ep, desc, sl.Interface())
- }
- if err := p.consumeOptionalSeparator(); err != nil {
- return err
- }
- continue
- }
-
- // This is a normal, non-extension field.
- name := tok.value
- var dst reflect.Value
- fi, props, ok := structFieldByName(sprops, name)
- if ok {
- dst = sv.Field(fi)
- } else if oop, ok := sprops.OneofTypes[name]; ok {
- // It is a oneof.
- props = oop.Prop
- nv := reflect.New(oop.Type.Elem())
- dst = nv.Elem().Field(0)
- field := sv.Field(oop.Field)
- if !field.IsNil() {
- return p.errorf("field '%s' would overwrite already parsed oneof '%s'", name, sv.Type().Field(oop.Field).Name)
- }
- field.Set(nv)
- }
- if !dst.IsValid() {
- return p.errorf("unknown field name %q in %v", name, st)
- }
-
- if dst.Kind() == reflect.Map {
- // Consume any colon.
- if err := p.checkForColon(props, dst.Type()); err != nil {
- return err
- }
-
- // Construct the map if it doesn't already exist.
- if dst.IsNil() {
- dst.Set(reflect.MakeMap(dst.Type()))
- }
- key := reflect.New(dst.Type().Key()).Elem()
- val := reflect.New(dst.Type().Elem()).Elem()
-
- // The map entry should be this sequence of tokens:
- // < key : KEY value : VALUE >
- // However, implementations may omit key or value, and technically
- // we should support them in any order. See b/28924776 for a time
- // this went wrong.
-
- tok := p.next()
- var terminator string
- switch tok.value {
- case "<":
- terminator = ">"
- case "{":
- terminator = "}"
- default:
- return p.errorf("expected '{' or '<', found %q", tok.value)
- }
- for {
- tok := p.next()
- if tok.err != nil {
- return tok.err
- }
- if tok.value == terminator {
- break
- }
- switch tok.value {
- case "key":
- if err := p.consumeToken(":"); err != nil {
- return err
- }
- if err := p.readAny(key, props.MapKeyProp); err != nil {
- return err
- }
- if err := p.consumeOptionalSeparator(); err != nil {
- return err
- }
- case "value":
- if err := p.checkForColon(props.MapValProp, dst.Type().Elem()); err != nil {
- return err
- }
- if err := p.readAny(val, props.MapValProp); err != nil {
- return err
- }
- if err := p.consumeOptionalSeparator(); err != nil {
- return err
- }
- default:
- p.back()
- return p.errorf(`expected "key", "value", or %q, found %q`, terminator, tok.value)
- }
- }
-
- dst.SetMapIndex(key, val)
- continue
- }
-
- // Check that it's not already set if it's not a repeated field.
- if !props.Repeated && fieldSet[name] {
- return p.errorf("non-repeated field %q was repeated", name)
- }
-
- if err := p.checkForColon(props, dst.Type()); err != nil {
- return err
- }
-
- // Parse into the field.
- fieldSet[name] = true
- if err := p.readAny(dst, props); err != nil {
- if _, ok := err.(*RequiredNotSetError); !ok {
- return err
- }
- reqFieldErr = err
- }
- if props.Required {
- reqCount--
- }
-
- if err := p.consumeOptionalSeparator(); err != nil {
- return err
- }
-
- }
-
- if reqCount > 0 {
- return p.missingRequiredFieldError(sv)
- }
- return reqFieldErr
-}
-
-// consumeExtName consumes extension name or expanded Any type URL and the
-// following ']'. It returns the name or URL consumed.
-func (p *textParser) consumeExtName() (string, error) {
- tok := p.next()
- if tok.err != nil {
- return "", tok.err
- }
-
- // If extension name or type url is quoted, it's a single token.
- if len(tok.value) > 2 && isQuote(tok.value[0]) && tok.value[len(tok.value)-1] == tok.value[0] {
- name, err := unquoteC(tok.value[1:len(tok.value)-1], rune(tok.value[0]))
- if err != nil {
- return "", err
- }
- return name, p.consumeToken("]")
- }
-
- // Consume everything up to "]"
- var parts []string
- for tok.value != "]" {
- parts = append(parts, tok.value)
- tok = p.next()
- if tok.err != nil {
- return "", p.errorf("unrecognized type_url or extension name: %s", tok.err)
- }
- if p.done && tok.value != "]" {
- return "", p.errorf("unclosed type_url or extension name")
- }
- }
- return strings.Join(parts, ""), nil
-}
-
-// consumeOptionalSeparator consumes an optional semicolon or comma.
-// It is used in readStruct to provide backward compatibility.
-func (p *textParser) consumeOptionalSeparator() error {
- tok := p.next()
- if tok.err != nil {
- return tok.err
- }
- if tok.value != ";" && tok.value != "," {
- p.back()
- }
- return nil
-}
-
-func (p *textParser) readAny(v reflect.Value, props *Properties) error {
- tok := p.next()
- if tok.err != nil {
- return tok.err
- }
- if tok.value == "" {
- return p.errorf("unexpected EOF")
- }
-
- switch fv := v; fv.Kind() {
- case reflect.Slice:
- at := v.Type()
- if at.Elem().Kind() == reflect.Uint8 {
- // Special case for []byte
- if tok.value[0] != '"' && tok.value[0] != '\'' {
- // Deliberately written out here, as the error after
- // this switch statement would write "invalid []byte: ...",
- // which is not as user-friendly.
- return p.errorf("invalid string: %v", tok.value)
- }
- bytes := []byte(tok.unquoted)
- fv.Set(reflect.ValueOf(bytes))
- return nil
- }
- // Repeated field.
- if tok.value == "[" {
- // Repeated field with list notation, like [1,2,3].
- for {
- fv.Set(reflect.Append(fv, reflect.New(at.Elem()).Elem()))
- err := p.readAny(fv.Index(fv.Len()-1), props)
- if err != nil {
- return err
- }
- tok := p.next()
- if tok.err != nil {
- return tok.err
- }
- if tok.value == "]" {
- break
- }
- if tok.value != "," {
- return p.errorf("Expected ']' or ',' found %q", tok.value)
- }
- }
- return nil
- }
- // One value of the repeated field.
- p.back()
- fv.Set(reflect.Append(fv, reflect.New(at.Elem()).Elem()))
- return p.readAny(fv.Index(fv.Len()-1), props)
- case reflect.Bool:
- // true/1/t/True or false/f/0/False.
- switch tok.value {
- case "true", "1", "t", "True":
- fv.SetBool(true)
- return nil
- case "false", "0", "f", "False":
- fv.SetBool(false)
- return nil
- }
- case reflect.Float32, reflect.Float64:
- v := tok.value
- // Ignore 'f' for compatibility with output generated by C++, but don't
- // remove 'f' when the value is "-inf" or "inf".
- if strings.HasSuffix(v, "f") && tok.value != "-inf" && tok.value != "inf" {
- v = v[:len(v)-1]
- }
- if f, err := strconv.ParseFloat(v, fv.Type().Bits()); err == nil {
- fv.SetFloat(f)
- return nil
- }
- case reflect.Int32:
- if x, err := strconv.ParseInt(tok.value, 0, 32); err == nil {
- fv.SetInt(x)
- return nil
- }
-
- if len(props.Enum) == 0 {
- break
- }
- m, ok := enumValueMaps[props.Enum]
- if !ok {
- break
- }
- x, ok := m[tok.value]
- if !ok {
- break
- }
- fv.SetInt(int64(x))
- return nil
- case reflect.Int64:
- if x, err := strconv.ParseInt(tok.value, 0, 64); err == nil {
- fv.SetInt(x)
- return nil
- }
-
- case reflect.Ptr:
- // A basic field (indirected through pointer), or a repeated message/group
- p.back()
- fv.Set(reflect.New(fv.Type().Elem()))
- return p.readAny(fv.Elem(), props)
- case reflect.String:
- if tok.value[0] == '"' || tok.value[0] == '\'' {
- fv.SetString(tok.unquoted)
- return nil
- }
- case reflect.Struct:
- var terminator string
- switch tok.value {
- case "{":
- terminator = "}"
- case "<":
- terminator = ">"
- default:
- return p.errorf("expected '{' or '<', found %q", tok.value)
- }
- // TODO: Handle nested messages which implement encoding.TextUnmarshaler.
- return p.readStruct(fv, terminator)
- case reflect.Uint32:
- if x, err := strconv.ParseUint(tok.value, 0, 32); err == nil {
- fv.SetUint(uint64(x))
- return nil
- }
- case reflect.Uint64:
- if x, err := strconv.ParseUint(tok.value, 0, 64); err == nil {
- fv.SetUint(x)
- return nil
- }
- }
- return p.errorf("invalid %v: %v", v.Type(), tok.value)
-}
-
-// UnmarshalText reads a protocol buffer in Text format. UnmarshalText resets pb
-// before starting to unmarshal, so any existing data in pb is always removed.
-// If a required field is not set and no other error occurs,
-// UnmarshalText returns *RequiredNotSetError.
-func UnmarshalText(s string, pb Message) error {
- if um, ok := pb.(encoding.TextUnmarshaler); ok {
- return um.UnmarshalText([]byte(s))
- }
- pb.Reset()
- v := reflect.ValueOf(pb)
- return newTextParser(s).readStruct(v.Elem(), "")
-}
diff --git a/vendor/github.com/gomodule/redigo/LICENSE b/vendor/github.com/gomodule/redigo/LICENSE
deleted file mode 100644
index 67db858..0000000
--- a/vendor/github.com/gomodule/redigo/LICENSE
+++ /dev/null
@@ -1,175 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
diff --git a/vendor/github.com/gomodule/redigo/internal/commandinfo.go b/vendor/github.com/gomodule/redigo/internal/commandinfo.go
deleted file mode 100644
index b763efb..0000000
--- a/vendor/github.com/gomodule/redigo/internal/commandinfo.go
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2014 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-package internal // import "github.com/gomodule/redigo/internal"
-
-import (
- "strings"
-)
-
-const (
- WatchState = 1 << iota
- MultiState
- SubscribeState
- MonitorState
-)
-
-type CommandInfo struct {
- Set, Clear int
-}
-
-var commandInfos = map[string]CommandInfo{
- "WATCH": {Set: WatchState},
- "UNWATCH": {Clear: WatchState},
- "MULTI": {Set: MultiState},
- "EXEC": {Clear: WatchState | MultiState},
- "DISCARD": {Clear: WatchState | MultiState},
- "PSUBSCRIBE": {Set: SubscribeState},
- "SUBSCRIBE": {Set: SubscribeState},
- "MONITOR": {Set: MonitorState},
-}
-
-func init() {
- for n, ci := range commandInfos {
- commandInfos[strings.ToLower(n)] = ci
- }
-}
-
-func LookupCommandInfo(commandName string) CommandInfo {
- if ci, ok := commandInfos[commandName]; ok {
- return ci
- }
- return commandInfos[strings.ToUpper(commandName)]
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/conn.go b/vendor/github.com/gomodule/redigo/redis/conn.go
deleted file mode 100644
index 5aa0f32..0000000
--- a/vendor/github.com/gomodule/redigo/redis/conn.go
+++ /dev/null
@@ -1,673 +0,0 @@
-// Copyright 2012 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-package redis
-
-import (
- "bufio"
- "bytes"
- "crypto/tls"
- "errors"
- "fmt"
- "io"
- "net"
- "net/url"
- "regexp"
- "strconv"
- "sync"
- "time"
-)
-
-var (
- _ ConnWithTimeout = (*conn)(nil)
-)
-
-// conn is the low-level implementation of Conn
-type conn struct {
- // Shared
- mu sync.Mutex
- pending int
- err error
- conn net.Conn
-
- // Read
- readTimeout time.Duration
- br *bufio.Reader
-
- // Write
- writeTimeout time.Duration
- bw *bufio.Writer
-
- // Scratch space for formatting argument length.
- // '*' or '$', length, "\r\n"
- lenScratch [32]byte
-
- // Scratch space for formatting integers and floats.
- numScratch [40]byte
-}
-
-// DialTimeout acts like Dial but takes timeouts for establishing the
-// connection to the server, writing a command and reading a reply.
-//
-// Deprecated: Use Dial with options instead.
-func DialTimeout(network, address string, connectTimeout, readTimeout, writeTimeout time.Duration) (Conn, error) {
- return Dial(network, address,
- DialConnectTimeout(connectTimeout),
- DialReadTimeout(readTimeout),
- DialWriteTimeout(writeTimeout))
-}
-
-// DialOption specifies an option for dialing a Redis server.
-type DialOption struct {
- f func(*dialOptions)
-}
-
-type dialOptions struct {
- readTimeout time.Duration
- writeTimeout time.Duration
- dialer *net.Dialer
- dial func(network, addr string) (net.Conn, error)
- db int
- password string
- useTLS bool
- skipVerify bool
- tlsConfig *tls.Config
-}
-
-// DialReadTimeout specifies the timeout for reading a single command reply.
-func DialReadTimeout(d time.Duration) DialOption {
- return DialOption{func(do *dialOptions) {
- do.readTimeout = d
- }}
-}
-
-// DialWriteTimeout specifies the timeout for writing a single command.
-func DialWriteTimeout(d time.Duration) DialOption {
- return DialOption{func(do *dialOptions) {
- do.writeTimeout = d
- }}
-}
-
-// DialConnectTimeout specifies the timeout for connecting to the Redis server when
-// no DialNetDial option is specified.
-func DialConnectTimeout(d time.Duration) DialOption {
- return DialOption{func(do *dialOptions) {
- do.dialer.Timeout = d
- }}
-}
-
-// DialKeepAlive specifies the keep-alive period for TCP connections to the Redis server
-// when no DialNetDial option is specified.
-// If zero, keep-alives are not enabled. If no DialKeepAlive option is specified then
-// the default of 5 minutes is used to ensure that half-closed TCP sessions are detected.
-func DialKeepAlive(d time.Duration) DialOption {
- return DialOption{func(do *dialOptions) {
- do.dialer.KeepAlive = d
- }}
-}
-
-// DialNetDial specifies a custom dial function for creating TCP
-// connections, otherwise a net.Dialer customized via the other options is used.
-// DialNetDial overrides DialConnectTimeout and DialKeepAlive.
-func DialNetDial(dial func(network, addr string) (net.Conn, error)) DialOption {
- return DialOption{func(do *dialOptions) {
- do.dial = dial
- }}
-}
-
-// DialDatabase specifies the database to select when dialing a connection.
-func DialDatabase(db int) DialOption {
- return DialOption{func(do *dialOptions) {
- do.db = db
- }}
-}
-
-// DialPassword specifies the password to use when connecting to
-// the Redis server.
-func DialPassword(password string) DialOption {
- return DialOption{func(do *dialOptions) {
- do.password = password
- }}
-}
-
-// DialTLSConfig specifies the config to use when a TLS connection is dialed.
-// Has no effect when not dialing a TLS connection.
-func DialTLSConfig(c *tls.Config) DialOption {
- return DialOption{func(do *dialOptions) {
- do.tlsConfig = c
- }}
-}
-
-// DialTLSSkipVerify disables server name verification when connecting over
-// TLS. Has no effect when not dialing a TLS connection.
-func DialTLSSkipVerify(skip bool) DialOption {
- return DialOption{func(do *dialOptions) {
- do.skipVerify = skip
- }}
-}
-
-// DialUseTLS specifies whether TLS should be used when connecting to the
-// server. This option is ignore by DialURL.
-func DialUseTLS(useTLS bool) DialOption {
- return DialOption{func(do *dialOptions) {
- do.useTLS = useTLS
- }}
-}
-
-// Dial connects to the Redis server at the given network and
-// address using the specified options.
-func Dial(network, address string, options ...DialOption) (Conn, error) {
- do := dialOptions{
- dialer: &net.Dialer{
- KeepAlive: time.Minute * 5,
- },
- }
- for _, option := range options {
- option.f(&do)
- }
- if do.dial == nil {
- do.dial = do.dialer.Dial
- }
-
- netConn, err := do.dial(network, address)
- if err != nil {
- return nil, err
- }
-
- if do.useTLS {
- var tlsConfig *tls.Config
- if do.tlsConfig == nil {
- tlsConfig = &tls.Config{InsecureSkipVerify: do.skipVerify}
- } else {
- tlsConfig = cloneTLSConfig(do.tlsConfig)
- }
- if tlsConfig.ServerName == "" {
- host, _, err := net.SplitHostPort(address)
- if err != nil {
- netConn.Close()
- return nil, err
- }
- tlsConfig.ServerName = host
- }
-
- tlsConn := tls.Client(netConn, tlsConfig)
- if err := tlsConn.Handshake(); err != nil {
- netConn.Close()
- return nil, err
- }
- netConn = tlsConn
- }
-
- c := &conn{
- conn: netConn,
- bw: bufio.NewWriter(netConn),
- br: bufio.NewReader(netConn),
- readTimeout: do.readTimeout,
- writeTimeout: do.writeTimeout,
- }
-
- if do.password != "" {
- if _, err := c.Do("AUTH", do.password); err != nil {
- netConn.Close()
- return nil, err
- }
- }
-
- if do.db != 0 {
- if _, err := c.Do("SELECT", do.db); err != nil {
- netConn.Close()
- return nil, err
- }
- }
-
- return c, nil
-}
-
-var pathDBRegexp = regexp.MustCompile(`/(\d*)\z`)
-
-// DialURL connects to a Redis server at the given URL using the Redis
-// URI scheme. URLs should follow the draft IANA specification for the
-// scheme (https://www.iana.org/assignments/uri-schemes/prov/redis).
-func DialURL(rawurl string, options ...DialOption) (Conn, error) {
- u, err := url.Parse(rawurl)
- if err != nil {
- return nil, err
- }
-
- if u.Scheme != "redis" && u.Scheme != "rediss" {
- return nil, fmt.Errorf("invalid redis URL scheme: %s", u.Scheme)
- }
-
- // As per the IANA draft spec, the host defaults to localhost and
- // the port defaults to 6379.
- host, port, err := net.SplitHostPort(u.Host)
- if err != nil {
- // assume port is missing
- host = u.Host
- port = "6379"
- }
- if host == "" {
- host = "localhost"
- }
- address := net.JoinHostPort(host, port)
-
- if u.User != nil {
- password, isSet := u.User.Password()
- if isSet {
- options = append(options, DialPassword(password))
- }
- }
-
- match := pathDBRegexp.FindStringSubmatch(u.Path)
- if len(match) == 2 {
- db := 0
- if len(match[1]) > 0 {
- db, err = strconv.Atoi(match[1])
- if err != nil {
- return nil, fmt.Errorf("invalid database: %s", u.Path[1:])
- }
- }
- if db != 0 {
- options = append(options, DialDatabase(db))
- }
- } else if u.Path != "" {
- return nil, fmt.Errorf("invalid database: %s", u.Path[1:])
- }
-
- options = append(options, DialUseTLS(u.Scheme == "rediss"))
-
- return Dial("tcp", address, options...)
-}
-
-// NewConn returns a new Redigo connection for the given net connection.
-func NewConn(netConn net.Conn, readTimeout, writeTimeout time.Duration) Conn {
- return &conn{
- conn: netConn,
- bw: bufio.NewWriter(netConn),
- br: bufio.NewReader(netConn),
- readTimeout: readTimeout,
- writeTimeout: writeTimeout,
- }
-}
-
-func (c *conn) Close() error {
- c.mu.Lock()
- err := c.err
- if c.err == nil {
- c.err = errors.New("redigo: closed")
- err = c.conn.Close()
- }
- c.mu.Unlock()
- return err
-}
-
-func (c *conn) fatal(err error) error {
- c.mu.Lock()
- if c.err == nil {
- c.err = err
- // Close connection to force errors on subsequent calls and to unblock
- // other reader or writer.
- c.conn.Close()
- }
- c.mu.Unlock()
- return err
-}
-
-func (c *conn) Err() error {
- c.mu.Lock()
- err := c.err
- c.mu.Unlock()
- return err
-}
-
-func (c *conn) writeLen(prefix byte, n int) error {
- c.lenScratch[len(c.lenScratch)-1] = '\n'
- c.lenScratch[len(c.lenScratch)-2] = '\r'
- i := len(c.lenScratch) - 3
- for {
- c.lenScratch[i] = byte('0' + n%10)
- i -= 1
- n = n / 10
- if n == 0 {
- break
- }
- }
- c.lenScratch[i] = prefix
- _, err := c.bw.Write(c.lenScratch[i:])
- return err
-}
-
-func (c *conn) writeString(s string) error {
- c.writeLen('$', len(s))
- c.bw.WriteString(s)
- _, err := c.bw.WriteString("\r\n")
- return err
-}
-
-func (c *conn) writeBytes(p []byte) error {
- c.writeLen('$', len(p))
- c.bw.Write(p)
- _, err := c.bw.WriteString("\r\n")
- return err
-}
-
-func (c *conn) writeInt64(n int64) error {
- return c.writeBytes(strconv.AppendInt(c.numScratch[:0], n, 10))
-}
-
-func (c *conn) writeFloat64(n float64) error {
- return c.writeBytes(strconv.AppendFloat(c.numScratch[:0], n, 'g', -1, 64))
-}
-
-func (c *conn) writeCommand(cmd string, args []interface{}) error {
- c.writeLen('*', 1+len(args))
- if err := c.writeString(cmd); err != nil {
- return err
- }
- for _, arg := range args {
- if err := c.writeArg(arg, true); err != nil {
- return err
- }
- }
- return nil
-}
-
-func (c *conn) writeArg(arg interface{}, argumentTypeOK bool) (err error) {
- switch arg := arg.(type) {
- case string:
- return c.writeString(arg)
- case []byte:
- return c.writeBytes(arg)
- case int:
- return c.writeInt64(int64(arg))
- case int64:
- return c.writeInt64(arg)
- case float64:
- return c.writeFloat64(arg)
- case bool:
- if arg {
- return c.writeString("1")
- } else {
- return c.writeString("0")
- }
- case nil:
- return c.writeString("")
- case Argument:
- if argumentTypeOK {
- return c.writeArg(arg.RedisArg(), false)
- }
- // See comment in default clause below.
- var buf bytes.Buffer
- fmt.Fprint(&buf, arg)
- return c.writeBytes(buf.Bytes())
- default:
- // This default clause is intended to handle builtin numeric types.
- // The function should return an error for other types, but this is not
- // done for compatibility with previous versions of the package.
- var buf bytes.Buffer
- fmt.Fprint(&buf, arg)
- return c.writeBytes(buf.Bytes())
- }
-}
-
-type protocolError string
-
-func (pe protocolError) Error() string {
- return fmt.Sprintf("redigo: %s (possible server error or unsupported concurrent read by application)", string(pe))
-}
-
-func (c *conn) readLine() ([]byte, error) {
- p, err := c.br.ReadSlice('\n')
- if err == bufio.ErrBufferFull {
- return nil, protocolError("long response line")
- }
- if err != nil {
- return nil, err
- }
- i := len(p) - 2
- if i < 0 || p[i] != '\r' {
- return nil, protocolError("bad response line terminator")
- }
- return p[:i], nil
-}
-
-// parseLen parses bulk string and array lengths.
-func parseLen(p []byte) (int, error) {
- if len(p) == 0 {
- return -1, protocolError("malformed length")
- }
-
- if p[0] == '-' && len(p) == 2 && p[1] == '1' {
- // handle $-1 and $-1 null replies.
- return -1, nil
- }
-
- var n int
- for _, b := range p {
- n *= 10
- if b < '0' || b > '9' {
- return -1, protocolError("illegal bytes in length")
- }
- n += int(b - '0')
- }
-
- return n, nil
-}
-
-// parseInt parses an integer reply.
-func parseInt(p []byte) (interface{}, error) {
- if len(p) == 0 {
- return 0, protocolError("malformed integer")
- }
-
- var negate bool
- if p[0] == '-' {
- negate = true
- p = p[1:]
- if len(p) == 0 {
- return 0, protocolError("malformed integer")
- }
- }
-
- var n int64
- for _, b := range p {
- n *= 10
- if b < '0' || b > '9' {
- return 0, protocolError("illegal bytes in length")
- }
- n += int64(b - '0')
- }
-
- if negate {
- n = -n
- }
- return n, nil
-}
-
-var (
- okReply interface{} = "OK"
- pongReply interface{} = "PONG"
-)
-
-func (c *conn) readReply() (interface{}, error) {
- line, err := c.readLine()
- if err != nil {
- return nil, err
- }
- if len(line) == 0 {
- return nil, protocolError("short response line")
- }
- switch line[0] {
- case '+':
- switch {
- case len(line) == 3 && line[1] == 'O' && line[2] == 'K':
- // Avoid allocation for frequent "+OK" response.
- return okReply, nil
- case len(line) == 5 && line[1] == 'P' && line[2] == 'O' && line[3] == 'N' && line[4] == 'G':
- // Avoid allocation in PING command benchmarks :)
- return pongReply, nil
- default:
- return string(line[1:]), nil
- }
- case '-':
- return Error(string(line[1:])), nil
- case ':':
- return parseInt(line[1:])
- case '$':
- n, err := parseLen(line[1:])
- if n < 0 || err != nil {
- return nil, err
- }
- p := make([]byte, n)
- _, err = io.ReadFull(c.br, p)
- if err != nil {
- return nil, err
- }
- if line, err := c.readLine(); err != nil {
- return nil, err
- } else if len(line) != 0 {
- return nil, protocolError("bad bulk string format")
- }
- return p, nil
- case '*':
- n, err := parseLen(line[1:])
- if n < 0 || err != nil {
- return nil, err
- }
- r := make([]interface{}, n)
- for i := range r {
- r[i], err = c.readReply()
- if err != nil {
- return nil, err
- }
- }
- return r, nil
- }
- return nil, protocolError("unexpected response line")
-}
-
-func (c *conn) Send(cmd string, args ...interface{}) error {
- c.mu.Lock()
- c.pending += 1
- c.mu.Unlock()
- if c.writeTimeout != 0 {
- c.conn.SetWriteDeadline(time.Now().Add(c.writeTimeout))
- }
- if err := c.writeCommand(cmd, args); err != nil {
- return c.fatal(err)
- }
- return nil
-}
-
-func (c *conn) Flush() error {
- if c.writeTimeout != 0 {
- c.conn.SetWriteDeadline(time.Now().Add(c.writeTimeout))
- }
- if err := c.bw.Flush(); err != nil {
- return c.fatal(err)
- }
- return nil
-}
-
-func (c *conn) Receive() (interface{}, error) {
- return c.ReceiveWithTimeout(c.readTimeout)
-}
-
-func (c *conn) ReceiveWithTimeout(timeout time.Duration) (reply interface{}, err error) {
- var deadline time.Time
- if timeout != 0 {
- deadline = time.Now().Add(timeout)
- }
- c.conn.SetReadDeadline(deadline)
-
- if reply, err = c.readReply(); err != nil {
- return nil, c.fatal(err)
- }
- // When using pub/sub, the number of receives can be greater than the
- // number of sends. To enable normal use of the connection after
- // unsubscribing from all channels, we do not decrement pending to a
- // negative value.
- //
- // The pending field is decremented after the reply is read to handle the
- // case where Receive is called before Send.
- c.mu.Lock()
- if c.pending > 0 {
- c.pending -= 1
- }
- c.mu.Unlock()
- if err, ok := reply.(Error); ok {
- return nil, err
- }
- return
-}
-
-func (c *conn) Do(cmd string, args ...interface{}) (interface{}, error) {
- return c.DoWithTimeout(c.readTimeout, cmd, args...)
-}
-
-func (c *conn) DoWithTimeout(readTimeout time.Duration, cmd string, args ...interface{}) (interface{}, error) {
- c.mu.Lock()
- pending := c.pending
- c.pending = 0
- c.mu.Unlock()
-
- if cmd == "" && pending == 0 {
- return nil, nil
- }
-
- if c.writeTimeout != 0 {
- c.conn.SetWriteDeadline(time.Now().Add(c.writeTimeout))
- }
-
- if cmd != "" {
- if err := c.writeCommand(cmd, args); err != nil {
- return nil, c.fatal(err)
- }
- }
-
- if err := c.bw.Flush(); err != nil {
- return nil, c.fatal(err)
- }
-
- var deadline time.Time
- if readTimeout != 0 {
- deadline = time.Now().Add(readTimeout)
- }
- c.conn.SetReadDeadline(deadline)
-
- if cmd == "" {
- reply := make([]interface{}, pending)
- for i := range reply {
- r, e := c.readReply()
- if e != nil {
- return nil, c.fatal(e)
- }
- reply[i] = r
- }
- return reply, nil
- }
-
- var err error
- var reply interface{}
- for i := 0; i <= pending; i++ {
- var e error
- if reply, e = c.readReply(); e != nil {
- return nil, c.fatal(e)
- }
- if e, ok := reply.(Error); ok && err == nil {
- err = e
- }
- }
- return reply, err
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/doc.go b/vendor/github.com/gomodule/redigo/redis/doc.go
deleted file mode 100644
index 70ec1ea..0000000
--- a/vendor/github.com/gomodule/redigo/redis/doc.go
+++ /dev/null
@@ -1,177 +0,0 @@
-// Copyright 2012 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-// Package redis is a client for the Redis database.
-//
-// The Redigo FAQ (https://github.com/gomodule/redigo/wiki/FAQ) contains more
-// documentation about this package.
-//
-// Connections
-//
-// The Conn interface is the primary interface for working with Redis.
-// Applications create connections by calling the Dial, DialWithTimeout or
-// NewConn functions. In the future, functions will be added for creating
-// sharded and other types of connections.
-//
-// The application must call the connection Close method when the application
-// is done with the connection.
-//
-// Executing Commands
-//
-// The Conn interface has a generic method for executing Redis commands:
-//
-// Do(commandName string, args ...interface{}) (reply interface{}, err error)
-//
-// The Redis command reference (http://redis.io/commands) lists the available
-// commands. An example of using the Redis APPEND command is:
-//
-// n, err := conn.Do("APPEND", "key", "value")
-//
-// The Do method converts command arguments to bulk strings for transmission
-// to the server as follows:
-//
-// Go Type Conversion
-// []byte Sent as is
-// string Sent as is
-// int, int64 strconv.FormatInt(v)
-// float64 strconv.FormatFloat(v, 'g', -1, 64)
-// bool true -> "1", false -> "0"
-// nil ""
-// all other types fmt.Fprint(w, v)
-//
-// Redis command reply types are represented using the following Go types:
-//
-// Redis type Go type
-// error redis.Error
-// integer int64
-// simple string string
-// bulk string []byte or nil if value not present.
-// array []interface{} or nil if value not present.
-//
-// Use type assertions or the reply helper functions to convert from
-// interface{} to the specific Go type for the command result.
-//
-// Pipelining
-//
-// Connections support pipelining using the Send, Flush and Receive methods.
-//
-// Send(commandName string, args ...interface{}) error
-// Flush() error
-// Receive() (reply interface{}, err error)
-//
-// Send writes the command to the connection's output buffer. Flush flushes the
-// connection's output buffer to the server. Receive reads a single reply from
-// the server. The following example shows a simple pipeline.
-//
-// c.Send("SET", "foo", "bar")
-// c.Send("GET", "foo")
-// c.Flush()
-// c.Receive() // reply from SET
-// v, err = c.Receive() // reply from GET
-//
-// The Do method combines the functionality of the Send, Flush and Receive
-// methods. The Do method starts by writing the command and flushing the output
-// buffer. Next, the Do method receives all pending replies including the reply
-// for the command just sent by Do. If any of the received replies is an error,
-// then Do returns the error. If there are no errors, then Do returns the last
-// reply. If the command argument to the Do method is "", then the Do method
-// will flush the output buffer and receive pending replies without sending a
-// command.
-//
-// Use the Send and Do methods to implement pipelined transactions.
-//
-// c.Send("MULTI")
-// c.Send("INCR", "foo")
-// c.Send("INCR", "bar")
-// r, err := c.Do("EXEC")
-// fmt.Println(r) // prints [1, 1]
-//
-// Concurrency
-//
-// Connections support one concurrent caller to the Receive method and one
-// concurrent caller to the Send and Flush methods. No other concurrency is
-// supported including concurrent calls to the Do method.
-//
-// For full concurrent access to Redis, use the thread-safe Pool to get, use
-// and release a connection from within a goroutine. Connections returned from
-// a Pool have the concurrency restrictions described in the previous
-// paragraph.
-//
-// Publish and Subscribe
-//
-// Use the Send, Flush and Receive methods to implement Pub/Sub subscribers.
-//
-// c.Send("SUBSCRIBE", "example")
-// c.Flush()
-// for {
-// reply, err := c.Receive()
-// if err != nil {
-// return err
-// }
-// // process pushed message
-// }
-//
-// The PubSubConn type wraps a Conn with convenience methods for implementing
-// subscribers. The Subscribe, PSubscribe, Unsubscribe and PUnsubscribe methods
-// send and flush a subscription management command. The receive method
-// converts a pushed message to convenient types for use in a type switch.
-//
-// psc := redis.PubSubConn{Conn: c}
-// psc.Subscribe("example")
-// for {
-// switch v := psc.Receive().(type) {
-// case redis.Message:
-// fmt.Printf("%s: message: %s\n", v.Channel, v.Data)
-// case redis.Subscription:
-// fmt.Printf("%s: %s %d\n", v.Channel, v.Kind, v.Count)
-// case error:
-// return v
-// }
-// }
-//
-// Reply Helpers
-//
-// The Bool, Int, Bytes, String, Strings and Values functions convert a reply
-// to a value of a specific type. To allow convenient wrapping of calls to the
-// connection Do and Receive methods, the functions take a second argument of
-// type error. If the error is non-nil, then the helper function returns the
-// error. If the error is nil, the function converts the reply to the specified
-// type:
-//
-// exists, err := redis.Bool(c.Do("EXISTS", "foo"))
-// if err != nil {
-// // handle error return from c.Do or type conversion error.
-// }
-//
-// The Scan function converts elements of a array reply to Go types:
-//
-// var value1 int
-// var value2 string
-// reply, err := redis.Values(c.Do("MGET", "key1", "key2"))
-// if err != nil {
-// // handle error
-// }
-// if _, err := redis.Scan(reply, &value1, &value2); err != nil {
-// // handle error
-// }
-//
-// Errors
-//
-// Connection methods return error replies from the server as type redis.Error.
-//
-// Call the connection Err() method to determine if the connection encountered
-// non-recoverable error such as a network error or protocol parsing error. If
-// Err() returns a non-nil value, then the connection is not usable and should
-// be closed.
-package redis // import "github.com/gomodule/redigo/redis"
diff --git a/vendor/github.com/gomodule/redigo/redis/go16.go b/vendor/github.com/gomodule/redigo/redis/go16.go
deleted file mode 100644
index f6b1a7c..0000000
--- a/vendor/github.com/gomodule/redigo/redis/go16.go
+++ /dev/null
@@ -1,27 +0,0 @@
-// +build !go1.7
-
-package redis
-
-import "crypto/tls"
-
-func cloneTLSConfig(cfg *tls.Config) *tls.Config {
- return &tls.Config{
- Rand: cfg.Rand,
- Time: cfg.Time,
- Certificates: cfg.Certificates,
- NameToCertificate: cfg.NameToCertificate,
- GetCertificate: cfg.GetCertificate,
- RootCAs: cfg.RootCAs,
- NextProtos: cfg.NextProtos,
- ServerName: cfg.ServerName,
- ClientAuth: cfg.ClientAuth,
- ClientCAs: cfg.ClientCAs,
- InsecureSkipVerify: cfg.InsecureSkipVerify,
- CipherSuites: cfg.CipherSuites,
- PreferServerCipherSuites: cfg.PreferServerCipherSuites,
- ClientSessionCache: cfg.ClientSessionCache,
- MinVersion: cfg.MinVersion,
- MaxVersion: cfg.MaxVersion,
- CurvePreferences: cfg.CurvePreferences,
- }
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/go17.go b/vendor/github.com/gomodule/redigo/redis/go17.go
deleted file mode 100644
index 5f36379..0000000
--- a/vendor/github.com/gomodule/redigo/redis/go17.go
+++ /dev/null
@@ -1,29 +0,0 @@
-// +build go1.7,!go1.8
-
-package redis
-
-import "crypto/tls"
-
-func cloneTLSConfig(cfg *tls.Config) *tls.Config {
- return &tls.Config{
- Rand: cfg.Rand,
- Time: cfg.Time,
- Certificates: cfg.Certificates,
- NameToCertificate: cfg.NameToCertificate,
- GetCertificate: cfg.GetCertificate,
- RootCAs: cfg.RootCAs,
- NextProtos: cfg.NextProtos,
- ServerName: cfg.ServerName,
- ClientAuth: cfg.ClientAuth,
- ClientCAs: cfg.ClientCAs,
- InsecureSkipVerify: cfg.InsecureSkipVerify,
- CipherSuites: cfg.CipherSuites,
- PreferServerCipherSuites: cfg.PreferServerCipherSuites,
- ClientSessionCache: cfg.ClientSessionCache,
- MinVersion: cfg.MinVersion,
- MaxVersion: cfg.MaxVersion,
- CurvePreferences: cfg.CurvePreferences,
- DynamicRecordSizingDisabled: cfg.DynamicRecordSizingDisabled,
- Renegotiation: cfg.Renegotiation,
- }
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/go18.go b/vendor/github.com/gomodule/redigo/redis/go18.go
deleted file mode 100644
index 558363b..0000000
--- a/vendor/github.com/gomodule/redigo/redis/go18.go
+++ /dev/null
@@ -1,9 +0,0 @@
-// +build go1.8
-
-package redis
-
-import "crypto/tls"
-
-func cloneTLSConfig(cfg *tls.Config) *tls.Config {
- return cfg.Clone()
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/log.go b/vendor/github.com/gomodule/redigo/redis/log.go
deleted file mode 100644
index b299661..0000000
--- a/vendor/github.com/gomodule/redigo/redis/log.go
+++ /dev/null
@@ -1,134 +0,0 @@
-// Copyright 2012 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-package redis
-
-import (
- "bytes"
- "fmt"
- "log"
- "time"
-)
-
-var (
- _ ConnWithTimeout = (*loggingConn)(nil)
-)
-
-// NewLoggingConn returns a logging wrapper around a connection.
-func NewLoggingConn(conn Conn, logger *log.Logger, prefix string) Conn {
- if prefix != "" {
- prefix = prefix + "."
- }
- return &loggingConn{conn, logger, prefix}
-}
-
-type loggingConn struct {
- Conn
- logger *log.Logger
- prefix string
-}
-
-func (c *loggingConn) Close() error {
- err := c.Conn.Close()
- var buf bytes.Buffer
- fmt.Fprintf(&buf, "%sClose() -> (%v)", c.prefix, err)
- c.logger.Output(2, buf.String())
- return err
-}
-
-func (c *loggingConn) printValue(buf *bytes.Buffer, v interface{}) {
- const chop = 32
- switch v := v.(type) {
- case []byte:
- if len(v) > chop {
- fmt.Fprintf(buf, "%q...", v[:chop])
- } else {
- fmt.Fprintf(buf, "%q", v)
- }
- case string:
- if len(v) > chop {
- fmt.Fprintf(buf, "%q...", v[:chop])
- } else {
- fmt.Fprintf(buf, "%q", v)
- }
- case []interface{}:
- if len(v) == 0 {
- buf.WriteString("[]")
- } else {
- sep := "["
- fin := "]"
- if len(v) > chop {
- v = v[:chop]
- fin = "...]"
- }
- for _, vv := range v {
- buf.WriteString(sep)
- c.printValue(buf, vv)
- sep = ", "
- }
- buf.WriteString(fin)
- }
- default:
- fmt.Fprint(buf, v)
- }
-}
-
-func (c *loggingConn) print(method, commandName string, args []interface{}, reply interface{}, err error) {
- var buf bytes.Buffer
- fmt.Fprintf(&buf, "%s%s(", c.prefix, method)
- if method != "Receive" {
- buf.WriteString(commandName)
- for _, arg := range args {
- buf.WriteString(", ")
- c.printValue(&buf, arg)
- }
- }
- buf.WriteString(") -> (")
- if method != "Send" {
- c.printValue(&buf, reply)
- buf.WriteString(", ")
- }
- fmt.Fprintf(&buf, "%v)", err)
- c.logger.Output(3, buf.String())
-}
-
-func (c *loggingConn) Do(commandName string, args ...interface{}) (interface{}, error) {
- reply, err := c.Conn.Do(commandName, args...)
- c.print("Do", commandName, args, reply, err)
- return reply, err
-}
-
-func (c *loggingConn) DoWithTimeout(timeout time.Duration, commandName string, args ...interface{}) (interface{}, error) {
- reply, err := DoWithTimeout(c.Conn, timeout, commandName, args...)
- c.print("DoWithTimeout", commandName, args, reply, err)
- return reply, err
-}
-
-func (c *loggingConn) Send(commandName string, args ...interface{}) error {
- err := c.Conn.Send(commandName, args...)
- c.print("Send", commandName, args, nil, err)
- return err
-}
-
-func (c *loggingConn) Receive() (interface{}, error) {
- reply, err := c.Conn.Receive()
- c.print("Receive", "", nil, reply, err)
- return reply, err
-}
-
-func (c *loggingConn) ReceiveWithTimeout(timeout time.Duration) (interface{}, error) {
- reply, err := ReceiveWithTimeout(c.Conn, timeout)
- c.print("ReceiveWithTimeout", "", nil, reply, err)
- return reply, err
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/pool.go b/vendor/github.com/gomodule/redigo/redis/pool.go
deleted file mode 100644
index d77da32..0000000
--- a/vendor/github.com/gomodule/redigo/redis/pool.go
+++ /dev/null
@@ -1,562 +0,0 @@
-// Copyright 2012 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-package redis
-
-import (
- "bytes"
- "crypto/rand"
- "crypto/sha1"
- "errors"
- "io"
- "strconv"
- "sync"
- "sync/atomic"
- "time"
-
- "github.com/gomodule/redigo/internal"
-)
-
-var (
- _ ConnWithTimeout = (*activeConn)(nil)
- _ ConnWithTimeout = (*errorConn)(nil)
-)
-
-var nowFunc = time.Now // for testing
-
-// ErrPoolExhausted is returned from a pool connection method (Do, Send,
-// Receive, Flush, Err) when the maximum number of database connections in the
-// pool has been reached.
-var ErrPoolExhausted = errors.New("redigo: connection pool exhausted")
-
-var (
- errPoolClosed = errors.New("redigo: connection pool closed")
- errConnClosed = errors.New("redigo: connection closed")
-)
-
-// Pool maintains a pool of connections. The application calls the Get method
-// to get a connection from the pool and the connection's Close method to
-// return the connection's resources to the pool.
-//
-// The following example shows how to use a pool in a web application. The
-// application creates a pool at application startup and makes it available to
-// request handlers using a package level variable. The pool configuration used
-// here is an example, not a recommendation.
-//
-// func newPool(addr string) *redis.Pool {
-// return &redis.Pool{
-// MaxIdle: 3,
-// IdleTimeout: 240 * time.Second,
-// Dial: func () (redis.Conn, error) { return redis.Dial("tcp", addr) },
-// }
-// }
-//
-// var (
-// pool *redis.Pool
-// redisServer = flag.String("redisServer", ":6379", "")
-// )
-//
-// func main() {
-// flag.Parse()
-// pool = newPool(*redisServer)
-// ...
-// }
-//
-// A request handler gets a connection from the pool and closes the connection
-// when the handler is done:
-//
-// func serveHome(w http.ResponseWriter, r *http.Request) {
-// conn := pool.Get()
-// defer conn.Close()
-// ...
-// }
-//
-// Use the Dial function to authenticate connections with the AUTH command or
-// select a database with the SELECT command:
-//
-// pool := &redis.Pool{
-// // Other pool configuration not shown in this example.
-// Dial: func () (redis.Conn, error) {
-// c, err := redis.Dial("tcp", server)
-// if err != nil {
-// return nil, err
-// }
-// if _, err := c.Do("AUTH", password); err != nil {
-// c.Close()
-// return nil, err
-// }
-// if _, err := c.Do("SELECT", db); err != nil {
-// c.Close()
-// return nil, err
-// }
-// return c, nil
-// },
-// }
-//
-// Use the TestOnBorrow function to check the health of an idle connection
-// before the connection is returned to the application. This example PINGs
-// connections that have been idle more than a minute:
-//
-// pool := &redis.Pool{
-// // Other pool configuration not shown in this example.
-// TestOnBorrow: func(c redis.Conn, t time.Time) error {
-// if time.Since(t) < time.Minute {
-// return nil
-// }
-// _, err := c.Do("PING")
-// return err
-// },
-// }
-//
-type Pool struct {
- // Dial is an application supplied function for creating and configuring a
- // connection.
- //
- // The connection returned from Dial must not be in a special state
- // (subscribed to pubsub channel, transaction started, ...).
- Dial func() (Conn, error)
-
- // TestOnBorrow is an optional application supplied function for checking
- // the health of an idle connection before the connection is used again by
- // the application. Argument t is the time that the connection was returned
- // to the pool. If the function returns an error, then the connection is
- // closed.
- TestOnBorrow func(c Conn, t time.Time) error
-
- // Maximum number of idle connections in the pool.
- MaxIdle int
-
- // Maximum number of connections allocated by the pool at a given time.
- // When zero, there is no limit on the number of connections in the pool.
- MaxActive int
-
- // Close connections after remaining idle for this duration. If the value
- // is zero, then idle connections are not closed. Applications should set
- // the timeout to a value less than the server's timeout.
- IdleTimeout time.Duration
-
- // If Wait is true and the pool is at the MaxActive limit, then Get() waits
- // for a connection to be returned to the pool before returning.
- Wait bool
-
- // Close connections older than this duration. If the value is zero, then
- // the pool does not close connections based on age.
- MaxConnLifetime time.Duration
-
- chInitialized uint32 // set to 1 when field ch is initialized
-
- mu sync.Mutex // mu protects the following fields
- closed bool // set to true when the pool is closed.
- active int // the number of open connections in the pool
- ch chan struct{} // limits open connections when p.Wait is true
- idle idleList // idle connections
-}
-
-// NewPool creates a new pool.
-//
-// Deprecated: Initialize the Pool directory as shown in the example.
-func NewPool(newFn func() (Conn, error), maxIdle int) *Pool {
- return &Pool{Dial: newFn, MaxIdle: maxIdle}
-}
-
-// Get gets a connection. The application must close the returned connection.
-// This method always returns a valid connection so that applications can defer
-// error handling to the first use of the connection. If there is an error
-// getting an underlying connection, then the connection Err, Do, Send, Flush
-// and Receive methods return that error.
-func (p *Pool) Get() Conn {
- pc, err := p.get(nil)
- if err != nil {
- return errorConn{err}
- }
- return &activeConn{p: p, pc: pc}
-}
-
-// PoolStats contains pool statistics.
-type PoolStats struct {
- // ActiveCount is the number of connections in the pool. The count includes
- // idle connections and connections in use.
- ActiveCount int
- // IdleCount is the number of idle connections in the pool.
- IdleCount int
-}
-
-// Stats returns pool's statistics.
-func (p *Pool) Stats() PoolStats {
- p.mu.Lock()
- stats := PoolStats{
- ActiveCount: p.active,
- IdleCount: p.idle.count,
- }
- p.mu.Unlock()
-
- return stats
-}
-
-// ActiveCount returns the number of connections in the pool. The count
-// includes idle connections and connections in use.
-func (p *Pool) ActiveCount() int {
- p.mu.Lock()
- active := p.active
- p.mu.Unlock()
- return active
-}
-
-// IdleCount returns the number of idle connections in the pool.
-func (p *Pool) IdleCount() int {
- p.mu.Lock()
- idle := p.idle.count
- p.mu.Unlock()
- return idle
-}
-
-// Close releases the resources used by the pool.
-func (p *Pool) Close() error {
- p.mu.Lock()
- if p.closed {
- p.mu.Unlock()
- return nil
- }
- p.closed = true
- p.active -= p.idle.count
- pc := p.idle.front
- p.idle.count = 0
- p.idle.front, p.idle.back = nil, nil
- if p.ch != nil {
- close(p.ch)
- }
- p.mu.Unlock()
- for ; pc != nil; pc = pc.next {
- pc.c.Close()
- }
- return nil
-}
-
-func (p *Pool) lazyInit() {
- // Fast path.
- if atomic.LoadUint32(&p.chInitialized) == 1 {
- return
- }
- // Slow path.
- p.mu.Lock()
- if p.chInitialized == 0 {
- p.ch = make(chan struct{}, p.MaxActive)
- if p.closed {
- close(p.ch)
- } else {
- for i := 0; i < p.MaxActive; i++ {
- p.ch <- struct{}{}
- }
- }
- atomic.StoreUint32(&p.chInitialized, 1)
- }
- p.mu.Unlock()
-}
-
-// get prunes stale connections and returns a connection from the idle list or
-// creates a new connection.
-func (p *Pool) get(ctx interface {
- Done() <-chan struct{}
- Err() error
-}) (*poolConn, error) {
-
- // Handle limit for p.Wait == true.
- if p.Wait && p.MaxActive > 0 {
- p.lazyInit()
- if ctx == nil {
- <-p.ch
- } else {
- select {
- case <-p.ch:
- case <-ctx.Done():
- return nil, ctx.Err()
- }
- }
- }
-
- p.mu.Lock()
-
- // Prune stale connections at the back of the idle list.
- if p.IdleTimeout > 0 {
- n := p.idle.count
- for i := 0; i < n && p.idle.back != nil && p.idle.back.t.Add(p.IdleTimeout).Before(nowFunc()); i++ {
- pc := p.idle.back
- p.idle.popBack()
- p.mu.Unlock()
- pc.c.Close()
- p.mu.Lock()
- p.active--
- }
- }
-
- // Get idle connection from the front of idle list.
- for p.idle.front != nil {
- pc := p.idle.front
- p.idle.popFront()
- p.mu.Unlock()
- if (p.TestOnBorrow == nil || p.TestOnBorrow(pc.c, pc.t) == nil) &&
- (p.MaxConnLifetime == 0 || nowFunc().Sub(pc.created) < p.MaxConnLifetime) {
- return pc, nil
- }
- pc.c.Close()
- p.mu.Lock()
- p.active--
- }
-
- // Check for pool closed before dialing a new connection.
- if p.closed {
- p.mu.Unlock()
- return nil, errors.New("redigo: get on closed pool")
- }
-
- // Handle limit for p.Wait == false.
- if !p.Wait && p.MaxActive > 0 && p.active >= p.MaxActive {
- p.mu.Unlock()
- return nil, ErrPoolExhausted
- }
-
- p.active++
- p.mu.Unlock()
- c, err := p.Dial()
- if err != nil {
- c = nil
- p.mu.Lock()
- p.active--
- if p.ch != nil && !p.closed {
- p.ch <- struct{}{}
- }
- p.mu.Unlock()
- }
- return &poolConn{c: c, created: nowFunc()}, err
-}
-
-func (p *Pool) put(pc *poolConn, forceClose bool) error {
- p.mu.Lock()
- if !p.closed && !forceClose {
- pc.t = nowFunc()
- p.idle.pushFront(pc)
- if p.idle.count > p.MaxIdle {
- pc = p.idle.back
- p.idle.popBack()
- } else {
- pc = nil
- }
- }
-
- if pc != nil {
- p.mu.Unlock()
- pc.c.Close()
- p.mu.Lock()
- p.active--
- }
-
- if p.ch != nil && !p.closed {
- p.ch <- struct{}{}
- }
- p.mu.Unlock()
- return nil
-}
-
-type activeConn struct {
- p *Pool
- pc *poolConn
- state int
-}
-
-var (
- sentinel []byte
- sentinelOnce sync.Once
-)
-
-func initSentinel() {
- p := make([]byte, 64)
- if _, err := rand.Read(p); err == nil {
- sentinel = p
- } else {
- h := sha1.New()
- io.WriteString(h, "Oops, rand failed. Use time instead.")
- io.WriteString(h, strconv.FormatInt(time.Now().UnixNano(), 10))
- sentinel = h.Sum(nil)
- }
-}
-
-func (ac *activeConn) Close() error {
- pc := ac.pc
- if pc == nil {
- return nil
- }
- ac.pc = nil
-
- if ac.state&internal.MultiState != 0 {
- pc.c.Send("DISCARD")
- ac.state &^= (internal.MultiState | internal.WatchState)
- } else if ac.state&internal.WatchState != 0 {
- pc.c.Send("UNWATCH")
- ac.state &^= internal.WatchState
- }
- if ac.state&internal.SubscribeState != 0 {
- pc.c.Send("UNSUBSCRIBE")
- pc.c.Send("PUNSUBSCRIBE")
- // To detect the end of the message stream, ask the server to echo
- // a sentinel value and read until we see that value.
- sentinelOnce.Do(initSentinel)
- pc.c.Send("ECHO", sentinel)
- pc.c.Flush()
- for {
- p, err := pc.c.Receive()
- if err != nil {
- break
- }
- if p, ok := p.([]byte); ok && bytes.Equal(p, sentinel) {
- ac.state &^= internal.SubscribeState
- break
- }
- }
- }
- pc.c.Do("")
- ac.p.put(pc, ac.state != 0 || pc.c.Err() != nil)
- return nil
-}
-
-func (ac *activeConn) Err() error {
- pc := ac.pc
- if pc == nil {
- return errConnClosed
- }
- return pc.c.Err()
-}
-
-func (ac *activeConn) Do(commandName string, args ...interface{}) (reply interface{}, err error) {
- pc := ac.pc
- if pc == nil {
- return nil, errConnClosed
- }
- ci := internal.LookupCommandInfo(commandName)
- ac.state = (ac.state | ci.Set) &^ ci.Clear
- return pc.c.Do(commandName, args...)
-}
-
-func (ac *activeConn) DoWithTimeout(timeout time.Duration, commandName string, args ...interface{}) (reply interface{}, err error) {
- pc := ac.pc
- if pc == nil {
- return nil, errConnClosed
- }
- cwt, ok := pc.c.(ConnWithTimeout)
- if !ok {
- return nil, errTimeoutNotSupported
- }
- ci := internal.LookupCommandInfo(commandName)
- ac.state = (ac.state | ci.Set) &^ ci.Clear
- return cwt.DoWithTimeout(timeout, commandName, args...)
-}
-
-func (ac *activeConn) Send(commandName string, args ...interface{}) error {
- pc := ac.pc
- if pc == nil {
- return errConnClosed
- }
- ci := internal.LookupCommandInfo(commandName)
- ac.state = (ac.state | ci.Set) &^ ci.Clear
- return pc.c.Send(commandName, args...)
-}
-
-func (ac *activeConn) Flush() error {
- pc := ac.pc
- if pc == nil {
- return errConnClosed
- }
- return pc.c.Flush()
-}
-
-func (ac *activeConn) Receive() (reply interface{}, err error) {
- pc := ac.pc
- if pc == nil {
- return nil, errConnClosed
- }
- return pc.c.Receive()
-}
-
-func (ac *activeConn) ReceiveWithTimeout(timeout time.Duration) (reply interface{}, err error) {
- pc := ac.pc
- if pc == nil {
- return nil, errConnClosed
- }
- cwt, ok := pc.c.(ConnWithTimeout)
- if !ok {
- return nil, errTimeoutNotSupported
- }
- return cwt.ReceiveWithTimeout(timeout)
-}
-
-type errorConn struct{ err error }
-
-func (ec errorConn) Do(string, ...interface{}) (interface{}, error) { return nil, ec.err }
-func (ec errorConn) DoWithTimeout(time.Duration, string, ...interface{}) (interface{}, error) {
- return nil, ec.err
-}
-func (ec errorConn) Send(string, ...interface{}) error { return ec.err }
-func (ec errorConn) Err() error { return ec.err }
-func (ec errorConn) Close() error { return nil }
-func (ec errorConn) Flush() error { return ec.err }
-func (ec errorConn) Receive() (interface{}, error) { return nil, ec.err }
-func (ec errorConn) ReceiveWithTimeout(time.Duration) (interface{}, error) { return nil, ec.err }
-
-type idleList struct {
- count int
- front, back *poolConn
-}
-
-type poolConn struct {
- c Conn
- t time.Time
- created time.Time
- next, prev *poolConn
-}
-
-func (l *idleList) pushFront(pc *poolConn) {
- pc.next = l.front
- pc.prev = nil
- if l.count == 0 {
- l.back = pc
- } else {
- l.front.prev = pc
- }
- l.front = pc
- l.count++
- return
-}
-
-func (l *idleList) popFront() {
- pc := l.front
- l.count--
- if l.count == 0 {
- l.front, l.back = nil, nil
- } else {
- pc.next.prev = nil
- l.front = pc.next
- }
- pc.next, pc.prev = nil, nil
-}
-
-func (l *idleList) popBack() {
- pc := l.back
- l.count--
- if l.count == 0 {
- l.front, l.back = nil, nil
- } else {
- pc.prev.next = nil
- l.back = pc.prev
- }
- pc.next, pc.prev = nil, nil
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/pool17.go b/vendor/github.com/gomodule/redigo/redis/pool17.go
deleted file mode 100644
index c1ea18e..0000000
--- a/vendor/github.com/gomodule/redigo/redis/pool17.go
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2018 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-// +build go1.7
-
-package redis
-
-import "context"
-
-// GetContext gets a connection using the provided context.
-//
-// The provided Context must be non-nil. If the context expires before the
-// connection is complete, an error is returned. Any expiration on the context
-// will not affect the returned connection.
-//
-// If the function completes without error, then the application must close the
-// returned connection.
-func (p *Pool) GetContext(ctx context.Context) (Conn, error) {
- pc, err := p.get(ctx)
- if err != nil {
- return errorConn{err}, err
- }
- return &activeConn{p: p, pc: pc}, nil
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/pubsub.go b/vendor/github.com/gomodule/redigo/redis/pubsub.go
deleted file mode 100644
index 2da6021..0000000
--- a/vendor/github.com/gomodule/redigo/redis/pubsub.go
+++ /dev/null
@@ -1,148 +0,0 @@
-// Copyright 2012 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-package redis
-
-import (
- "errors"
- "time"
-)
-
-// Subscription represents a subscribe or unsubscribe notification.
-type Subscription struct {
- // Kind is "subscribe", "unsubscribe", "psubscribe" or "punsubscribe"
- Kind string
-
- // The channel that was changed.
- Channel string
-
- // The current number of subscriptions for connection.
- Count int
-}
-
-// Message represents a message notification.
-type Message struct {
- // The originating channel.
- Channel string
-
- // The matched pattern, if any
- Pattern string
-
- // The message data.
- Data []byte
-}
-
-// Pong represents a pubsub pong notification.
-type Pong struct {
- Data string
-}
-
-// PubSubConn wraps a Conn with convenience methods for subscribers.
-type PubSubConn struct {
- Conn Conn
-}
-
-// Close closes the connection.
-func (c PubSubConn) Close() error {
- return c.Conn.Close()
-}
-
-// Subscribe subscribes the connection to the specified channels.
-func (c PubSubConn) Subscribe(channel ...interface{}) error {
- c.Conn.Send("SUBSCRIBE", channel...)
- return c.Conn.Flush()
-}
-
-// PSubscribe subscribes the connection to the given patterns.
-func (c PubSubConn) PSubscribe(channel ...interface{}) error {
- c.Conn.Send("PSUBSCRIBE", channel...)
- return c.Conn.Flush()
-}
-
-// Unsubscribe unsubscribes the connection from the given channels, or from all
-// of them if none is given.
-func (c PubSubConn) Unsubscribe(channel ...interface{}) error {
- c.Conn.Send("UNSUBSCRIBE", channel...)
- return c.Conn.Flush()
-}
-
-// PUnsubscribe unsubscribes the connection from the given patterns, or from all
-// of them if none is given.
-func (c PubSubConn) PUnsubscribe(channel ...interface{}) error {
- c.Conn.Send("PUNSUBSCRIBE", channel...)
- return c.Conn.Flush()
-}
-
-// Ping sends a PING to the server with the specified data.
-//
-// The connection must be subscribed to at least one channel or pattern when
-// calling this method.
-func (c PubSubConn) Ping(data string) error {
- c.Conn.Send("PING", data)
- return c.Conn.Flush()
-}
-
-// Receive returns a pushed message as a Subscription, Message, Pong or error.
-// The return value is intended to be used directly in a type switch as
-// illustrated in the PubSubConn example.
-func (c PubSubConn) Receive() interface{} {
- return c.receiveInternal(c.Conn.Receive())
-}
-
-// ReceiveWithTimeout is like Receive, but it allows the application to
-// override the connection's default timeout.
-func (c PubSubConn) ReceiveWithTimeout(timeout time.Duration) interface{} {
- return c.receiveInternal(ReceiveWithTimeout(c.Conn, timeout))
-}
-
-func (c PubSubConn) receiveInternal(replyArg interface{}, errArg error) interface{} {
- reply, err := Values(replyArg, errArg)
- if err != nil {
- return err
- }
-
- var kind string
- reply, err = Scan(reply, &kind)
- if err != nil {
- return err
- }
-
- switch kind {
- case "message":
- var m Message
- if _, err := Scan(reply, &m.Channel, &m.Data); err != nil {
- return err
- }
- return m
- case "pmessage":
- var m Message
- if _, err := Scan(reply, &m.Pattern, &m.Channel, &m.Data); err != nil {
- return err
- }
- return m
- case "subscribe", "psubscribe", "unsubscribe", "punsubscribe":
- s := Subscription{Kind: kind}
- if _, err := Scan(reply, &s.Channel, &s.Count); err != nil {
- return err
- }
- return s
- case "pong":
- var p Pong
- if _, err := Scan(reply, &p.Data); err != nil {
- return err
- }
- return p
- }
- return errors.New("redigo: unknown pubsub notification")
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/redis.go b/vendor/github.com/gomodule/redigo/redis/redis.go
deleted file mode 100644
index 141fa4a..0000000
--- a/vendor/github.com/gomodule/redigo/redis/redis.go
+++ /dev/null
@@ -1,117 +0,0 @@
-// Copyright 2012 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-package redis
-
-import (
- "errors"
- "time"
-)
-
-// Error represents an error returned in a command reply.
-type Error string
-
-func (err Error) Error() string { return string(err) }
-
-// Conn represents a connection to a Redis server.
-type Conn interface {
- // Close closes the connection.
- Close() error
-
- // Err returns a non-nil value when the connection is not usable.
- Err() error
-
- // Do sends a command to the server and returns the received reply.
- Do(commandName string, args ...interface{}) (reply interface{}, err error)
-
- // Send writes the command to the client's output buffer.
- Send(commandName string, args ...interface{}) error
-
- // Flush flushes the output buffer to the Redis server.
- Flush() error
-
- // Receive receives a single reply from the Redis server
- Receive() (reply interface{}, err error)
-}
-
-// Argument is the interface implemented by an object which wants to control how
-// the object is converted to Redis bulk strings.
-type Argument interface {
- // RedisArg returns a value to be encoded as a bulk string per the
- // conversions listed in the section 'Executing Commands'.
- // Implementations should typically return a []byte or string.
- RedisArg() interface{}
-}
-
-// Scanner is implemented by an object which wants to control its value is
-// interpreted when read from Redis.
-type Scanner interface {
- // RedisScan assigns a value from a Redis value. The argument src is one of
- // the reply types listed in the section `Executing Commands`.
- //
- // An error should be returned if the value cannot be stored without
- // loss of information.
- RedisScan(src interface{}) error
-}
-
-// ConnWithTimeout is an optional interface that allows the caller to override
-// a connection's default read timeout. This interface is useful for executing
-// the BLPOP, BRPOP, BRPOPLPUSH, XREAD and other commands that block at the
-// server.
-//
-// A connection's default read timeout is set with the DialReadTimeout dial
-// option. Applications should rely on the default timeout for commands that do
-// not block at the server.
-//
-// All of the Conn implementations in this package satisfy the ConnWithTimeout
-// interface.
-//
-// Use the DoWithTimeout and ReceiveWithTimeout helper functions to simplify
-// use of this interface.
-type ConnWithTimeout interface {
- Conn
-
- // Do sends a command to the server and returns the received reply.
- // The timeout overrides the read timeout set when dialing the
- // connection.
- DoWithTimeout(timeout time.Duration, commandName string, args ...interface{}) (reply interface{}, err error)
-
- // Receive receives a single reply from the Redis server. The timeout
- // overrides the read timeout set when dialing the connection.
- ReceiveWithTimeout(timeout time.Duration) (reply interface{}, err error)
-}
-
-var errTimeoutNotSupported = errors.New("redis: connection does not support ConnWithTimeout")
-
-// DoWithTimeout executes a Redis command with the specified read timeout. If
-// the connection does not satisfy the ConnWithTimeout interface, then an error
-// is returned.
-func DoWithTimeout(c Conn, timeout time.Duration, cmd string, args ...interface{}) (interface{}, error) {
- cwt, ok := c.(ConnWithTimeout)
- if !ok {
- return nil, errTimeoutNotSupported
- }
- return cwt.DoWithTimeout(timeout, cmd, args...)
-}
-
-// ReceiveWithTimeout receives a reply with the specified read timeout. If the
-// connection does not satisfy the ConnWithTimeout interface, then an error is
-// returned.
-func ReceiveWithTimeout(c Conn, timeout time.Duration) (interface{}, error) {
- cwt, ok := c.(ConnWithTimeout)
- if !ok {
- return nil, errTimeoutNotSupported
- }
- return cwt.ReceiveWithTimeout(timeout)
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/reply.go b/vendor/github.com/gomodule/redigo/redis/reply.go
deleted file mode 100644
index c2b3b2b..0000000
--- a/vendor/github.com/gomodule/redigo/redis/reply.go
+++ /dev/null
@@ -1,479 +0,0 @@
-// Copyright 2012 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-package redis
-
-import (
- "errors"
- "fmt"
- "strconv"
-)
-
-// ErrNil indicates that a reply value is nil.
-var ErrNil = errors.New("redigo: nil returned")
-
-// Int is a helper that converts a command reply to an integer. If err is not
-// equal to nil, then Int returns 0, err. Otherwise, Int converts the
-// reply to an int as follows:
-//
-// Reply type Result
-// integer int(reply), nil
-// bulk string parsed reply, nil
-// nil 0, ErrNil
-// other 0, error
-func Int(reply interface{}, err error) (int, error) {
- if err != nil {
- return 0, err
- }
- switch reply := reply.(type) {
- case int64:
- x := int(reply)
- if int64(x) != reply {
- return 0, strconv.ErrRange
- }
- return x, nil
- case []byte:
- n, err := strconv.ParseInt(string(reply), 10, 0)
- return int(n), err
- case nil:
- return 0, ErrNil
- case Error:
- return 0, reply
- }
- return 0, fmt.Errorf("redigo: unexpected type for Int, got type %T", reply)
-}
-
-// Int64 is a helper that converts a command reply to 64 bit integer. If err is
-// not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the
-// reply to an int64 as follows:
-//
-// Reply type Result
-// integer reply, nil
-// bulk string parsed reply, nil
-// nil 0, ErrNil
-// other 0, error
-func Int64(reply interface{}, err error) (int64, error) {
- if err != nil {
- return 0, err
- }
- switch reply := reply.(type) {
- case int64:
- return reply, nil
- case []byte:
- n, err := strconv.ParseInt(string(reply), 10, 64)
- return n, err
- case nil:
- return 0, ErrNil
- case Error:
- return 0, reply
- }
- return 0, fmt.Errorf("redigo: unexpected type for Int64, got type %T", reply)
-}
-
-var errNegativeInt = errors.New("redigo: unexpected value for Uint64")
-
-// Uint64 is a helper that converts a command reply to 64 bit integer. If err is
-// not equal to nil, then Int returns 0, err. Otherwise, Int64 converts the
-// reply to an int64 as follows:
-//
-// Reply type Result
-// integer reply, nil
-// bulk string parsed reply, nil
-// nil 0, ErrNil
-// other 0, error
-func Uint64(reply interface{}, err error) (uint64, error) {
- if err != nil {
- return 0, err
- }
- switch reply := reply.(type) {
- case int64:
- if reply < 0 {
- return 0, errNegativeInt
- }
- return uint64(reply), nil
- case []byte:
- n, err := strconv.ParseUint(string(reply), 10, 64)
- return n, err
- case nil:
- return 0, ErrNil
- case Error:
- return 0, reply
- }
- return 0, fmt.Errorf("redigo: unexpected type for Uint64, got type %T", reply)
-}
-
-// Float64 is a helper that converts a command reply to 64 bit float. If err is
-// not equal to nil, then Float64 returns 0, err. Otherwise, Float64 converts
-// the reply to an int as follows:
-//
-// Reply type Result
-// bulk string parsed reply, nil
-// nil 0, ErrNil
-// other 0, error
-func Float64(reply interface{}, err error) (float64, error) {
- if err != nil {
- return 0, err
- }
- switch reply := reply.(type) {
- case []byte:
- n, err := strconv.ParseFloat(string(reply), 64)
- return n, err
- case nil:
- return 0, ErrNil
- case Error:
- return 0, reply
- }
- return 0, fmt.Errorf("redigo: unexpected type for Float64, got type %T", reply)
-}
-
-// String is a helper that converts a command reply to a string. If err is not
-// equal to nil, then String returns "", err. Otherwise String converts the
-// reply to a string as follows:
-//
-// Reply type Result
-// bulk string string(reply), nil
-// simple string reply, nil
-// nil "", ErrNil
-// other "", error
-func String(reply interface{}, err error) (string, error) {
- if err != nil {
- return "", err
- }
- switch reply := reply.(type) {
- case []byte:
- return string(reply), nil
- case string:
- return reply, nil
- case nil:
- return "", ErrNil
- case Error:
- return "", reply
- }
- return "", fmt.Errorf("redigo: unexpected type for String, got type %T", reply)
-}
-
-// Bytes is a helper that converts a command reply to a slice of bytes. If err
-// is not equal to nil, then Bytes returns nil, err. Otherwise Bytes converts
-// the reply to a slice of bytes as follows:
-//
-// Reply type Result
-// bulk string reply, nil
-// simple string []byte(reply), nil
-// nil nil, ErrNil
-// other nil, error
-func Bytes(reply interface{}, err error) ([]byte, error) {
- if err != nil {
- return nil, err
- }
- switch reply := reply.(type) {
- case []byte:
- return reply, nil
- case string:
- return []byte(reply), nil
- case nil:
- return nil, ErrNil
- case Error:
- return nil, reply
- }
- return nil, fmt.Errorf("redigo: unexpected type for Bytes, got type %T", reply)
-}
-
-// Bool is a helper that converts a command reply to a boolean. If err is not
-// equal to nil, then Bool returns false, err. Otherwise Bool converts the
-// reply to boolean as follows:
-//
-// Reply type Result
-// integer value != 0, nil
-// bulk string strconv.ParseBool(reply)
-// nil false, ErrNil
-// other false, error
-func Bool(reply interface{}, err error) (bool, error) {
- if err != nil {
- return false, err
- }
- switch reply := reply.(type) {
- case int64:
- return reply != 0, nil
- case []byte:
- return strconv.ParseBool(string(reply))
- case nil:
- return false, ErrNil
- case Error:
- return false, reply
- }
- return false, fmt.Errorf("redigo: unexpected type for Bool, got type %T", reply)
-}
-
-// MultiBulk is a helper that converts an array command reply to a []interface{}.
-//
-// Deprecated: Use Values instead.
-func MultiBulk(reply interface{}, err error) ([]interface{}, error) { return Values(reply, err) }
-
-// Values is a helper that converts an array command reply to a []interface{}.
-// If err is not equal to nil, then Values returns nil, err. Otherwise, Values
-// converts the reply as follows:
-//
-// Reply type Result
-// array reply, nil
-// nil nil, ErrNil
-// other nil, error
-func Values(reply interface{}, err error) ([]interface{}, error) {
- if err != nil {
- return nil, err
- }
- switch reply := reply.(type) {
- case []interface{}:
- return reply, nil
- case nil:
- return nil, ErrNil
- case Error:
- return nil, reply
- }
- return nil, fmt.Errorf("redigo: unexpected type for Values, got type %T", reply)
-}
-
-func sliceHelper(reply interface{}, err error, name string, makeSlice func(int), assign func(int, interface{}) error) error {
- if err != nil {
- return err
- }
- switch reply := reply.(type) {
- case []interface{}:
- makeSlice(len(reply))
- for i := range reply {
- if reply[i] == nil {
- continue
- }
- if err := assign(i, reply[i]); err != nil {
- return err
- }
- }
- return nil
- case nil:
- return ErrNil
- case Error:
- return reply
- }
- return fmt.Errorf("redigo: unexpected type for %s, got type %T", name, reply)
-}
-
-// Float64s is a helper that converts an array command reply to a []float64. If
-// err is not equal to nil, then Float64s returns nil, err. Nil array items are
-// converted to 0 in the output slice. Floats64 returns an error if an array
-// item is not a bulk string or nil.
-func Float64s(reply interface{}, err error) ([]float64, error) {
- var result []float64
- err = sliceHelper(reply, err, "Float64s", func(n int) { result = make([]float64, n) }, func(i int, v interface{}) error {
- p, ok := v.([]byte)
- if !ok {
- return fmt.Errorf("redigo: unexpected element type for Floats64, got type %T", v)
- }
- f, err := strconv.ParseFloat(string(p), 64)
- result[i] = f
- return err
- })
- return result, err
-}
-
-// Strings is a helper that converts an array command reply to a []string. If
-// err is not equal to nil, then Strings returns nil, err. Nil array items are
-// converted to "" in the output slice. Strings returns an error if an array
-// item is not a bulk string or nil.
-func Strings(reply interface{}, err error) ([]string, error) {
- var result []string
- err = sliceHelper(reply, err, "Strings", func(n int) { result = make([]string, n) }, func(i int, v interface{}) error {
- switch v := v.(type) {
- case string:
- result[i] = v
- return nil
- case []byte:
- result[i] = string(v)
- return nil
- default:
- return fmt.Errorf("redigo: unexpected element type for Strings, got type %T", v)
- }
- })
- return result, err
-}
-
-// ByteSlices is a helper that converts an array command reply to a [][]byte.
-// If err is not equal to nil, then ByteSlices returns nil, err. Nil array
-// items are stay nil. ByteSlices returns an error if an array item is not a
-// bulk string or nil.
-func ByteSlices(reply interface{}, err error) ([][]byte, error) {
- var result [][]byte
- err = sliceHelper(reply, err, "ByteSlices", func(n int) { result = make([][]byte, n) }, func(i int, v interface{}) error {
- p, ok := v.([]byte)
- if !ok {
- return fmt.Errorf("redigo: unexpected element type for ByteSlices, got type %T", v)
- }
- result[i] = p
- return nil
- })
- return result, err
-}
-
-// Int64s is a helper that converts an array command reply to a []int64.
-// If err is not equal to nil, then Int64s returns nil, err. Nil array
-// items are stay nil. Int64s returns an error if an array item is not a
-// bulk string or nil.
-func Int64s(reply interface{}, err error) ([]int64, error) {
- var result []int64
- err = sliceHelper(reply, err, "Int64s", func(n int) { result = make([]int64, n) }, func(i int, v interface{}) error {
- switch v := v.(type) {
- case int64:
- result[i] = v
- return nil
- case []byte:
- n, err := strconv.ParseInt(string(v), 10, 64)
- result[i] = n
- return err
- default:
- return fmt.Errorf("redigo: unexpected element type for Int64s, got type %T", v)
- }
- })
- return result, err
-}
-
-// Ints is a helper that converts an array command reply to a []in.
-// If err is not equal to nil, then Ints returns nil, err. Nil array
-// items are stay nil. Ints returns an error if an array item is not a
-// bulk string or nil.
-func Ints(reply interface{}, err error) ([]int, error) {
- var result []int
- err = sliceHelper(reply, err, "Ints", func(n int) { result = make([]int, n) }, func(i int, v interface{}) error {
- switch v := v.(type) {
- case int64:
- n := int(v)
- if int64(n) != v {
- return strconv.ErrRange
- }
- result[i] = n
- return nil
- case []byte:
- n, err := strconv.Atoi(string(v))
- result[i] = n
- return err
- default:
- return fmt.Errorf("redigo: unexpected element type for Ints, got type %T", v)
- }
- })
- return result, err
-}
-
-// StringMap is a helper that converts an array of strings (alternating key, value)
-// into a map[string]string. The HGETALL and CONFIG GET commands return replies in this format.
-// Requires an even number of values in result.
-func StringMap(result interface{}, err error) (map[string]string, error) {
- values, err := Values(result, err)
- if err != nil {
- return nil, err
- }
- if len(values)%2 != 0 {
- return nil, errors.New("redigo: StringMap expects even number of values result")
- }
- m := make(map[string]string, len(values)/2)
- for i := 0; i < len(values); i += 2 {
- key, okKey := values[i].([]byte)
- value, okValue := values[i+1].([]byte)
- if !okKey || !okValue {
- return nil, errors.New("redigo: StringMap key not a bulk string value")
- }
- m[string(key)] = string(value)
- }
- return m, nil
-}
-
-// IntMap is a helper that converts an array of strings (alternating key, value)
-// into a map[string]int. The HGETALL commands return replies in this format.
-// Requires an even number of values in result.
-func IntMap(result interface{}, err error) (map[string]int, error) {
- values, err := Values(result, err)
- if err != nil {
- return nil, err
- }
- if len(values)%2 != 0 {
- return nil, errors.New("redigo: IntMap expects even number of values result")
- }
- m := make(map[string]int, len(values)/2)
- for i := 0; i < len(values); i += 2 {
- key, ok := values[i].([]byte)
- if !ok {
- return nil, errors.New("redigo: IntMap key not a bulk string value")
- }
- value, err := Int(values[i+1], nil)
- if err != nil {
- return nil, err
- }
- m[string(key)] = value
- }
- return m, nil
-}
-
-// Int64Map is a helper that converts an array of strings (alternating key, value)
-// into a map[string]int64. The HGETALL commands return replies in this format.
-// Requires an even number of values in result.
-func Int64Map(result interface{}, err error) (map[string]int64, error) {
- values, err := Values(result, err)
- if err != nil {
- return nil, err
- }
- if len(values)%2 != 0 {
- return nil, errors.New("redigo: Int64Map expects even number of values result")
- }
- m := make(map[string]int64, len(values)/2)
- for i := 0; i < len(values); i += 2 {
- key, ok := values[i].([]byte)
- if !ok {
- return nil, errors.New("redigo: Int64Map key not a bulk string value")
- }
- value, err := Int64(values[i+1], nil)
- if err != nil {
- return nil, err
- }
- m[string(key)] = value
- }
- return m, nil
-}
-
-// Positions is a helper that converts an array of positions (lat, long)
-// into a [][2]float64. The GEOPOS command returns replies in this format.
-func Positions(result interface{}, err error) ([]*[2]float64, error) {
- values, err := Values(result, err)
- if err != nil {
- return nil, err
- }
- positions := make([]*[2]float64, len(values))
- for i := range values {
- if values[i] == nil {
- continue
- }
- p, ok := values[i].([]interface{})
- if !ok {
- return nil, fmt.Errorf("redigo: unexpected element type for interface slice, got type %T", values[i])
- }
- if len(p) != 2 {
- return nil, fmt.Errorf("redigo: unexpected number of values for a member position, got %d", len(p))
- }
- lat, err := Float64(p[0], nil)
- if err != nil {
- return nil, err
- }
- long, err := Float64(p[1], nil)
- if err != nil {
- return nil, err
- }
- positions[i] = &[2]float64{lat, long}
- }
- return positions, nil
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/scan.go b/vendor/github.com/gomodule/redigo/redis/scan.go
deleted file mode 100644
index ef9551b..0000000
--- a/vendor/github.com/gomodule/redigo/redis/scan.go
+++ /dev/null
@@ -1,585 +0,0 @@
-// Copyright 2012 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-package redis
-
-import (
- "errors"
- "fmt"
- "reflect"
- "strconv"
- "strings"
- "sync"
-)
-
-func ensureLen(d reflect.Value, n int) {
- if n > d.Cap() {
- d.Set(reflect.MakeSlice(d.Type(), n, n))
- } else {
- d.SetLen(n)
- }
-}
-
-func cannotConvert(d reflect.Value, s interface{}) error {
- var sname string
- switch s.(type) {
- case string:
- sname = "Redis simple string"
- case Error:
- sname = "Redis error"
- case int64:
- sname = "Redis integer"
- case []byte:
- sname = "Redis bulk string"
- case []interface{}:
- sname = "Redis array"
- default:
- sname = reflect.TypeOf(s).String()
- }
- return fmt.Errorf("cannot convert from %s to %s", sname, d.Type())
-}
-
-func convertAssignBulkString(d reflect.Value, s []byte) (err error) {
- switch d.Type().Kind() {
- case reflect.Float32, reflect.Float64:
- var x float64
- x, err = strconv.ParseFloat(string(s), d.Type().Bits())
- d.SetFloat(x)
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- var x int64
- x, err = strconv.ParseInt(string(s), 10, d.Type().Bits())
- d.SetInt(x)
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
- var x uint64
- x, err = strconv.ParseUint(string(s), 10, d.Type().Bits())
- d.SetUint(x)
- case reflect.Bool:
- var x bool
- x, err = strconv.ParseBool(string(s))
- d.SetBool(x)
- case reflect.String:
- d.SetString(string(s))
- case reflect.Slice:
- if d.Type().Elem().Kind() != reflect.Uint8 {
- err = cannotConvert(d, s)
- } else {
- d.SetBytes(s)
- }
- default:
- err = cannotConvert(d, s)
- }
- return
-}
-
-func convertAssignInt(d reflect.Value, s int64) (err error) {
- switch d.Type().Kind() {
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- d.SetInt(s)
- if d.Int() != s {
- err = strconv.ErrRange
- d.SetInt(0)
- }
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
- if s < 0 {
- err = strconv.ErrRange
- } else {
- x := uint64(s)
- d.SetUint(x)
- if d.Uint() != x {
- err = strconv.ErrRange
- d.SetUint(0)
- }
- }
- case reflect.Bool:
- d.SetBool(s != 0)
- default:
- err = cannotConvert(d, s)
- }
- return
-}
-
-func convertAssignValue(d reflect.Value, s interface{}) (err error) {
- if d.Kind() != reflect.Ptr {
- if d.CanAddr() {
- d2 := d.Addr()
- if d2.CanInterface() {
- if scanner, ok := d2.Interface().(Scanner); ok {
- return scanner.RedisScan(s)
- }
- }
- }
- } else if d.CanInterface() {
- // Already a reflect.Ptr
- if d.IsNil() {
- d.Set(reflect.New(d.Type().Elem()))
- }
- if scanner, ok := d.Interface().(Scanner); ok {
- return scanner.RedisScan(s)
- }
- }
-
- switch s := s.(type) {
- case []byte:
- err = convertAssignBulkString(d, s)
- case int64:
- err = convertAssignInt(d, s)
- default:
- err = cannotConvert(d, s)
- }
- return err
-}
-
-func convertAssignArray(d reflect.Value, s []interface{}) error {
- if d.Type().Kind() != reflect.Slice {
- return cannotConvert(d, s)
- }
- ensureLen(d, len(s))
- for i := 0; i < len(s); i++ {
- if err := convertAssignValue(d.Index(i), s[i]); err != nil {
- return err
- }
- }
- return nil
-}
-
-func convertAssign(d interface{}, s interface{}) (err error) {
- if scanner, ok := d.(Scanner); ok {
- return scanner.RedisScan(s)
- }
-
- // Handle the most common destination types using type switches and
- // fall back to reflection for all other types.
- switch s := s.(type) {
- case nil:
- // ignore
- case []byte:
- switch d := d.(type) {
- case *string:
- *d = string(s)
- case *int:
- *d, err = strconv.Atoi(string(s))
- case *bool:
- *d, err = strconv.ParseBool(string(s))
- case *[]byte:
- *d = s
- case *interface{}:
- *d = s
- case nil:
- // skip value
- default:
- if d := reflect.ValueOf(d); d.Type().Kind() != reflect.Ptr {
- err = cannotConvert(d, s)
- } else {
- err = convertAssignBulkString(d.Elem(), s)
- }
- }
- case int64:
- switch d := d.(type) {
- case *int:
- x := int(s)
- if int64(x) != s {
- err = strconv.ErrRange
- x = 0
- }
- *d = x
- case *bool:
- *d = s != 0
- case *interface{}:
- *d = s
- case nil:
- // skip value
- default:
- if d := reflect.ValueOf(d); d.Type().Kind() != reflect.Ptr {
- err = cannotConvert(d, s)
- } else {
- err = convertAssignInt(d.Elem(), s)
- }
- }
- case string:
- switch d := d.(type) {
- case *string:
- *d = s
- case *interface{}:
- *d = s
- case nil:
- // skip value
- default:
- err = cannotConvert(reflect.ValueOf(d), s)
- }
- case []interface{}:
- switch d := d.(type) {
- case *[]interface{}:
- *d = s
- case *interface{}:
- *d = s
- case nil:
- // skip value
- default:
- if d := reflect.ValueOf(d); d.Type().Kind() != reflect.Ptr {
- err = cannotConvert(d, s)
- } else {
- err = convertAssignArray(d.Elem(), s)
- }
- }
- case Error:
- err = s
- default:
- err = cannotConvert(reflect.ValueOf(d), s)
- }
- return
-}
-
-// Scan copies from src to the values pointed at by dest.
-//
-// Scan uses RedisScan if available otherwise:
-//
-// The values pointed at by dest must be an integer, float, boolean, string,
-// []byte, interface{} or slices of these types. Scan uses the standard strconv
-// package to convert bulk strings to numeric and boolean types.
-//
-// If a dest value is nil, then the corresponding src value is skipped.
-//
-// If a src element is nil, then the corresponding dest value is not modified.
-//
-// To enable easy use of Scan in a loop, Scan returns the slice of src
-// following the copied values.
-func Scan(src []interface{}, dest ...interface{}) ([]interface{}, error) {
- if len(src) < len(dest) {
- return nil, errors.New("redigo.Scan: array short")
- }
- var err error
- for i, d := range dest {
- err = convertAssign(d, src[i])
- if err != nil {
- err = fmt.Errorf("redigo.Scan: cannot assign to dest %d: %v", i, err)
- break
- }
- }
- return src[len(dest):], err
-}
-
-type fieldSpec struct {
- name string
- index []int
- omitEmpty bool
-}
-
-type structSpec struct {
- m map[string]*fieldSpec
- l []*fieldSpec
-}
-
-func (ss *structSpec) fieldSpec(name []byte) *fieldSpec {
- return ss.m[string(name)]
-}
-
-func compileStructSpec(t reflect.Type, depth map[string]int, index []int, ss *structSpec) {
- for i := 0; i < t.NumField(); i++ {
- f := t.Field(i)
- switch {
- case f.PkgPath != "" && !f.Anonymous:
- // Ignore unexported fields.
- case f.Anonymous:
- // TODO: Handle pointers. Requires change to decoder and
- // protection against infinite recursion.
- if f.Type.Kind() == reflect.Struct {
- compileStructSpec(f.Type, depth, append(index, i), ss)
- }
- default:
- fs := &fieldSpec{name: f.Name}
- tag := f.Tag.Get("redis")
- p := strings.Split(tag, ",")
- if len(p) > 0 {
- if p[0] == "-" {
- continue
- }
- if len(p[0]) > 0 {
- fs.name = p[0]
- }
- for _, s := range p[1:] {
- switch s {
- case "omitempty":
- fs.omitEmpty = true
- default:
- panic(fmt.Errorf("redigo: unknown field tag %s for type %s", s, t.Name()))
- }
- }
- }
- d, found := depth[fs.name]
- if !found {
- d = 1 << 30
- }
- switch {
- case len(index) == d:
- // At same depth, remove from result.
- delete(ss.m, fs.name)
- j := 0
- for i := 0; i < len(ss.l); i++ {
- if fs.name != ss.l[i].name {
- ss.l[j] = ss.l[i]
- j += 1
- }
- }
- ss.l = ss.l[:j]
- case len(index) < d:
- fs.index = make([]int, len(index)+1)
- copy(fs.index, index)
- fs.index[len(index)] = i
- depth[fs.name] = len(index)
- ss.m[fs.name] = fs
- ss.l = append(ss.l, fs)
- }
- }
- }
-}
-
-var (
- structSpecMutex sync.RWMutex
- structSpecCache = make(map[reflect.Type]*structSpec)
- defaultFieldSpec = &fieldSpec{}
-)
-
-func structSpecForType(t reflect.Type) *structSpec {
-
- structSpecMutex.RLock()
- ss, found := structSpecCache[t]
- structSpecMutex.RUnlock()
- if found {
- return ss
- }
-
- structSpecMutex.Lock()
- defer structSpecMutex.Unlock()
- ss, found = structSpecCache[t]
- if found {
- return ss
- }
-
- ss = &structSpec{m: make(map[string]*fieldSpec)}
- compileStructSpec(t, make(map[string]int), nil, ss)
- structSpecCache[t] = ss
- return ss
-}
-
-var errScanStructValue = errors.New("redigo.ScanStruct: value must be non-nil pointer to a struct")
-
-// ScanStruct scans alternating names and values from src to a struct. The
-// HGETALL and CONFIG GET commands return replies in this format.
-//
-// ScanStruct uses exported field names to match values in the response. Use
-// 'redis' field tag to override the name:
-//
-// Field int `redis:"myName"`
-//
-// Fields with the tag redis:"-" are ignored.
-//
-// Each field uses RedisScan if available otherwise:
-// Integer, float, boolean, string and []byte fields are supported. Scan uses the
-// standard strconv package to convert bulk string values to numeric and
-// boolean types.
-//
-// If a src element is nil, then the corresponding field is not modified.
-func ScanStruct(src []interface{}, dest interface{}) error {
- d := reflect.ValueOf(dest)
- if d.Kind() != reflect.Ptr || d.IsNil() {
- return errScanStructValue
- }
- d = d.Elem()
- if d.Kind() != reflect.Struct {
- return errScanStructValue
- }
- ss := structSpecForType(d.Type())
-
- if len(src)%2 != 0 {
- return errors.New("redigo.ScanStruct: number of values not a multiple of 2")
- }
-
- for i := 0; i < len(src); i += 2 {
- s := src[i+1]
- if s == nil {
- continue
- }
- name, ok := src[i].([]byte)
- if !ok {
- return fmt.Errorf("redigo.ScanStruct: key %d not a bulk string value", i)
- }
- fs := ss.fieldSpec(name)
- if fs == nil {
- continue
- }
- if err := convertAssignValue(d.FieldByIndex(fs.index), s); err != nil {
- return fmt.Errorf("redigo.ScanStruct: cannot assign field %s: %v", fs.name, err)
- }
- }
- return nil
-}
-
-var (
- errScanSliceValue = errors.New("redigo.ScanSlice: dest must be non-nil pointer to a struct")
-)
-
-// ScanSlice scans src to the slice pointed to by dest. The elements the dest
-// slice must be integer, float, boolean, string, struct or pointer to struct
-// values.
-//
-// Struct fields must be integer, float, boolean or string values. All struct
-// fields are used unless a subset is specified using fieldNames.
-func ScanSlice(src []interface{}, dest interface{}, fieldNames ...string) error {
- d := reflect.ValueOf(dest)
- if d.Kind() != reflect.Ptr || d.IsNil() {
- return errScanSliceValue
- }
- d = d.Elem()
- if d.Kind() != reflect.Slice {
- return errScanSliceValue
- }
-
- isPtr := false
- t := d.Type().Elem()
- if t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct {
- isPtr = true
- t = t.Elem()
- }
-
- if t.Kind() != reflect.Struct {
- ensureLen(d, len(src))
- for i, s := range src {
- if s == nil {
- continue
- }
- if err := convertAssignValue(d.Index(i), s); err != nil {
- return fmt.Errorf("redigo.ScanSlice: cannot assign element %d: %v", i, err)
- }
- }
- return nil
- }
-
- ss := structSpecForType(t)
- fss := ss.l
- if len(fieldNames) > 0 {
- fss = make([]*fieldSpec, len(fieldNames))
- for i, name := range fieldNames {
- fss[i] = ss.m[name]
- if fss[i] == nil {
- return fmt.Errorf("redigo.ScanSlice: ScanSlice bad field name %s", name)
- }
- }
- }
-
- if len(fss) == 0 {
- return errors.New("redigo.ScanSlice: no struct fields")
- }
-
- n := len(src) / len(fss)
- if n*len(fss) != len(src) {
- return errors.New("redigo.ScanSlice: length not a multiple of struct field count")
- }
-
- ensureLen(d, n)
- for i := 0; i < n; i++ {
- d := d.Index(i)
- if isPtr {
- if d.IsNil() {
- d.Set(reflect.New(t))
- }
- d = d.Elem()
- }
- for j, fs := range fss {
- s := src[i*len(fss)+j]
- if s == nil {
- continue
- }
- if err := convertAssignValue(d.FieldByIndex(fs.index), s); err != nil {
- return fmt.Errorf("redigo.ScanSlice: cannot assign element %d to field %s: %v", i*len(fss)+j, fs.name, err)
- }
- }
- }
- return nil
-}
-
-// Args is a helper for constructing command arguments from structured values.
-type Args []interface{}
-
-// Add returns the result of appending value to args.
-func (args Args) Add(value ...interface{}) Args {
- return append(args, value...)
-}
-
-// AddFlat returns the result of appending the flattened value of v to args.
-//
-// Maps are flattened by appending the alternating keys and map values to args.
-//
-// Slices are flattened by appending the slice elements to args.
-//
-// Structs are flattened by appending the alternating names and values of
-// exported fields to args. If v is a nil struct pointer, then nothing is
-// appended. The 'redis' field tag overrides struct field names. See ScanStruct
-// for more information on the use of the 'redis' field tag.
-//
-// Other types are appended to args as is.
-func (args Args) AddFlat(v interface{}) Args {
- rv := reflect.ValueOf(v)
- switch rv.Kind() {
- case reflect.Struct:
- args = flattenStruct(args, rv)
- case reflect.Slice:
- for i := 0; i < rv.Len(); i++ {
- args = append(args, rv.Index(i).Interface())
- }
- case reflect.Map:
- for _, k := range rv.MapKeys() {
- args = append(args, k.Interface(), rv.MapIndex(k).Interface())
- }
- case reflect.Ptr:
- if rv.Type().Elem().Kind() == reflect.Struct {
- if !rv.IsNil() {
- args = flattenStruct(args, rv.Elem())
- }
- } else {
- args = append(args, v)
- }
- default:
- args = append(args, v)
- }
- return args
-}
-
-func flattenStruct(args Args, v reflect.Value) Args {
- ss := structSpecForType(v.Type())
- for _, fs := range ss.l {
- fv := v.FieldByIndex(fs.index)
- if fs.omitEmpty {
- var empty = false
- switch fv.Kind() {
- case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
- empty = fv.Len() == 0
- case reflect.Bool:
- empty = !fv.Bool()
- case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
- empty = fv.Int() == 0
- case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
- empty = fv.Uint() == 0
- case reflect.Float32, reflect.Float64:
- empty = fv.Float() == 0
- case reflect.Interface, reflect.Ptr:
- empty = fv.IsNil()
- }
- if empty {
- continue
- }
- }
- args = append(args, fs.name, fv.Interface())
- }
- return args
-}
diff --git a/vendor/github.com/gomodule/redigo/redis/script.go b/vendor/github.com/gomodule/redigo/redis/script.go
deleted file mode 100644
index 0ef1c82..0000000
--- a/vendor/github.com/gomodule/redigo/redis/script.go
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2012 Gary Burd
-//
-// Licensed under the Apache License, Version 2.0 (the "License"): you may
-// not use this file except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-// License for the specific language governing permissions and limitations
-// under the License.
-
-package redis
-
-import (
- "crypto/sha1"
- "encoding/hex"
- "io"
- "strings"
-)
-
-// Script encapsulates the source, hash and key count for a Lua script. See
-// http://redis.io/commands/eval for information on scripts in Redis.
-type Script struct {
- keyCount int
- src string
- hash string
-}
-
-// NewScript returns a new script object. If keyCount is greater than or equal
-// to zero, then the count is automatically inserted in the EVAL command
-// argument list. If keyCount is less than zero, then the application supplies
-// the count as the first value in the keysAndArgs argument to the Do, Send and
-// SendHash methods.
-func NewScript(keyCount int, src string) *Script {
- h := sha1.New()
- io.WriteString(h, src)
- return &Script{keyCount, src, hex.EncodeToString(h.Sum(nil))}
-}
-
-func (s *Script) args(spec string, keysAndArgs []interface{}) []interface{} {
- var args []interface{}
- if s.keyCount < 0 {
- args = make([]interface{}, 1+len(keysAndArgs))
- args[0] = spec
- copy(args[1:], keysAndArgs)
- } else {
- args = make([]interface{}, 2+len(keysAndArgs))
- args[0] = spec
- args[1] = s.keyCount
- copy(args[2:], keysAndArgs)
- }
- return args
-}
-
-// Hash returns the script hash.
-func (s *Script) Hash() string {
- return s.hash
-}
-
-// Do evaluates the script. Under the covers, Do optimistically evaluates the
-// script using the EVALSHA command. If the command fails because the script is
-// not loaded, then Do evaluates the script using the EVAL command (thus
-// causing the script to load).
-func (s *Script) Do(c Conn, keysAndArgs ...interface{}) (interface{}, error) {
- v, err := c.Do("EVALSHA", s.args(s.hash, keysAndArgs)...)
- if e, ok := err.(Error); ok && strings.HasPrefix(string(e), "NOSCRIPT ") {
- v, err = c.Do("EVAL", s.args(s.src, keysAndArgs)...)
- }
- return v, err
-}
-
-// SendHash evaluates the script without waiting for the reply. The script is
-// evaluated with the EVALSHA command. The application must ensure that the
-// script is loaded by a previous call to Send, Do or Load methods.
-func (s *Script) SendHash(c Conn, keysAndArgs ...interface{}) error {
- return c.Send("EVALSHA", s.args(s.hash, keysAndArgs)...)
-}
-
-// Send evaluates the script without waiting for the reply.
-func (s *Script) Send(c Conn, keysAndArgs ...interface{}) error {
- return c.Send("EVAL", s.args(s.src, keysAndArgs)...)
-}
-
-// Load loads the script without evaluating it.
-func (s *Script) Load(c Conn) error {
- _, err := c.Do("SCRIPT", "LOAD", s.src)
- return err
-}
diff --git a/vendor/github.com/gorilla/context/.travis.yml b/vendor/github.com/gorilla/context/.travis.yml
deleted file mode 100644
index 6f440f1..0000000
--- a/vendor/github.com/gorilla/context/.travis.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-language: go
-sudo: false
-
-matrix:
- include:
- - go: 1.3
- - go: 1.4
- - go: 1.5
- - go: 1.6
- - go: 1.7
- - go: tip
- allow_failures:
- - go: tip
-
-script:
- - go get -t -v ./...
- - diff -u <(echo -n) <(gofmt -d .)
- - go vet $(go list ./... | grep -v /vendor/)
- - go test -v -race ./...
diff --git a/vendor/github.com/gorilla/context/LICENSE b/vendor/github.com/gorilla/context/LICENSE
deleted file mode 100644
index 0e5fb87..0000000
--- a/vendor/github.com/gorilla/context/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/gorilla/context/README.md b/vendor/github.com/gorilla/context/README.md
deleted file mode 100644
index 08f8669..0000000
--- a/vendor/github.com/gorilla/context/README.md
+++ /dev/null
@@ -1,10 +0,0 @@
-context
-=======
-[![Build Status](https://travis-ci.org/gorilla/context.png?branch=master)](https://travis-ci.org/gorilla/context)
-
-gorilla/context is a general purpose registry for global request variables.
-
-> Note: gorilla/context, having been born well before `context.Context` existed, does not play well
-> with the shallow copying of the request that [`http.Request.WithContext`](https://golang.org/pkg/net/http/#Request.WithContext) (added to net/http Go 1.7 onwards) performs. You should either use *just* gorilla/context, or moving forward, the new `http.Request.Context()`.
-
-Read the full documentation here: http://www.gorillatoolkit.org/pkg/context
diff --git a/vendor/github.com/gorilla/context/context.go b/vendor/github.com/gorilla/context/context.go
deleted file mode 100644
index 81cb128..0000000
--- a/vendor/github.com/gorilla/context/context.go
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package context
-
-import (
- "net/http"
- "sync"
- "time"
-)
-
-var (
- mutex sync.RWMutex
- data = make(map[*http.Request]map[interface{}]interface{})
- datat = make(map[*http.Request]int64)
-)
-
-// Set stores a value for a given key in a given request.
-func Set(r *http.Request, key, val interface{}) {
- mutex.Lock()
- if data[r] == nil {
- data[r] = make(map[interface{}]interface{})
- datat[r] = time.Now().Unix()
- }
- data[r][key] = val
- mutex.Unlock()
-}
-
-// Get returns a value stored for a given key in a given request.
-func Get(r *http.Request, key interface{}) interface{} {
- mutex.RLock()
- if ctx := data[r]; ctx != nil {
- value := ctx[key]
- mutex.RUnlock()
- return value
- }
- mutex.RUnlock()
- return nil
-}
-
-// GetOk returns stored value and presence state like multi-value return of map access.
-func GetOk(r *http.Request, key interface{}) (interface{}, bool) {
- mutex.RLock()
- if _, ok := data[r]; ok {
- value, ok := data[r][key]
- mutex.RUnlock()
- return value, ok
- }
- mutex.RUnlock()
- return nil, false
-}
-
-// GetAll returns all stored values for the request as a map. Nil is returned for invalid requests.
-func GetAll(r *http.Request) map[interface{}]interface{} {
- mutex.RLock()
- if context, ok := data[r]; ok {
- result := make(map[interface{}]interface{}, len(context))
- for k, v := range context {
- result[k] = v
- }
- mutex.RUnlock()
- return result
- }
- mutex.RUnlock()
- return nil
-}
-
-// GetAllOk returns all stored values for the request as a map and a boolean value that indicates if
-// the request was registered.
-func GetAllOk(r *http.Request) (map[interface{}]interface{}, bool) {
- mutex.RLock()
- context, ok := data[r]
- result := make(map[interface{}]interface{}, len(context))
- for k, v := range context {
- result[k] = v
- }
- mutex.RUnlock()
- return result, ok
-}
-
-// Delete removes a value stored for a given key in a given request.
-func Delete(r *http.Request, key interface{}) {
- mutex.Lock()
- if data[r] != nil {
- delete(data[r], key)
- }
- mutex.Unlock()
-}
-
-// Clear removes all values stored for a given request.
-//
-// This is usually called by a handler wrapper to clean up request
-// variables at the end of a request lifetime. See ClearHandler().
-func Clear(r *http.Request) {
- mutex.Lock()
- clear(r)
- mutex.Unlock()
-}
-
-// clear is Clear without the lock.
-func clear(r *http.Request) {
- delete(data, r)
- delete(datat, r)
-}
-
-// Purge removes request data stored for longer than maxAge, in seconds.
-// It returns the amount of requests removed.
-//
-// If maxAge <= 0, all request data is removed.
-//
-// This is only used for sanity check: in case context cleaning was not
-// properly set some request data can be kept forever, consuming an increasing
-// amount of memory. In case this is detected, Purge() must be called
-// periodically until the problem is fixed.
-func Purge(maxAge int) int {
- mutex.Lock()
- count := 0
- if maxAge <= 0 {
- count = len(data)
- data = make(map[*http.Request]map[interface{}]interface{})
- datat = make(map[*http.Request]int64)
- } else {
- min := time.Now().Unix() - int64(maxAge)
- for r := range data {
- if datat[r] < min {
- clear(r)
- count++
- }
- }
- }
- mutex.Unlock()
- return count
-}
-
-// ClearHandler wraps an http.Handler and clears request values at the end
-// of a request lifetime.
-func ClearHandler(h http.Handler) http.Handler {
- return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- defer Clear(r)
- h.ServeHTTP(w, r)
- })
-}
diff --git a/vendor/github.com/gorilla/context/doc.go b/vendor/github.com/gorilla/context/doc.go
deleted file mode 100644
index 448d1bf..0000000
--- a/vendor/github.com/gorilla/context/doc.go
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-/*
-Package context stores values shared during a request lifetime.
-
-Note: gorilla/context, having been born well before `context.Context` existed,
-does not play well > with the shallow copying of the request that
-[`http.Request.WithContext`](https://golang.org/pkg/net/http/#Request.WithContext)
-(added to net/http Go 1.7 onwards) performs. You should either use *just*
-gorilla/context, or moving forward, the new `http.Request.Context()`.
-
-For example, a router can set variables extracted from the URL and later
-application handlers can access those values, or it can be used to store
-sessions values to be saved at the end of a request. There are several
-others common uses.
-
-The idea was posted by Brad Fitzpatrick to the go-nuts mailing list:
-
- http://groups.google.com/group/golang-nuts/msg/e2d679d303aa5d53
-
-Here's the basic usage: first define the keys that you will need. The key
-type is interface{} so a key can be of any type that supports equality.
-Here we define a key using a custom int type to avoid name collisions:
-
- package foo
-
- import (
- "github.com/gorilla/context"
- )
-
- type key int
-
- const MyKey key = 0
-
-Then set a variable. Variables are bound to an http.Request object, so you
-need a request instance to set a value:
-
- context.Set(r, MyKey, "bar")
-
-The application can later access the variable using the same key you provided:
-
- func MyHandler(w http.ResponseWriter, r *http.Request) {
- // val is "bar".
- val := context.Get(r, foo.MyKey)
-
- // returns ("bar", true)
- val, ok := context.GetOk(r, foo.MyKey)
- // ...
- }
-
-And that's all about the basic usage. We discuss some other ideas below.
-
-Any type can be stored in the context. To enforce a given type, make the key
-private and wrap Get() and Set() to accept and return values of a specific
-type:
-
- type key int
-
- const mykey key = 0
-
- // GetMyKey returns a value for this package from the request values.
- func GetMyKey(r *http.Request) SomeType {
- if rv := context.Get(r, mykey); rv != nil {
- return rv.(SomeType)
- }
- return nil
- }
-
- // SetMyKey sets a value for this package in the request values.
- func SetMyKey(r *http.Request, val SomeType) {
- context.Set(r, mykey, val)
- }
-
-Variables must be cleared at the end of a request, to remove all values
-that were stored. This can be done in an http.Handler, after a request was
-served. Just call Clear() passing the request:
-
- context.Clear(r)
-
-...or use ClearHandler(), which conveniently wraps an http.Handler to clear
-variables at the end of a request lifetime.
-
-The Routers from the packages gorilla/mux and gorilla/pat call Clear()
-so if you are using either of them you don't need to clear the context manually.
-*/
-package context
diff --git a/vendor/github.com/gorilla/securecookie/.travis.yml b/vendor/github.com/gorilla/securecookie/.travis.yml
deleted file mode 100644
index 6f440f1..0000000
--- a/vendor/github.com/gorilla/securecookie/.travis.yml
+++ /dev/null
@@ -1,19 +0,0 @@
-language: go
-sudo: false
-
-matrix:
- include:
- - go: 1.3
- - go: 1.4
- - go: 1.5
- - go: 1.6
- - go: 1.7
- - go: tip
- allow_failures:
- - go: tip
-
-script:
- - go get -t -v ./...
- - diff -u <(echo -n) <(gofmt -d .)
- - go vet $(go list ./... | grep -v /vendor/)
- - go test -v -race ./...
diff --git a/vendor/github.com/gorilla/securecookie/LICENSE b/vendor/github.com/gorilla/securecookie/LICENSE
deleted file mode 100644
index 0e5fb87..0000000
--- a/vendor/github.com/gorilla/securecookie/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/gorilla/securecookie/README.md b/vendor/github.com/gorilla/securecookie/README.md
deleted file mode 100644
index aa7bd1a..0000000
--- a/vendor/github.com/gorilla/securecookie/README.md
+++ /dev/null
@@ -1,80 +0,0 @@
-securecookie
-============
-[![GoDoc](https://godoc.org/github.com/gorilla/securecookie?status.svg)](https://godoc.org/github.com/gorilla/securecookie) [![Build Status](https://travis-ci.org/gorilla/securecookie.png?branch=master)](https://travis-ci.org/gorilla/securecookie)
-[![Sourcegraph](https://sourcegraph.com/github.com/gorilla/securecookie/-/badge.svg)](https://sourcegraph.com/github.com/gorilla/securecookie?badge)
-
-
-securecookie encodes and decodes authenticated and optionally encrypted
-cookie values.
-
-Secure cookies can't be forged, because their values are validated using HMAC.
-When encrypted, the content is also inaccessible to malicious eyes. It is still
-recommended that sensitive data not be stored in cookies, and that HTTPS be used
-to prevent cookie [replay attacks](https://en.wikipedia.org/wiki/Replay_attack).
-
-## Examples
-
-To use it, first create a new SecureCookie instance:
-
-```go
-// Hash keys should be at least 32 bytes long
-var hashKey = []byte("very-secret")
-// Block keys should be 16 bytes (AES-128) or 32 bytes (AES-256) long.
-// Shorter keys may weaken the encryption used.
-var blockKey = []byte("a-lot-secret")
-var s = securecookie.New(hashKey, blockKey)
-```
-
-The hashKey is required, used to authenticate the cookie value using HMAC.
-It is recommended to use a key with 32 or 64 bytes.
-
-The blockKey is optional, used to encrypt the cookie value -- set it to nil
-to not use encryption. If set, the length must correspond to the block size
-of the encryption algorithm. For AES, used by default, valid lengths are
-16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
-
-Strong keys can be created using the convenience function GenerateRandomKey().
-
-Once a SecureCookie instance is set, use it to encode a cookie value:
-
-```go
-func SetCookieHandler(w http.ResponseWriter, r *http.Request) {
- value := map[string]string{
- "foo": "bar",
- }
- if encoded, err := s.Encode("cookie-name", value); err == nil {
- cookie := &http.Cookie{
- Name: "cookie-name",
- Value: encoded,
- Path: "/",
- Secure: true,
- HttpOnly: true,
- }
- http.SetCookie(w, cookie)
- }
-}
-```
-
-Later, use the same SecureCookie instance to decode and validate a cookie
-value:
-
-```go
-func ReadCookieHandler(w http.ResponseWriter, r *http.Request) {
- if cookie, err := r.Cookie("cookie-name"); err == nil {
- value := make(map[string]string)
- if err = s2.Decode("cookie-name", cookie.Value, &value); err == nil {
- fmt.Fprintf(w, "The value of foo is %q", value["foo"])
- }
- }
-}
-```
-
-We stored a map[string]string, but secure cookies can hold any value that
-can be encoded using `encoding/gob`. To store custom types, they must be
-registered first using gob.Register(). For basic types this is not needed;
-it works out of the box. An optional JSON encoder that uses `encoding/json` is
-available for types compatible with JSON.
-
-## License
-
-BSD licensed. See the LICENSE file for details.
diff --git a/vendor/github.com/gorilla/securecookie/doc.go b/vendor/github.com/gorilla/securecookie/doc.go
deleted file mode 100644
index ae89408..0000000
--- a/vendor/github.com/gorilla/securecookie/doc.go
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-/*
-Package securecookie encodes and decodes authenticated and optionally
-encrypted cookie values.
-
-Secure cookies can't be forged, because their values are validated using HMAC.
-When encrypted, the content is also inaccessible to malicious eyes.
-
-To use it, first create a new SecureCookie instance:
-
- var hashKey = []byte("very-secret")
- var blockKey = []byte("a-lot-secret")
- var s = securecookie.New(hashKey, blockKey)
-
-The hashKey is required, used to authenticate the cookie value using HMAC.
-It is recommended to use a key with 32 or 64 bytes.
-
-The blockKey is optional, used to encrypt the cookie value -- set it to nil
-to not use encryption. If set, the length must correspond to the block size
-of the encryption algorithm. For AES, used by default, valid lengths are
-16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
-
-Strong keys can be created using the convenience function GenerateRandomKey().
-
-Once a SecureCookie instance is set, use it to encode a cookie value:
-
- func SetCookieHandler(w http.ResponseWriter, r *http.Request) {
- value := map[string]string{
- "foo": "bar",
- }
- if encoded, err := s.Encode("cookie-name", value); err == nil {
- cookie := &http.Cookie{
- Name: "cookie-name",
- Value: encoded,
- Path: "/",
- }
- http.SetCookie(w, cookie)
- }
- }
-
-Later, use the same SecureCookie instance to decode and validate a cookie
-value:
-
- func ReadCookieHandler(w http.ResponseWriter, r *http.Request) {
- if cookie, err := r.Cookie("cookie-name"); err == nil {
- value := make(map[string]string)
- if err = s2.Decode("cookie-name", cookie.Value, &value); err == nil {
- fmt.Fprintf(w, "The value of foo is %q", value["foo"])
- }
- }
- }
-
-We stored a map[string]string, but secure cookies can hold any value that
-can be encoded using encoding/gob. To store custom types, they must be
-registered first using gob.Register(). For basic types this is not needed;
-it works out of the box.
-*/
-package securecookie
diff --git a/vendor/github.com/gorilla/securecookie/fuzz.go b/vendor/github.com/gorilla/securecookie/fuzz.go
deleted file mode 100644
index e4d0534..0000000
--- a/vendor/github.com/gorilla/securecookie/fuzz.go
+++ /dev/null
@@ -1,25 +0,0 @@
-// +build gofuzz
-
-package securecookie
-
-var hashKey = []byte("very-secret12345")
-var blockKey = []byte("a-lot-secret1234")
-var s = New(hashKey, blockKey)
-
-type Cookie struct {
- B bool
- I int
- S string
-}
-
-func Fuzz(data []byte) int {
- datas := string(data)
- var c Cookie
- if err := s.Decode("fuzz", datas, &c); err != nil {
- return 0
- }
- if _, err := s.Encode("fuzz", c); err != nil {
- panic(err)
- }
- return 1
-}
diff --git a/vendor/github.com/gorilla/securecookie/securecookie.go b/vendor/github.com/gorilla/securecookie/securecookie.go
deleted file mode 100644
index cd4e097..0000000
--- a/vendor/github.com/gorilla/securecookie/securecookie.go
+++ /dev/null
@@ -1,646 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package securecookie
-
-import (
- "bytes"
- "crypto/aes"
- "crypto/cipher"
- "crypto/hmac"
- "crypto/rand"
- "crypto/sha256"
- "crypto/subtle"
- "encoding/base64"
- "encoding/gob"
- "encoding/json"
- "fmt"
- "hash"
- "io"
- "strconv"
- "strings"
- "time"
-)
-
-// Error is the interface of all errors returned by functions in this library.
-type Error interface {
- error
-
- // IsUsage returns true for errors indicating the client code probably
- // uses this library incorrectly. For example, the client may have
- // failed to provide a valid hash key, or may have failed to configure
- // the Serializer adequately for encoding value.
- IsUsage() bool
-
- // IsDecode returns true for errors indicating that a cookie could not
- // be decoded and validated. Since cookies are usually untrusted
- // user-provided input, errors of this type should be expected.
- // Usually, the proper action is simply to reject the request.
- IsDecode() bool
-
- // IsInternal returns true for unexpected errors occurring in the
- // securecookie implementation.
- IsInternal() bool
-
- // Cause, if it returns a non-nil value, indicates that this error was
- // propagated from some underlying library. If this method returns nil,
- // this error was raised directly by this library.
- //
- // Cause is provided principally for debugging/logging purposes; it is
- // rare that application logic should perform meaningfully different
- // logic based on Cause. See, for example, the caveats described on
- // (MultiError).Cause().
- Cause() error
-}
-
-// errorType is a bitmask giving the error type(s) of an cookieError value.
-type errorType int
-
-const (
- usageError = errorType(1 << iota)
- decodeError
- internalError
-)
-
-type cookieError struct {
- typ errorType
- msg string
- cause error
-}
-
-func (e cookieError) IsUsage() bool { return (e.typ & usageError) != 0 }
-func (e cookieError) IsDecode() bool { return (e.typ & decodeError) != 0 }
-func (e cookieError) IsInternal() bool { return (e.typ & internalError) != 0 }
-
-func (e cookieError) Cause() error { return e.cause }
-
-func (e cookieError) Error() string {
- parts := []string{"securecookie: "}
- if e.msg == "" {
- parts = append(parts, "error")
- } else {
- parts = append(parts, e.msg)
- }
- if c := e.Cause(); c != nil {
- parts = append(parts, " - caused by: ", c.Error())
- }
- return strings.Join(parts, "")
-}
-
-var (
- errGeneratingIV = cookieError{typ: internalError, msg: "failed to generate random iv"}
-
- errNoCodecs = cookieError{typ: usageError, msg: "no codecs provided"}
- errHashKeyNotSet = cookieError{typ: usageError, msg: "hash key is not set"}
- errBlockKeyNotSet = cookieError{typ: usageError, msg: "block key is not set"}
- errEncodedValueTooLong = cookieError{typ: usageError, msg: "the value is too long"}
-
- errValueToDecodeTooLong = cookieError{typ: decodeError, msg: "the value is too long"}
- errTimestampInvalid = cookieError{typ: decodeError, msg: "invalid timestamp"}
- errTimestampTooNew = cookieError{typ: decodeError, msg: "timestamp is too new"}
- errTimestampExpired = cookieError{typ: decodeError, msg: "expired timestamp"}
- errDecryptionFailed = cookieError{typ: decodeError, msg: "the value could not be decrypted"}
- errValueNotByte = cookieError{typ: decodeError, msg: "value not a []byte."}
- errValueNotBytePtr = cookieError{typ: decodeError, msg: "value not a pointer to []byte."}
-
- // ErrMacInvalid indicates that cookie decoding failed because the HMAC
- // could not be extracted and verified. Direct use of this error
- // variable is deprecated; it is public only for legacy compatibility,
- // and may be privatized in the future, as it is rarely useful to
- // distinguish between this error and other Error implementations.
- ErrMacInvalid = cookieError{typ: decodeError, msg: "the value is not valid"}
-)
-
-// Codec defines an interface to encode and decode cookie values.
-type Codec interface {
- Encode(name string, value interface{}) (string, error)
- Decode(name, value string, dst interface{}) error
-}
-
-// New returns a new SecureCookie.
-//
-// hashKey is required, used to authenticate values using HMAC. Create it using
-// GenerateRandomKey(). It is recommended to use a key with 32 or 64 bytes.
-//
-// blockKey is optional, used to encrypt values. Create it using
-// GenerateRandomKey(). The key length must correspond to the block size
-// of the encryption algorithm. For AES, used by default, valid lengths are
-// 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
-// The default encoder used for cookie serialization is encoding/gob.
-//
-// Note that keys created using GenerateRandomKey() are not automatically
-// persisted. New keys will be created when the application is restarted, and
-// previously issued cookies will not be able to be decoded.
-func New(hashKey, blockKey []byte) *SecureCookie {
- s := &SecureCookie{
- hashKey: hashKey,
- blockKey: blockKey,
- hashFunc: sha256.New,
- maxAge: 86400 * 30,
- maxLength: 4096,
- sz: GobEncoder{},
- }
- if hashKey == nil {
- s.err = errHashKeyNotSet
- }
- if blockKey != nil {
- s.BlockFunc(aes.NewCipher)
- }
- return s
-}
-
-// SecureCookie encodes and decodes authenticated and optionally encrypted
-// cookie values.
-type SecureCookie struct {
- hashKey []byte
- hashFunc func() hash.Hash
- blockKey []byte
- block cipher.Block
- maxLength int
- maxAge int64
- minAge int64
- err error
- sz Serializer
- // For testing purposes, the function that returns the current timestamp.
- // If not set, it will use time.Now().UTC().Unix().
- timeFunc func() int64
-}
-
-// Serializer provides an interface for providing custom serializers for cookie
-// values.
-type Serializer interface {
- Serialize(src interface{}) ([]byte, error)
- Deserialize(src []byte, dst interface{}) error
-}
-
-// GobEncoder encodes cookie values using encoding/gob. This is the simplest
-// encoder and can handle complex types via gob.Register.
-type GobEncoder struct{}
-
-// JSONEncoder encodes cookie values using encoding/json. Users who wish to
-// encode complex types need to satisfy the json.Marshaller and
-// json.Unmarshaller interfaces.
-type JSONEncoder struct{}
-
-// NopEncoder does not encode cookie values, and instead simply accepts a []byte
-// (as an interface{}) and returns a []byte. This is particularly useful when
-// you encoding an object upstream and do not wish to re-encode it.
-type NopEncoder struct{}
-
-// MaxLength restricts the maximum length, in bytes, for the cookie value.
-//
-// Default is 4096, which is the maximum value accepted by Internet Explorer.
-func (s *SecureCookie) MaxLength(value int) *SecureCookie {
- s.maxLength = value
- return s
-}
-
-// MaxAge restricts the maximum age, in seconds, for the cookie value.
-//
-// Default is 86400 * 30. Set it to 0 for no restriction.
-func (s *SecureCookie) MaxAge(value int) *SecureCookie {
- s.maxAge = int64(value)
- return s
-}
-
-// MinAge restricts the minimum age, in seconds, for the cookie value.
-//
-// Default is 0 (no restriction).
-func (s *SecureCookie) MinAge(value int) *SecureCookie {
- s.minAge = int64(value)
- return s
-}
-
-// HashFunc sets the hash function used to create HMAC.
-//
-// Default is crypto/sha256.New.
-func (s *SecureCookie) HashFunc(f func() hash.Hash) *SecureCookie {
- s.hashFunc = f
- return s
-}
-
-// BlockFunc sets the encryption function used to create a cipher.Block.
-//
-// Default is crypto/aes.New.
-func (s *SecureCookie) BlockFunc(f func([]byte) (cipher.Block, error)) *SecureCookie {
- if s.blockKey == nil {
- s.err = errBlockKeyNotSet
- } else if block, err := f(s.blockKey); err == nil {
- s.block = block
- } else {
- s.err = cookieError{cause: err, typ: usageError}
- }
- return s
-}
-
-// Encoding sets the encoding/serialization method for cookies.
-//
-// Default is encoding/gob. To encode special structures using encoding/gob,
-// they must be registered first using gob.Register().
-func (s *SecureCookie) SetSerializer(sz Serializer) *SecureCookie {
- s.sz = sz
-
- return s
-}
-
-// Encode encodes a cookie value.
-//
-// It serializes, optionally encrypts, signs with a message authentication code,
-// and finally encodes the value.
-//
-// The name argument is the cookie name. It is stored with the encoded value.
-// The value argument is the value to be encoded. It can be any value that can
-// be encoded using the currently selected serializer; see SetSerializer().
-//
-// It is the client's responsibility to ensure that value, when encoded using
-// the current serialization/encryption settings on s and then base64-encoded,
-// is shorter than the maximum permissible length.
-func (s *SecureCookie) Encode(name string, value interface{}) (string, error) {
- if s.err != nil {
- return "", s.err
- }
- if s.hashKey == nil {
- s.err = errHashKeyNotSet
- return "", s.err
- }
- var err error
- var b []byte
- // 1. Serialize.
- if b, err = s.sz.Serialize(value); err != nil {
- return "", cookieError{cause: err, typ: usageError}
- }
- // 2. Encrypt (optional).
- if s.block != nil {
- if b, err = encrypt(s.block, b); err != nil {
- return "", cookieError{cause: err, typ: usageError}
- }
- }
- b = encode(b)
- // 3. Create MAC for "name|date|value". Extra pipe to be used later.
- b = []byte(fmt.Sprintf("%s|%d|%s|", name, s.timestamp(), b))
- mac := createMac(hmac.New(s.hashFunc, s.hashKey), b[:len(b)-1])
- // Append mac, remove name.
- b = append(b, mac...)[len(name)+1:]
- // 4. Encode to base64.
- b = encode(b)
- // 5. Check length.
- if s.maxLength != 0 && len(b) > s.maxLength {
- return "", errEncodedValueTooLong
- }
- // Done.
- return string(b), nil
-}
-
-// Decode decodes a cookie value.
-//
-// It decodes, verifies a message authentication code, optionally decrypts and
-// finally deserializes the value.
-//
-// The name argument is the cookie name. It must be the same name used when
-// it was stored. The value argument is the encoded cookie value. The dst
-// argument is where the cookie will be decoded. It must be a pointer.
-func (s *SecureCookie) Decode(name, value string, dst interface{}) error {
- if s.err != nil {
- return s.err
- }
- if s.hashKey == nil {
- s.err = errHashKeyNotSet
- return s.err
- }
- // 1. Check length.
- if s.maxLength != 0 && len(value) > s.maxLength {
- return errValueToDecodeTooLong
- }
- // 2. Decode from base64.
- b, err := decode([]byte(value))
- if err != nil {
- return err
- }
- // 3. Verify MAC. Value is "date|value|mac".
- parts := bytes.SplitN(b, []byte("|"), 3)
- if len(parts) != 3 {
- return ErrMacInvalid
- }
- h := hmac.New(s.hashFunc, s.hashKey)
- b = append([]byte(name+"|"), b[:len(b)-len(parts[2])-1]...)
- if err = verifyMac(h, b, parts[2]); err != nil {
- return err
- }
- // 4. Verify date ranges.
- var t1 int64
- if t1, err = strconv.ParseInt(string(parts[0]), 10, 64); err != nil {
- return errTimestampInvalid
- }
- t2 := s.timestamp()
- if s.minAge != 0 && t1 > t2-s.minAge {
- return errTimestampTooNew
- }
- if s.maxAge != 0 && t1 < t2-s.maxAge {
- return errTimestampExpired
- }
- // 5. Decrypt (optional).
- b, err = decode(parts[1])
- if err != nil {
- return err
- }
- if s.block != nil {
- if b, err = decrypt(s.block, b); err != nil {
- return err
- }
- }
- // 6. Deserialize.
- if err = s.sz.Deserialize(b, dst); err != nil {
- return cookieError{cause: err, typ: decodeError}
- }
- // Done.
- return nil
-}
-
-// timestamp returns the current timestamp, in seconds.
-//
-// For testing purposes, the function that generates the timestamp can be
-// overridden. If not set, it will return time.Now().UTC().Unix().
-func (s *SecureCookie) timestamp() int64 {
- if s.timeFunc == nil {
- return time.Now().UTC().Unix()
- }
- return s.timeFunc()
-}
-
-// Authentication -------------------------------------------------------------
-
-// createMac creates a message authentication code (MAC).
-func createMac(h hash.Hash, value []byte) []byte {
- h.Write(value)
- return h.Sum(nil)
-}
-
-// verifyMac verifies that a message authentication code (MAC) is valid.
-func verifyMac(h hash.Hash, value []byte, mac []byte) error {
- mac2 := createMac(h, value)
- // Check that both MACs are of equal length, as subtle.ConstantTimeCompare
- // does not do this prior to Go 1.4.
- if len(mac) == len(mac2) && subtle.ConstantTimeCompare(mac, mac2) == 1 {
- return nil
- }
- return ErrMacInvalid
-}
-
-// Encryption -----------------------------------------------------------------
-
-// encrypt encrypts a value using the given block in counter mode.
-//
-// A random initialization vector (http://goo.gl/zF67k) with the length of the
-// block size is prepended to the resulting ciphertext.
-func encrypt(block cipher.Block, value []byte) ([]byte, error) {
- iv := GenerateRandomKey(block.BlockSize())
- if iv == nil {
- return nil, errGeneratingIV
- }
- // Encrypt it.
- stream := cipher.NewCTR(block, iv)
- stream.XORKeyStream(value, value)
- // Return iv + ciphertext.
- return append(iv, value...), nil
-}
-
-// decrypt decrypts a value using the given block in counter mode.
-//
-// The value to be decrypted must be prepended by a initialization vector
-// (http://goo.gl/zF67k) with the length of the block size.
-func decrypt(block cipher.Block, value []byte) ([]byte, error) {
- size := block.BlockSize()
- if len(value) > size {
- // Extract iv.
- iv := value[:size]
- // Extract ciphertext.
- value = value[size:]
- // Decrypt it.
- stream := cipher.NewCTR(block, iv)
- stream.XORKeyStream(value, value)
- return value, nil
- }
- return nil, errDecryptionFailed
-}
-
-// Serialization --------------------------------------------------------------
-
-// Serialize encodes a value using gob.
-func (e GobEncoder) Serialize(src interface{}) ([]byte, error) {
- buf := new(bytes.Buffer)
- enc := gob.NewEncoder(buf)
- if err := enc.Encode(src); err != nil {
- return nil, cookieError{cause: err, typ: usageError}
- }
- return buf.Bytes(), nil
-}
-
-// Deserialize decodes a value using gob.
-func (e GobEncoder) Deserialize(src []byte, dst interface{}) error {
- dec := gob.NewDecoder(bytes.NewBuffer(src))
- if err := dec.Decode(dst); err != nil {
- return cookieError{cause: err, typ: decodeError}
- }
- return nil
-}
-
-// Serialize encodes a value using encoding/json.
-func (e JSONEncoder) Serialize(src interface{}) ([]byte, error) {
- buf := new(bytes.Buffer)
- enc := json.NewEncoder(buf)
- if err := enc.Encode(src); err != nil {
- return nil, cookieError{cause: err, typ: usageError}
- }
- return buf.Bytes(), nil
-}
-
-// Deserialize decodes a value using encoding/json.
-func (e JSONEncoder) Deserialize(src []byte, dst interface{}) error {
- dec := json.NewDecoder(bytes.NewReader(src))
- if err := dec.Decode(dst); err != nil {
- return cookieError{cause: err, typ: decodeError}
- }
- return nil
-}
-
-// Serialize passes a []byte through as-is.
-func (e NopEncoder) Serialize(src interface{}) ([]byte, error) {
- if b, ok := src.([]byte); ok {
- return b, nil
- }
-
- return nil, errValueNotByte
-}
-
-// Deserialize passes a []byte through as-is.
-func (e NopEncoder) Deserialize(src []byte, dst interface{}) error {
- if dat, ok := dst.(*[]byte); ok {
- *dat = src
- return nil
- }
- return errValueNotBytePtr
-}
-
-// Encoding -------------------------------------------------------------------
-
-// encode encodes a value using base64.
-func encode(value []byte) []byte {
- encoded := make([]byte, base64.URLEncoding.EncodedLen(len(value)))
- base64.URLEncoding.Encode(encoded, value)
- return encoded
-}
-
-// decode decodes a cookie using base64.
-func decode(value []byte) ([]byte, error) {
- decoded := make([]byte, base64.URLEncoding.DecodedLen(len(value)))
- b, err := base64.URLEncoding.Decode(decoded, value)
- if err != nil {
- return nil, cookieError{cause: err, typ: decodeError, msg: "base64 decode failed"}
- }
- return decoded[:b], nil
-}
-
-// Helpers --------------------------------------------------------------------
-
-// GenerateRandomKey creates a random key with the given length in bytes.
-// On failure, returns nil.
-//
-// Callers should explicitly check for the possibility of a nil return, treat
-// it as a failure of the system random number generator, and not continue.
-func GenerateRandomKey(length int) []byte {
- k := make([]byte, length)
- if _, err := io.ReadFull(rand.Reader, k); err != nil {
- return nil
- }
- return k
-}
-
-// CodecsFromPairs returns a slice of SecureCookie instances.
-//
-// It is a convenience function to create a list of codecs for key rotation. Note
-// that the generated Codecs will have the default options applied: callers
-// should iterate over each Codec and type-assert the underlying *SecureCookie to
-// change these.
-//
-// Example:
-//
-// codecs := securecookie.CodecsFromPairs(
-// []byte("new-hash-key"),
-// []byte("new-block-key"),
-// []byte("old-hash-key"),
-// []byte("old-block-key"),
-// )
-//
-// // Modify each instance.
-// for _, s := range codecs {
-// if cookie, ok := s.(*securecookie.SecureCookie); ok {
-// cookie.MaxAge(86400 * 7)
-// cookie.SetSerializer(securecookie.JSONEncoder{})
-// cookie.HashFunc(sha512.New512_256)
-// }
-// }
-//
-func CodecsFromPairs(keyPairs ...[]byte) []Codec {
- codecs := make([]Codec, len(keyPairs)/2+len(keyPairs)%2)
- for i := 0; i < len(keyPairs); i += 2 {
- var blockKey []byte
- if i+1 < len(keyPairs) {
- blockKey = keyPairs[i+1]
- }
- codecs[i/2] = New(keyPairs[i], blockKey)
- }
- return codecs
-}
-
-// EncodeMulti encodes a cookie value using a group of codecs.
-//
-// The codecs are tried in order. Multiple codecs are accepted to allow
-// key rotation.
-//
-// On error, may return a MultiError.
-func EncodeMulti(name string, value interface{}, codecs ...Codec) (string, error) {
- if len(codecs) == 0 {
- return "", errNoCodecs
- }
-
- var errors MultiError
- for _, codec := range codecs {
- encoded, err := codec.Encode(name, value)
- if err == nil {
- return encoded, nil
- }
- errors = append(errors, err)
- }
- return "", errors
-}
-
-// DecodeMulti decodes a cookie value using a group of codecs.
-//
-// The codecs are tried in order. Multiple codecs are accepted to allow
-// key rotation.
-//
-// On error, may return a MultiError.
-func DecodeMulti(name string, value string, dst interface{}, codecs ...Codec) error {
- if len(codecs) == 0 {
- return errNoCodecs
- }
-
- var errors MultiError
- for _, codec := range codecs {
- err := codec.Decode(name, value, dst)
- if err == nil {
- return nil
- }
- errors = append(errors, err)
- }
- return errors
-}
-
-// MultiError groups multiple errors.
-type MultiError []error
-
-func (m MultiError) IsUsage() bool { return m.any(func(e Error) bool { return e.IsUsage() }) }
-func (m MultiError) IsDecode() bool { return m.any(func(e Error) bool { return e.IsDecode() }) }
-func (m MultiError) IsInternal() bool { return m.any(func(e Error) bool { return e.IsInternal() }) }
-
-// Cause returns nil for MultiError; there is no unique underlying cause in the
-// general case.
-//
-// Note: we could conceivably return a non-nil Cause only when there is exactly
-// one child error with a Cause. However, it would be brittle for client code
-// to rely on the arity of causes inside a MultiError, so we have opted not to
-// provide this functionality. Clients which really wish to access the Causes
-// of the underlying errors are free to iterate through the errors themselves.
-func (m MultiError) Cause() error { return nil }
-
-func (m MultiError) Error() string {
- s, n := "", 0
- for _, e := range m {
- if e != nil {
- if n == 0 {
- s = e.Error()
- }
- n++
- }
- }
- switch n {
- case 0:
- return "(0 errors)"
- case 1:
- return s
- case 2:
- return s + " (and 1 other error)"
- }
- return fmt.Sprintf("%s (and %d other errors)", s, n-1)
-}
-
-// any returns true if any element of m is an Error for which pred returns true.
-func (m MultiError) any(pred func(Error) bool) bool {
- for _, e := range m {
- if ourErr, ok := e.(Error); ok && pred(ourErr) {
- return true
- }
- }
- return false
-}
diff --git a/vendor/github.com/gorilla/sessions/.travis.yml b/vendor/github.com/gorilla/sessions/.travis.yml
deleted file mode 100644
index 899d4cb..0000000
--- a/vendor/github.com/gorilla/sessions/.travis.yml
+++ /dev/null
@@ -1,28 +0,0 @@
-language: go
-sudo: false
-
-matrix:
- include:
- - go: 1.3.x
- - go: 1.4.x
- - go: 1.5.x
- - go: 1.6.x
- - go: 1.7.x
- - go: 1.8.x
- - go: 1.9.x
- - go: 1.10.x
- - go: 1.11.x
- - go: 1.x
- env: LATEST=true
- - go: tip
- allow_failures:
- - go: tip
-
-install:
- - # skip
-
-script:
- - go get -t -v ./...
- - diff -u <(echo -n) <(gofmt -d .)
- - if [[ "$LATEST" = true ]]; then go vet $(go list ./... | grep -v /vendor/); fi
- - go test -v -race ./...
diff --git a/vendor/github.com/gorilla/sessions/AUTHORS b/vendor/github.com/gorilla/sessions/AUTHORS
deleted file mode 100644
index 1e3e7ac..0000000
--- a/vendor/github.com/gorilla/sessions/AUTHORS
+++ /dev/null
@@ -1,43 +0,0 @@
-# This is the official list of gorilla/sessions authors for copyright purposes.
-#
-# Please keep the list sorted.
-
-Ahmadreza Zibaei
-Anton Lindström
-Brian Jones
-Collin Stedman
-Deniz Eren
-Dmitry Chestnykh
-Dustin Oprea
-Egon Elbre
-enumappstore
-Geofrey Ernest
-Google LLC (https://opensource.google.com/)
-Jerry Saravia
-Jonathan Gillham
-Justin Clift
-Justin Hellings
-Kamil Kisiel
-Keiji Yoshida
-kliron
-Kshitij Saraogi
-Lauris BH
-Lukas Rist
-Mark Dain
-Matt Ho
-Matt Silverlock
-Mattias Wadman
-Michael Schuett
-Michael Stapelberg
-Mirco Zeiss
-moraes
-nvcnvn
-pappz
-Pontus Leitzler
-QuaSoft
-rcadena
-rodrigo moraes
-Shawn Smith
-Taylor Hurt
-Tortuoise
-Vitor De Mario
diff --git a/vendor/github.com/gorilla/sessions/LICENSE b/vendor/github.com/gorilla/sessions/LICENSE
deleted file mode 100644
index 6903df6..0000000
--- a/vendor/github.com/gorilla/sessions/LICENSE
+++ /dev/null
@@ -1,27 +0,0 @@
-Copyright (c) 2012-2018 The Gorilla Authors. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/gorilla/sessions/README.md b/vendor/github.com/gorilla/sessions/README.md
deleted file mode 100644
index 12dd18a..0000000
--- a/vendor/github.com/gorilla/sessions/README.md
+++ /dev/null
@@ -1,95 +0,0 @@
-# sessions
-
-[![GoDoc](https://godoc.org/github.com/gorilla/sessions?status.svg)](https://godoc.org/github.com/gorilla/sessions) [![Build Status](https://travis-ci.org/gorilla/sessions.svg?branch=master)](https://travis-ci.org/gorilla/sessions)
-[![Sourcegraph](https://sourcegraph.com/github.com/gorilla/sessions/-/badge.svg)](https://sourcegraph.com/github.com/gorilla/sessions?badge)
-
-gorilla/sessions provides cookie and filesystem sessions and infrastructure for
-custom session backends.
-
-The key features are:
-
-- Simple API: use it as an easy way to set signed (and optionally
- encrypted) cookies.
-- Built-in backends to store sessions in cookies or the filesystem.
-- Flash messages: session values that last until read.
-- Convenient way to switch session persistency (aka "remember me") and set
- other attributes.
-- Mechanism to rotate authentication and encryption keys.
-- Multiple sessions per request, even using different backends.
-- Interfaces and infrastructure for custom session backends: sessions from
- different stores can be retrieved and batch-saved using a common API.
-
-Let's start with an example that shows the sessions API in a nutshell:
-
-```go
- import (
- "net/http"
- "github.com/gorilla/sessions"
- )
-
- // Note: Don't store your key in your source code. Pass it via an
- // environmental variable, or flag (or both), and don't accidentally commit it
- // alongside your code. Ensure your key is sufficiently random - i.e. use Go's
- // crypto/rand or securecookie.GenerateRandomKey(32) and persist the result.
- var store = sessions.NewCookieStore(os.Getenv("SESSION_KEY"))
-
- func MyHandler(w http.ResponseWriter, r *http.Request) {
- // Get a session. We're ignoring the error resulted from decoding an
- // existing session: Get() always returns a session, even if empty.
- session, _ := store.Get(r, "session-name")
- // Set some session values.
- session.Values["foo"] = "bar"
- session.Values[42] = 43
- // Save it before we write to the response/return from the handler.
- session.Save(r, w)
- }
-```
-
-First we initialize a session store calling `NewCookieStore()` and passing a
-secret key used to authenticate the session. Inside the handler, we call
-`store.Get()` to retrieve an existing session or create a new one. Then we set
-some session values in session.Values, which is a `map[interface{}]interface{}`.
-And finally we call `session.Save()` to save the session in the response.
-
-Important Note: If you aren't using gorilla/mux, you need to wrap your handlers
-with
-[`context.ClearHandler`](http://www.gorillatoolkit.org/pkg/context#ClearHandler)
-or else you will leak memory! An easy way to do this is to wrap the top-level
-mux when calling http.ListenAndServe:
-
-```go
- http.ListenAndServe(":8080", context.ClearHandler(http.DefaultServeMux))
-```
-
-The ClearHandler function is provided by the gorilla/context package.
-
-More examples are available [on the Gorilla
-website](http://www.gorillatoolkit.org/pkg/sessions).
-
-## Store Implementations
-
-Other implementations of the `sessions.Store` interface:
-
-- [github.com/starJammer/gorilla-sessions-arangodb](https://github.com/starJammer/gorilla-sessions-arangodb) - ArangoDB
-- [github.com/yosssi/boltstore](https://github.com/yosssi/boltstore) - Bolt
-- [github.com/srinathgs/couchbasestore](https://github.com/srinathgs/couchbasestore) - Couchbase
-- [github.com/denizeren/dynamostore](https://github.com/denizeren/dynamostore) - Dynamodb on AWS
-- [github.com/savaki/dynastore](https://github.com/savaki/dynastore) - DynamoDB on AWS (Official AWS library)
-- [github.com/bradleypeabody/gorilla-sessions-memcache](https://github.com/bradleypeabody/gorilla-sessions-memcache) - Memcache
-- [github.com/dsoprea/go-appengine-sessioncascade](https://github.com/dsoprea/go-appengine-sessioncascade) - Memcache/Datastore/Context in AppEngine
-- [github.com/kidstuff/mongostore](https://github.com/kidstuff/mongostore) - MongoDB
-- [github.com/srinathgs/mysqlstore](https://github.com/srinathgs/mysqlstore) - MySQL
-- [github.com/EnumApps/clustersqlstore](https://github.com/EnumApps/clustersqlstore) - MySQL Cluster
-- [github.com/antonlindstrom/pgstore](https://github.com/antonlindstrom/pgstore) - PostgreSQL
-- [github.com/boj/redistore](https://github.com/boj/redistore) - Redis
-- [github.com/boj/rethinkstore](https://github.com/boj/rethinkstore) - RethinkDB
-- [github.com/boj/riakstore](https://github.com/boj/riakstore) - Riak
-- [github.com/michaeljs1990/sqlitestore](https://github.com/michaeljs1990/sqlitestore) - SQLite
-- [github.com/wader/gormstore](https://github.com/wader/gormstore) - GORM (MySQL, PostgreSQL, SQLite)
-- [github.com/gernest/qlstore](https://github.com/gernest/qlstore) - ql
-- [github.com/quasoft/memstore](https://github.com/quasoft/memstore) - In-memory implementation for use in unit tests
-- [github.com/lafriks/xormstore](https://github.com/lafriks/xormstore) - XORM (MySQL, PostgreSQL, SQLite, Microsoft SQL Server, TiDB)
-
-## License
-
-BSD licensed. See the LICENSE file for details.
diff --git a/vendor/github.com/gorilla/sessions/cookie.go b/vendor/github.com/gorilla/sessions/cookie.go
deleted file mode 100644
index 1928b04..0000000
--- a/vendor/github.com/gorilla/sessions/cookie.go
+++ /dev/null
@@ -1,19 +0,0 @@
-// +build !go1.11
-
-package sessions
-
-import "net/http"
-
-// newCookieFromOptions returns an http.Cookie with the options set.
-func newCookieFromOptions(name, value string, options *Options) *http.Cookie {
- return &http.Cookie{
- Name: name,
- Value: value,
- Path: options.Path,
- Domain: options.Domain,
- MaxAge: options.MaxAge,
- Secure: options.Secure,
- HttpOnly: options.HttpOnly,
- }
-
-}
diff --git a/vendor/github.com/gorilla/sessions/cookie_go111.go b/vendor/github.com/gorilla/sessions/cookie_go111.go
deleted file mode 100644
index 173d1a3..0000000
--- a/vendor/github.com/gorilla/sessions/cookie_go111.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// +build go1.11
-
-package sessions
-
-import "net/http"
-
-// newCookieFromOptions returns an http.Cookie with the options set.
-func newCookieFromOptions(name, value string, options *Options) *http.Cookie {
- return &http.Cookie{
- Name: name,
- Value: value,
- Path: options.Path,
- Domain: options.Domain,
- MaxAge: options.MaxAge,
- Secure: options.Secure,
- HttpOnly: options.HttpOnly,
- SameSite: options.SameSite,
- }
-
-}
diff --git a/vendor/github.com/gorilla/sessions/doc.go b/vendor/github.com/gorilla/sessions/doc.go
deleted file mode 100644
index 7db6729..0000000
--- a/vendor/github.com/gorilla/sessions/doc.go
+++ /dev/null
@@ -1,202 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-/*
-Package sessions provides cookie and filesystem sessions and
-infrastructure for custom session backends.
-
-The key features are:
-
- * Simple API: use it as an easy way to set signed (and optionally
- encrypted) cookies.
- * Built-in backends to store sessions in cookies or the filesystem.
- * Flash messages: session values that last until read.
- * Convenient way to switch session persistency (aka "remember me") and set
- other attributes.
- * Mechanism to rotate authentication and encryption keys.
- * Multiple sessions per request, even using different backends.
- * Interfaces and infrastructure for custom session backends: sessions from
- different stores can be retrieved and batch-saved using a common API.
-
-Let's start with an example that shows the sessions API in a nutshell:
-
- import (
- "net/http"
- "github.com/gorilla/sessions"
- )
-
- // Note: Don't store your key in your source code. Pass it via an
- // environmental variable, or flag (or both), and don't accidentally commit it
- // alongside your code. Ensure your key is sufficiently random - i.e. use Go's
- // crypto/rand or securecookie.GenerateRandomKey(32) and persist the result.
- var store = sessions.NewCookieStore(os.Getenv("SESSION_KEY"))
-
- func MyHandler(w http.ResponseWriter, r *http.Request) {
- // Get a session. Get() always returns a session, even if empty.
- session, err := store.Get(r, "session-name")
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
-
- // Set some session values.
- session.Values["foo"] = "bar"
- session.Values[42] = 43
- // Save it before we write to the response/return from the handler.
- session.Save(r, w)
- }
-
-First we initialize a session store calling NewCookieStore() and passing a
-secret key used to authenticate the session. Inside the handler, we call
-store.Get() to retrieve an existing session or a new one. Then we set some
-session values in session.Values, which is a map[interface{}]interface{}.
-And finally we call session.Save() to save the session in the response.
-
-Note that in production code, we should check for errors when calling
-session.Save(r, w), and either display an error message or otherwise handle it.
-
-Save must be called before writing to the response, otherwise the session
-cookie will not be sent to the client.
-
-Important Note: If you aren't using gorilla/mux, you need to wrap your handlers
-with context.ClearHandler as or else you will leak memory! An easy way to do this
-is to wrap the top-level mux when calling http.ListenAndServe:
-
- http.ListenAndServe(":8080", context.ClearHandler(http.DefaultServeMux))
-
-The ClearHandler function is provided by the gorilla/context package.
-
-That's all you need to know for the basic usage. Let's take a look at other
-options, starting with flash messages.
-
-Flash messages are session values that last until read. The term appeared with
-Ruby On Rails a few years back. When we request a flash message, it is removed
-from the session. To add a flash, call session.AddFlash(), and to get all
-flashes, call session.Flashes(). Here is an example:
-
- func MyHandler(w http.ResponseWriter, r *http.Request) {
- // Get a session.
- session, err := store.Get(r, "session-name")
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
-
- // Get the previous flashes, if any.
- if flashes := session.Flashes(); len(flashes) > 0 {
- // Use the flash values.
- } else {
- // Set a new flash.
- session.AddFlash("Hello, flash messages world!")
- }
- session.Save(r, w)
- }
-
-Flash messages are useful to set information to be read after a redirection,
-like after form submissions.
-
-There may also be cases where you want to store a complex datatype within a
-session, such as a struct. Sessions are serialised using the encoding/gob package,
-so it is easy to register new datatypes for storage in sessions:
-
- import(
- "encoding/gob"
- "github.com/gorilla/sessions"
- )
-
- type Person struct {
- FirstName string
- LastName string
- Email string
- Age int
- }
-
- type M map[string]interface{}
-
- func init() {
-
- gob.Register(&Person{})
- gob.Register(&M{})
- }
-
-As it's not possible to pass a raw type as a parameter to a function, gob.Register()
-relies on us passing it a value of the desired type. In the example above we've passed
-it a pointer to a struct and a pointer to a custom type representing a
-map[string]interface. (We could have passed non-pointer values if we wished.) This will
-then allow us to serialise/deserialise values of those types to and from our sessions.
-
-Note that because session values are stored in a map[string]interface{}, there's
-a need to type-assert data when retrieving it. We'll use the Person struct we registered above:
-
- func MyHandler(w http.ResponseWriter, r *http.Request) {
- session, err := store.Get(r, "session-name")
- if err != nil {
- http.Error(w, err.Error(), http.StatusInternalServerError)
- return
- }
-
- // Retrieve our struct and type-assert it
- val := session.Values["person"]
- var person = &Person{}
- if person, ok := val.(*Person); !ok {
- // Handle the case that it's not an expected type
- }
-
- // Now we can use our person object
- }
-
-By default, session cookies last for a month. This is probably too long for
-some cases, but it is easy to change this and other attributes during
-runtime. Sessions can be configured individually or the store can be
-configured and then all sessions saved using it will use that configuration.
-We access session.Options or store.Options to set a new configuration. The
-fields are basically a subset of http.Cookie fields. Let's change the
-maximum age of a session to one week:
-
- session.Options = &sessions.Options{
- Path: "/",
- MaxAge: 86400 * 7,
- HttpOnly: true,
- }
-
-Sometimes we may want to change authentication and/or encryption keys without
-breaking existing sessions. The CookieStore supports key rotation, and to use
-it you just need to set multiple authentication and encryption keys, in pairs,
-to be tested in order:
-
- var store = sessions.NewCookieStore(
- []byte("new-authentication-key"),
- []byte("new-encryption-key"),
- []byte("old-authentication-key"),
- []byte("old-encryption-key"),
- )
-
-New sessions will be saved using the first pair. Old sessions can still be
-read because the first pair will fail, and the second will be tested. This
-makes it easy to "rotate" secret keys and still be able to validate existing
-sessions. Note: for all pairs the encryption key is optional; set it to nil
-or omit it and and encryption won't be used.
-
-Multiple sessions can be used in the same request, even with different
-session backends. When this happens, calling Save() on each session
-individually would be cumbersome, so we have a way to save all sessions
-at once: it's sessions.Save(). Here's an example:
-
- var store = sessions.NewCookieStore([]byte("something-very-secret"))
-
- func MyHandler(w http.ResponseWriter, r *http.Request) {
- // Get a session and set a value.
- session1, _ := store.Get(r, "session-one")
- session1.Values["foo"] = "bar"
- // Get another session and set another value.
- session2, _ := store.Get(r, "session-two")
- session2.Values[42] = 43
- // Save all sessions.
- sessions.Save(r, w)
- }
-
-This is possible because when we call Get() from a session store, it adds the
-session to a common registry. Save() uses it to save all registered sessions.
-*/
-package sessions
diff --git a/vendor/github.com/gorilla/sessions/go.mod b/vendor/github.com/gorilla/sessions/go.mod
deleted file mode 100644
index 44befd4..0000000
--- a/vendor/github.com/gorilla/sessions/go.mod
+++ /dev/null
@@ -1,6 +0,0 @@
-module "github.com/gorilla/sessions"
-
-require (
- "github.com/gorilla/context" v1.1.1
- "github.com/gorilla/securecookie" v1.1.1
-)
diff --git a/vendor/github.com/gorilla/sessions/lex.go b/vendor/github.com/gorilla/sessions/lex.go
deleted file mode 100644
index 4bbbe10..0000000
--- a/vendor/github.com/gorilla/sessions/lex.go
+++ /dev/null
@@ -1,102 +0,0 @@
-// This file contains code adapted from the Go standard library
-// https://github.com/golang/go/blob/39ad0fd0789872f9469167be7fe9578625ff246e/src/net/http/lex.go
-
-package sessions
-
-import "strings"
-
-var isTokenTable = [127]bool{
- '!': true,
- '#': true,
- '$': true,
- '%': true,
- '&': true,
- '\'': true,
- '*': true,
- '+': true,
- '-': true,
- '.': true,
- '0': true,
- '1': true,
- '2': true,
- '3': true,
- '4': true,
- '5': true,
- '6': true,
- '7': true,
- '8': true,
- '9': true,
- 'A': true,
- 'B': true,
- 'C': true,
- 'D': true,
- 'E': true,
- 'F': true,
- 'G': true,
- 'H': true,
- 'I': true,
- 'J': true,
- 'K': true,
- 'L': true,
- 'M': true,
- 'N': true,
- 'O': true,
- 'P': true,
- 'Q': true,
- 'R': true,
- 'S': true,
- 'T': true,
- 'U': true,
- 'W': true,
- 'V': true,
- 'X': true,
- 'Y': true,
- 'Z': true,
- '^': true,
- '_': true,
- '`': true,
- 'a': true,
- 'b': true,
- 'c': true,
- 'd': true,
- 'e': true,
- 'f': true,
- 'g': true,
- 'h': true,
- 'i': true,
- 'j': true,
- 'k': true,
- 'l': true,
- 'm': true,
- 'n': true,
- 'o': true,
- 'p': true,
- 'q': true,
- 'r': true,
- 's': true,
- 't': true,
- 'u': true,
- 'v': true,
- 'w': true,
- 'x': true,
- 'y': true,
- 'z': true,
- '|': true,
- '~': true,
-}
-
-func isToken(r rune) bool {
- i := int(r)
- return i < len(isTokenTable) && isTokenTable[i]
-}
-
-func isNotToken(r rune) bool {
- return !isToken(r)
-}
-
-func isCookieNameValid(raw string) bool {
- if raw == "" {
- return false
- }
- return strings.IndexFunc(raw, isNotToken) < 0
-}
diff --git a/vendor/github.com/gorilla/sessions/options.go b/vendor/github.com/gorilla/sessions/options.go
deleted file mode 100644
index 38ba72f..0000000
--- a/vendor/github.com/gorilla/sessions/options.go
+++ /dev/null
@@ -1,18 +0,0 @@
-// +build !go1.11
-
-package sessions
-
-// Options stores configuration for a session or session store.
-//
-// Fields are a subset of http.Cookie fields.
-type Options struct {
- Path string
- Domain string
- // MaxAge=0 means no Max-Age attribute specified and the cookie will be
- // deleted after the browser session ends.
- // MaxAge<0 means delete cookie immediately.
- // MaxAge>0 means Max-Age attribute present and given in seconds.
- MaxAge int
- Secure bool
- HttpOnly bool
-}
diff --git a/vendor/github.com/gorilla/sessions/options_go111.go b/vendor/github.com/gorilla/sessions/options_go111.go
deleted file mode 100644
index 388112a..0000000
--- a/vendor/github.com/gorilla/sessions/options_go111.go
+++ /dev/null
@@ -1,22 +0,0 @@
-// +build go1.11
-
-package sessions
-
-import "net/http"
-
-// Options stores configuration for a session or session store.
-//
-// Fields are a subset of http.Cookie fields.
-type Options struct {
- Path string
- Domain string
- // MaxAge=0 means no Max-Age attribute specified and the cookie will be
- // deleted after the browser session ends.
- // MaxAge<0 means delete cookie immediately.
- // MaxAge>0 means Max-Age attribute present and given in seconds.
- MaxAge int
- Secure bool
- HttpOnly bool
- // Defaults to http.SameSiteDefaultMode
- SameSite http.SameSite
-}
diff --git a/vendor/github.com/gorilla/sessions/sessions.go b/vendor/github.com/gorilla/sessions/sessions.go
deleted file mode 100644
index a821d31..0000000
--- a/vendor/github.com/gorilla/sessions/sessions.go
+++ /dev/null
@@ -1,218 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sessions
-
-import (
- "encoding/gob"
- "fmt"
- "net/http"
- "time"
-
- "github.com/gorilla/context"
-)
-
-// Default flashes key.
-const flashesKey = "_flash"
-
-// Session --------------------------------------------------------------------
-
-// NewSession is called by session stores to create a new session instance.
-func NewSession(store Store, name string) *Session {
- return &Session{
- Values: make(map[interface{}]interface{}),
- store: store,
- name: name,
- Options: new(Options),
- }
-}
-
-// Session stores the values and optional configuration for a session.
-type Session struct {
- // The ID of the session, generated by stores. It should not be used for
- // user data.
- ID string
- // Values contains the user-data for the session.
- Values map[interface{}]interface{}
- Options *Options
- IsNew bool
- store Store
- name string
-}
-
-// Flashes returns a slice of flash messages from the session.
-//
-// A single variadic argument is accepted, and it is optional: it defines
-// the flash key. If not defined "_flash" is used by default.
-func (s *Session) Flashes(vars ...string) []interface{} {
- var flashes []interface{}
- key := flashesKey
- if len(vars) > 0 {
- key = vars[0]
- }
- if v, ok := s.Values[key]; ok {
- // Drop the flashes and return it.
- delete(s.Values, key)
- flashes = v.([]interface{})
- }
- return flashes
-}
-
-// AddFlash adds a flash message to the session.
-//
-// A single variadic argument is accepted, and it is optional: it defines
-// the flash key. If not defined "_flash" is used by default.
-func (s *Session) AddFlash(value interface{}, vars ...string) {
- key := flashesKey
- if len(vars) > 0 {
- key = vars[0]
- }
- var flashes []interface{}
- if v, ok := s.Values[key]; ok {
- flashes = v.([]interface{})
- }
- s.Values[key] = append(flashes, value)
-}
-
-// Save is a convenience method to save this session. It is the same as calling
-// store.Save(request, response, session). You should call Save before writing to
-// the response or returning from the handler.
-func (s *Session) Save(r *http.Request, w http.ResponseWriter) error {
- return s.store.Save(r, w, s)
-}
-
-// Name returns the name used to register the session.
-func (s *Session) Name() string {
- return s.name
-}
-
-// Store returns the session store used to register the session.
-func (s *Session) Store() Store {
- return s.store
-}
-
-// Registry -------------------------------------------------------------------
-
-// sessionInfo stores a session tracked by the registry.
-type sessionInfo struct {
- s *Session
- e error
-}
-
-// contextKey is the type used to store the registry in the context.
-type contextKey int
-
-// registryKey is the key used to store the registry in the context.
-const registryKey contextKey = 0
-
-// GetRegistry returns a registry instance for the current request.
-func GetRegistry(r *http.Request) *Registry {
- registry := context.Get(r, registryKey)
- if registry != nil {
- return registry.(*Registry)
- }
- newRegistry := &Registry{
- request: r,
- sessions: make(map[string]sessionInfo),
- }
- context.Set(r, registryKey, newRegistry)
- return newRegistry
-}
-
-// Registry stores sessions used during a request.
-type Registry struct {
- request *http.Request
- sessions map[string]sessionInfo
-}
-
-// Get registers and returns a session for the given name and session store.
-//
-// It returns a new session if there are no sessions registered for the name.
-func (s *Registry) Get(store Store, name string) (session *Session, err error) {
- if !isCookieNameValid(name) {
- return nil, fmt.Errorf("sessions: invalid character in cookie name: %s", name)
- }
- if info, ok := s.sessions[name]; ok {
- session, err = info.s, info.e
- } else {
- session, err = store.New(s.request, name)
- session.name = name
- s.sessions[name] = sessionInfo{s: session, e: err}
- }
- session.store = store
- return
-}
-
-// Save saves all sessions registered for the current request.
-func (s *Registry) Save(w http.ResponseWriter) error {
- var errMulti MultiError
- for name, info := range s.sessions {
- session := info.s
- if session.store == nil {
- errMulti = append(errMulti, fmt.Errorf(
- "sessions: missing store for session %q", name))
- } else if err := session.store.Save(s.request, w, session); err != nil {
- errMulti = append(errMulti, fmt.Errorf(
- "sessions: error saving session %q -- %v", name, err))
- }
- }
- if errMulti != nil {
- return errMulti
- }
- return nil
-}
-
-// Helpers --------------------------------------------------------------------
-
-func init() {
- gob.Register([]interface{}{})
-}
-
-// Save saves all sessions used during the current request.
-func Save(r *http.Request, w http.ResponseWriter) error {
- return GetRegistry(r).Save(w)
-}
-
-// NewCookie returns an http.Cookie with the options set. It also sets
-// the Expires field calculated based on the MaxAge value, for Internet
-// Explorer compatibility.
-func NewCookie(name, value string, options *Options) *http.Cookie {
- cookie := newCookieFromOptions(name, value, options)
- if options.MaxAge > 0 {
- d := time.Duration(options.MaxAge) * time.Second
- cookie.Expires = time.Now().Add(d)
- } else if options.MaxAge < 0 {
- // Set it to the past to expire now.
- cookie.Expires = time.Unix(1, 0)
- }
- return cookie
-}
-
-// Error ----------------------------------------------------------------------
-
-// MultiError stores multiple errors.
-//
-// Borrowed from the App Engine SDK.
-type MultiError []error
-
-func (m MultiError) Error() string {
- s, n := "", 0
- for _, e := range m {
- if e != nil {
- if n == 0 {
- s = e.Error()
- }
- n++
- }
- }
- switch n {
- case 0:
- return "(0 errors)"
- case 1:
- return s
- case 2:
- return s + " (and 1 other error)"
- }
- return fmt.Sprintf("%s (and %d other errors)", s, n-1)
-}
diff --git a/vendor/github.com/gorilla/sessions/store.go b/vendor/github.com/gorilla/sessions/store.go
deleted file mode 100644
index bb7f964..0000000
--- a/vendor/github.com/gorilla/sessions/store.go
+++ /dev/null
@@ -1,292 +0,0 @@
-// Copyright 2012 The Gorilla Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package sessions
-
-import (
- "encoding/base32"
- "io/ioutil"
- "net/http"
- "os"
- "path/filepath"
- "strings"
- "sync"
-
- "github.com/gorilla/securecookie"
-)
-
-// Store is an interface for custom session stores.
-//
-// See CookieStore and FilesystemStore for examples.
-type Store interface {
- // Get should return a cached session.
- Get(r *http.Request, name string) (*Session, error)
-
- // New should create and return a new session.
- //
- // Note that New should never return a nil session, even in the case of
- // an error if using the Registry infrastructure to cache the session.
- New(r *http.Request, name string) (*Session, error)
-
- // Save should persist session to the underlying store implementation.
- Save(r *http.Request, w http.ResponseWriter, s *Session) error
-}
-
-// CookieStore ----------------------------------------------------------------
-
-// NewCookieStore returns a new CookieStore.
-//
-// Keys are defined in pairs to allow key rotation, but the common case is
-// to set a single authentication key and optionally an encryption key.
-//
-// The first key in a pair is used for authentication and the second for
-// encryption. The encryption key can be set to nil or omitted in the last
-// pair, but the authentication key is required in all pairs.
-//
-// It is recommended to use an authentication key with 32 or 64 bytes.
-// The encryption key, if set, must be either 16, 24, or 32 bytes to select
-// AES-128, AES-192, or AES-256 modes.
-func NewCookieStore(keyPairs ...[]byte) *CookieStore {
- cs := &CookieStore{
- Codecs: securecookie.CodecsFromPairs(keyPairs...),
- Options: &Options{
- Path: "/",
- MaxAge: 86400 * 30,
- },
- }
-
- cs.MaxAge(cs.Options.MaxAge)
- return cs
-}
-
-// CookieStore stores sessions using secure cookies.
-type CookieStore struct {
- Codecs []securecookie.Codec
- Options *Options // default configuration
-}
-
-// Get returns a session for the given name after adding it to the registry.
-//
-// It returns a new session if the sessions doesn't exist. Access IsNew on
-// the session to check if it is an existing session or a new one.
-//
-// It returns a new session and an error if the session exists but could
-// not be decoded.
-func (s *CookieStore) Get(r *http.Request, name string) (*Session, error) {
- return GetRegistry(r).Get(s, name)
-}
-
-// New returns a session for the given name without adding it to the registry.
-//
-// The difference between New() and Get() is that calling New() twice will
-// decode the session data twice, while Get() registers and reuses the same
-// decoded session after the first call.
-func (s *CookieStore) New(r *http.Request, name string) (*Session, error) {
- session := NewSession(s, name)
- opts := *s.Options
- session.Options = &opts
- session.IsNew = true
- var err error
- if c, errCookie := r.Cookie(name); errCookie == nil {
- err = securecookie.DecodeMulti(name, c.Value, &session.Values,
- s.Codecs...)
- if err == nil {
- session.IsNew = false
- }
- }
- return session, err
-}
-
-// Save adds a single session to the response.
-func (s *CookieStore) Save(r *http.Request, w http.ResponseWriter,
- session *Session) error {
- encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
- s.Codecs...)
- if err != nil {
- return err
- }
- http.SetCookie(w, NewCookie(session.Name(), encoded, session.Options))
- return nil
-}
-
-// MaxAge sets the maximum age for the store and the underlying cookie
-// implementation. Individual sessions can be deleted by setting Options.MaxAge
-// = -1 for that session.
-func (s *CookieStore) MaxAge(age int) {
- s.Options.MaxAge = age
-
- // Set the maxAge for each securecookie instance.
- for _, codec := range s.Codecs {
- if sc, ok := codec.(*securecookie.SecureCookie); ok {
- sc.MaxAge(age)
- }
- }
-}
-
-// FilesystemStore ------------------------------------------------------------
-
-var fileMutex sync.RWMutex
-
-// NewFilesystemStore returns a new FilesystemStore.
-//
-// The path argument is the directory where sessions will be saved. If empty
-// it will use os.TempDir().
-//
-// See NewCookieStore() for a description of the other parameters.
-func NewFilesystemStore(path string, keyPairs ...[]byte) *FilesystemStore {
- if path == "" {
- path = os.TempDir()
- }
- fs := &FilesystemStore{
- Codecs: securecookie.CodecsFromPairs(keyPairs...),
- Options: &Options{
- Path: "/",
- MaxAge: 86400 * 30,
- },
- path: path,
- }
-
- fs.MaxAge(fs.Options.MaxAge)
- return fs
-}
-
-// FilesystemStore stores sessions in the filesystem.
-//
-// It also serves as a reference for custom stores.
-//
-// This store is still experimental and not well tested. Feedback is welcome.
-type FilesystemStore struct {
- Codecs []securecookie.Codec
- Options *Options // default configuration
- path string
-}
-
-// MaxLength restricts the maximum length of new sessions to l.
-// If l is 0 there is no limit to the size of a session, use with caution.
-// The default for a new FilesystemStore is 4096.
-func (s *FilesystemStore) MaxLength(l int) {
- for _, c := range s.Codecs {
- if codec, ok := c.(*securecookie.SecureCookie); ok {
- codec.MaxLength(l)
- }
- }
-}
-
-// Get returns a session for the given name after adding it to the registry.
-//
-// See CookieStore.Get().
-func (s *FilesystemStore) Get(r *http.Request, name string) (*Session, error) {
- return GetRegistry(r).Get(s, name)
-}
-
-// New returns a session for the given name without adding it to the registry.
-//
-// See CookieStore.New().
-func (s *FilesystemStore) New(r *http.Request, name string) (*Session, error) {
- session := NewSession(s, name)
- opts := *s.Options
- session.Options = &opts
- session.IsNew = true
- var err error
- if c, errCookie := r.Cookie(name); errCookie == nil {
- err = securecookie.DecodeMulti(name, c.Value, &session.ID, s.Codecs...)
- if err == nil {
- err = s.load(session)
- if err == nil {
- session.IsNew = false
- }
- }
- }
- return session, err
-}
-
-// Save adds a single session to the response.
-//
-// If the Options.MaxAge of the session is <= 0 then the session file will be
-// deleted from the store path. With this process it enforces the properly
-// session cookie handling so no need to trust in the cookie management in the
-// web browser.
-func (s *FilesystemStore) Save(r *http.Request, w http.ResponseWriter,
- session *Session) error {
- // Delete if max-age is <= 0
- if session.Options.MaxAge <= 0 {
- if err := s.erase(session); err != nil {
- return err
- }
- http.SetCookie(w, NewCookie(session.Name(), "", session.Options))
- return nil
- }
-
- if session.ID == "" {
- // Because the ID is used in the filename, encode it to
- // use alphanumeric characters only.
- session.ID = strings.TrimRight(
- base32.StdEncoding.EncodeToString(
- securecookie.GenerateRandomKey(32)), "=")
- }
- if err := s.save(session); err != nil {
- return err
- }
- encoded, err := securecookie.EncodeMulti(session.Name(), session.ID,
- s.Codecs...)
- if err != nil {
- return err
- }
- http.SetCookie(w, NewCookie(session.Name(), encoded, session.Options))
- return nil
-}
-
-// MaxAge sets the maximum age for the store and the underlying cookie
-// implementation. Individual sessions can be deleted by setting Options.MaxAge
-// = -1 for that session.
-func (s *FilesystemStore) MaxAge(age int) {
- s.Options.MaxAge = age
-
- // Set the maxAge for each securecookie instance.
- for _, codec := range s.Codecs {
- if sc, ok := codec.(*securecookie.SecureCookie); ok {
- sc.MaxAge(age)
- }
- }
-}
-
-// save writes encoded session.Values to a file.
-func (s *FilesystemStore) save(session *Session) error {
- encoded, err := securecookie.EncodeMulti(session.Name(), session.Values,
- s.Codecs...)
- if err != nil {
- return err
- }
- filename := filepath.Join(s.path, "session_"+session.ID)
- fileMutex.Lock()
- defer fileMutex.Unlock()
- return ioutil.WriteFile(filename, []byte(encoded), 0600)
-}
-
-// load reads a file and decodes its content into session.Values.
-func (s *FilesystemStore) load(session *Session) error {
- filename := filepath.Join(s.path, "session_"+session.ID)
- fileMutex.RLock()
- defer fileMutex.RUnlock()
- fdata, err := ioutil.ReadFile(filename)
- if err != nil {
- return err
- }
- if err = securecookie.DecodeMulti(session.Name(), string(fdata),
- &session.Values, s.Codecs...); err != nil {
- return err
- }
- return nil
-}
-
-// delete session file
-func (s *FilesystemStore) erase(session *Session) error {
- filename := filepath.Join(s.path, "session_"+session.ID)
-
- fileMutex.RLock()
- defer fileMutex.RUnlock()
-
- err := os.Remove(filename)
- return err
-}
diff --git a/vendor/github.com/jmoiron/sqlx/.gitignore b/vendor/github.com/jmoiron/sqlx/.gitignore
deleted file mode 100644
index 529841c..0000000
--- a/vendor/github.com/jmoiron/sqlx/.gitignore
+++ /dev/null
@@ -1,24 +0,0 @@
-# Compiled Object files, Static and Dynamic libs (Shared Objects)
-*.o
-*.a
-*.so
-
-# Folders
-_obj
-_test
-
-# Architecture specific extensions/prefixes
-*.[568vq]
-[568vq].out
-
-*.cgo1.go
-*.cgo2.c
-_cgo_defun.c
-_cgo_gotypes.go
-_cgo_export.*
-
-_testmain.go
-
-*.exe
-tags
-environ
diff --git a/vendor/github.com/jmoiron/sqlx/.travis.yml b/vendor/github.com/jmoiron/sqlx/.travis.yml
deleted file mode 100644
index 6bc68d6..0000000
--- a/vendor/github.com/jmoiron/sqlx/.travis.yml
+++ /dev/null
@@ -1,27 +0,0 @@
-# vim: ft=yaml sw=2 ts=2
-
-language: go
-
-# enable database services
-services:
- - mysql
- - postgresql
-
-# create test database
-before_install:
- - mysql -e 'CREATE DATABASE IF NOT EXISTS sqlxtest;'
- - psql -c 'create database sqlxtest;' -U postgres
- - go get github.com/mattn/goveralls
- - export SQLX_MYSQL_DSN="travis:@/sqlxtest?parseTime=true"
- - export SQLX_POSTGRES_DSN="postgres://postgres:@localhost/sqlxtest?sslmode=disable"
- - export SQLX_SQLITE_DSN="$HOME/sqlxtest.db"
-
-# go versions to test
-go:
- - "1.8"
- - "1.9"
- - "1.10.x"
-
-# run tests w/ coverage
-script:
- - travis_retry $GOPATH/bin/goveralls -service=travis-ci
diff --git a/vendor/github.com/jmoiron/sqlx/LICENSE b/vendor/github.com/jmoiron/sqlx/LICENSE
deleted file mode 100644
index 0d31edf..0000000
--- a/vendor/github.com/jmoiron/sqlx/LICENSE
+++ /dev/null
@@ -1,23 +0,0 @@
- Copyright (c) 2013, Jason Moiron
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
-
diff --git a/vendor/github.com/jmoiron/sqlx/README.md b/vendor/github.com/jmoiron/sqlx/README.md
deleted file mode 100644
index 8390343..0000000
--- a/vendor/github.com/jmoiron/sqlx/README.md
+++ /dev/null
@@ -1,187 +0,0 @@
-# sqlx
-
-[![Build Status](https://travis-ci.org/jmoiron/sqlx.svg?branch=master)](https://travis-ci.org/jmoiron/sqlx) [![Coverage Status](https://coveralls.io/repos/github/jmoiron/sqlx/badge.svg?branch=master)](https://coveralls.io/github/jmoiron/sqlx?branch=master) [![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/jmoiron/sqlx) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/jmoiron/sqlx/master/LICENSE)
-
-sqlx is a library which provides a set of extensions on go's standard
-`database/sql` library. The sqlx versions of `sql.DB`, `sql.TX`, `sql.Stmt`,
-et al. all leave the underlying interfaces untouched, so that their interfaces
-are a superset on the standard ones. This makes it relatively painless to
-integrate existing codebases using database/sql with sqlx.
-
-Major additional concepts are:
-
-* Marshal rows into structs (with embedded struct support), maps, and slices
-* Named parameter support including prepared statements
-* `Get` and `Select` to go quickly from query to struct/slice
-
-In addition to the [godoc API documentation](http://godoc.org/github.com/jmoiron/sqlx),
-there is also some [standard documentation](http://jmoiron.github.io/sqlx/) that
-explains how to use `database/sql` along with sqlx.
-
-## Recent Changes
-
-* The [introduction](https://github.com/jmoiron/sqlx/pull/387) of `sql.ColumnType` sets the required minimum Go version to 1.8.
-
-* sqlx/types.JsonText has been renamed to JSONText to follow Go naming conventions.
-
-This breaks backwards compatibility, but it's in a way that is trivially fixable
-(`s/JsonText/JSONText/g`). The `types` package is both experimental and not in
-active development currently.
-
-* Using Go 1.6 and below with `types.JSONText` and `types.GzippedText` can be _potentially unsafe_, **especially** when used with common auto-scan sqlx idioms like `Select` and `Get`. See [golang bug #13905](https://github.com/golang/go/issues/13905).
-
-### Backwards Compatibility
-
-There is no Go1-like promise of absolute stability, but I take the issue seriously
-and will maintain the library in a compatible state unless vital bugs prevent me
-from doing so. Since [#59](https://github.com/jmoiron/sqlx/issues/59) and
-[#60](https://github.com/jmoiron/sqlx/issues/60) necessitated breaking behavior,
-a wider API cleanup was done at the time of fixing. It's possible this will happen
-in future; if it does, a git tag will be provided for users requiring the old
-behavior to continue to use it until such a time as they can migrate.
-
-## install
-
- go get github.com/jmoiron/sqlx
-
-## issues
-
-Row headers can be ambiguous (`SELECT 1 AS a, 2 AS a`), and the result of
-`Columns()` does not fully qualify column names in queries like:
-
-```sql
-SELECT a.id, a.name, b.id, b.name FROM foos AS a JOIN foos AS b ON a.parent = b.id;
-```
-
-making a struct or map destination ambiguous. Use `AS` in your queries
-to give columns distinct names, `rows.Scan` to scan them manually, or
-`SliceScan` to get a slice of results.
-
-## usage
-
-Below is an example which shows some common use cases for sqlx. Check
-[sqlx_test.go](https://github.com/jmoiron/sqlx/blob/master/sqlx_test.go) for more
-usage.
-
-
-```go
-package main
-
-import (
- "database/sql"
- "fmt"
- "log"
-
- _ "github.com/lib/pq"
- "github.com/jmoiron/sqlx"
-)
-
-var schema = `
-CREATE TABLE person (
- first_name text,
- last_name text,
- email text
-);
-
-CREATE TABLE place (
- country text,
- city text NULL,
- telcode integer
-)`
-
-type Person struct {
- FirstName string `db:"first_name"`
- LastName string `db:"last_name"`
- Email string
-}
-
-type Place struct {
- Country string
- City sql.NullString
- TelCode int
-}
-
-func main() {
- // this Pings the database trying to connect, panics on error
- // use sqlx.Open() for sql.Open() semantics
- db, err := sqlx.Connect("postgres", "user=foo dbname=bar sslmode=disable")
- if err != nil {
- log.Fatalln(err)
- }
-
- // exec the schema or fail; multi-statement Exec behavior varies between
- // database drivers; pq will exec them all, sqlite3 won't, ymmv
- db.MustExec(schema)
-
- tx := db.MustBegin()
- tx.MustExec("INSERT INTO person (first_name, last_name, email) VALUES ($1, $2, $3)", "Jason", "Moiron", "jmoiron@jmoiron.net")
- tx.MustExec("INSERT INTO person (first_name, last_name, email) VALUES ($1, $2, $3)", "John", "Doe", "johndoeDNE@gmail.net")
- tx.MustExec("INSERT INTO place (country, city, telcode) VALUES ($1, $2, $3)", "United States", "New York", "1")
- tx.MustExec("INSERT INTO place (country, telcode) VALUES ($1, $2)", "Hong Kong", "852")
- tx.MustExec("INSERT INTO place (country, telcode) VALUES ($1, $2)", "Singapore", "65")
- // Named queries can use structs, so if you have an existing struct (i.e. person := &Person{}) that you have populated, you can pass it in as &person
- tx.NamedExec("INSERT INTO person (first_name, last_name, email) VALUES (:first_name, :last_name, :email)", &Person{"Jane", "Citizen", "jane.citzen@example.com"})
- tx.Commit()
-
- // Query the database, storing results in a []Person (wrapped in []interface{})
- people := []Person{}
- db.Select(&people, "SELECT * FROM person ORDER BY first_name ASC")
- jason, john := people[0], people[1]
-
- fmt.Printf("%#v\n%#v", jason, john)
- // Person{FirstName:"Jason", LastName:"Moiron", Email:"jmoiron@jmoiron.net"}
- // Person{FirstName:"John", LastName:"Doe", Email:"johndoeDNE@gmail.net"}
-
- // You can also get a single result, a la QueryRow
- jason = Person{}
- err = db.Get(&jason, "SELECT * FROM person WHERE first_name=$1", "Jason")
- fmt.Printf("%#v\n", jason)
- // Person{FirstName:"Jason", LastName:"Moiron", Email:"jmoiron@jmoiron.net"}
-
- // if you have null fields and use SELECT *, you must use sql.Null* in your struct
- places := []Place{}
- err = db.Select(&places, "SELECT * FROM place ORDER BY telcode ASC")
- if err != nil {
- fmt.Println(err)
- return
- }
- usa, singsing, honkers := places[0], places[1], places[2]
-
- fmt.Printf("%#v\n%#v\n%#v\n", usa, singsing, honkers)
- // Place{Country:"United States", City:sql.NullString{String:"New York", Valid:true}, TelCode:1}
- // Place{Country:"Singapore", City:sql.NullString{String:"", Valid:false}, TelCode:65}
- // Place{Country:"Hong Kong", City:sql.NullString{String:"", Valid:false}, TelCode:852}
-
- // Loop through rows using only one struct
- place := Place{}
- rows, err := db.Queryx("SELECT * FROM place")
- for rows.Next() {
- err := rows.StructScan(&place)
- if err != nil {
- log.Fatalln(err)
- }
- fmt.Printf("%#v\n", place)
- }
- // Place{Country:"United States", City:sql.NullString{String:"New York", Valid:true}, TelCode:1}
- // Place{Country:"Hong Kong", City:sql.NullString{String:"", Valid:false}, TelCode:852}
- // Place{Country:"Singapore", City:sql.NullString{String:"", Valid:false}, TelCode:65}
-
- // Named queries, using `:name` as the bindvar. Automatic bindvar support
- // which takes into account the dbtype based on the driverName on sqlx.Open/Connect
- _, err = db.NamedExec(`INSERT INTO person (first_name,last_name,email) VALUES (:first,:last,:email)`,
- map[string]interface{}{
- "first": "Bin",
- "last": "Smuth",
- "email": "bensmith@allblacks.nz",
- })
-
- // Selects Mr. Smith from the database
- rows, err = db.NamedQuery(`SELECT * FROM person WHERE first_name=:fn`, map[string]interface{}{"fn": "Bin"})
-
- // Named queries can also use structs. Their bind names follow the same rules
- // as the name -> db mapping, so struct fields are lowercased and the `db` tag
- // is taken into consideration.
- rows, err = db.NamedQuery(`SELECT * FROM person WHERE first_name=:first_name`, jason)
-}
-```
-
diff --git a/vendor/github.com/jmoiron/sqlx/bind.go b/vendor/github.com/jmoiron/sqlx/bind.go
deleted file mode 100644
index 0a48252..0000000
--- a/vendor/github.com/jmoiron/sqlx/bind.go
+++ /dev/null
@@ -1,217 +0,0 @@
-package sqlx
-
-import (
- "bytes"
- "database/sql/driver"
- "errors"
- "reflect"
- "strconv"
- "strings"
-
- "github.com/jmoiron/sqlx/reflectx"
-)
-
-// Bindvar types supported by Rebind, BindMap and BindStruct.
-const (
- UNKNOWN = iota
- QUESTION
- DOLLAR
- NAMED
- AT
-)
-
-// BindType returns the bindtype for a given database given a drivername.
-func BindType(driverName string) int {
- switch driverName {
- case "postgres", "pgx", "pq-timeouts", "cloudsqlpostgres":
- return DOLLAR
- case "mysql":
- return QUESTION
- case "sqlite3":
- return QUESTION
- case "oci8", "ora", "goracle":
- return NAMED
- case "sqlserver":
- return AT
- }
- return UNKNOWN
-}
-
-// FIXME: this should be able to be tolerant of escaped ?'s in queries without
-// losing much speed, and should be to avoid confusion.
-
-// Rebind a query from the default bindtype (QUESTION) to the target bindtype.
-func Rebind(bindType int, query string) string {
- switch bindType {
- case QUESTION, UNKNOWN:
- return query
- }
-
- // Add space enough for 10 params before we have to allocate
- rqb := make([]byte, 0, len(query)+10)
-
- var i, j int
-
- for i = strings.Index(query, "?"); i != -1; i = strings.Index(query, "?") {
- rqb = append(rqb, query[:i]...)
-
- switch bindType {
- case DOLLAR:
- rqb = append(rqb, '$')
- case NAMED:
- rqb = append(rqb, ':', 'a', 'r', 'g')
- case AT:
- rqb = append(rqb, '@', 'p')
- }
-
- j++
- rqb = strconv.AppendInt(rqb, int64(j), 10)
-
- query = query[i+1:]
- }
-
- return string(append(rqb, query...))
-}
-
-// Experimental implementation of Rebind which uses a bytes.Buffer. The code is
-// much simpler and should be more resistant to odd unicode, but it is twice as
-// slow. Kept here for benchmarking purposes and to possibly replace Rebind if
-// problems arise with its somewhat naive handling of unicode.
-func rebindBuff(bindType int, query string) string {
- if bindType != DOLLAR {
- return query
- }
-
- b := make([]byte, 0, len(query))
- rqb := bytes.NewBuffer(b)
- j := 1
- for _, r := range query {
- if r == '?' {
- rqb.WriteRune('$')
- rqb.WriteString(strconv.Itoa(j))
- j++
- } else {
- rqb.WriteRune(r)
- }
- }
-
- return rqb.String()
-}
-
-// In expands slice values in args, returning the modified query string
-// and a new arg list that can be executed by a database. The `query` should
-// use the `?` bindVar. The return value uses the `?` bindVar.
-func In(query string, args ...interface{}) (string, []interface{}, error) {
- // argMeta stores reflect.Value and length for slices and
- // the value itself for non-slice arguments
- type argMeta struct {
- v reflect.Value
- i interface{}
- length int
- }
-
- var flatArgsCount int
- var anySlices bool
-
- meta := make([]argMeta, len(args))
-
- for i, arg := range args {
- if a, ok := arg.(driver.Valuer); ok {
- arg, _ = a.Value()
- }
- v := reflect.ValueOf(arg)
- t := reflectx.Deref(v.Type())
-
- // []byte is a driver.Value type so it should not be expanded
- if t.Kind() == reflect.Slice && t != reflect.TypeOf([]byte{}) {
- meta[i].length = v.Len()
- meta[i].v = v
-
- anySlices = true
- flatArgsCount += meta[i].length
-
- if meta[i].length == 0 {
- return "", nil, errors.New("empty slice passed to 'in' query")
- }
- } else {
- meta[i].i = arg
- flatArgsCount++
- }
- }
-
- // don't do any parsing if there aren't any slices; note that this means
- // some errors that we might have caught below will not be returned.
- if !anySlices {
- return query, args, nil
- }
-
- newArgs := make([]interface{}, 0, flatArgsCount)
- buf := make([]byte, 0, len(query)+len(", ?")*flatArgsCount)
-
- var arg, offset int
-
- for i := strings.IndexByte(query[offset:], '?'); i != -1; i = strings.IndexByte(query[offset:], '?') {
- if arg >= len(meta) {
- // if an argument wasn't passed, lets return an error; this is
- // not actually how database/sql Exec/Query works, but since we are
- // creating an argument list programmatically, we want to be able
- // to catch these programmer errors earlier.
- return "", nil, errors.New("number of bindVars exceeds arguments")
- }
-
- argMeta := meta[arg]
- arg++
-
- // not a slice, continue.
- // our questionmark will either be written before the next expansion
- // of a slice or after the loop when writing the rest of the query
- if argMeta.length == 0 {
- offset = offset + i + 1
- newArgs = append(newArgs, argMeta.i)
- continue
- }
-
- // write everything up to and including our ? character
- buf = append(buf, query[:offset+i+1]...)
-
- for si := 1; si < argMeta.length; si++ {
- buf = append(buf, ", ?"...)
- }
-
- newArgs = appendReflectSlice(newArgs, argMeta.v, argMeta.length)
-
- // slice the query and reset the offset. this avoids some bookkeeping for
- // the write after the loop
- query = query[offset+i+1:]
- offset = 0
- }
-
- buf = append(buf, query...)
-
- if arg < len(meta) {
- return "", nil, errors.New("number of bindVars less than number arguments")
- }
-
- return string(buf), newArgs, nil
-}
-
-func appendReflectSlice(args []interface{}, v reflect.Value, vlen int) []interface{} {
- switch val := v.Interface().(type) {
- case []interface{}:
- args = append(args, val...)
- case []int:
- for i := range val {
- args = append(args, val[i])
- }
- case []string:
- for i := range val {
- args = append(args, val[i])
- }
- default:
- for si := 0; si < vlen; si++ {
- args = append(args, v.Index(si).Interface())
- }
- }
-
- return args
-}
diff --git a/vendor/github.com/jmoiron/sqlx/doc.go b/vendor/github.com/jmoiron/sqlx/doc.go
deleted file mode 100644
index e2b4e60..0000000
--- a/vendor/github.com/jmoiron/sqlx/doc.go
+++ /dev/null
@@ -1,12 +0,0 @@
-// Package sqlx provides general purpose extensions to database/sql.
-//
-// It is intended to seamlessly wrap database/sql and provide convenience
-// methods which are useful in the development of database driven applications.
-// None of the underlying database/sql methods are changed. Instead all extended
-// behavior is implemented through new methods defined on wrapper types.
-//
-// Additions include scanning into structs, named query support, rebinding
-// queries for different drivers, convenient shorthands for common error handling
-// and more.
-//
-package sqlx
diff --git a/vendor/github.com/jmoiron/sqlx/go.mod b/vendor/github.com/jmoiron/sqlx/go.mod
deleted file mode 100644
index 66c6756..0000000
--- a/vendor/github.com/jmoiron/sqlx/go.mod
+++ /dev/null
@@ -1,7 +0,0 @@
-module github.com/jmoiron/sqlx
-
-require (
- github.com/go-sql-driver/mysql v1.4.0
- github.com/lib/pq v1.0.0
- github.com/mattn/go-sqlite3 v1.9.0
-)
diff --git a/vendor/github.com/jmoiron/sqlx/go.sum b/vendor/github.com/jmoiron/sqlx/go.sum
deleted file mode 100644
index a3239ad..0000000
--- a/vendor/github.com/jmoiron/sqlx/go.sum
+++ /dev/null
@@ -1,6 +0,0 @@
-github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk=
-github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
-github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
-github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
-github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4=
-github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
diff --git a/vendor/github.com/jmoiron/sqlx/named.go b/vendor/github.com/jmoiron/sqlx/named.go
deleted file mode 100644
index fa82b56..0000000
--- a/vendor/github.com/jmoiron/sqlx/named.go
+++ /dev/null
@@ -1,356 +0,0 @@
-package sqlx
-
-// Named Query Support
-//
-// * BindMap - bind query bindvars to map/struct args
-// * NamedExec, NamedQuery - named query w/ struct or map
-// * NamedStmt - a pre-compiled named query which is a prepared statement
-//
-// Internal Interfaces:
-//
-// * compileNamedQuery - rebind a named query, returning a query and list of names
-// * bindArgs, bindMapArgs, bindAnyArgs - given a list of names, return an arglist
-//
-import (
- "database/sql"
- "errors"
- "fmt"
- "reflect"
- "strconv"
- "unicode"
-
- "github.com/jmoiron/sqlx/reflectx"
-)
-
-// NamedStmt is a prepared statement that executes named queries. Prepare it
-// how you would execute a NamedQuery, but pass in a struct or map when executing.
-type NamedStmt struct {
- Params []string
- QueryString string
- Stmt *Stmt
-}
-
-// Close closes the named statement.
-func (n *NamedStmt) Close() error {
- return n.Stmt.Close()
-}
-
-// Exec executes a named statement using the struct passed.
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) Exec(arg interface{}) (sql.Result, error) {
- args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
- if err != nil {
- return *new(sql.Result), err
- }
- return n.Stmt.Exec(args...)
-}
-
-// Query executes a named statement using the struct argument, returning rows.
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) Query(arg interface{}) (*sql.Rows, error) {
- args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
- if err != nil {
- return nil, err
- }
- return n.Stmt.Query(args...)
-}
-
-// QueryRow executes a named statement against the database. Because sqlx cannot
-// create a *sql.Row with an error condition pre-set for binding errors, sqlx
-// returns a *sqlx.Row instead.
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) QueryRow(arg interface{}) *Row {
- args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
- if err != nil {
- return &Row{err: err}
- }
- return n.Stmt.QueryRowx(args...)
-}
-
-// MustExec execs a NamedStmt, panicing on error
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) MustExec(arg interface{}) sql.Result {
- res, err := n.Exec(arg)
- if err != nil {
- panic(err)
- }
- return res
-}
-
-// Queryx using this NamedStmt
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) Queryx(arg interface{}) (*Rows, error) {
- r, err := n.Query(arg)
- if err != nil {
- return nil, err
- }
- return &Rows{Rows: r, Mapper: n.Stmt.Mapper, unsafe: isUnsafe(n)}, err
-}
-
-// QueryRowx this NamedStmt. Because of limitations with QueryRow, this is
-// an alias for QueryRow.
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) QueryRowx(arg interface{}) *Row {
- return n.QueryRow(arg)
-}
-
-// Select using this NamedStmt
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) Select(dest interface{}, arg interface{}) error {
- rows, err := n.Queryx(arg)
- if err != nil {
- return err
- }
- // if something happens here, we want to make sure the rows are Closed
- defer rows.Close()
- return scanAll(rows, dest, false)
-}
-
-// Get using this NamedStmt
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) Get(dest interface{}, arg interface{}) error {
- r := n.QueryRowx(arg)
- return r.scanAny(dest, false)
-}
-
-// Unsafe creates an unsafe version of the NamedStmt
-func (n *NamedStmt) Unsafe() *NamedStmt {
- r := &NamedStmt{Params: n.Params, Stmt: n.Stmt, QueryString: n.QueryString}
- r.Stmt.unsafe = true
- return r
-}
-
-// A union interface of preparer and binder, required to be able to prepare
-// named statements (as the bindtype must be determined).
-type namedPreparer interface {
- Preparer
- binder
-}
-
-func prepareNamed(p namedPreparer, query string) (*NamedStmt, error) {
- bindType := BindType(p.DriverName())
- q, args, err := compileNamedQuery([]byte(query), bindType)
- if err != nil {
- return nil, err
- }
- stmt, err := Preparex(p, q)
- if err != nil {
- return nil, err
- }
- return &NamedStmt{
- QueryString: q,
- Params: args,
- Stmt: stmt,
- }, nil
-}
-
-func bindAnyArgs(names []string, arg interface{}, m *reflectx.Mapper) ([]interface{}, error) {
- if maparg, ok := arg.(map[string]interface{}); ok {
- return bindMapArgs(names, maparg)
- }
- return bindArgs(names, arg, m)
-}
-
-// private interface to generate a list of interfaces from a given struct
-// type, given a list of names to pull out of the struct. Used by public
-// BindStruct interface.
-func bindArgs(names []string, arg interface{}, m *reflectx.Mapper) ([]interface{}, error) {
- arglist := make([]interface{}, 0, len(names))
-
- // grab the indirected value of arg
- v := reflect.ValueOf(arg)
- for v = reflect.ValueOf(arg); v.Kind() == reflect.Ptr; {
- v = v.Elem()
- }
-
- err := m.TraversalsByNameFunc(v.Type(), names, func(i int, t []int) error {
- if len(t) == 0 {
- return fmt.Errorf("could not find name %s in %#v", names[i], arg)
- }
-
- val := reflectx.FieldByIndexesReadOnly(v, t)
- arglist = append(arglist, val.Interface())
-
- return nil
- })
-
- return arglist, err
-}
-
-// like bindArgs, but for maps.
-func bindMapArgs(names []string, arg map[string]interface{}) ([]interface{}, error) {
- arglist := make([]interface{}, 0, len(names))
-
- for _, name := range names {
- val, ok := arg[name]
- if !ok {
- return arglist, fmt.Errorf("could not find name %s in %#v", name, arg)
- }
- arglist = append(arglist, val)
- }
- return arglist, nil
-}
-
-// bindStruct binds a named parameter query with fields from a struct argument.
-// The rules for binding field names to parameter names follow the same
-// conventions as for StructScan, including obeying the `db` struct tags.
-func bindStruct(bindType int, query string, arg interface{}, m *reflectx.Mapper) (string, []interface{}, error) {
- bound, names, err := compileNamedQuery([]byte(query), bindType)
- if err != nil {
- return "", []interface{}{}, err
- }
-
- arglist, err := bindArgs(names, arg, m)
- if err != nil {
- return "", []interface{}{}, err
- }
-
- return bound, arglist, nil
-}
-
-// bindMap binds a named parameter query with a map of arguments.
-func bindMap(bindType int, query string, args map[string]interface{}) (string, []interface{}, error) {
- bound, names, err := compileNamedQuery([]byte(query), bindType)
- if err != nil {
- return "", []interface{}{}, err
- }
-
- arglist, err := bindMapArgs(names, args)
- return bound, arglist, err
-}
-
-// -- Compilation of Named Queries
-
-// Allow digits and letters in bind params; additionally runes are
-// checked against underscores, meaning that bind params can have be
-// alphanumeric with underscores. Mind the difference between unicode
-// digits and numbers, where '5' is a digit but '五' is not.
-var allowedBindRunes = []*unicode.RangeTable{unicode.Letter, unicode.Digit}
-
-// FIXME: this function isn't safe for unicode named params, as a failing test
-// can testify. This is not a regression but a failure of the original code
-// as well. It should be modified to range over runes in a string rather than
-// bytes, even though this is less convenient and slower. Hopefully the
-// addition of the prepared NamedStmt (which will only do this once) will make
-// up for the slightly slower ad-hoc NamedExec/NamedQuery.
-
-// compile a NamedQuery into an unbound query (using the '?' bindvar) and
-// a list of names.
-func compileNamedQuery(qs []byte, bindType int) (query string, names []string, err error) {
- names = make([]string, 0, 10)
- rebound := make([]byte, 0, len(qs))
-
- inName := false
- last := len(qs) - 1
- currentVar := 1
- name := make([]byte, 0, 10)
-
- for i, b := range qs {
- // a ':' while we're in a name is an error
- if b == ':' {
- // if this is the second ':' in a '::' escape sequence, append a ':'
- if inName && i > 0 && qs[i-1] == ':' {
- rebound = append(rebound, ':')
- inName = false
- continue
- } else if inName {
- err = errors.New("unexpected `:` while reading named param at " + strconv.Itoa(i))
- return query, names, err
- }
- inName = true
- name = []byte{}
- } else if inName && i > 0 && b == '=' {
- rebound = append(rebound, ':', '=')
- inName = false
- continue
- // if we're in a name, and this is an allowed character, continue
- } else if inName && (unicode.IsOneOf(allowedBindRunes, rune(b)) || b == '_' || b == '.') && i != last {
- // append the byte to the name if we are in a name and not on the last byte
- name = append(name, b)
- // if we're in a name and it's not an allowed character, the name is done
- } else if inName {
- inName = false
- // if this is the final byte of the string and it is part of the name, then
- // make sure to add it to the name
- if i == last && unicode.IsOneOf(allowedBindRunes, rune(b)) {
- name = append(name, b)
- }
- // add the string representation to the names list
- names = append(names, string(name))
- // add a proper bindvar for the bindType
- switch bindType {
- // oracle only supports named type bind vars even for positional
- case NAMED:
- rebound = append(rebound, ':')
- rebound = append(rebound, name...)
- case QUESTION, UNKNOWN:
- rebound = append(rebound, '?')
- case DOLLAR:
- rebound = append(rebound, '$')
- for _, b := range strconv.Itoa(currentVar) {
- rebound = append(rebound, byte(b))
- }
- currentVar++
- case AT:
- rebound = append(rebound, '@', 'p')
- for _, b := range strconv.Itoa(currentVar) {
- rebound = append(rebound, byte(b))
- }
- currentVar++
- }
- // add this byte to string unless it was not part of the name
- if i != last {
- rebound = append(rebound, b)
- } else if !unicode.IsOneOf(allowedBindRunes, rune(b)) {
- rebound = append(rebound, b)
- }
- } else {
- // this is a normal byte and should just go onto the rebound query
- rebound = append(rebound, b)
- }
- }
-
- return string(rebound), names, err
-}
-
-// BindNamed binds a struct or a map to a query with named parameters.
-// DEPRECATED: use sqlx.Named` instead of this, it may be removed in future.
-func BindNamed(bindType int, query string, arg interface{}) (string, []interface{}, error) {
- return bindNamedMapper(bindType, query, arg, mapper())
-}
-
-// Named takes a query using named parameters and an argument and
-// returns a new query with a list of args that can be executed by
-// a database. The return value uses the `?` bindvar.
-func Named(query string, arg interface{}) (string, []interface{}, error) {
- return bindNamedMapper(QUESTION, query, arg, mapper())
-}
-
-func bindNamedMapper(bindType int, query string, arg interface{}, m *reflectx.Mapper) (string, []interface{}, error) {
- if maparg, ok := arg.(map[string]interface{}); ok {
- return bindMap(bindType, query, maparg)
- }
- return bindStruct(bindType, query, arg, m)
-}
-
-// NamedQuery binds a named query and then runs Query on the result using the
-// provided Ext (sqlx.Tx, sqlx.Db). It works with both structs and with
-// map[string]interface{} types.
-func NamedQuery(e Ext, query string, arg interface{}) (*Rows, error) {
- q, args, err := bindNamedMapper(BindType(e.DriverName()), query, arg, mapperFor(e))
- if err != nil {
- return nil, err
- }
- return e.Queryx(q, args...)
-}
-
-// NamedExec uses BindStruct to get a query executable by the driver and
-// then runs Exec on the result. Returns an error from the binding
-// or the query excution itself.
-func NamedExec(e Ext, query string, arg interface{}) (sql.Result, error) {
- q, args, err := bindNamedMapper(BindType(e.DriverName()), query, arg, mapperFor(e))
- if err != nil {
- return nil, err
- }
- return e.Exec(q, args...)
-}
diff --git a/vendor/github.com/jmoiron/sqlx/named_context.go b/vendor/github.com/jmoiron/sqlx/named_context.go
deleted file mode 100644
index 9405007..0000000
--- a/vendor/github.com/jmoiron/sqlx/named_context.go
+++ /dev/null
@@ -1,132 +0,0 @@
-// +build go1.8
-
-package sqlx
-
-import (
- "context"
- "database/sql"
-)
-
-// A union interface of contextPreparer and binder, required to be able to
-// prepare named statements with context (as the bindtype must be determined).
-type namedPreparerContext interface {
- PreparerContext
- binder
-}
-
-func prepareNamedContext(ctx context.Context, p namedPreparerContext, query string) (*NamedStmt, error) {
- bindType := BindType(p.DriverName())
- q, args, err := compileNamedQuery([]byte(query), bindType)
- if err != nil {
- return nil, err
- }
- stmt, err := PreparexContext(ctx, p, q)
- if err != nil {
- return nil, err
- }
- return &NamedStmt{
- QueryString: q,
- Params: args,
- Stmt: stmt,
- }, nil
-}
-
-// ExecContext executes a named statement using the struct passed.
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) ExecContext(ctx context.Context, arg interface{}) (sql.Result, error) {
- args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
- if err != nil {
- return *new(sql.Result), err
- }
- return n.Stmt.ExecContext(ctx, args...)
-}
-
-// QueryContext executes a named statement using the struct argument, returning rows.
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) QueryContext(ctx context.Context, arg interface{}) (*sql.Rows, error) {
- args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
- if err != nil {
- return nil, err
- }
- return n.Stmt.QueryContext(ctx, args...)
-}
-
-// QueryRowContext executes a named statement against the database. Because sqlx cannot
-// create a *sql.Row with an error condition pre-set for binding errors, sqlx
-// returns a *sqlx.Row instead.
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) QueryRowContext(ctx context.Context, arg interface{}) *Row {
- args, err := bindAnyArgs(n.Params, arg, n.Stmt.Mapper)
- if err != nil {
- return &Row{err: err}
- }
- return n.Stmt.QueryRowxContext(ctx, args...)
-}
-
-// MustExecContext execs a NamedStmt, panicing on error
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) MustExecContext(ctx context.Context, arg interface{}) sql.Result {
- res, err := n.ExecContext(ctx, arg)
- if err != nil {
- panic(err)
- }
- return res
-}
-
-// QueryxContext using this NamedStmt
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) QueryxContext(ctx context.Context, arg interface{}) (*Rows, error) {
- r, err := n.QueryContext(ctx, arg)
- if err != nil {
- return nil, err
- }
- return &Rows{Rows: r, Mapper: n.Stmt.Mapper, unsafe: isUnsafe(n)}, err
-}
-
-// QueryRowxContext this NamedStmt. Because of limitations with QueryRow, this is
-// an alias for QueryRow.
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) QueryRowxContext(ctx context.Context, arg interface{}) *Row {
- return n.QueryRowContext(ctx, arg)
-}
-
-// SelectContext using this NamedStmt
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) SelectContext(ctx context.Context, dest interface{}, arg interface{}) error {
- rows, err := n.QueryxContext(ctx, arg)
- if err != nil {
- return err
- }
- // if something happens here, we want to make sure the rows are Closed
- defer rows.Close()
- return scanAll(rows, dest, false)
-}
-
-// GetContext using this NamedStmt
-// Any named placeholder parameters are replaced with fields from arg.
-func (n *NamedStmt) GetContext(ctx context.Context, dest interface{}, arg interface{}) error {
- r := n.QueryRowxContext(ctx, arg)
- return r.scanAny(dest, false)
-}
-
-// NamedQueryContext binds a named query and then runs Query on the result using the
-// provided Ext (sqlx.Tx, sqlx.Db). It works with both structs and with
-// map[string]interface{} types.
-func NamedQueryContext(ctx context.Context, e ExtContext, query string, arg interface{}) (*Rows, error) {
- q, args, err := bindNamedMapper(BindType(e.DriverName()), query, arg, mapperFor(e))
- if err != nil {
- return nil, err
- }
- return e.QueryxContext(ctx, q, args...)
-}
-
-// NamedExecContext uses BindStruct to get a query executable by the driver and
-// then runs Exec on the result. Returns an error from the binding
-// or the query excution itself.
-func NamedExecContext(ctx context.Context, e ExtContext, query string, arg interface{}) (sql.Result, error) {
- q, args, err := bindNamedMapper(BindType(e.DriverName()), query, arg, mapperFor(e))
- if err != nil {
- return nil, err
- }
- return e.ExecContext(ctx, q, args...)
-}
diff --git a/vendor/github.com/jmoiron/sqlx/reflectx/README.md b/vendor/github.com/jmoiron/sqlx/reflectx/README.md
deleted file mode 100644
index f01d3d1..0000000
--- a/vendor/github.com/jmoiron/sqlx/reflectx/README.md
+++ /dev/null
@@ -1,17 +0,0 @@
-# reflectx
-
-The sqlx package has special reflect needs. In particular, it needs to:
-
-* be able to map a name to a field
-* understand embedded structs
-* understand mapping names to fields by a particular tag
-* user specified name -> field mapping functions
-
-These behaviors mimic the behaviors by the standard library marshallers and also the
-behavior of standard Go accessors.
-
-The first two are amply taken care of by `Reflect.Value.FieldByName`, and the third is
-addressed by `Reflect.Value.FieldByNameFunc`, but these don't quite understand struct
-tags in the ways that are vital to most marshallers, and they are slow.
-
-This reflectx package extends reflect to achieve these goals.
diff --git a/vendor/github.com/jmoiron/sqlx/reflectx/reflect.go b/vendor/github.com/jmoiron/sqlx/reflectx/reflect.go
deleted file mode 100644
index 73c21eb..0000000
--- a/vendor/github.com/jmoiron/sqlx/reflectx/reflect.go
+++ /dev/null
@@ -1,441 +0,0 @@
-// Package reflectx implements extensions to the standard reflect lib suitable
-// for implementing marshalling and unmarshalling packages. The main Mapper type
-// allows for Go-compatible named attribute access, including accessing embedded
-// struct attributes and the ability to use functions and struct tags to
-// customize field names.
-//
-package reflectx
-
-import (
- "reflect"
- "runtime"
- "strings"
- "sync"
-)
-
-// A FieldInfo is metadata for a struct field.
-type FieldInfo struct {
- Index []int
- Path string
- Field reflect.StructField
- Zero reflect.Value
- Name string
- Options map[string]string
- Embedded bool
- Children []*FieldInfo
- Parent *FieldInfo
-}
-
-// A StructMap is an index of field metadata for a struct.
-type StructMap struct {
- Tree *FieldInfo
- Index []*FieldInfo
- Paths map[string]*FieldInfo
- Names map[string]*FieldInfo
-}
-
-// GetByPath returns a *FieldInfo for a given string path.
-func (f StructMap) GetByPath(path string) *FieldInfo {
- return f.Paths[path]
-}
-
-// GetByTraversal returns a *FieldInfo for a given integer path. It is
-// analogous to reflect.FieldByIndex, but using the cached traversal
-// rather than re-executing the reflect machinery each time.
-func (f StructMap) GetByTraversal(index []int) *FieldInfo {
- if len(index) == 0 {
- return nil
- }
-
- tree := f.Tree
- for _, i := range index {
- if i >= len(tree.Children) || tree.Children[i] == nil {
- return nil
- }
- tree = tree.Children[i]
- }
- return tree
-}
-
-// Mapper is a general purpose mapper of names to struct fields. A Mapper
-// behaves like most marshallers in the standard library, obeying a field tag
-// for name mapping but also providing a basic transform function.
-type Mapper struct {
- cache map[reflect.Type]*StructMap
- tagName string
- tagMapFunc func(string) string
- mapFunc func(string) string
- mutex sync.Mutex
-}
-
-// NewMapper returns a new mapper using the tagName as its struct field tag.
-// If tagName is the empty string, it is ignored.
-func NewMapper(tagName string) *Mapper {
- return &Mapper{
- cache: make(map[reflect.Type]*StructMap),
- tagName: tagName,
- }
-}
-
-// NewMapperTagFunc returns a new mapper which contains a mapper for field names
-// AND a mapper for tag values. This is useful for tags like json which can
-// have values like "name,omitempty".
-func NewMapperTagFunc(tagName string, mapFunc, tagMapFunc func(string) string) *Mapper {
- return &Mapper{
- cache: make(map[reflect.Type]*StructMap),
- tagName: tagName,
- mapFunc: mapFunc,
- tagMapFunc: tagMapFunc,
- }
-}
-
-// NewMapperFunc returns a new mapper which optionally obeys a field tag and
-// a struct field name mapper func given by f. Tags will take precedence, but
-// for any other field, the mapped name will be f(field.Name)
-func NewMapperFunc(tagName string, f func(string) string) *Mapper {
- return &Mapper{
- cache: make(map[reflect.Type]*StructMap),
- tagName: tagName,
- mapFunc: f,
- }
-}
-
-// TypeMap returns a mapping of field strings to int slices representing
-// the traversal down the struct to reach the field.
-func (m *Mapper) TypeMap(t reflect.Type) *StructMap {
- m.mutex.Lock()
- mapping, ok := m.cache[t]
- if !ok {
- mapping = getMapping(t, m.tagName, m.mapFunc, m.tagMapFunc)
- m.cache[t] = mapping
- }
- m.mutex.Unlock()
- return mapping
-}
-
-// FieldMap returns the mapper's mapping of field names to reflect values. Panics
-// if v's Kind is not Struct, or v is not Indirectable to a struct kind.
-func (m *Mapper) FieldMap(v reflect.Value) map[string]reflect.Value {
- v = reflect.Indirect(v)
- mustBe(v, reflect.Struct)
-
- r := map[string]reflect.Value{}
- tm := m.TypeMap(v.Type())
- for tagName, fi := range tm.Names {
- r[tagName] = FieldByIndexes(v, fi.Index)
- }
- return r
-}
-
-// FieldByName returns a field by its mapped name as a reflect.Value.
-// Panics if v's Kind is not Struct or v is not Indirectable to a struct Kind.
-// Returns zero Value if the name is not found.
-func (m *Mapper) FieldByName(v reflect.Value, name string) reflect.Value {
- v = reflect.Indirect(v)
- mustBe(v, reflect.Struct)
-
- tm := m.TypeMap(v.Type())
- fi, ok := tm.Names[name]
- if !ok {
- return v
- }
- return FieldByIndexes(v, fi.Index)
-}
-
-// FieldsByName returns a slice of values corresponding to the slice of names
-// for the value. Panics if v's Kind is not Struct or v is not Indirectable
-// to a struct Kind. Returns zero Value for each name not found.
-func (m *Mapper) FieldsByName(v reflect.Value, names []string) []reflect.Value {
- v = reflect.Indirect(v)
- mustBe(v, reflect.Struct)
-
- tm := m.TypeMap(v.Type())
- vals := make([]reflect.Value, 0, len(names))
- for _, name := range names {
- fi, ok := tm.Names[name]
- if !ok {
- vals = append(vals, *new(reflect.Value))
- } else {
- vals = append(vals, FieldByIndexes(v, fi.Index))
- }
- }
- return vals
-}
-
-// TraversalsByName returns a slice of int slices which represent the struct
-// traversals for each mapped name. Panics if t is not a struct or Indirectable
-// to a struct. Returns empty int slice for each name not found.
-func (m *Mapper) TraversalsByName(t reflect.Type, names []string) [][]int {
- r := make([][]int, 0, len(names))
- m.TraversalsByNameFunc(t, names, func(_ int, i []int) error {
- if i == nil {
- r = append(r, []int{})
- } else {
- r = append(r, i)
- }
-
- return nil
- })
- return r
-}
-
-// TraversalsByNameFunc traverses the mapped names and calls fn with the index of
-// each name and the struct traversal represented by that name. Panics if t is not
-// a struct or Indirectable to a struct. Returns the first error returned by fn or nil.
-func (m *Mapper) TraversalsByNameFunc(t reflect.Type, names []string, fn func(int, []int) error) error {
- t = Deref(t)
- mustBe(t, reflect.Struct)
- tm := m.TypeMap(t)
- for i, name := range names {
- fi, ok := tm.Names[name]
- if !ok {
- if err := fn(i, nil); err != nil {
- return err
- }
- } else {
- if err := fn(i, fi.Index); err != nil {
- return err
- }
- }
- }
- return nil
-}
-
-// FieldByIndexes returns a value for the field given by the struct traversal
-// for the given value.
-func FieldByIndexes(v reflect.Value, indexes []int) reflect.Value {
- for _, i := range indexes {
- v = reflect.Indirect(v).Field(i)
- // if this is a pointer and it's nil, allocate a new value and set it
- if v.Kind() == reflect.Ptr && v.IsNil() {
- alloc := reflect.New(Deref(v.Type()))
- v.Set(alloc)
- }
- if v.Kind() == reflect.Map && v.IsNil() {
- v.Set(reflect.MakeMap(v.Type()))
- }
- }
- return v
-}
-
-// FieldByIndexesReadOnly returns a value for a particular struct traversal,
-// but is not concerned with allocating nil pointers because the value is
-// going to be used for reading and not setting.
-func FieldByIndexesReadOnly(v reflect.Value, indexes []int) reflect.Value {
- for _, i := range indexes {
- v = reflect.Indirect(v).Field(i)
- }
- return v
-}
-
-// Deref is Indirect for reflect.Types
-func Deref(t reflect.Type) reflect.Type {
- if t.Kind() == reflect.Ptr {
- t = t.Elem()
- }
- return t
-}
-
-// -- helpers & utilities --
-
-type kinder interface {
- Kind() reflect.Kind
-}
-
-// mustBe checks a value against a kind, panicing with a reflect.ValueError
-// if the kind isn't that which is required.
-func mustBe(v kinder, expected reflect.Kind) {
- if k := v.Kind(); k != expected {
- panic(&reflect.ValueError{Method: methodName(), Kind: k})
- }
-}
-
-// methodName returns the caller of the function calling methodName
-func methodName() string {
- pc, _, _, _ := runtime.Caller(2)
- f := runtime.FuncForPC(pc)
- if f == nil {
- return "unknown method"
- }
- return f.Name()
-}
-
-type typeQueue struct {
- t reflect.Type
- fi *FieldInfo
- pp string // Parent path
-}
-
-// A copying append that creates a new slice each time.
-func apnd(is []int, i int) []int {
- x := make([]int, len(is)+1)
- for p, n := range is {
- x[p] = n
- }
- x[len(x)-1] = i
- return x
-}
-
-type mapf func(string) string
-
-// parseName parses the tag and the target name for the given field using
-// the tagName (eg 'json' for `json:"foo"` tags), mapFunc for mapping the
-// field's name to a target name, and tagMapFunc for mapping the tag to
-// a target name.
-func parseName(field reflect.StructField, tagName string, mapFunc, tagMapFunc mapf) (tag, fieldName string) {
- // first, set the fieldName to the field's name
- fieldName = field.Name
- // if a mapFunc is set, use that to override the fieldName
- if mapFunc != nil {
- fieldName = mapFunc(fieldName)
- }
-
- // if there's no tag to look for, return the field name
- if tagName == "" {
- return "", fieldName
- }
-
- // if this tag is not set using the normal convention in the tag,
- // then return the fieldname.. this check is done because according
- // to the reflect documentation:
- // If the tag does not have the conventional format,
- // the value returned by Get is unspecified.
- // which doesn't sound great.
- if !strings.Contains(string(field.Tag), tagName+":") {
- return "", fieldName
- }
-
- // at this point we're fairly sure that we have a tag, so lets pull it out
- tag = field.Tag.Get(tagName)
-
- // if we have a mapper function, call it on the whole tag
- // XXX: this is a change from the old version, which pulled out the name
- // before the tagMapFunc could be run, but I think this is the right way
- if tagMapFunc != nil {
- tag = tagMapFunc(tag)
- }
-
- // finally, split the options from the name
- parts := strings.Split(tag, ",")
- fieldName = parts[0]
-
- return tag, fieldName
-}
-
-// parseOptions parses options out of a tag string, skipping the name
-func parseOptions(tag string) map[string]string {
- parts := strings.Split(tag, ",")
- options := make(map[string]string, len(parts))
- if len(parts) > 1 {
- for _, opt := range parts[1:] {
- // short circuit potentially expensive split op
- if strings.Contains(opt, "=") {
- kv := strings.Split(opt, "=")
- options[kv[0]] = kv[1]
- continue
- }
- options[opt] = ""
- }
- }
- return options
-}
-
-// getMapping returns a mapping for the t type, using the tagName, mapFunc and
-// tagMapFunc to determine the canonical names of fields.
-func getMapping(t reflect.Type, tagName string, mapFunc, tagMapFunc mapf) *StructMap {
- m := []*FieldInfo{}
-
- root := &FieldInfo{}
- queue := []typeQueue{}
- queue = append(queue, typeQueue{Deref(t), root, ""})
-
-QueueLoop:
- for len(queue) != 0 {
- // pop the first item off of the queue
- tq := queue[0]
- queue = queue[1:]
-
- // ignore recursive field
- for p := tq.fi.Parent; p != nil; p = p.Parent {
- if tq.fi.Field.Type == p.Field.Type {
- continue QueueLoop
- }
- }
-
- nChildren := 0
- if tq.t.Kind() == reflect.Struct {
- nChildren = tq.t.NumField()
- }
- tq.fi.Children = make([]*FieldInfo, nChildren)
-
- // iterate through all of its fields
- for fieldPos := 0; fieldPos < nChildren; fieldPos++ {
-
- f := tq.t.Field(fieldPos)
-
- // parse the tag and the target name using the mapping options for this field
- tag, name := parseName(f, tagName, mapFunc, tagMapFunc)
-
- // if the name is "-", disabled via a tag, skip it
- if name == "-" {
- continue
- }
-
- fi := FieldInfo{
- Field: f,
- Name: name,
- Zero: reflect.New(f.Type).Elem(),
- Options: parseOptions(tag),
- }
-
- // if the path is empty this path is just the name
- if tq.pp == "" {
- fi.Path = fi.Name
- } else {
- fi.Path = tq.pp + "." + fi.Name
- }
-
- // skip unexported fields
- if len(f.PkgPath) != 0 && !f.Anonymous {
- continue
- }
-
- // bfs search of anonymous embedded structs
- if f.Anonymous {
- pp := tq.pp
- if tag != "" {
- pp = fi.Path
- }
-
- fi.Embedded = true
- fi.Index = apnd(tq.fi.Index, fieldPos)
- nChildren := 0
- ft := Deref(f.Type)
- if ft.Kind() == reflect.Struct {
- nChildren = ft.NumField()
- }
- fi.Children = make([]*FieldInfo, nChildren)
- queue = append(queue, typeQueue{Deref(f.Type), &fi, pp})
- } else if fi.Zero.Kind() == reflect.Struct || (fi.Zero.Kind() == reflect.Ptr && fi.Zero.Type().Elem().Kind() == reflect.Struct) {
- fi.Index = apnd(tq.fi.Index, fieldPos)
- fi.Children = make([]*FieldInfo, Deref(f.Type).NumField())
- queue = append(queue, typeQueue{Deref(f.Type), &fi, fi.Path})
- }
-
- fi.Index = apnd(tq.fi.Index, fieldPos)
- fi.Parent = tq.fi
- tq.fi.Children[fieldPos] = &fi
- m = append(m, &fi)
- }
- }
-
- flds := &StructMap{Index: m, Tree: root, Paths: map[string]*FieldInfo{}, Names: map[string]*FieldInfo{}}
- for _, fi := range flds.Index {
- flds.Paths[fi.Path] = fi
- if fi.Name != "" && !fi.Embedded {
- flds.Names[fi.Path] = fi
- }
- }
-
- return flds
-}
diff --git a/vendor/github.com/jmoiron/sqlx/sqlx.go b/vendor/github.com/jmoiron/sqlx/sqlx.go
deleted file mode 100644
index 3f000f4..0000000
--- a/vendor/github.com/jmoiron/sqlx/sqlx.go
+++ /dev/null
@@ -1,1045 +0,0 @@
-package sqlx
-
-import (
- "database/sql"
- "database/sql/driver"
- "errors"
- "fmt"
-
- "io/ioutil"
- "path/filepath"
- "reflect"
- "strings"
- "sync"
-
- "github.com/jmoiron/sqlx/reflectx"
-)
-
-// Although the NameMapper is convenient, in practice it should not
-// be relied on except for application code. If you are writing a library
-// that uses sqlx, you should be aware that the name mappings you expect
-// can be overridden by your user's application.
-
-// NameMapper is used to map column names to struct field names. By default,
-// it uses strings.ToLower to lowercase struct field names. It can be set
-// to whatever you want, but it is encouraged to be set before sqlx is used
-// as name-to-field mappings are cached after first use on a type.
-var NameMapper = strings.ToLower
-var origMapper = reflect.ValueOf(NameMapper)
-
-// Rather than creating on init, this is created when necessary so that
-// importers have time to customize the NameMapper.
-var mpr *reflectx.Mapper
-
-// mprMu protects mpr.
-var mprMu sync.Mutex
-
-// mapper returns a valid mapper using the configured NameMapper func.
-func mapper() *reflectx.Mapper {
- mprMu.Lock()
- defer mprMu.Unlock()
-
- if mpr == nil {
- mpr = reflectx.NewMapperFunc("db", NameMapper)
- } else if origMapper != reflect.ValueOf(NameMapper) {
- // if NameMapper has changed, create a new mapper
- mpr = reflectx.NewMapperFunc("db", NameMapper)
- origMapper = reflect.ValueOf(NameMapper)
- }
- return mpr
-}
-
-// isScannable takes the reflect.Type and the actual dest value and returns
-// whether or not it's Scannable. Something is scannable if:
-// * it is not a struct
-// * it implements sql.Scanner
-// * it has no exported fields
-func isScannable(t reflect.Type) bool {
- if reflect.PtrTo(t).Implements(_scannerInterface) {
- return true
- }
- if t.Kind() != reflect.Struct {
- return true
- }
-
- // it's not important that we use the right mapper for this particular object,
- // we're only concerned on how many exported fields this struct has
- m := mapper()
- if len(m.TypeMap(t).Index) == 0 {
- return true
- }
- return false
-}
-
-// ColScanner is an interface used by MapScan and SliceScan
-type ColScanner interface {
- Columns() ([]string, error)
- Scan(dest ...interface{}) error
- Err() error
-}
-
-// Queryer is an interface used by Get and Select
-type Queryer interface {
- Query(query string, args ...interface{}) (*sql.Rows, error)
- Queryx(query string, args ...interface{}) (*Rows, error)
- QueryRowx(query string, args ...interface{}) *Row
-}
-
-// Execer is an interface used by MustExec and LoadFile
-type Execer interface {
- Exec(query string, args ...interface{}) (sql.Result, error)
-}
-
-// Binder is an interface for something which can bind queries (Tx, DB)
-type binder interface {
- DriverName() string
- Rebind(string) string
- BindNamed(string, interface{}) (string, []interface{}, error)
-}
-
-// Ext is a union interface which can bind, query, and exec, used by
-// NamedQuery and NamedExec.
-type Ext interface {
- binder
- Queryer
- Execer
-}
-
-// Preparer is an interface used by Preparex.
-type Preparer interface {
- Prepare(query string) (*sql.Stmt, error)
-}
-
-// determine if any of our extensions are unsafe
-func isUnsafe(i interface{}) bool {
- switch v := i.(type) {
- case Row:
- return v.unsafe
- case *Row:
- return v.unsafe
- case Rows:
- return v.unsafe
- case *Rows:
- return v.unsafe
- case NamedStmt:
- return v.Stmt.unsafe
- case *NamedStmt:
- return v.Stmt.unsafe
- case Stmt:
- return v.unsafe
- case *Stmt:
- return v.unsafe
- case qStmt:
- return v.unsafe
- case *qStmt:
- return v.unsafe
- case DB:
- return v.unsafe
- case *DB:
- return v.unsafe
- case Tx:
- return v.unsafe
- case *Tx:
- return v.unsafe
- case sql.Rows, *sql.Rows:
- return false
- default:
- return false
- }
-}
-
-func mapperFor(i interface{}) *reflectx.Mapper {
- switch i.(type) {
- case DB:
- return i.(DB).Mapper
- case *DB:
- return i.(*DB).Mapper
- case Tx:
- return i.(Tx).Mapper
- case *Tx:
- return i.(*Tx).Mapper
- default:
- return mapper()
- }
-}
-
-var _scannerInterface = reflect.TypeOf((*sql.Scanner)(nil)).Elem()
-var _valuerInterface = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
-
-// Row is a reimplementation of sql.Row in order to gain access to the underlying
-// sql.Rows.Columns() data, necessary for StructScan.
-type Row struct {
- err error
- unsafe bool
- rows *sql.Rows
- Mapper *reflectx.Mapper
-}
-
-// Scan is a fixed implementation of sql.Row.Scan, which does not discard the
-// underlying error from the internal rows object if it exists.
-func (r *Row) Scan(dest ...interface{}) error {
- if r.err != nil {
- return r.err
- }
-
- // TODO(bradfitz): for now we need to defensively clone all
- // []byte that the driver returned (not permitting
- // *RawBytes in Rows.Scan), since we're about to close
- // the Rows in our defer, when we return from this function.
- // the contract with the driver.Next(...) interface is that it
- // can return slices into read-only temporary memory that's
- // only valid until the next Scan/Close. But the TODO is that
- // for a lot of drivers, this copy will be unnecessary. We
- // should provide an optional interface for drivers to
- // implement to say, "don't worry, the []bytes that I return
- // from Next will not be modified again." (for instance, if
- // they were obtained from the network anyway) But for now we
- // don't care.
- defer r.rows.Close()
- for _, dp := range dest {
- if _, ok := dp.(*sql.RawBytes); ok {
- return errors.New("sql: RawBytes isn't allowed on Row.Scan")
- }
- }
-
- if !r.rows.Next() {
- if err := r.rows.Err(); err != nil {
- return err
- }
- return sql.ErrNoRows
- }
- err := r.rows.Scan(dest...)
- if err != nil {
- return err
- }
- // Make sure the query can be processed to completion with no errors.
- if err := r.rows.Close(); err != nil {
- return err
- }
- return nil
-}
-
-// Columns returns the underlying sql.Rows.Columns(), or the deferred error usually
-// returned by Row.Scan()
-func (r *Row) Columns() ([]string, error) {
- if r.err != nil {
- return []string{}, r.err
- }
- return r.rows.Columns()
-}
-
-// ColumnTypes returns the underlying sql.Rows.ColumnTypes(), or the deferred error
-func (r *Row) ColumnTypes() ([]*sql.ColumnType, error) {
- if r.err != nil {
- return []*sql.ColumnType{}, r.err
- }
- return r.rows.ColumnTypes()
-}
-
-// Err returns the error encountered while scanning.
-func (r *Row) Err() error {
- return r.err
-}
-
-// DB is a wrapper around sql.DB which keeps track of the driverName upon Open,
-// used mostly to automatically bind named queries using the right bindvars.
-type DB struct {
- *sql.DB
- driverName string
- unsafe bool
- Mapper *reflectx.Mapper
-}
-
-// NewDb returns a new sqlx DB wrapper for a pre-existing *sql.DB. The
-// driverName of the original database is required for named query support.
-func NewDb(db *sql.DB, driverName string) *DB {
- return &DB{DB: db, driverName: driverName, Mapper: mapper()}
-}
-
-// DriverName returns the driverName passed to the Open function for this DB.
-func (db *DB) DriverName() string {
- return db.driverName
-}
-
-// Open is the same as sql.Open, but returns an *sqlx.DB instead.
-func Open(driverName, dataSourceName string) (*DB, error) {
- db, err := sql.Open(driverName, dataSourceName)
- if err != nil {
- return nil, err
- }
- return &DB{DB: db, driverName: driverName, Mapper: mapper()}, err
-}
-
-// MustOpen is the same as sql.Open, but returns an *sqlx.DB instead and panics on error.
-func MustOpen(driverName, dataSourceName string) *DB {
- db, err := Open(driverName, dataSourceName)
- if err != nil {
- panic(err)
- }
- return db
-}
-
-// MapperFunc sets a new mapper for this db using the default sqlx struct tag
-// and the provided mapper function.
-func (db *DB) MapperFunc(mf func(string) string) {
- db.Mapper = reflectx.NewMapperFunc("db", mf)
-}
-
-// Rebind transforms a query from QUESTION to the DB driver's bindvar type.
-func (db *DB) Rebind(query string) string {
- return Rebind(BindType(db.driverName), query)
-}
-
-// Unsafe returns a version of DB which will silently succeed to scan when
-// columns in the SQL result have no fields in the destination struct.
-// sqlx.Stmt and sqlx.Tx which are created from this DB will inherit its
-// safety behavior.
-func (db *DB) Unsafe() *DB {
- return &DB{DB: db.DB, driverName: db.driverName, unsafe: true, Mapper: db.Mapper}
-}
-
-// BindNamed binds a query using the DB driver's bindvar type.
-func (db *DB) BindNamed(query string, arg interface{}) (string, []interface{}, error) {
- return bindNamedMapper(BindType(db.driverName), query, arg, db.Mapper)
-}
-
-// NamedQuery using this DB.
-// Any named placeholder parameters are replaced with fields from arg.
-func (db *DB) NamedQuery(query string, arg interface{}) (*Rows, error) {
- return NamedQuery(db, query, arg)
-}
-
-// NamedExec using this DB.
-// Any named placeholder parameters are replaced with fields from arg.
-func (db *DB) NamedExec(query string, arg interface{}) (sql.Result, error) {
- return NamedExec(db, query, arg)
-}
-
-// Select using this DB.
-// Any placeholder parameters are replaced with supplied args.
-func (db *DB) Select(dest interface{}, query string, args ...interface{}) error {
- return Select(db, dest, query, args...)
-}
-
-// Get using this DB.
-// Any placeholder parameters are replaced with supplied args.
-// An error is returned if the result set is empty.
-func (db *DB) Get(dest interface{}, query string, args ...interface{}) error {
- return Get(db, dest, query, args...)
-}
-
-// MustBegin starts a transaction, and panics on error. Returns an *sqlx.Tx instead
-// of an *sql.Tx.
-func (db *DB) MustBegin() *Tx {
- tx, err := db.Beginx()
- if err != nil {
- panic(err)
- }
- return tx
-}
-
-// Beginx begins a transaction and returns an *sqlx.Tx instead of an *sql.Tx.
-func (db *DB) Beginx() (*Tx, error) {
- tx, err := db.DB.Begin()
- if err != nil {
- return nil, err
- }
- return &Tx{Tx: tx, driverName: db.driverName, unsafe: db.unsafe, Mapper: db.Mapper}, err
-}
-
-// Queryx queries the database and returns an *sqlx.Rows.
-// Any placeholder parameters are replaced with supplied args.
-func (db *DB) Queryx(query string, args ...interface{}) (*Rows, error) {
- r, err := db.DB.Query(query, args...)
- if err != nil {
- return nil, err
- }
- return &Rows{Rows: r, unsafe: db.unsafe, Mapper: db.Mapper}, err
-}
-
-// QueryRowx queries the database and returns an *sqlx.Row.
-// Any placeholder parameters are replaced with supplied args.
-func (db *DB) QueryRowx(query string, args ...interface{}) *Row {
- rows, err := db.DB.Query(query, args...)
- return &Row{rows: rows, err: err, unsafe: db.unsafe, Mapper: db.Mapper}
-}
-
-// MustExec (panic) runs MustExec using this database.
-// Any placeholder parameters are replaced with supplied args.
-func (db *DB) MustExec(query string, args ...interface{}) sql.Result {
- return MustExec(db, query, args...)
-}
-
-// Preparex returns an sqlx.Stmt instead of a sql.Stmt
-func (db *DB) Preparex(query string) (*Stmt, error) {
- return Preparex(db, query)
-}
-
-// PrepareNamed returns an sqlx.NamedStmt
-func (db *DB) PrepareNamed(query string) (*NamedStmt, error) {
- return prepareNamed(db, query)
-}
-
-// Tx is an sqlx wrapper around sql.Tx with extra functionality
-type Tx struct {
- *sql.Tx
- driverName string
- unsafe bool
- Mapper *reflectx.Mapper
-}
-
-// DriverName returns the driverName used by the DB which began this transaction.
-func (tx *Tx) DriverName() string {
- return tx.driverName
-}
-
-// Rebind a query within a transaction's bindvar type.
-func (tx *Tx) Rebind(query string) string {
- return Rebind(BindType(tx.driverName), query)
-}
-
-// Unsafe returns a version of Tx which will silently succeed to scan when
-// columns in the SQL result have no fields in the destination struct.
-func (tx *Tx) Unsafe() *Tx {
- return &Tx{Tx: tx.Tx, driverName: tx.driverName, unsafe: true, Mapper: tx.Mapper}
-}
-
-// BindNamed binds a query within a transaction's bindvar type.
-func (tx *Tx) BindNamed(query string, arg interface{}) (string, []interface{}, error) {
- return bindNamedMapper(BindType(tx.driverName), query, arg, tx.Mapper)
-}
-
-// NamedQuery within a transaction.
-// Any named placeholder parameters are replaced with fields from arg.
-func (tx *Tx) NamedQuery(query string, arg interface{}) (*Rows, error) {
- return NamedQuery(tx, query, arg)
-}
-
-// NamedExec a named query within a transaction.
-// Any named placeholder parameters are replaced with fields from arg.
-func (tx *Tx) NamedExec(query string, arg interface{}) (sql.Result, error) {
- return NamedExec(tx, query, arg)
-}
-
-// Select within a transaction.
-// Any placeholder parameters are replaced with supplied args.
-func (tx *Tx) Select(dest interface{}, query string, args ...interface{}) error {
- return Select(tx, dest, query, args...)
-}
-
-// Queryx within a transaction.
-// Any placeholder parameters are replaced with supplied args.
-func (tx *Tx) Queryx(query string, args ...interface{}) (*Rows, error) {
- r, err := tx.Tx.Query(query, args...)
- if err != nil {
- return nil, err
- }
- return &Rows{Rows: r, unsafe: tx.unsafe, Mapper: tx.Mapper}, err
-}
-
-// QueryRowx within a transaction.
-// Any placeholder parameters are replaced with supplied args.
-func (tx *Tx) QueryRowx(query string, args ...interface{}) *Row {
- rows, err := tx.Tx.Query(query, args...)
- return &Row{rows: rows, err: err, unsafe: tx.unsafe, Mapper: tx.Mapper}
-}
-
-// Get within a transaction.
-// Any placeholder parameters are replaced with supplied args.
-// An error is returned if the result set is empty.
-func (tx *Tx) Get(dest interface{}, query string, args ...interface{}) error {
- return Get(tx, dest, query, args...)
-}
-
-// MustExec runs MustExec within a transaction.
-// Any placeholder parameters are replaced with supplied args.
-func (tx *Tx) MustExec(query string, args ...interface{}) sql.Result {
- return MustExec(tx, query, args...)
-}
-
-// Preparex a statement within a transaction.
-func (tx *Tx) Preparex(query string) (*Stmt, error) {
- return Preparex(tx, query)
-}
-
-// Stmtx returns a version of the prepared statement which runs within a transaction. Provided
-// stmt can be either *sql.Stmt or *sqlx.Stmt.
-func (tx *Tx) Stmtx(stmt interface{}) *Stmt {
- var s *sql.Stmt
- switch v := stmt.(type) {
- case Stmt:
- s = v.Stmt
- case *Stmt:
- s = v.Stmt
- case *sql.Stmt:
- s = v
- default:
- panic(fmt.Sprintf("non-statement type %v passed to Stmtx", reflect.ValueOf(stmt).Type()))
- }
- return &Stmt{Stmt: tx.Stmt(s), Mapper: tx.Mapper}
-}
-
-// NamedStmt returns a version of the prepared statement which runs within a transaction.
-func (tx *Tx) NamedStmt(stmt *NamedStmt) *NamedStmt {
- return &NamedStmt{
- QueryString: stmt.QueryString,
- Params: stmt.Params,
- Stmt: tx.Stmtx(stmt.Stmt),
- }
-}
-
-// PrepareNamed returns an sqlx.NamedStmt
-func (tx *Tx) PrepareNamed(query string) (*NamedStmt, error) {
- return prepareNamed(tx, query)
-}
-
-// Stmt is an sqlx wrapper around sql.Stmt with extra functionality
-type Stmt struct {
- *sql.Stmt
- unsafe bool
- Mapper *reflectx.Mapper
-}
-
-// Unsafe returns a version of Stmt which will silently succeed to scan when
-// columns in the SQL result have no fields in the destination struct.
-func (s *Stmt) Unsafe() *Stmt {
- return &Stmt{Stmt: s.Stmt, unsafe: true, Mapper: s.Mapper}
-}
-
-// Select using the prepared statement.
-// Any placeholder parameters are replaced with supplied args.
-func (s *Stmt) Select(dest interface{}, args ...interface{}) error {
- return Select(&qStmt{s}, dest, "", args...)
-}
-
-// Get using the prepared statement.
-// Any placeholder parameters are replaced with supplied args.
-// An error is returned if the result set is empty.
-func (s *Stmt) Get(dest interface{}, args ...interface{}) error {
- return Get(&qStmt{s}, dest, "", args...)
-}
-
-// MustExec (panic) using this statement. Note that the query portion of the error
-// output will be blank, as Stmt does not expose its query.
-// Any placeholder parameters are replaced with supplied args.
-func (s *Stmt) MustExec(args ...interface{}) sql.Result {
- return MustExec(&qStmt{s}, "", args...)
-}
-
-// QueryRowx using this statement.
-// Any placeholder parameters are replaced with supplied args.
-func (s *Stmt) QueryRowx(args ...interface{}) *Row {
- qs := &qStmt{s}
- return qs.QueryRowx("", args...)
-}
-
-// Queryx using this statement.
-// Any placeholder parameters are replaced with supplied args.
-func (s *Stmt) Queryx(args ...interface{}) (*Rows, error) {
- qs := &qStmt{s}
- return qs.Queryx("", args...)
-}
-
-// qStmt is an unexposed wrapper which lets you use a Stmt as a Queryer & Execer by
-// implementing those interfaces and ignoring the `query` argument.
-type qStmt struct{ *Stmt }
-
-func (q *qStmt) Query(query string, args ...interface{}) (*sql.Rows, error) {
- return q.Stmt.Query(args...)
-}
-
-func (q *qStmt) Queryx(query string, args ...interface{}) (*Rows, error) {
- r, err := q.Stmt.Query(args...)
- if err != nil {
- return nil, err
- }
- return &Rows{Rows: r, unsafe: q.Stmt.unsafe, Mapper: q.Stmt.Mapper}, err
-}
-
-func (q *qStmt) QueryRowx(query string, args ...interface{}) *Row {
- rows, err := q.Stmt.Query(args...)
- return &Row{rows: rows, err: err, unsafe: q.Stmt.unsafe, Mapper: q.Stmt.Mapper}
-}
-
-func (q *qStmt) Exec(query string, args ...interface{}) (sql.Result, error) {
- return q.Stmt.Exec(args...)
-}
-
-// Rows is a wrapper around sql.Rows which caches costly reflect operations
-// during a looped StructScan
-type Rows struct {
- *sql.Rows
- unsafe bool
- Mapper *reflectx.Mapper
- // these fields cache memory use for a rows during iteration w/ structScan
- started bool
- fields [][]int
- values []interface{}
-}
-
-// SliceScan using this Rows.
-func (r *Rows) SliceScan() ([]interface{}, error) {
- return SliceScan(r)
-}
-
-// MapScan using this Rows.
-func (r *Rows) MapScan(dest map[string]interface{}) error {
- return MapScan(r, dest)
-}
-
-// StructScan is like sql.Rows.Scan, but scans a single Row into a single Struct.
-// Use this and iterate over Rows manually when the memory load of Select() might be
-// prohibitive. *Rows.StructScan caches the reflect work of matching up column
-// positions to fields to avoid that overhead per scan, which means it is not safe
-// to run StructScan on the same Rows instance with different struct types.
-func (r *Rows) StructScan(dest interface{}) error {
- v := reflect.ValueOf(dest)
-
- if v.Kind() != reflect.Ptr {
- return errors.New("must pass a pointer, not a value, to StructScan destination")
- }
-
- v = v.Elem()
-
- if !r.started {
- columns, err := r.Columns()
- if err != nil {
- return err
- }
- m := r.Mapper
-
- r.fields = m.TraversalsByName(v.Type(), columns)
- // if we are not unsafe and are missing fields, return an error
- if f, err := missingFields(r.fields); err != nil && !r.unsafe {
- return fmt.Errorf("missing destination name %s in %T", columns[f], dest)
- }
- r.values = make([]interface{}, len(columns))
- r.started = true
- }
-
- err := fieldsByTraversal(v, r.fields, r.values, true)
- if err != nil {
- return err
- }
- // scan into the struct field pointers and append to our results
- err = r.Scan(r.values...)
- if err != nil {
- return err
- }
- return r.Err()
-}
-
-// Connect to a database and verify with a ping.
-func Connect(driverName, dataSourceName string) (*DB, error) {
- db, err := Open(driverName, dataSourceName)
- if err != nil {
- return nil, err
- }
- err = db.Ping()
- if err != nil {
- db.Close()
- return nil, err
- }
- return db, nil
-}
-
-// MustConnect connects to a database and panics on error.
-func MustConnect(driverName, dataSourceName string) *DB {
- db, err := Connect(driverName, dataSourceName)
- if err != nil {
- panic(err)
- }
- return db
-}
-
-// Preparex prepares a statement.
-func Preparex(p Preparer, query string) (*Stmt, error) {
- s, err := p.Prepare(query)
- if err != nil {
- return nil, err
- }
- return &Stmt{Stmt: s, unsafe: isUnsafe(p), Mapper: mapperFor(p)}, err
-}
-
-// Select executes a query using the provided Queryer, and StructScans each row
-// into dest, which must be a slice. If the slice elements are scannable, then
-// the result set must have only one column. Otherwise, StructScan is used.
-// The *sql.Rows are closed automatically.
-// Any placeholder parameters are replaced with supplied args.
-func Select(q Queryer, dest interface{}, query string, args ...interface{}) error {
- rows, err := q.Queryx(query, args...)
- if err != nil {
- return err
- }
- // if something happens here, we want to make sure the rows are Closed
- defer rows.Close()
- return scanAll(rows, dest, false)
-}
-
-// Get does a QueryRow using the provided Queryer, and scans the resulting row
-// to dest. If dest is scannable, the result must only have one column. Otherwise,
-// StructScan is used. Get will return sql.ErrNoRows like row.Scan would.
-// Any placeholder parameters are replaced with supplied args.
-// An error is returned if the result set is empty.
-func Get(q Queryer, dest interface{}, query string, args ...interface{}) error {
- r := q.QueryRowx(query, args...)
- return r.scanAny(dest, false)
-}
-
-// LoadFile exec's every statement in a file (as a single call to Exec).
-// LoadFile may return a nil *sql.Result if errors are encountered locating or
-// reading the file at path. LoadFile reads the entire file into memory, so it
-// is not suitable for loading large data dumps, but can be useful for initializing
-// schemas or loading indexes.
-//
-// FIXME: this does not really work with multi-statement files for mattn/go-sqlite3
-// or the go-mysql-driver/mysql drivers; pq seems to be an exception here. Detecting
-// this by requiring something with DriverName() and then attempting to split the
-// queries will be difficult to get right, and its current driver-specific behavior
-// is deemed at least not complex in its incorrectness.
-func LoadFile(e Execer, path string) (*sql.Result, error) {
- realpath, err := filepath.Abs(path)
- if err != nil {
- return nil, err
- }
- contents, err := ioutil.ReadFile(realpath)
- if err != nil {
- return nil, err
- }
- res, err := e.Exec(string(contents))
- return &res, err
-}
-
-// MustExec execs the query using e and panics if there was an error.
-// Any placeholder parameters are replaced with supplied args.
-func MustExec(e Execer, query string, args ...interface{}) sql.Result {
- res, err := e.Exec(query, args...)
- if err != nil {
- panic(err)
- }
- return res
-}
-
-// SliceScan using this Rows.
-func (r *Row) SliceScan() ([]interface{}, error) {
- return SliceScan(r)
-}
-
-// MapScan using this Rows.
-func (r *Row) MapScan(dest map[string]interface{}) error {
- return MapScan(r, dest)
-}
-
-func (r *Row) scanAny(dest interface{}, structOnly bool) error {
- if r.err != nil {
- return r.err
- }
- if r.rows == nil {
- r.err = sql.ErrNoRows
- return r.err
- }
- defer r.rows.Close()
-
- v := reflect.ValueOf(dest)
- if v.Kind() != reflect.Ptr {
- return errors.New("must pass a pointer, not a value, to StructScan destination")
- }
- if v.IsNil() {
- return errors.New("nil pointer passed to StructScan destination")
- }
-
- base := reflectx.Deref(v.Type())
- scannable := isScannable(base)
-
- if structOnly && scannable {
- return structOnlyError(base)
- }
-
- columns, err := r.Columns()
- if err != nil {
- return err
- }
-
- if scannable && len(columns) > 1 {
- return fmt.Errorf("scannable dest type %s with >1 columns (%d) in result", base.Kind(), len(columns))
- }
-
- if scannable {
- return r.Scan(dest)
- }
-
- m := r.Mapper
-
- fields := m.TraversalsByName(v.Type(), columns)
- // if we are not unsafe and are missing fields, return an error
- if f, err := missingFields(fields); err != nil && !r.unsafe {
- return fmt.Errorf("missing destination name %s in %T", columns[f], dest)
- }
- values := make([]interface{}, len(columns))
-
- err = fieldsByTraversal(v, fields, values, true)
- if err != nil {
- return err
- }
- // scan into the struct field pointers and append to our results
- return r.Scan(values...)
-}
-
-// StructScan a single Row into dest.
-func (r *Row) StructScan(dest interface{}) error {
- return r.scanAny(dest, true)
-}
-
-// SliceScan a row, returning a []interface{} with values similar to MapScan.
-// This function is primarily intended for use where the number of columns
-// is not known. Because you can pass an []interface{} directly to Scan,
-// it's recommended that you do that as it will not have to allocate new
-// slices per row.
-func SliceScan(r ColScanner) ([]interface{}, error) {
- // ignore r.started, since we needn't use reflect for anything.
- columns, err := r.Columns()
- if err != nil {
- return []interface{}{}, err
- }
-
- values := make([]interface{}, len(columns))
- for i := range values {
- values[i] = new(interface{})
- }
-
- err = r.Scan(values...)
-
- if err != nil {
- return values, err
- }
-
- for i := range columns {
- values[i] = *(values[i].(*interface{}))
- }
-
- return values, r.Err()
-}
-
-// MapScan scans a single Row into the dest map[string]interface{}.
-// Use this to get results for SQL that might not be under your control
-// (for instance, if you're building an interface for an SQL server that
-// executes SQL from input). Please do not use this as a primary interface!
-// This will modify the map sent to it in place, so reuse the same map with
-// care. Columns which occur more than once in the result will overwrite
-// each other!
-func MapScan(r ColScanner, dest map[string]interface{}) error {
- // ignore r.started, since we needn't use reflect for anything.
- columns, err := r.Columns()
- if err != nil {
- return err
- }
-
- values := make([]interface{}, len(columns))
- for i := range values {
- values[i] = new(interface{})
- }
-
- err = r.Scan(values...)
- if err != nil {
- return err
- }
-
- for i, column := range columns {
- dest[column] = *(values[i].(*interface{}))
- }
-
- return r.Err()
-}
-
-type rowsi interface {
- Close() error
- Columns() ([]string, error)
- Err() error
- Next() bool
- Scan(...interface{}) error
-}
-
-// structOnlyError returns an error appropriate for type when a non-scannable
-// struct is expected but something else is given
-func structOnlyError(t reflect.Type) error {
- isStruct := t.Kind() == reflect.Struct
- isScanner := reflect.PtrTo(t).Implements(_scannerInterface)
- if !isStruct {
- return fmt.Errorf("expected %s but got %s", reflect.Struct, t.Kind())
- }
- if isScanner {
- return fmt.Errorf("structscan expects a struct dest but the provided struct type %s implements scanner", t.Name())
- }
- return fmt.Errorf("expected a struct, but struct %s has no exported fields", t.Name())
-}
-
-// scanAll scans all rows into a destination, which must be a slice of any
-// type. If the destination slice type is a Struct, then StructScan will be
-// used on each row. If the destination is some other kind of base type, then
-// each row must only have one column which can scan into that type. This
-// allows you to do something like:
-//
-// rows, _ := db.Query("select id from people;")
-// var ids []int
-// scanAll(rows, &ids, false)
-//
-// and ids will be a list of the id results. I realize that this is a desirable
-// interface to expose to users, but for now it will only be exposed via changes
-// to `Get` and `Select`. The reason that this has been implemented like this is
-// this is the only way to not duplicate reflect work in the new API while
-// maintaining backwards compatibility.
-func scanAll(rows rowsi, dest interface{}, structOnly bool) error {
- var v, vp reflect.Value
-
- value := reflect.ValueOf(dest)
-
- // json.Unmarshal returns errors for these
- if value.Kind() != reflect.Ptr {
- return errors.New("must pass a pointer, not a value, to StructScan destination")
- }
- if value.IsNil() {
- return errors.New("nil pointer passed to StructScan destination")
- }
- direct := reflect.Indirect(value)
-
- slice, err := baseType(value.Type(), reflect.Slice)
- if err != nil {
- return err
- }
-
- isPtr := slice.Elem().Kind() == reflect.Ptr
- base := reflectx.Deref(slice.Elem())
- scannable := isScannable(base)
-
- if structOnly && scannable {
- return structOnlyError(base)
- }
-
- columns, err := rows.Columns()
- if err != nil {
- return err
- }
-
- // if it's a base type make sure it only has 1 column; if not return an error
- if scannable && len(columns) > 1 {
- return fmt.Errorf("non-struct dest type %s with >1 columns (%d)", base.Kind(), len(columns))
- }
-
- if !scannable {
- var values []interface{}
- var m *reflectx.Mapper
-
- switch rows.(type) {
- case *Rows:
- m = rows.(*Rows).Mapper
- default:
- m = mapper()
- }
-
- fields := m.TraversalsByName(base, columns)
- // if we are not unsafe and are missing fields, return an error
- if f, err := missingFields(fields); err != nil && !isUnsafe(rows) {
- return fmt.Errorf("missing destination name %s in %T", columns[f], dest)
- }
- values = make([]interface{}, len(columns))
-
- for rows.Next() {
- // create a new struct type (which returns PtrTo) and indirect it
- vp = reflect.New(base)
- v = reflect.Indirect(vp)
-
- err = fieldsByTraversal(v, fields, values, true)
- if err != nil {
- return err
- }
-
- // scan into the struct field pointers and append to our results
- err = rows.Scan(values...)
- if err != nil {
- return err
- }
-
- if isPtr {
- direct.Set(reflect.Append(direct, vp))
- } else {
- direct.Set(reflect.Append(direct, v))
- }
- }
- } else {
- for rows.Next() {
- vp = reflect.New(base)
- err = rows.Scan(vp.Interface())
- if err != nil {
- return err
- }
- // append
- if isPtr {
- direct.Set(reflect.Append(direct, vp))
- } else {
- direct.Set(reflect.Append(direct, reflect.Indirect(vp)))
- }
- }
- }
-
- return rows.Err()
-}
-
-// FIXME: StructScan was the very first bit of API in sqlx, and now unfortunately
-// it doesn't really feel like it's named properly. There is an incongruency
-// between this and the way that StructScan (which might better be ScanStruct
-// anyway) works on a rows object.
-
-// StructScan all rows from an sql.Rows or an sqlx.Rows into the dest slice.
-// StructScan will scan in the entire rows result, so if you do not want to
-// allocate structs for the entire result, use Queryx and see sqlx.Rows.StructScan.
-// If rows is sqlx.Rows, it will use its mapper, otherwise it will use the default.
-func StructScan(rows rowsi, dest interface{}) error {
- return scanAll(rows, dest, true)
-
-}
-
-// reflect helpers
-
-func baseType(t reflect.Type, expected reflect.Kind) (reflect.Type, error) {
- t = reflectx.Deref(t)
- if t.Kind() != expected {
- return nil, fmt.Errorf("expected %s but got %s", expected, t.Kind())
- }
- return t, nil
-}
-
-// fieldsByName fills a values interface with fields from the passed value based
-// on the traversals in int. If ptrs is true, return addresses instead of values.
-// We write this instead of using FieldsByName to save allocations and map lookups
-// when iterating over many rows. Empty traversals will get an interface pointer.
-// Because of the necessity of requesting ptrs or values, it's considered a bit too
-// specialized for inclusion in reflectx itself.
-func fieldsByTraversal(v reflect.Value, traversals [][]int, values []interface{}, ptrs bool) error {
- v = reflect.Indirect(v)
- if v.Kind() != reflect.Struct {
- return errors.New("argument not a struct")
- }
-
- for i, traversal := range traversals {
- if len(traversal) == 0 {
- values[i] = new(interface{})
- continue
- }
- f := reflectx.FieldByIndexes(v, traversal)
- if ptrs {
- values[i] = f.Addr().Interface()
- } else {
- values[i] = f.Interface()
- }
- }
- return nil
-}
-
-func missingFields(transversals [][]int) (field int, err error) {
- for i, t := range transversals {
- if len(t) == 0 {
- return i, errors.New("missing field")
- }
- }
- return 0, nil
-}
diff --git a/vendor/github.com/jmoiron/sqlx/sqlx_context.go b/vendor/github.com/jmoiron/sqlx/sqlx_context.go
deleted file mode 100644
index 0603311..0000000
--- a/vendor/github.com/jmoiron/sqlx/sqlx_context.go
+++ /dev/null
@@ -1,346 +0,0 @@
-// +build go1.8
-
-package sqlx
-
-import (
- "context"
- "database/sql"
- "fmt"
- "io/ioutil"
- "path/filepath"
- "reflect"
-)
-
-// ConnectContext to a database and verify with a ping.
-func ConnectContext(ctx context.Context, driverName, dataSourceName string) (*DB, error) {
- db, err := Open(driverName, dataSourceName)
- if err != nil {
- return db, err
- }
- err = db.PingContext(ctx)
- return db, err
-}
-
-// QueryerContext is an interface used by GetContext and SelectContext
-type QueryerContext interface {
- QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row
-}
-
-// PreparerContext is an interface used by PreparexContext.
-type PreparerContext interface {
- PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
-}
-
-// ExecerContext is an interface used by MustExecContext and LoadFileContext
-type ExecerContext interface {
- ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
-}
-
-// ExtContext is a union interface which can bind, query, and exec, with Context
-// used by NamedQueryContext and NamedExecContext.
-type ExtContext interface {
- binder
- QueryerContext
- ExecerContext
-}
-
-// SelectContext executes a query using the provided Queryer, and StructScans
-// each row into dest, which must be a slice. If the slice elements are
-// scannable, then the result set must have only one column. Otherwise,
-// StructScan is used. The *sql.Rows are closed automatically.
-// Any placeholder parameters are replaced with supplied args.
-func SelectContext(ctx context.Context, q QueryerContext, dest interface{}, query string, args ...interface{}) error {
- rows, err := q.QueryxContext(ctx, query, args...)
- if err != nil {
- return err
- }
- // if something happens here, we want to make sure the rows are Closed
- defer rows.Close()
- return scanAll(rows, dest, false)
-}
-
-// PreparexContext prepares a statement.
-//
-// The provided context is used for the preparation of the statement, not for
-// the execution of the statement.
-func PreparexContext(ctx context.Context, p PreparerContext, query string) (*Stmt, error) {
- s, err := p.PrepareContext(ctx, query)
- if err != nil {
- return nil, err
- }
- return &Stmt{Stmt: s, unsafe: isUnsafe(p), Mapper: mapperFor(p)}, err
-}
-
-// GetContext does a QueryRow using the provided Queryer, and scans the
-// resulting row to dest. If dest is scannable, the result must only have one
-// column. Otherwise, StructScan is used. Get will return sql.ErrNoRows like
-// row.Scan would. Any placeholder parameters are replaced with supplied args.
-// An error is returned if the result set is empty.
-func GetContext(ctx context.Context, q QueryerContext, dest interface{}, query string, args ...interface{}) error {
- r := q.QueryRowxContext(ctx, query, args...)
- return r.scanAny(dest, false)
-}
-
-// LoadFileContext exec's every statement in a file (as a single call to Exec).
-// LoadFileContext may return a nil *sql.Result if errors are encountered
-// locating or reading the file at path. LoadFile reads the entire file into
-// memory, so it is not suitable for loading large data dumps, but can be useful
-// for initializing schemas or loading indexes.
-//
-// FIXME: this does not really work with multi-statement files for mattn/go-sqlite3
-// or the go-mysql-driver/mysql drivers; pq seems to be an exception here. Detecting
-// this by requiring something with DriverName() and then attempting to split the
-// queries will be difficult to get right, and its current driver-specific behavior
-// is deemed at least not complex in its incorrectness.
-func LoadFileContext(ctx context.Context, e ExecerContext, path string) (*sql.Result, error) {
- realpath, err := filepath.Abs(path)
- if err != nil {
- return nil, err
- }
- contents, err := ioutil.ReadFile(realpath)
- if err != nil {
- return nil, err
- }
- res, err := e.ExecContext(ctx, string(contents))
- return &res, err
-}
-
-// MustExecContext execs the query using e and panics if there was an error.
-// Any placeholder parameters are replaced with supplied args.
-func MustExecContext(ctx context.Context, e ExecerContext, query string, args ...interface{}) sql.Result {
- res, err := e.ExecContext(ctx, query, args...)
- if err != nil {
- panic(err)
- }
- return res
-}
-
-// PrepareNamedContext returns an sqlx.NamedStmt
-func (db *DB) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error) {
- return prepareNamedContext(ctx, db, query)
-}
-
-// NamedQueryContext using this DB.
-// Any named placeholder parameters are replaced with fields from arg.
-func (db *DB) NamedQueryContext(ctx context.Context, query string, arg interface{}) (*Rows, error) {
- return NamedQueryContext(ctx, db, query, arg)
-}
-
-// NamedExecContext using this DB.
-// Any named placeholder parameters are replaced with fields from arg.
-func (db *DB) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) {
- return NamedExecContext(ctx, db, query, arg)
-}
-
-// SelectContext using this DB.
-// Any placeholder parameters are replaced with supplied args.
-func (db *DB) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
- return SelectContext(ctx, db, dest, query, args...)
-}
-
-// GetContext using this DB.
-// Any placeholder parameters are replaced with supplied args.
-// An error is returned if the result set is empty.
-func (db *DB) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
- return GetContext(ctx, db, dest, query, args...)
-}
-
-// PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.
-//
-// The provided context is used for the preparation of the statement, not for
-// the execution of the statement.
-func (db *DB) PreparexContext(ctx context.Context, query string) (*Stmt, error) {
- return PreparexContext(ctx, db, query)
-}
-
-// QueryxContext queries the database and returns an *sqlx.Rows.
-// Any placeholder parameters are replaced with supplied args.
-func (db *DB) QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
- r, err := db.DB.QueryContext(ctx, query, args...)
- if err != nil {
- return nil, err
- }
- return &Rows{Rows: r, unsafe: db.unsafe, Mapper: db.Mapper}, err
-}
-
-// QueryRowxContext queries the database and returns an *sqlx.Row.
-// Any placeholder parameters are replaced with supplied args.
-func (db *DB) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row {
- rows, err := db.DB.QueryContext(ctx, query, args...)
- return &Row{rows: rows, err: err, unsafe: db.unsafe, Mapper: db.Mapper}
-}
-
-// MustBeginTx starts a transaction, and panics on error. Returns an *sqlx.Tx instead
-// of an *sql.Tx.
-//
-// The provided context is used until the transaction is committed or rolled
-// back. If the context is canceled, the sql package will roll back the
-// transaction. Tx.Commit will return an error if the context provided to
-// MustBeginContext is canceled.
-func (db *DB) MustBeginTx(ctx context.Context, opts *sql.TxOptions) *Tx {
- tx, err := db.BeginTxx(ctx, opts)
- if err != nil {
- panic(err)
- }
- return tx
-}
-
-// MustExecContext (panic) runs MustExec using this database.
-// Any placeholder parameters are replaced with supplied args.
-func (db *DB) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result {
- return MustExecContext(ctx, db, query, args...)
-}
-
-// BeginTxx begins a transaction and returns an *sqlx.Tx instead of an
-// *sql.Tx.
-//
-// The provided context is used until the transaction is committed or rolled
-// back. If the context is canceled, the sql package will roll back the
-// transaction. Tx.Commit will return an error if the context provided to
-// BeginxContext is canceled.
-func (db *DB) BeginTxx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
- tx, err := db.DB.BeginTx(ctx, opts)
- if err != nil {
- return nil, err
- }
- return &Tx{Tx: tx, driverName: db.driverName, unsafe: db.unsafe, Mapper: db.Mapper}, err
-}
-
-// StmtxContext returns a version of the prepared statement which runs within a
-// transaction. Provided stmt can be either *sql.Stmt or *sqlx.Stmt.
-func (tx *Tx) StmtxContext(ctx context.Context, stmt interface{}) *Stmt {
- var s *sql.Stmt
- switch v := stmt.(type) {
- case Stmt:
- s = v.Stmt
- case *Stmt:
- s = v.Stmt
- case *sql.Stmt:
- s = v
- default:
- panic(fmt.Sprintf("non-statement type %v passed to Stmtx", reflect.ValueOf(stmt).Type()))
- }
- return &Stmt{Stmt: tx.StmtContext(ctx, s), Mapper: tx.Mapper}
-}
-
-// NamedStmtContext returns a version of the prepared statement which runs
-// within a transaction.
-func (tx *Tx) NamedStmtContext(ctx context.Context, stmt *NamedStmt) *NamedStmt {
- return &NamedStmt{
- QueryString: stmt.QueryString,
- Params: stmt.Params,
- Stmt: tx.StmtxContext(ctx, stmt.Stmt),
- }
-}
-
-// PreparexContext returns an sqlx.Stmt instead of a sql.Stmt.
-//
-// The provided context is used for the preparation of the statement, not for
-// the execution of the statement.
-func (tx *Tx) PreparexContext(ctx context.Context, query string) (*Stmt, error) {
- return PreparexContext(ctx, tx, query)
-}
-
-// PrepareNamedContext returns an sqlx.NamedStmt
-func (tx *Tx) PrepareNamedContext(ctx context.Context, query string) (*NamedStmt, error) {
- return prepareNamedContext(ctx, tx, query)
-}
-
-// MustExecContext runs MustExecContext within a transaction.
-// Any placeholder parameters are replaced with supplied args.
-func (tx *Tx) MustExecContext(ctx context.Context, query string, args ...interface{}) sql.Result {
- return MustExecContext(ctx, tx, query, args...)
-}
-
-// QueryxContext within a transaction and context.
-// Any placeholder parameters are replaced with supplied args.
-func (tx *Tx) QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
- r, err := tx.Tx.QueryContext(ctx, query, args...)
- if err != nil {
- return nil, err
- }
- return &Rows{Rows: r, unsafe: tx.unsafe, Mapper: tx.Mapper}, err
-}
-
-// SelectContext within a transaction and context.
-// Any placeholder parameters are replaced with supplied args.
-func (tx *Tx) SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
- return SelectContext(ctx, tx, dest, query, args...)
-}
-
-// GetContext within a transaction and context.
-// Any placeholder parameters are replaced with supplied args.
-// An error is returned if the result set is empty.
-func (tx *Tx) GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
- return GetContext(ctx, tx, dest, query, args...)
-}
-
-// QueryRowxContext within a transaction and context.
-// Any placeholder parameters are replaced with supplied args.
-func (tx *Tx) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row {
- rows, err := tx.Tx.QueryContext(ctx, query, args...)
- return &Row{rows: rows, err: err, unsafe: tx.unsafe, Mapper: tx.Mapper}
-}
-
-// NamedExecContext using this Tx.
-// Any named placeholder parameters are replaced with fields from arg.
-func (tx *Tx) NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) {
- return NamedExecContext(ctx, tx, query, arg)
-}
-
-// SelectContext using the prepared statement.
-// Any placeholder parameters are replaced with supplied args.
-func (s *Stmt) SelectContext(ctx context.Context, dest interface{}, args ...interface{}) error {
- return SelectContext(ctx, &qStmt{s}, dest, "", args...)
-}
-
-// GetContext using the prepared statement.
-// Any placeholder parameters are replaced with supplied args.
-// An error is returned if the result set is empty.
-func (s *Stmt) GetContext(ctx context.Context, dest interface{}, args ...interface{}) error {
- return GetContext(ctx, &qStmt{s}, dest, "", args...)
-}
-
-// MustExecContext (panic) using this statement. Note that the query portion of
-// the error output will be blank, as Stmt does not expose its query.
-// Any placeholder parameters are replaced with supplied args.
-func (s *Stmt) MustExecContext(ctx context.Context, args ...interface{}) sql.Result {
- return MustExecContext(ctx, &qStmt{s}, "", args...)
-}
-
-// QueryRowxContext using this statement.
-// Any placeholder parameters are replaced with supplied args.
-func (s *Stmt) QueryRowxContext(ctx context.Context, args ...interface{}) *Row {
- qs := &qStmt{s}
- return qs.QueryRowxContext(ctx, "", args...)
-}
-
-// QueryxContext using this statement.
-// Any placeholder parameters are replaced with supplied args.
-func (s *Stmt) QueryxContext(ctx context.Context, args ...interface{}) (*Rows, error) {
- qs := &qStmt{s}
- return qs.QueryxContext(ctx, "", args...)
-}
-
-func (q *qStmt) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) {
- return q.Stmt.QueryContext(ctx, args...)
-}
-
-func (q *qStmt) QueryxContext(ctx context.Context, query string, args ...interface{}) (*Rows, error) {
- r, err := q.Stmt.QueryContext(ctx, args...)
- if err != nil {
- return nil, err
- }
- return &Rows{Rows: r, unsafe: q.Stmt.unsafe, Mapper: q.Stmt.Mapper}, err
-}
-
-func (q *qStmt) QueryRowxContext(ctx context.Context, query string, args ...interface{}) *Row {
- rows, err := q.Stmt.QueryContext(ctx, args...)
- return &Row{rows: rows, err: err, unsafe: q.Stmt.unsafe, Mapper: q.Stmt.Mapper}
-}
-
-func (q *qStmt) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
- return q.Stmt.ExecContext(ctx, args...)
-}
diff --git a/vendor/github.com/json-iterator/go/.codecov.yml b/vendor/github.com/json-iterator/go/.codecov.yml
deleted file mode 100644
index 955dc0b..0000000
--- a/vendor/github.com/json-iterator/go/.codecov.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-ignore:
- - "output_tests/.*"
-
diff --git a/vendor/github.com/json-iterator/go/.gitignore b/vendor/github.com/json-iterator/go/.gitignore
deleted file mode 100644
index 1555653..0000000
--- a/vendor/github.com/json-iterator/go/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-/vendor
-/bug_test.go
-/coverage.txt
-/.idea
diff --git a/vendor/github.com/json-iterator/go/.travis.yml b/vendor/github.com/json-iterator/go/.travis.yml
deleted file mode 100644
index 449e67c..0000000
--- a/vendor/github.com/json-iterator/go/.travis.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-language: go
-
-go:
- - 1.8.x
- - 1.x
-
-before_install:
- - go get -t -v ./...
-
-script:
- - ./test.sh
-
-after_success:
- - bash <(curl -s https://codecov.io/bash)
diff --git a/vendor/github.com/json-iterator/go/Gopkg.lock b/vendor/github.com/json-iterator/go/Gopkg.lock
deleted file mode 100644
index c8a9fbb..0000000
--- a/vendor/github.com/json-iterator/go/Gopkg.lock
+++ /dev/null
@@ -1,21 +0,0 @@
-# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
-
-
-[[projects]]
- name = "github.com/modern-go/concurrent"
- packages = ["."]
- revision = "e0a39a4cb4216ea8db28e22a69f4ec25610d513a"
- version = "1.0.0"
-
-[[projects]]
- name = "github.com/modern-go/reflect2"
- packages = ["."]
- revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd"
- version = "1.0.1"
-
-[solve-meta]
- analyzer-name = "dep"
- analyzer-version = 1
- inputs-digest = "ea54a775e5a354cb015502d2e7aa4b74230fc77e894f34a838b268c25ec8eeb8"
- solver-name = "gps-cdcl"
- solver-version = 1
diff --git a/vendor/github.com/json-iterator/go/Gopkg.toml b/vendor/github.com/json-iterator/go/Gopkg.toml
deleted file mode 100644
index 313a0f8..0000000
--- a/vendor/github.com/json-iterator/go/Gopkg.toml
+++ /dev/null
@@ -1,26 +0,0 @@
-# Gopkg.toml example
-#
-# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
-# for detailed Gopkg.toml documentation.
-#
-# required = ["github.com/user/thing/cmd/thing"]
-# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
-#
-# [[constraint]]
-# name = "github.com/user/project"
-# version = "1.0.0"
-#
-# [[constraint]]
-# name = "github.com/user/project2"
-# branch = "dev"
-# source = "github.com/myfork/project2"
-#
-# [[override]]
-# name = "github.com/x/y"
-# version = "2.4.0"
-
-ignored = ["github.com/davecgh/go-spew*","github.com/google/gofuzz*","github.com/stretchr/testify*"]
-
-[[constraint]]
- name = "github.com/modern-go/reflect2"
- version = "1.0.1"
diff --git a/vendor/github.com/json-iterator/go/LICENSE b/vendor/github.com/json-iterator/go/LICENSE
deleted file mode 100644
index 2cf4f5a..0000000
--- a/vendor/github.com/json-iterator/go/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2016 json-iterator
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/vendor/github.com/json-iterator/go/README.md b/vendor/github.com/json-iterator/go/README.md
deleted file mode 100644
index 54d5afe..0000000
--- a/vendor/github.com/json-iterator/go/README.md
+++ /dev/null
@@ -1,91 +0,0 @@
-[![Sourcegraph](https://sourcegraph.com/github.com/json-iterator/go/-/badge.svg)](https://sourcegraph.com/github.com/json-iterator/go?badge)
-[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/json-iterator/go)
-[![Build Status](https://travis-ci.org/json-iterator/go.svg?branch=master)](https://travis-ci.org/json-iterator/go)
-[![codecov](https://codecov.io/gh/json-iterator/go/branch/master/graph/badge.svg)](https://codecov.io/gh/json-iterator/go)
-[![rcard](https://goreportcard.com/badge/github.com/json-iterator/go)](https://goreportcard.com/report/github.com/json-iterator/go)
-[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/json-iterator/go/master/LICENSE)
-[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/json-iterator/Lobby)
-
-A high-performance 100% compatible drop-in replacement of "encoding/json"
-
-You can also use thrift like JSON using [thrift-iterator](https://github.com/thrift-iterator/go)
-
-```
-Go开发者们请加入我们,滴滴出行平台技术部 taowen@didichuxing.com
-```
-
-# Benchmark
-
-![benchmark](http://jsoniter.com/benchmarks/go-benchmark.png)
-
-Source code: https://github.com/json-iterator/go-benchmark/blob/master/src/github.com/json-iterator/go-benchmark/benchmark_medium_payload_test.go
-
-Raw Result (easyjson requires static code generation)
-
-| | ns/op | allocation bytes | allocation times |
-| --- | --- | --- | --- |
-| std decode | 35510 ns/op | 1960 B/op | 99 allocs/op |
-| easyjson decode | 8499 ns/op | 160 B/op | 4 allocs/op |
-| jsoniter decode | 5623 ns/op | 160 B/op | 3 allocs/op |
-| std encode | 2213 ns/op | 712 B/op | 5 allocs/op |
-| easyjson encode | 883 ns/op | 576 B/op | 3 allocs/op |
-| jsoniter encode | 837 ns/op | 384 B/op | 4 allocs/op |
-
-Always benchmark with your own workload.
-The result depends heavily on the data input.
-
-# Usage
-
-100% compatibility with standard lib
-
-Replace
-
-```go
-import "encoding/json"
-json.Marshal(&data)
-```
-
-with
-
-```go
-import "github.com/json-iterator/go"
-
-var json = jsoniter.ConfigCompatibleWithStandardLibrary
-json.Marshal(&data)
-```
-
-Replace
-
-```go
-import "encoding/json"
-json.Unmarshal(input, &data)
-```
-
-with
-
-```go
-import "github.com/json-iterator/go"
-
-var json = jsoniter.ConfigCompatibleWithStandardLibrary
-json.Unmarshal(input, &data)
-```
-
-[More documentation](http://jsoniter.com/migrate-from-go-std.html)
-
-# How to get
-
-```
-go get github.com/json-iterator/go
-```
-
-# Contribution Welcomed !
-
-Contributors
-
-* [thockin](https://github.com/thockin)
-* [mattn](https://github.com/mattn)
-* [cch123](https://github.com/cch123)
-* [Oleg Shaldybin](https://github.com/olegshaldybin)
-* [Jason Toffaletti](https://github.com/toffaletti)
-
-Report issue or pull request, or email taowen@gmail.com, or [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/json-iterator/Lobby)
diff --git a/vendor/github.com/json-iterator/go/adapter.go b/vendor/github.com/json-iterator/go/adapter.go
deleted file mode 100644
index e674d0f..0000000
--- a/vendor/github.com/json-iterator/go/adapter.go
+++ /dev/null
@@ -1,150 +0,0 @@
-package jsoniter
-
-import (
- "bytes"
- "io"
-)
-
-// RawMessage to make replace json with jsoniter
-type RawMessage []byte
-
-// Unmarshal adapts to json/encoding Unmarshal API
-//
-// Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v.
-// Refer to https://godoc.org/encoding/json#Unmarshal for more information
-func Unmarshal(data []byte, v interface{}) error {
- return ConfigDefault.Unmarshal(data, v)
-}
-
-// UnmarshalFromString convenient method to read from string instead of []byte
-func UnmarshalFromString(str string, v interface{}) error {
- return ConfigDefault.UnmarshalFromString(str, v)
-}
-
-// Get quick method to get value from deeply nested JSON structure
-func Get(data []byte, path ...interface{}) Any {
- return ConfigDefault.Get(data, path...)
-}
-
-// Marshal adapts to json/encoding Marshal API
-//
-// Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API
-// Refer to https://godoc.org/encoding/json#Marshal for more information
-func Marshal(v interface{}) ([]byte, error) {
- return ConfigDefault.Marshal(v)
-}
-
-// MarshalIndent same as json.MarshalIndent. Prefix is not supported.
-func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
- return ConfigDefault.MarshalIndent(v, prefix, indent)
-}
-
-// MarshalToString convenient method to write as string instead of []byte
-func MarshalToString(v interface{}) (string, error) {
- return ConfigDefault.MarshalToString(v)
-}
-
-// NewDecoder adapts to json/stream NewDecoder API.
-//
-// NewDecoder returns a new decoder that reads from r.
-//
-// Instead of a json/encoding Decoder, an Decoder is returned
-// Refer to https://godoc.org/encoding/json#NewDecoder for more information
-func NewDecoder(reader io.Reader) *Decoder {
- return ConfigDefault.NewDecoder(reader)
-}
-
-// Decoder reads and decodes JSON values from an input stream.
-// Decoder provides identical APIs with json/stream Decoder (Token() and UseNumber() are in progress)
-type Decoder struct {
- iter *Iterator
-}
-
-// Decode decode JSON into interface{}
-func (adapter *Decoder) Decode(obj interface{}) error {
- if adapter.iter.head == adapter.iter.tail && adapter.iter.reader != nil {
- if !adapter.iter.loadMore() {
- return io.EOF
- }
- }
- adapter.iter.ReadVal(obj)
- err := adapter.iter.Error
- if err == io.EOF {
- return nil
- }
- return adapter.iter.Error
-}
-
-// More is there more?
-func (adapter *Decoder) More() bool {
- iter := adapter.iter
- if iter.Error != nil {
- return false
- }
- c := iter.nextToken()
- if c == 0 {
- return false
- }
- iter.unreadByte()
- return c != ']' && c != '}'
-}
-
-// Buffered remaining buffer
-func (adapter *Decoder) Buffered() io.Reader {
- remaining := adapter.iter.buf[adapter.iter.head:adapter.iter.tail]
- return bytes.NewReader(remaining)
-}
-
-// UseNumber causes the Decoder to unmarshal a number into an interface{} as a
-// Number instead of as a float64.
-func (adapter *Decoder) UseNumber() {
- cfg := adapter.iter.cfg.configBeforeFrozen
- cfg.UseNumber = true
- adapter.iter.cfg = cfg.frozeWithCacheReuse(adapter.iter.cfg.extraExtensions)
-}
-
-// DisallowUnknownFields causes the Decoder to return an error when the destination
-// is a struct and the input contains object keys which do not match any
-// non-ignored, exported fields in the destination.
-func (adapter *Decoder) DisallowUnknownFields() {
- cfg := adapter.iter.cfg.configBeforeFrozen
- cfg.DisallowUnknownFields = true
- adapter.iter.cfg = cfg.frozeWithCacheReuse(adapter.iter.cfg.extraExtensions)
-}
-
-// NewEncoder same as json.NewEncoder
-func NewEncoder(writer io.Writer) *Encoder {
- return ConfigDefault.NewEncoder(writer)
-}
-
-// Encoder same as json.Encoder
-type Encoder struct {
- stream *Stream
-}
-
-// Encode encode interface{} as JSON to io.Writer
-func (adapter *Encoder) Encode(val interface{}) error {
- adapter.stream.WriteVal(val)
- adapter.stream.WriteRaw("\n")
- adapter.stream.Flush()
- return adapter.stream.Error
-}
-
-// SetIndent set the indention. Prefix is not supported
-func (adapter *Encoder) SetIndent(prefix, indent string) {
- config := adapter.stream.cfg.configBeforeFrozen
- config.IndentionStep = len(indent)
- adapter.stream.cfg = config.frozeWithCacheReuse(adapter.stream.cfg.extraExtensions)
-}
-
-// SetEscapeHTML escape html by default, set to false to disable
-func (adapter *Encoder) SetEscapeHTML(escapeHTML bool) {
- config := adapter.stream.cfg.configBeforeFrozen
- config.EscapeHTML = escapeHTML
- adapter.stream.cfg = config.frozeWithCacheReuse(adapter.stream.cfg.extraExtensions)
-}
-
-// Valid reports whether data is a valid JSON encoding.
-func Valid(data []byte) bool {
- return ConfigDefault.Valid(data)
-}
diff --git a/vendor/github.com/json-iterator/go/any.go b/vendor/github.com/json-iterator/go/any.go
deleted file mode 100644
index daecfed..0000000
--- a/vendor/github.com/json-iterator/go/any.go
+++ /dev/null
@@ -1,321 +0,0 @@
-package jsoniter
-
-import (
- "errors"
- "fmt"
- "github.com/modern-go/reflect2"
- "io"
- "reflect"
- "strconv"
- "unsafe"
-)
-
-// Any generic object representation.
-// The lazy json implementation holds []byte and parse lazily.
-type Any interface {
- LastError() error
- ValueType() ValueType
- MustBeValid() Any
- ToBool() bool
- ToInt() int
- ToInt32() int32
- ToInt64() int64
- ToUint() uint
- ToUint32() uint32
- ToUint64() uint64
- ToFloat32() float32
- ToFloat64() float64
- ToString() string
- ToVal(val interface{})
- Get(path ...interface{}) Any
- Size() int
- Keys() []string
- GetInterface() interface{}
- WriteTo(stream *Stream)
-}
-
-type baseAny struct{}
-
-func (any *baseAny) Get(path ...interface{}) Any {
- return &invalidAny{baseAny{}, fmt.Errorf("GetIndex %v from simple value", path)}
-}
-
-func (any *baseAny) Size() int {
- return 0
-}
-
-func (any *baseAny) Keys() []string {
- return []string{}
-}
-
-func (any *baseAny) ToVal(obj interface{}) {
- panic("not implemented")
-}
-
-// WrapInt32 turn int32 into Any interface
-func WrapInt32(val int32) Any {
- return &int32Any{baseAny{}, val}
-}
-
-// WrapInt64 turn int64 into Any interface
-func WrapInt64(val int64) Any {
- return &int64Any{baseAny{}, val}
-}
-
-// WrapUint32 turn uint32 into Any interface
-func WrapUint32(val uint32) Any {
- return &uint32Any{baseAny{}, val}
-}
-
-// WrapUint64 turn uint64 into Any interface
-func WrapUint64(val uint64) Any {
- return &uint64Any{baseAny{}, val}
-}
-
-// WrapFloat64 turn float64 into Any interface
-func WrapFloat64(val float64) Any {
- return &floatAny{baseAny{}, val}
-}
-
-// WrapString turn string into Any interface
-func WrapString(val string) Any {
- return &stringAny{baseAny{}, val}
-}
-
-// Wrap turn a go object into Any interface
-func Wrap(val interface{}) Any {
- if val == nil {
- return &nilAny{}
- }
- asAny, isAny := val.(Any)
- if isAny {
- return asAny
- }
- typ := reflect2.TypeOf(val)
- switch typ.Kind() {
- case reflect.Slice:
- return wrapArray(val)
- case reflect.Struct:
- return wrapStruct(val)
- case reflect.Map:
- return wrapMap(val)
- case reflect.String:
- return WrapString(val.(string))
- case reflect.Int:
- if strconv.IntSize == 32 {
- return WrapInt32(int32(val.(int)))
- }
- return WrapInt64(int64(val.(int)))
- case reflect.Int8:
- return WrapInt32(int32(val.(int8)))
- case reflect.Int16:
- return WrapInt32(int32(val.(int16)))
- case reflect.Int32:
- return WrapInt32(val.(int32))
- case reflect.Int64:
- return WrapInt64(val.(int64))
- case reflect.Uint:
- if strconv.IntSize == 32 {
- return WrapUint32(uint32(val.(uint)))
- }
- return WrapUint64(uint64(val.(uint)))
- case reflect.Uintptr:
- if ptrSize == 32 {
- return WrapUint32(uint32(val.(uintptr)))
- }
- return WrapUint64(uint64(val.(uintptr)))
- case reflect.Uint8:
- return WrapUint32(uint32(val.(uint8)))
- case reflect.Uint16:
- return WrapUint32(uint32(val.(uint16)))
- case reflect.Uint32:
- return WrapUint32(uint32(val.(uint32)))
- case reflect.Uint64:
- return WrapUint64(val.(uint64))
- case reflect.Float32:
- return WrapFloat64(float64(val.(float32)))
- case reflect.Float64:
- return WrapFloat64(val.(float64))
- case reflect.Bool:
- if val.(bool) == true {
- return &trueAny{}
- }
- return &falseAny{}
- }
- return &invalidAny{baseAny{}, fmt.Errorf("unsupported type: %v", typ)}
-}
-
-// ReadAny read next JSON element as an Any object. It is a better json.RawMessage.
-func (iter *Iterator) ReadAny() Any {
- return iter.readAny()
-}
-
-func (iter *Iterator) readAny() Any {
- c := iter.nextToken()
- switch c {
- case '"':
- iter.unreadByte()
- return &stringAny{baseAny{}, iter.ReadString()}
- case 'n':
- iter.skipThreeBytes('u', 'l', 'l') // null
- return &nilAny{}
- case 't':
- iter.skipThreeBytes('r', 'u', 'e') // true
- return &trueAny{}
- case 'f':
- iter.skipFourBytes('a', 'l', 's', 'e') // false
- return &falseAny{}
- case '{':
- return iter.readObjectAny()
- case '[':
- return iter.readArrayAny()
- case '-':
- return iter.readNumberAny(false)
- case 0:
- return &invalidAny{baseAny{}, errors.New("input is empty")}
- default:
- return iter.readNumberAny(true)
- }
-}
-
-func (iter *Iterator) readNumberAny(positive bool) Any {
- iter.startCapture(iter.head - 1)
- iter.skipNumber()
- lazyBuf := iter.stopCapture()
- return &numberLazyAny{baseAny{}, iter.cfg, lazyBuf, nil}
-}
-
-func (iter *Iterator) readObjectAny() Any {
- iter.startCapture(iter.head - 1)
- iter.skipObject()
- lazyBuf := iter.stopCapture()
- return &objectLazyAny{baseAny{}, iter.cfg, lazyBuf, nil}
-}
-
-func (iter *Iterator) readArrayAny() Any {
- iter.startCapture(iter.head - 1)
- iter.skipArray()
- lazyBuf := iter.stopCapture()
- return &arrayLazyAny{baseAny{}, iter.cfg, lazyBuf, nil}
-}
-
-func locateObjectField(iter *Iterator, target string) []byte {
- var found []byte
- iter.ReadObjectCB(func(iter *Iterator, field string) bool {
- if field == target {
- found = iter.SkipAndReturnBytes()
- return false
- }
- iter.Skip()
- return true
- })
- return found
-}
-
-func locateArrayElement(iter *Iterator, target int) []byte {
- var found []byte
- n := 0
- iter.ReadArrayCB(func(iter *Iterator) bool {
- if n == target {
- found = iter.SkipAndReturnBytes()
- return false
- }
- iter.Skip()
- n++
- return true
- })
- return found
-}
-
-func locatePath(iter *Iterator, path []interface{}) Any {
- for i, pathKeyObj := range path {
- switch pathKey := pathKeyObj.(type) {
- case string:
- valueBytes := locateObjectField(iter, pathKey)
- if valueBytes == nil {
- return newInvalidAny(path[i:])
- }
- iter.ResetBytes(valueBytes)
- case int:
- valueBytes := locateArrayElement(iter, pathKey)
- if valueBytes == nil {
- return newInvalidAny(path[i:])
- }
- iter.ResetBytes(valueBytes)
- case int32:
- if '*' == pathKey {
- return iter.readAny().Get(path[i:]...)
- }
- return newInvalidAny(path[i:])
- default:
- return newInvalidAny(path[i:])
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- return &invalidAny{baseAny{}, iter.Error}
- }
- return iter.readAny()
-}
-
-var anyType = reflect2.TypeOfPtr((*Any)(nil)).Elem()
-
-func createDecoderOfAny(ctx *ctx, typ reflect2.Type) ValDecoder {
- if typ == anyType {
- return &directAnyCodec{}
- }
- if typ.Implements(anyType) {
- return &anyCodec{
- valType: typ,
- }
- }
- return nil
-}
-
-func createEncoderOfAny(ctx *ctx, typ reflect2.Type) ValEncoder {
- if typ == anyType {
- return &directAnyCodec{}
- }
- if typ.Implements(anyType) {
- return &anyCodec{
- valType: typ,
- }
- }
- return nil
-}
-
-type anyCodec struct {
- valType reflect2.Type
-}
-
-func (codec *anyCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- panic("not implemented")
-}
-
-func (codec *anyCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
- obj := codec.valType.UnsafeIndirect(ptr)
- any := obj.(Any)
- any.WriteTo(stream)
-}
-
-func (codec *anyCodec) IsEmpty(ptr unsafe.Pointer) bool {
- obj := codec.valType.UnsafeIndirect(ptr)
- any := obj.(Any)
- return any.Size() == 0
-}
-
-type directAnyCodec struct {
-}
-
-func (codec *directAnyCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- *(*Any)(ptr) = iter.readAny()
-}
-
-func (codec *directAnyCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
- any := *(*Any)(ptr)
- any.WriteTo(stream)
-}
-
-func (codec *directAnyCodec) IsEmpty(ptr unsafe.Pointer) bool {
- any := *(*Any)(ptr)
- return any.Size() == 0
-}
diff --git a/vendor/github.com/json-iterator/go/any_array.go b/vendor/github.com/json-iterator/go/any_array.go
deleted file mode 100644
index 0449e9a..0000000
--- a/vendor/github.com/json-iterator/go/any_array.go
+++ /dev/null
@@ -1,278 +0,0 @@
-package jsoniter
-
-import (
- "reflect"
- "unsafe"
-)
-
-type arrayLazyAny struct {
- baseAny
- cfg *frozenConfig
- buf []byte
- err error
-}
-
-func (any *arrayLazyAny) ValueType() ValueType {
- return ArrayValue
-}
-
-func (any *arrayLazyAny) MustBeValid() Any {
- return any
-}
-
-func (any *arrayLazyAny) LastError() error {
- return any.err
-}
-
-func (any *arrayLazyAny) ToBool() bool {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- return iter.ReadArray()
-}
-
-func (any *arrayLazyAny) ToInt() int {
- if any.ToBool() {
- return 1
- }
- return 0
-}
-
-func (any *arrayLazyAny) ToInt32() int32 {
- if any.ToBool() {
- return 1
- }
- return 0
-}
-
-func (any *arrayLazyAny) ToInt64() int64 {
- if any.ToBool() {
- return 1
- }
- return 0
-}
-
-func (any *arrayLazyAny) ToUint() uint {
- if any.ToBool() {
- return 1
- }
- return 0
-}
-
-func (any *arrayLazyAny) ToUint32() uint32 {
- if any.ToBool() {
- return 1
- }
- return 0
-}
-
-func (any *arrayLazyAny) ToUint64() uint64 {
- if any.ToBool() {
- return 1
- }
- return 0
-}
-
-func (any *arrayLazyAny) ToFloat32() float32 {
- if any.ToBool() {
- return 1
- }
- return 0
-}
-
-func (any *arrayLazyAny) ToFloat64() float64 {
- if any.ToBool() {
- return 1
- }
- return 0
-}
-
-func (any *arrayLazyAny) ToString() string {
- return *(*string)(unsafe.Pointer(&any.buf))
-}
-
-func (any *arrayLazyAny) ToVal(val interface{}) {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- iter.ReadVal(val)
-}
-
-func (any *arrayLazyAny) Get(path ...interface{}) Any {
- if len(path) == 0 {
- return any
- }
- switch firstPath := path[0].(type) {
- case int:
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- valueBytes := locateArrayElement(iter, firstPath)
- if valueBytes == nil {
- return newInvalidAny(path)
- }
- iter.ResetBytes(valueBytes)
- return locatePath(iter, path[1:])
- case int32:
- if '*' == firstPath {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- arr := make([]Any, 0)
- iter.ReadArrayCB(func(iter *Iterator) bool {
- found := iter.readAny().Get(path[1:]...)
- if found.ValueType() != InvalidValue {
- arr = append(arr, found)
- }
- return true
- })
- return wrapArray(arr)
- }
- return newInvalidAny(path)
- default:
- return newInvalidAny(path)
- }
-}
-
-func (any *arrayLazyAny) Size() int {
- size := 0
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- iter.ReadArrayCB(func(iter *Iterator) bool {
- size++
- iter.Skip()
- return true
- })
- return size
-}
-
-func (any *arrayLazyAny) WriteTo(stream *Stream) {
- stream.Write(any.buf)
-}
-
-func (any *arrayLazyAny) GetInterface() interface{} {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- return iter.Read()
-}
-
-type arrayAny struct {
- baseAny
- val reflect.Value
-}
-
-func wrapArray(val interface{}) *arrayAny {
- return &arrayAny{baseAny{}, reflect.ValueOf(val)}
-}
-
-func (any *arrayAny) ValueType() ValueType {
- return ArrayValue
-}
-
-func (any *arrayAny) MustBeValid() Any {
- return any
-}
-
-func (any *arrayAny) LastError() error {
- return nil
-}
-
-func (any *arrayAny) ToBool() bool {
- return any.val.Len() != 0
-}
-
-func (any *arrayAny) ToInt() int {
- if any.val.Len() == 0 {
- return 0
- }
- return 1
-}
-
-func (any *arrayAny) ToInt32() int32 {
- if any.val.Len() == 0 {
- return 0
- }
- return 1
-}
-
-func (any *arrayAny) ToInt64() int64 {
- if any.val.Len() == 0 {
- return 0
- }
- return 1
-}
-
-func (any *arrayAny) ToUint() uint {
- if any.val.Len() == 0 {
- return 0
- }
- return 1
-}
-
-func (any *arrayAny) ToUint32() uint32 {
- if any.val.Len() == 0 {
- return 0
- }
- return 1
-}
-
-func (any *arrayAny) ToUint64() uint64 {
- if any.val.Len() == 0 {
- return 0
- }
- return 1
-}
-
-func (any *arrayAny) ToFloat32() float32 {
- if any.val.Len() == 0 {
- return 0
- }
- return 1
-}
-
-func (any *arrayAny) ToFloat64() float64 {
- if any.val.Len() == 0 {
- return 0
- }
- return 1
-}
-
-func (any *arrayAny) ToString() string {
- str, _ := MarshalToString(any.val.Interface())
- return str
-}
-
-func (any *arrayAny) Get(path ...interface{}) Any {
- if len(path) == 0 {
- return any
- }
- switch firstPath := path[0].(type) {
- case int:
- if firstPath < 0 || firstPath >= any.val.Len() {
- return newInvalidAny(path)
- }
- return Wrap(any.val.Index(firstPath).Interface())
- case int32:
- if '*' == firstPath {
- mappedAll := make([]Any, 0)
- for i := 0; i < any.val.Len(); i++ {
- mapped := Wrap(any.val.Index(i).Interface()).Get(path[1:]...)
- if mapped.ValueType() != InvalidValue {
- mappedAll = append(mappedAll, mapped)
- }
- }
- return wrapArray(mappedAll)
- }
- return newInvalidAny(path)
- default:
- return newInvalidAny(path)
- }
-}
-
-func (any *arrayAny) Size() int {
- return any.val.Len()
-}
-
-func (any *arrayAny) WriteTo(stream *Stream) {
- stream.WriteVal(any.val)
-}
-
-func (any *arrayAny) GetInterface() interface{} {
- return any.val.Interface()
-}
diff --git a/vendor/github.com/json-iterator/go/any_bool.go b/vendor/github.com/json-iterator/go/any_bool.go
deleted file mode 100644
index 9452324..0000000
--- a/vendor/github.com/json-iterator/go/any_bool.go
+++ /dev/null
@@ -1,137 +0,0 @@
-package jsoniter
-
-type trueAny struct {
- baseAny
-}
-
-func (any *trueAny) LastError() error {
- return nil
-}
-
-func (any *trueAny) ToBool() bool {
- return true
-}
-
-func (any *trueAny) ToInt() int {
- return 1
-}
-
-func (any *trueAny) ToInt32() int32 {
- return 1
-}
-
-func (any *trueAny) ToInt64() int64 {
- return 1
-}
-
-func (any *trueAny) ToUint() uint {
- return 1
-}
-
-func (any *trueAny) ToUint32() uint32 {
- return 1
-}
-
-func (any *trueAny) ToUint64() uint64 {
- return 1
-}
-
-func (any *trueAny) ToFloat32() float32 {
- return 1
-}
-
-func (any *trueAny) ToFloat64() float64 {
- return 1
-}
-
-func (any *trueAny) ToString() string {
- return "true"
-}
-
-func (any *trueAny) WriteTo(stream *Stream) {
- stream.WriteTrue()
-}
-
-func (any *trueAny) Parse() *Iterator {
- return nil
-}
-
-func (any *trueAny) GetInterface() interface{} {
- return true
-}
-
-func (any *trueAny) ValueType() ValueType {
- return BoolValue
-}
-
-func (any *trueAny) MustBeValid() Any {
- return any
-}
-
-type falseAny struct {
- baseAny
-}
-
-func (any *falseAny) LastError() error {
- return nil
-}
-
-func (any *falseAny) ToBool() bool {
- return false
-}
-
-func (any *falseAny) ToInt() int {
- return 0
-}
-
-func (any *falseAny) ToInt32() int32 {
- return 0
-}
-
-func (any *falseAny) ToInt64() int64 {
- return 0
-}
-
-func (any *falseAny) ToUint() uint {
- return 0
-}
-
-func (any *falseAny) ToUint32() uint32 {
- return 0
-}
-
-func (any *falseAny) ToUint64() uint64 {
- return 0
-}
-
-func (any *falseAny) ToFloat32() float32 {
- return 0
-}
-
-func (any *falseAny) ToFloat64() float64 {
- return 0
-}
-
-func (any *falseAny) ToString() string {
- return "false"
-}
-
-func (any *falseAny) WriteTo(stream *Stream) {
- stream.WriteFalse()
-}
-
-func (any *falseAny) Parse() *Iterator {
- return nil
-}
-
-func (any *falseAny) GetInterface() interface{} {
- return false
-}
-
-func (any *falseAny) ValueType() ValueType {
- return BoolValue
-}
-
-func (any *falseAny) MustBeValid() Any {
- return any
-}
diff --git a/vendor/github.com/json-iterator/go/any_float.go b/vendor/github.com/json-iterator/go/any_float.go
deleted file mode 100644
index 35fdb09..0000000
--- a/vendor/github.com/json-iterator/go/any_float.go
+++ /dev/null
@@ -1,83 +0,0 @@
-package jsoniter
-
-import (
- "strconv"
-)
-
-type floatAny struct {
- baseAny
- val float64
-}
-
-func (any *floatAny) Parse() *Iterator {
- return nil
-}
-
-func (any *floatAny) ValueType() ValueType {
- return NumberValue
-}
-
-func (any *floatAny) MustBeValid() Any {
- return any
-}
-
-func (any *floatAny) LastError() error {
- return nil
-}
-
-func (any *floatAny) ToBool() bool {
- return any.ToFloat64() != 0
-}
-
-func (any *floatAny) ToInt() int {
- return int(any.val)
-}
-
-func (any *floatAny) ToInt32() int32 {
- return int32(any.val)
-}
-
-func (any *floatAny) ToInt64() int64 {
- return int64(any.val)
-}
-
-func (any *floatAny) ToUint() uint {
- if any.val > 0 {
- return uint(any.val)
- }
- return 0
-}
-
-func (any *floatAny) ToUint32() uint32 {
- if any.val > 0 {
- return uint32(any.val)
- }
- return 0
-}
-
-func (any *floatAny) ToUint64() uint64 {
- if any.val > 0 {
- return uint64(any.val)
- }
- return 0
-}
-
-func (any *floatAny) ToFloat32() float32 {
- return float32(any.val)
-}
-
-func (any *floatAny) ToFloat64() float64 {
- return any.val
-}
-
-func (any *floatAny) ToString() string {
- return strconv.FormatFloat(any.val, 'E', -1, 64)
-}
-
-func (any *floatAny) WriteTo(stream *Stream) {
- stream.WriteFloat64(any.val)
-}
-
-func (any *floatAny) GetInterface() interface{} {
- return any.val
-}
diff --git a/vendor/github.com/json-iterator/go/any_int32.go b/vendor/github.com/json-iterator/go/any_int32.go
deleted file mode 100644
index 1b56f39..0000000
--- a/vendor/github.com/json-iterator/go/any_int32.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package jsoniter
-
-import (
- "strconv"
-)
-
-type int32Any struct {
- baseAny
- val int32
-}
-
-func (any *int32Any) LastError() error {
- return nil
-}
-
-func (any *int32Any) ValueType() ValueType {
- return NumberValue
-}
-
-func (any *int32Any) MustBeValid() Any {
- return any
-}
-
-func (any *int32Any) ToBool() bool {
- return any.val != 0
-}
-
-func (any *int32Any) ToInt() int {
- return int(any.val)
-}
-
-func (any *int32Any) ToInt32() int32 {
- return any.val
-}
-
-func (any *int32Any) ToInt64() int64 {
- return int64(any.val)
-}
-
-func (any *int32Any) ToUint() uint {
- return uint(any.val)
-}
-
-func (any *int32Any) ToUint32() uint32 {
- return uint32(any.val)
-}
-
-func (any *int32Any) ToUint64() uint64 {
- return uint64(any.val)
-}
-
-func (any *int32Any) ToFloat32() float32 {
- return float32(any.val)
-}
-
-func (any *int32Any) ToFloat64() float64 {
- return float64(any.val)
-}
-
-func (any *int32Any) ToString() string {
- return strconv.FormatInt(int64(any.val), 10)
-}
-
-func (any *int32Any) WriteTo(stream *Stream) {
- stream.WriteInt32(any.val)
-}
-
-func (any *int32Any) Parse() *Iterator {
- return nil
-}
-
-func (any *int32Any) GetInterface() interface{} {
- return any.val
-}
diff --git a/vendor/github.com/json-iterator/go/any_int64.go b/vendor/github.com/json-iterator/go/any_int64.go
deleted file mode 100644
index c440d72..0000000
--- a/vendor/github.com/json-iterator/go/any_int64.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package jsoniter
-
-import (
- "strconv"
-)
-
-type int64Any struct {
- baseAny
- val int64
-}
-
-func (any *int64Any) LastError() error {
- return nil
-}
-
-func (any *int64Any) ValueType() ValueType {
- return NumberValue
-}
-
-func (any *int64Any) MustBeValid() Any {
- return any
-}
-
-func (any *int64Any) ToBool() bool {
- return any.val != 0
-}
-
-func (any *int64Any) ToInt() int {
- return int(any.val)
-}
-
-func (any *int64Any) ToInt32() int32 {
- return int32(any.val)
-}
-
-func (any *int64Any) ToInt64() int64 {
- return any.val
-}
-
-func (any *int64Any) ToUint() uint {
- return uint(any.val)
-}
-
-func (any *int64Any) ToUint32() uint32 {
- return uint32(any.val)
-}
-
-func (any *int64Any) ToUint64() uint64 {
- return uint64(any.val)
-}
-
-func (any *int64Any) ToFloat32() float32 {
- return float32(any.val)
-}
-
-func (any *int64Any) ToFloat64() float64 {
- return float64(any.val)
-}
-
-func (any *int64Any) ToString() string {
- return strconv.FormatInt(any.val, 10)
-}
-
-func (any *int64Any) WriteTo(stream *Stream) {
- stream.WriteInt64(any.val)
-}
-
-func (any *int64Any) Parse() *Iterator {
- return nil
-}
-
-func (any *int64Any) GetInterface() interface{} {
- return any.val
-}
diff --git a/vendor/github.com/json-iterator/go/any_invalid.go b/vendor/github.com/json-iterator/go/any_invalid.go
deleted file mode 100644
index 1d859ea..0000000
--- a/vendor/github.com/json-iterator/go/any_invalid.go
+++ /dev/null
@@ -1,82 +0,0 @@
-package jsoniter
-
-import "fmt"
-
-type invalidAny struct {
- baseAny
- err error
-}
-
-func newInvalidAny(path []interface{}) *invalidAny {
- return &invalidAny{baseAny{}, fmt.Errorf("%v not found", path)}
-}
-
-func (any *invalidAny) LastError() error {
- return any.err
-}
-
-func (any *invalidAny) ValueType() ValueType {
- return InvalidValue
-}
-
-func (any *invalidAny) MustBeValid() Any {
- panic(any.err)
-}
-
-func (any *invalidAny) ToBool() bool {
- return false
-}
-
-func (any *invalidAny) ToInt() int {
- return 0
-}
-
-func (any *invalidAny) ToInt32() int32 {
- return 0
-}
-
-func (any *invalidAny) ToInt64() int64 {
- return 0
-}
-
-func (any *invalidAny) ToUint() uint {
- return 0
-}
-
-func (any *invalidAny) ToUint32() uint32 {
- return 0
-}
-
-func (any *invalidAny) ToUint64() uint64 {
- return 0
-}
-
-func (any *invalidAny) ToFloat32() float32 {
- return 0
-}
-
-func (any *invalidAny) ToFloat64() float64 {
- return 0
-}
-
-func (any *invalidAny) ToString() string {
- return ""
-}
-
-func (any *invalidAny) WriteTo(stream *Stream) {
-}
-
-func (any *invalidAny) Get(path ...interface{}) Any {
- if any.err == nil {
- return &invalidAny{baseAny{}, fmt.Errorf("get %v from invalid", path)}
- }
- return &invalidAny{baseAny{}, fmt.Errorf("%v, get %v from invalid", any.err, path)}
-}
-
-func (any *invalidAny) Parse() *Iterator {
- return nil
-}
-
-func (any *invalidAny) GetInterface() interface{} {
- return nil
-}
diff --git a/vendor/github.com/json-iterator/go/any_nil.go b/vendor/github.com/json-iterator/go/any_nil.go
deleted file mode 100644
index d04cb54..0000000
--- a/vendor/github.com/json-iterator/go/any_nil.go
+++ /dev/null
@@ -1,69 +0,0 @@
-package jsoniter
-
-type nilAny struct {
- baseAny
-}
-
-func (any *nilAny) LastError() error {
- return nil
-}
-
-func (any *nilAny) ValueType() ValueType {
- return NilValue
-}
-
-func (any *nilAny) MustBeValid() Any {
- return any
-}
-
-func (any *nilAny) ToBool() bool {
- return false
-}
-
-func (any *nilAny) ToInt() int {
- return 0
-}
-
-func (any *nilAny) ToInt32() int32 {
- return 0
-}
-
-func (any *nilAny) ToInt64() int64 {
- return 0
-}
-
-func (any *nilAny) ToUint() uint {
- return 0
-}
-
-func (any *nilAny) ToUint32() uint32 {
- return 0
-}
-
-func (any *nilAny) ToUint64() uint64 {
- return 0
-}
-
-func (any *nilAny) ToFloat32() float32 {
- return 0
-}
-
-func (any *nilAny) ToFloat64() float64 {
- return 0
-}
-
-func (any *nilAny) ToString() string {
- return ""
-}
-
-func (any *nilAny) WriteTo(stream *Stream) {
- stream.WriteNil()
-}
-
-func (any *nilAny) Parse() *Iterator {
- return nil
-}
-
-func (any *nilAny) GetInterface() interface{} {
- return nil
-}
diff --git a/vendor/github.com/json-iterator/go/any_number.go b/vendor/github.com/json-iterator/go/any_number.go
deleted file mode 100644
index 9d1e901..0000000
--- a/vendor/github.com/json-iterator/go/any_number.go
+++ /dev/null
@@ -1,123 +0,0 @@
-package jsoniter
-
-import (
- "io"
- "unsafe"
-)
-
-type numberLazyAny struct {
- baseAny
- cfg *frozenConfig
- buf []byte
- err error
-}
-
-func (any *numberLazyAny) ValueType() ValueType {
- return NumberValue
-}
-
-func (any *numberLazyAny) MustBeValid() Any {
- return any
-}
-
-func (any *numberLazyAny) LastError() error {
- return any.err
-}
-
-func (any *numberLazyAny) ToBool() bool {
- return any.ToFloat64() != 0
-}
-
-func (any *numberLazyAny) ToInt() int {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- val := iter.ReadInt()
- if iter.Error != nil && iter.Error != io.EOF {
- any.err = iter.Error
- }
- return val
-}
-
-func (any *numberLazyAny) ToInt32() int32 {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- val := iter.ReadInt32()
- if iter.Error != nil && iter.Error != io.EOF {
- any.err = iter.Error
- }
- return val
-}
-
-func (any *numberLazyAny) ToInt64() int64 {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- val := iter.ReadInt64()
- if iter.Error != nil && iter.Error != io.EOF {
- any.err = iter.Error
- }
- return val
-}
-
-func (any *numberLazyAny) ToUint() uint {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- val := iter.ReadUint()
- if iter.Error != nil && iter.Error != io.EOF {
- any.err = iter.Error
- }
- return val
-}
-
-func (any *numberLazyAny) ToUint32() uint32 {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- val := iter.ReadUint32()
- if iter.Error != nil && iter.Error != io.EOF {
- any.err = iter.Error
- }
- return val
-}
-
-func (any *numberLazyAny) ToUint64() uint64 {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- val := iter.ReadUint64()
- if iter.Error != nil && iter.Error != io.EOF {
- any.err = iter.Error
- }
- return val
-}
-
-func (any *numberLazyAny) ToFloat32() float32 {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- val := iter.ReadFloat32()
- if iter.Error != nil && iter.Error != io.EOF {
- any.err = iter.Error
- }
- return val
-}
-
-func (any *numberLazyAny) ToFloat64() float64 {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- val := iter.ReadFloat64()
- if iter.Error != nil && iter.Error != io.EOF {
- any.err = iter.Error
- }
- return val
-}
-
-func (any *numberLazyAny) ToString() string {
- return *(*string)(unsafe.Pointer(&any.buf))
-}
-
-func (any *numberLazyAny) WriteTo(stream *Stream) {
- stream.Write(any.buf)
-}
-
-func (any *numberLazyAny) GetInterface() interface{} {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- return iter.Read()
-}
diff --git a/vendor/github.com/json-iterator/go/any_object.go b/vendor/github.com/json-iterator/go/any_object.go
deleted file mode 100644
index c44ef5c..0000000
--- a/vendor/github.com/json-iterator/go/any_object.go
+++ /dev/null
@@ -1,374 +0,0 @@
-package jsoniter
-
-import (
- "reflect"
- "unsafe"
-)
-
-type objectLazyAny struct {
- baseAny
- cfg *frozenConfig
- buf []byte
- err error
-}
-
-func (any *objectLazyAny) ValueType() ValueType {
- return ObjectValue
-}
-
-func (any *objectLazyAny) MustBeValid() Any {
- return any
-}
-
-func (any *objectLazyAny) LastError() error {
- return any.err
-}
-
-func (any *objectLazyAny) ToBool() bool {
- return true
-}
-
-func (any *objectLazyAny) ToInt() int {
- return 0
-}
-
-func (any *objectLazyAny) ToInt32() int32 {
- return 0
-}
-
-func (any *objectLazyAny) ToInt64() int64 {
- return 0
-}
-
-func (any *objectLazyAny) ToUint() uint {
- return 0
-}
-
-func (any *objectLazyAny) ToUint32() uint32 {
- return 0
-}
-
-func (any *objectLazyAny) ToUint64() uint64 {
- return 0
-}
-
-func (any *objectLazyAny) ToFloat32() float32 {
- return 0
-}
-
-func (any *objectLazyAny) ToFloat64() float64 {
- return 0
-}
-
-func (any *objectLazyAny) ToString() string {
- return *(*string)(unsafe.Pointer(&any.buf))
-}
-
-func (any *objectLazyAny) ToVal(obj interface{}) {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- iter.ReadVal(obj)
-}
-
-func (any *objectLazyAny) Get(path ...interface{}) Any {
- if len(path) == 0 {
- return any
- }
- switch firstPath := path[0].(type) {
- case string:
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- valueBytes := locateObjectField(iter, firstPath)
- if valueBytes == nil {
- return newInvalidAny(path)
- }
- iter.ResetBytes(valueBytes)
- return locatePath(iter, path[1:])
- case int32:
- if '*' == firstPath {
- mappedAll := map[string]Any{}
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- iter.ReadMapCB(func(iter *Iterator, field string) bool {
- mapped := locatePath(iter, path[1:])
- if mapped.ValueType() != InvalidValue {
- mappedAll[field] = mapped
- }
- return true
- })
- return wrapMap(mappedAll)
- }
- return newInvalidAny(path)
- default:
- return newInvalidAny(path)
- }
-}
-
-func (any *objectLazyAny) Keys() []string {
- keys := []string{}
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- iter.ReadMapCB(func(iter *Iterator, field string) bool {
- iter.Skip()
- keys = append(keys, field)
- return true
- })
- return keys
-}
-
-func (any *objectLazyAny) Size() int {
- size := 0
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- iter.ReadObjectCB(func(iter *Iterator, field string) bool {
- iter.Skip()
- size++
- return true
- })
- return size
-}
-
-func (any *objectLazyAny) WriteTo(stream *Stream) {
- stream.Write(any.buf)
-}
-
-func (any *objectLazyAny) GetInterface() interface{} {
- iter := any.cfg.BorrowIterator(any.buf)
- defer any.cfg.ReturnIterator(iter)
- return iter.Read()
-}
-
-type objectAny struct {
- baseAny
- err error
- val reflect.Value
-}
-
-func wrapStruct(val interface{}) *objectAny {
- return &objectAny{baseAny{}, nil, reflect.ValueOf(val)}
-}
-
-func (any *objectAny) ValueType() ValueType {
- return ObjectValue
-}
-
-func (any *objectAny) MustBeValid() Any {
- return any
-}
-
-func (any *objectAny) Parse() *Iterator {
- return nil
-}
-
-func (any *objectAny) LastError() error {
- return any.err
-}
-
-func (any *objectAny) ToBool() bool {
- return any.val.NumField() != 0
-}
-
-func (any *objectAny) ToInt() int {
- return 0
-}
-
-func (any *objectAny) ToInt32() int32 {
- return 0
-}
-
-func (any *objectAny) ToInt64() int64 {
- return 0
-}
-
-func (any *objectAny) ToUint() uint {
- return 0
-}
-
-func (any *objectAny) ToUint32() uint32 {
- return 0
-}
-
-func (any *objectAny) ToUint64() uint64 {
- return 0
-}
-
-func (any *objectAny) ToFloat32() float32 {
- return 0
-}
-
-func (any *objectAny) ToFloat64() float64 {
- return 0
-}
-
-func (any *objectAny) ToString() string {
- str, err := MarshalToString(any.val.Interface())
- any.err = err
- return str
-}
-
-func (any *objectAny) Get(path ...interface{}) Any {
- if len(path) == 0 {
- return any
- }
- switch firstPath := path[0].(type) {
- case string:
- field := any.val.FieldByName(firstPath)
- if !field.IsValid() {
- return newInvalidAny(path)
- }
- return Wrap(field.Interface())
- case int32:
- if '*' == firstPath {
- mappedAll := map[string]Any{}
- for i := 0; i < any.val.NumField(); i++ {
- field := any.val.Field(i)
- if field.CanInterface() {
- mapped := Wrap(field.Interface()).Get(path[1:]...)
- if mapped.ValueType() != InvalidValue {
- mappedAll[any.val.Type().Field(i).Name] = mapped
- }
- }
- }
- return wrapMap(mappedAll)
- }
- return newInvalidAny(path)
- default:
- return newInvalidAny(path)
- }
-}
-
-func (any *objectAny) Keys() []string {
- keys := make([]string, 0, any.val.NumField())
- for i := 0; i < any.val.NumField(); i++ {
- keys = append(keys, any.val.Type().Field(i).Name)
- }
- return keys
-}
-
-func (any *objectAny) Size() int {
- return any.val.NumField()
-}
-
-func (any *objectAny) WriteTo(stream *Stream) {
- stream.WriteVal(any.val)
-}
-
-func (any *objectAny) GetInterface() interface{} {
- return any.val.Interface()
-}
-
-type mapAny struct {
- baseAny
- err error
- val reflect.Value
-}
-
-func wrapMap(val interface{}) *mapAny {
- return &mapAny{baseAny{}, nil, reflect.ValueOf(val)}
-}
-
-func (any *mapAny) ValueType() ValueType {
- return ObjectValue
-}
-
-func (any *mapAny) MustBeValid() Any {
- return any
-}
-
-func (any *mapAny) Parse() *Iterator {
- return nil
-}
-
-func (any *mapAny) LastError() error {
- return any.err
-}
-
-func (any *mapAny) ToBool() bool {
- return true
-}
-
-func (any *mapAny) ToInt() int {
- return 0
-}
-
-func (any *mapAny) ToInt32() int32 {
- return 0
-}
-
-func (any *mapAny) ToInt64() int64 {
- return 0
-}
-
-func (any *mapAny) ToUint() uint {
- return 0
-}
-
-func (any *mapAny) ToUint32() uint32 {
- return 0
-}
-
-func (any *mapAny) ToUint64() uint64 {
- return 0
-}
-
-func (any *mapAny) ToFloat32() float32 {
- return 0
-}
-
-func (any *mapAny) ToFloat64() float64 {
- return 0
-}
-
-func (any *mapAny) ToString() string {
- str, err := MarshalToString(any.val.Interface())
- any.err = err
- return str
-}
-
-func (any *mapAny) Get(path ...interface{}) Any {
- if len(path) == 0 {
- return any
- }
- switch firstPath := path[0].(type) {
- case int32:
- if '*' == firstPath {
- mappedAll := map[string]Any{}
- for _, key := range any.val.MapKeys() {
- keyAsStr := key.String()
- element := Wrap(any.val.MapIndex(key).Interface())
- mapped := element.Get(path[1:]...)
- if mapped.ValueType() != InvalidValue {
- mappedAll[keyAsStr] = mapped
- }
- }
- return wrapMap(mappedAll)
- }
- return newInvalidAny(path)
- default:
- value := any.val.MapIndex(reflect.ValueOf(firstPath))
- if !value.IsValid() {
- return newInvalidAny(path)
- }
- return Wrap(value.Interface())
- }
-}
-
-func (any *mapAny) Keys() []string {
- keys := make([]string, 0, any.val.Len())
- for _, key := range any.val.MapKeys() {
- keys = append(keys, key.String())
- }
- return keys
-}
-
-func (any *mapAny) Size() int {
- return any.val.Len()
-}
-
-func (any *mapAny) WriteTo(stream *Stream) {
- stream.WriteVal(any.val)
-}
-
-func (any *mapAny) GetInterface() interface{} {
- return any.val.Interface()
-}
diff --git a/vendor/github.com/json-iterator/go/any_str.go b/vendor/github.com/json-iterator/go/any_str.go
deleted file mode 100644
index a4b93c7..0000000
--- a/vendor/github.com/json-iterator/go/any_str.go
+++ /dev/null
@@ -1,166 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "strconv"
-)
-
-type stringAny struct {
- baseAny
- val string
-}
-
-func (any *stringAny) Get(path ...interface{}) Any {
- if len(path) == 0 {
- return any
- }
- return &invalidAny{baseAny{}, fmt.Errorf("GetIndex %v from simple value", path)}
-}
-
-func (any *stringAny) Parse() *Iterator {
- return nil
-}
-
-func (any *stringAny) ValueType() ValueType {
- return StringValue
-}
-
-func (any *stringAny) MustBeValid() Any {
- return any
-}
-
-func (any *stringAny) LastError() error {
- return nil
-}
-
-func (any *stringAny) ToBool() bool {
- str := any.ToString()
- if str == "0" {
- return false
- }
- for _, c := range str {
- switch c {
- case ' ', '\n', '\r', '\t':
- default:
- return true
- }
- }
- return false
-}
-
-func (any *stringAny) ToInt() int {
- return int(any.ToInt64())
-
-}
-
-func (any *stringAny) ToInt32() int32 {
- return int32(any.ToInt64())
-}
-
-func (any *stringAny) ToInt64() int64 {
- if any.val == "" {
- return 0
- }
-
- flag := 1
- startPos := 0
- endPos := 0
- if any.val[0] == '+' || any.val[0] == '-' {
- startPos = 1
- }
-
- if any.val[0] == '-' {
- flag = -1
- }
-
- for i := startPos; i < len(any.val); i++ {
- if any.val[i] >= '0' && any.val[i] <= '9' {
- endPos = i + 1
- } else {
- break
- }
- }
- parsed, _ := strconv.ParseInt(any.val[startPos:endPos], 10, 64)
- return int64(flag) * parsed
-}
-
-func (any *stringAny) ToUint() uint {
- return uint(any.ToUint64())
-}
-
-func (any *stringAny) ToUint32() uint32 {
- return uint32(any.ToUint64())
-}
-
-func (any *stringAny) ToUint64() uint64 {
- if any.val == "" {
- return 0
- }
-
- startPos := 0
- endPos := 0
-
- if any.val[0] == '-' {
- return 0
- }
- if any.val[0] == '+' {
- startPos = 1
- }
-
- for i := startPos; i < len(any.val); i++ {
- if any.val[i] >= '0' && any.val[i] <= '9' {
- endPos = i + 1
- } else {
- break
- }
- }
- parsed, _ := strconv.ParseUint(any.val[startPos:endPos], 10, 64)
- return parsed
-}
-
-func (any *stringAny) ToFloat32() float32 {
- return float32(any.ToFloat64())
-}
-
-func (any *stringAny) ToFloat64() float64 {
- if len(any.val) == 0 {
- return 0
- }
-
- // first char invalid
- if any.val[0] != '+' && any.val[0] != '-' && (any.val[0] > '9' || any.val[0] < '0') {
- return 0
- }
-
- // extract valid num expression from string
- // eg 123true => 123, -12.12xxa => -12.12
- endPos := 1
- for i := 1; i < len(any.val); i++ {
- if any.val[i] == '.' || any.val[i] == 'e' || any.val[i] == 'E' || any.val[i] == '+' || any.val[i] == '-' {
- endPos = i + 1
- continue
- }
-
- // end position is the first char which is not digit
- if any.val[i] >= '0' && any.val[i] <= '9' {
- endPos = i + 1
- } else {
- endPos = i
- break
- }
- }
- parsed, _ := strconv.ParseFloat(any.val[:endPos], 64)
- return parsed
-}
-
-func (any *stringAny) ToString() string {
- return any.val
-}
-
-func (any *stringAny) WriteTo(stream *Stream) {
- stream.WriteString(any.val)
-}
-
-func (any *stringAny) GetInterface() interface{} {
- return any.val
-}
diff --git a/vendor/github.com/json-iterator/go/any_uint32.go b/vendor/github.com/json-iterator/go/any_uint32.go
deleted file mode 100644
index 656bbd3..0000000
--- a/vendor/github.com/json-iterator/go/any_uint32.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package jsoniter
-
-import (
- "strconv"
-)
-
-type uint32Any struct {
- baseAny
- val uint32
-}
-
-func (any *uint32Any) LastError() error {
- return nil
-}
-
-func (any *uint32Any) ValueType() ValueType {
- return NumberValue
-}
-
-func (any *uint32Any) MustBeValid() Any {
- return any
-}
-
-func (any *uint32Any) ToBool() bool {
- return any.val != 0
-}
-
-func (any *uint32Any) ToInt() int {
- return int(any.val)
-}
-
-func (any *uint32Any) ToInt32() int32 {
- return int32(any.val)
-}
-
-func (any *uint32Any) ToInt64() int64 {
- return int64(any.val)
-}
-
-func (any *uint32Any) ToUint() uint {
- return uint(any.val)
-}
-
-func (any *uint32Any) ToUint32() uint32 {
- return any.val
-}
-
-func (any *uint32Any) ToUint64() uint64 {
- return uint64(any.val)
-}
-
-func (any *uint32Any) ToFloat32() float32 {
- return float32(any.val)
-}
-
-func (any *uint32Any) ToFloat64() float64 {
- return float64(any.val)
-}
-
-func (any *uint32Any) ToString() string {
- return strconv.FormatInt(int64(any.val), 10)
-}
-
-func (any *uint32Any) WriteTo(stream *Stream) {
- stream.WriteUint32(any.val)
-}
-
-func (any *uint32Any) Parse() *Iterator {
- return nil
-}
-
-func (any *uint32Any) GetInterface() interface{} {
- return any.val
-}
diff --git a/vendor/github.com/json-iterator/go/any_uint64.go b/vendor/github.com/json-iterator/go/any_uint64.go
deleted file mode 100644
index 7df2fce..0000000
--- a/vendor/github.com/json-iterator/go/any_uint64.go
+++ /dev/null
@@ -1,74 +0,0 @@
-package jsoniter
-
-import (
- "strconv"
-)
-
-type uint64Any struct {
- baseAny
- val uint64
-}
-
-func (any *uint64Any) LastError() error {
- return nil
-}
-
-func (any *uint64Any) ValueType() ValueType {
- return NumberValue
-}
-
-func (any *uint64Any) MustBeValid() Any {
- return any
-}
-
-func (any *uint64Any) ToBool() bool {
- return any.val != 0
-}
-
-func (any *uint64Any) ToInt() int {
- return int(any.val)
-}
-
-func (any *uint64Any) ToInt32() int32 {
- return int32(any.val)
-}
-
-func (any *uint64Any) ToInt64() int64 {
- return int64(any.val)
-}
-
-func (any *uint64Any) ToUint() uint {
- return uint(any.val)
-}
-
-func (any *uint64Any) ToUint32() uint32 {
- return uint32(any.val)
-}
-
-func (any *uint64Any) ToUint64() uint64 {
- return any.val
-}
-
-func (any *uint64Any) ToFloat32() float32 {
- return float32(any.val)
-}
-
-func (any *uint64Any) ToFloat64() float64 {
- return float64(any.val)
-}
-
-func (any *uint64Any) ToString() string {
- return strconv.FormatUint(any.val, 10)
-}
-
-func (any *uint64Any) WriteTo(stream *Stream) {
- stream.WriteUint64(any.val)
-}
-
-func (any *uint64Any) Parse() *Iterator {
- return nil
-}
-
-func (any *uint64Any) GetInterface() interface{} {
- return any.val
-}
diff --git a/vendor/github.com/json-iterator/go/build.sh b/vendor/github.com/json-iterator/go/build.sh
deleted file mode 100644
index b45ef68..0000000
--- a/vendor/github.com/json-iterator/go/build.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-set -e
-set -x
-
-if [ ! -d /tmp/build-golang/src/github.com/json-iterator ]; then
- mkdir -p /tmp/build-golang/src/github.com/json-iterator
- ln -s $PWD /tmp/build-golang/src/github.com/json-iterator/go
-fi
-export GOPATH=/tmp/build-golang
-go get -u github.com/golang/dep/cmd/dep
-cd /tmp/build-golang/src/github.com/json-iterator/go
-exec $GOPATH/bin/dep ensure -update
diff --git a/vendor/github.com/json-iterator/go/config.go b/vendor/github.com/json-iterator/go/config.go
deleted file mode 100644
index 8c58fcb..0000000
--- a/vendor/github.com/json-iterator/go/config.go
+++ /dev/null
@@ -1,375 +0,0 @@
-package jsoniter
-
-import (
- "encoding/json"
- "io"
- "reflect"
- "sync"
- "unsafe"
-
- "github.com/modern-go/concurrent"
- "github.com/modern-go/reflect2"
-)
-
-// Config customize how the API should behave.
-// The API is created from Config by Froze.
-type Config struct {
- IndentionStep int
- MarshalFloatWith6Digits bool
- EscapeHTML bool
- SortMapKeys bool
- UseNumber bool
- DisallowUnknownFields bool
- TagKey string
- OnlyTaggedField bool
- ValidateJsonRawMessage bool
- ObjectFieldMustBeSimpleString bool
- CaseSensitive bool
-}
-
-// API the public interface of this package.
-// Primary Marshal and Unmarshal.
-type API interface {
- IteratorPool
- StreamPool
- MarshalToString(v interface{}) (string, error)
- Marshal(v interface{}) ([]byte, error)
- MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)
- UnmarshalFromString(str string, v interface{}) error
- Unmarshal(data []byte, v interface{}) error
- Get(data []byte, path ...interface{}) Any
- NewEncoder(writer io.Writer) *Encoder
- NewDecoder(reader io.Reader) *Decoder
- Valid(data []byte) bool
- RegisterExtension(extension Extension)
- DecoderOf(typ reflect2.Type) ValDecoder
- EncoderOf(typ reflect2.Type) ValEncoder
-}
-
-// ConfigDefault the default API
-var ConfigDefault = Config{
- EscapeHTML: true,
-}.Froze()
-
-// ConfigCompatibleWithStandardLibrary tries to be 100% compatible with standard library behavior
-var ConfigCompatibleWithStandardLibrary = Config{
- EscapeHTML: true,
- SortMapKeys: true,
- ValidateJsonRawMessage: true,
-}.Froze()
-
-// ConfigFastest marshals float with only 6 digits precision
-var ConfigFastest = Config{
- EscapeHTML: false,
- MarshalFloatWith6Digits: true, // will lose precession
- ObjectFieldMustBeSimpleString: true, // do not unescape object field
-}.Froze()
-
-type frozenConfig struct {
- configBeforeFrozen Config
- sortMapKeys bool
- indentionStep int
- objectFieldMustBeSimpleString bool
- onlyTaggedField bool
- disallowUnknownFields bool
- decoderCache *concurrent.Map
- encoderCache *concurrent.Map
- encoderExtension Extension
- decoderExtension Extension
- extraExtensions []Extension
- streamPool *sync.Pool
- iteratorPool *sync.Pool
- caseSensitive bool
-}
-
-func (cfg *frozenConfig) initCache() {
- cfg.decoderCache = concurrent.NewMap()
- cfg.encoderCache = concurrent.NewMap()
-}
-
-func (cfg *frozenConfig) addDecoderToCache(cacheKey uintptr, decoder ValDecoder) {
- cfg.decoderCache.Store(cacheKey, decoder)
-}
-
-func (cfg *frozenConfig) addEncoderToCache(cacheKey uintptr, encoder ValEncoder) {
- cfg.encoderCache.Store(cacheKey, encoder)
-}
-
-func (cfg *frozenConfig) getDecoderFromCache(cacheKey uintptr) ValDecoder {
- decoder, found := cfg.decoderCache.Load(cacheKey)
- if found {
- return decoder.(ValDecoder)
- }
- return nil
-}
-
-func (cfg *frozenConfig) getEncoderFromCache(cacheKey uintptr) ValEncoder {
- encoder, found := cfg.encoderCache.Load(cacheKey)
- if found {
- return encoder.(ValEncoder)
- }
- return nil
-}
-
-var cfgCache = concurrent.NewMap()
-
-func getFrozenConfigFromCache(cfg Config) *frozenConfig {
- obj, found := cfgCache.Load(cfg)
- if found {
- return obj.(*frozenConfig)
- }
- return nil
-}
-
-func addFrozenConfigToCache(cfg Config, frozenConfig *frozenConfig) {
- cfgCache.Store(cfg, frozenConfig)
-}
-
-// Froze forge API from config
-func (cfg Config) Froze() API {
- api := &frozenConfig{
- sortMapKeys: cfg.SortMapKeys,
- indentionStep: cfg.IndentionStep,
- objectFieldMustBeSimpleString: cfg.ObjectFieldMustBeSimpleString,
- onlyTaggedField: cfg.OnlyTaggedField,
- disallowUnknownFields: cfg.DisallowUnknownFields,
- caseSensitive: cfg.CaseSensitive,
- }
- api.streamPool = &sync.Pool{
- New: func() interface{} {
- return NewStream(api, nil, 512)
- },
- }
- api.iteratorPool = &sync.Pool{
- New: func() interface{} {
- return NewIterator(api)
- },
- }
- api.initCache()
- encoderExtension := EncoderExtension{}
- decoderExtension := DecoderExtension{}
- if cfg.MarshalFloatWith6Digits {
- api.marshalFloatWith6Digits(encoderExtension)
- }
- if cfg.EscapeHTML {
- api.escapeHTML(encoderExtension)
- }
- if cfg.UseNumber {
- api.useNumber(decoderExtension)
- }
- if cfg.ValidateJsonRawMessage {
- api.validateJsonRawMessage(encoderExtension)
- }
- api.encoderExtension = encoderExtension
- api.decoderExtension = decoderExtension
- api.configBeforeFrozen = cfg
- return api
-}
-
-func (cfg Config) frozeWithCacheReuse(extraExtensions []Extension) *frozenConfig {
- api := getFrozenConfigFromCache(cfg)
- if api != nil {
- return api
- }
- api = cfg.Froze().(*frozenConfig)
- for _, extension := range extraExtensions {
- api.RegisterExtension(extension)
- }
- addFrozenConfigToCache(cfg, api)
- return api
-}
-
-func (cfg *frozenConfig) validateJsonRawMessage(extension EncoderExtension) {
- encoder := &funcEncoder{func(ptr unsafe.Pointer, stream *Stream) {
- rawMessage := *(*json.RawMessage)(ptr)
- iter := cfg.BorrowIterator([]byte(rawMessage))
- iter.Read()
- if iter.Error != nil {
- stream.WriteRaw("null")
- } else {
- cfg.ReturnIterator(iter)
- stream.WriteRaw(string(rawMessage))
- }
- }, func(ptr unsafe.Pointer) bool {
- return len(*((*json.RawMessage)(ptr))) == 0
- }}
- extension[reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem()] = encoder
- extension[reflect2.TypeOfPtr((*RawMessage)(nil)).Elem()] = encoder
-}
-
-func (cfg *frozenConfig) useNumber(extension DecoderExtension) {
- extension[reflect2.TypeOfPtr((*interface{})(nil)).Elem()] = &funcDecoder{func(ptr unsafe.Pointer, iter *Iterator) {
- exitingValue := *((*interface{})(ptr))
- if exitingValue != nil && reflect.TypeOf(exitingValue).Kind() == reflect.Ptr {
- iter.ReadVal(exitingValue)
- return
- }
- if iter.WhatIsNext() == NumberValue {
- *((*interface{})(ptr)) = json.Number(iter.readNumberAsString())
- } else {
- *((*interface{})(ptr)) = iter.Read()
- }
- }}
-}
-func (cfg *frozenConfig) getTagKey() string {
- tagKey := cfg.configBeforeFrozen.TagKey
- if tagKey == "" {
- return "json"
- }
- return tagKey
-}
-
-func (cfg *frozenConfig) RegisterExtension(extension Extension) {
- cfg.extraExtensions = append(cfg.extraExtensions, extension)
- copied := cfg.configBeforeFrozen
- cfg.configBeforeFrozen = copied
-}
-
-type lossyFloat32Encoder struct {
-}
-
-func (encoder *lossyFloat32Encoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteFloat32Lossy(*((*float32)(ptr)))
-}
-
-func (encoder *lossyFloat32Encoder) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*float32)(ptr)) == 0
-}
-
-type lossyFloat64Encoder struct {
-}
-
-func (encoder *lossyFloat64Encoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteFloat64Lossy(*((*float64)(ptr)))
-}
-
-func (encoder *lossyFloat64Encoder) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*float64)(ptr)) == 0
-}
-
-// EnableLossyFloatMarshalling keeps 10**(-6) precision
-// for float variables for better performance.
-func (cfg *frozenConfig) marshalFloatWith6Digits(extension EncoderExtension) {
- // for better performance
- extension[reflect2.TypeOfPtr((*float32)(nil)).Elem()] = &lossyFloat32Encoder{}
- extension[reflect2.TypeOfPtr((*float64)(nil)).Elem()] = &lossyFloat64Encoder{}
-}
-
-type htmlEscapedStringEncoder struct {
-}
-
-func (encoder *htmlEscapedStringEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- str := *((*string)(ptr))
- stream.WriteStringWithHTMLEscaped(str)
-}
-
-func (encoder *htmlEscapedStringEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*string)(ptr)) == ""
-}
-
-func (cfg *frozenConfig) escapeHTML(encoderExtension EncoderExtension) {
- encoderExtension[reflect2.TypeOfPtr((*string)(nil)).Elem()] = &htmlEscapedStringEncoder{}
-}
-
-func (cfg *frozenConfig) cleanDecoders() {
- typeDecoders = map[string]ValDecoder{}
- fieldDecoders = map[string]ValDecoder{}
- *cfg = *(cfg.configBeforeFrozen.Froze().(*frozenConfig))
-}
-
-func (cfg *frozenConfig) cleanEncoders() {
- typeEncoders = map[string]ValEncoder{}
- fieldEncoders = map[string]ValEncoder{}
- *cfg = *(cfg.configBeforeFrozen.Froze().(*frozenConfig))
-}
-
-func (cfg *frozenConfig) MarshalToString(v interface{}) (string, error) {
- stream := cfg.BorrowStream(nil)
- defer cfg.ReturnStream(stream)
- stream.WriteVal(v)
- if stream.Error != nil {
- return "", stream.Error
- }
- return string(stream.Buffer()), nil
-}
-
-func (cfg *frozenConfig) Marshal(v interface{}) ([]byte, error) {
- stream := cfg.BorrowStream(nil)
- defer cfg.ReturnStream(stream)
- stream.WriteVal(v)
- if stream.Error != nil {
- return nil, stream.Error
- }
- result := stream.Buffer()
- copied := make([]byte, len(result))
- copy(copied, result)
- return copied, nil
-}
-
-func (cfg *frozenConfig) MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
- if prefix != "" {
- panic("prefix is not supported")
- }
- for _, r := range indent {
- if r != ' ' {
- panic("indent can only be space")
- }
- }
- newCfg := cfg.configBeforeFrozen
- newCfg.IndentionStep = len(indent)
- return newCfg.frozeWithCacheReuse(cfg.extraExtensions).Marshal(v)
-}
-
-func (cfg *frozenConfig) UnmarshalFromString(str string, v interface{}) error {
- data := []byte(str)
- iter := cfg.BorrowIterator(data)
- defer cfg.ReturnIterator(iter)
- iter.ReadVal(v)
- c := iter.nextToken()
- if c == 0 {
- if iter.Error == io.EOF {
- return nil
- }
- return iter.Error
- }
- iter.ReportError("Unmarshal", "there are bytes left after unmarshal")
- return iter.Error
-}
-
-func (cfg *frozenConfig) Get(data []byte, path ...interface{}) Any {
- iter := cfg.BorrowIterator(data)
- defer cfg.ReturnIterator(iter)
- return locatePath(iter, path)
-}
-
-func (cfg *frozenConfig) Unmarshal(data []byte, v interface{}) error {
- iter := cfg.BorrowIterator(data)
- defer cfg.ReturnIterator(iter)
- iter.ReadVal(v)
- c := iter.nextToken()
- if c == 0 {
- if iter.Error == io.EOF {
- return nil
- }
- return iter.Error
- }
- iter.ReportError("Unmarshal", "there are bytes left after unmarshal")
- return iter.Error
-}
-
-func (cfg *frozenConfig) NewEncoder(writer io.Writer) *Encoder {
- stream := NewStream(cfg, writer, 512)
- return &Encoder{stream}
-}
-
-func (cfg *frozenConfig) NewDecoder(reader io.Reader) *Decoder {
- iter := Parse(cfg, reader, 512)
- return &Decoder{iter}
-}
-
-func (cfg *frozenConfig) Valid(data []byte) bool {
- iter := cfg.BorrowIterator(data)
- defer cfg.ReturnIterator(iter)
- iter.Skip()
- return iter.Error == nil
-}
diff --git a/vendor/github.com/json-iterator/go/fuzzy_mode_convert_table.md b/vendor/github.com/json-iterator/go/fuzzy_mode_convert_table.md
deleted file mode 100644
index 3095662..0000000
--- a/vendor/github.com/json-iterator/go/fuzzy_mode_convert_table.md
+++ /dev/null
@@ -1,7 +0,0 @@
-| json type \ dest type | bool | int | uint | float |string|
-| --- | --- | --- | --- |--|--|
-| number | positive => true negative => true zero => false| 23.2 => 23 -32.1 => -32| 12.1 => 12 -12.1 => 0|as normal|same as origin|
-| string | empty string => false string "0" => false other strings => true | "123.32" => 123 "-123.4" => -123 "123.23xxxw" => 123 "abcde12" => 0 "-32.1" => -32| 13.2 => 13 -1.1 => 0 |12.1 => 12.1 -12.3 => -12.3 12.4xxa => 12.4 +1.1e2 =>110 |same as origin|
-| bool | true => true false => false| true => 1 false => 0 | true => 1 false => 0 |true => 1 false => 0|true => "true" false => "false"|
-| object | true | 0 | 0 |0|originnal json|
-| array | empty array => false nonempty array => true| [] => 0 [1,2] => 1 | [] => 0 [1,2] => 1 |[] => 0 [1,2] => 1|original json|
\ No newline at end of file
diff --git a/vendor/github.com/json-iterator/go/iter.go b/vendor/github.com/json-iterator/go/iter.go
deleted file mode 100644
index 95ae54f..0000000
--- a/vendor/github.com/json-iterator/go/iter.go
+++ /dev/null
@@ -1,322 +0,0 @@
-package jsoniter
-
-import (
- "encoding/json"
- "fmt"
- "io"
-)
-
-// ValueType the type for JSON element
-type ValueType int
-
-const (
- // InvalidValue invalid JSON element
- InvalidValue ValueType = iota
- // StringValue JSON element "string"
- StringValue
- // NumberValue JSON element 100 or 0.10
- NumberValue
- // NilValue JSON element null
- NilValue
- // BoolValue JSON element true or false
- BoolValue
- // ArrayValue JSON element []
- ArrayValue
- // ObjectValue JSON element {}
- ObjectValue
-)
-
-var hexDigits []byte
-var valueTypes []ValueType
-
-func init() {
- hexDigits = make([]byte, 256)
- for i := 0; i < len(hexDigits); i++ {
- hexDigits[i] = 255
- }
- for i := '0'; i <= '9'; i++ {
- hexDigits[i] = byte(i - '0')
- }
- for i := 'a'; i <= 'f'; i++ {
- hexDigits[i] = byte((i - 'a') + 10)
- }
- for i := 'A'; i <= 'F'; i++ {
- hexDigits[i] = byte((i - 'A') + 10)
- }
- valueTypes = make([]ValueType, 256)
- for i := 0; i < len(valueTypes); i++ {
- valueTypes[i] = InvalidValue
- }
- valueTypes['"'] = StringValue
- valueTypes['-'] = NumberValue
- valueTypes['0'] = NumberValue
- valueTypes['1'] = NumberValue
- valueTypes['2'] = NumberValue
- valueTypes['3'] = NumberValue
- valueTypes['4'] = NumberValue
- valueTypes['5'] = NumberValue
- valueTypes['6'] = NumberValue
- valueTypes['7'] = NumberValue
- valueTypes['8'] = NumberValue
- valueTypes['9'] = NumberValue
- valueTypes['t'] = BoolValue
- valueTypes['f'] = BoolValue
- valueTypes['n'] = NilValue
- valueTypes['['] = ArrayValue
- valueTypes['{'] = ObjectValue
-}
-
-// Iterator is a io.Reader like object, with JSON specific read functions.
-// Error is not returned as return value, but stored as Error member on this iterator instance.
-type Iterator struct {
- cfg *frozenConfig
- reader io.Reader
- buf []byte
- head int
- tail int
- captureStartedAt int
- captured []byte
- Error error
- Attachment interface{} // open for customized decoder
-}
-
-// NewIterator creates an empty Iterator instance
-func NewIterator(cfg API) *Iterator {
- return &Iterator{
- cfg: cfg.(*frozenConfig),
- reader: nil,
- buf: nil,
- head: 0,
- tail: 0,
- }
-}
-
-// Parse creates an Iterator instance from io.Reader
-func Parse(cfg API, reader io.Reader, bufSize int) *Iterator {
- return &Iterator{
- cfg: cfg.(*frozenConfig),
- reader: reader,
- buf: make([]byte, bufSize),
- head: 0,
- tail: 0,
- }
-}
-
-// ParseBytes creates an Iterator instance from byte array
-func ParseBytes(cfg API, input []byte) *Iterator {
- return &Iterator{
- cfg: cfg.(*frozenConfig),
- reader: nil,
- buf: input,
- head: 0,
- tail: len(input),
- }
-}
-
-// ParseString creates an Iterator instance from string
-func ParseString(cfg API, input string) *Iterator {
- return ParseBytes(cfg, []byte(input))
-}
-
-// Pool returns a pool can provide more iterator with same configuration
-func (iter *Iterator) Pool() IteratorPool {
- return iter.cfg
-}
-
-// Reset reuse iterator instance by specifying another reader
-func (iter *Iterator) Reset(reader io.Reader) *Iterator {
- iter.reader = reader
- iter.head = 0
- iter.tail = 0
- return iter
-}
-
-// ResetBytes reuse iterator instance by specifying another byte array as input
-func (iter *Iterator) ResetBytes(input []byte) *Iterator {
- iter.reader = nil
- iter.buf = input
- iter.head = 0
- iter.tail = len(input)
- return iter
-}
-
-// WhatIsNext gets ValueType of relatively next json element
-func (iter *Iterator) WhatIsNext() ValueType {
- valueType := valueTypes[iter.nextToken()]
- iter.unreadByte()
- return valueType
-}
-
-func (iter *Iterator) skipWhitespacesWithoutLoadMore() bool {
- for i := iter.head; i < iter.tail; i++ {
- c := iter.buf[i]
- switch c {
- case ' ', '\n', '\t', '\r':
- continue
- }
- iter.head = i
- return false
- }
- return true
-}
-
-func (iter *Iterator) isObjectEnd() bool {
- c := iter.nextToken()
- if c == ',' {
- return false
- }
- if c == '}' {
- return true
- }
- iter.ReportError("isObjectEnd", "object ended prematurely, unexpected char "+string([]byte{c}))
- return true
-}
-
-func (iter *Iterator) nextToken() byte {
- // a variation of skip whitespaces, returning the next non-whitespace token
- for {
- for i := iter.head; i < iter.tail; i++ {
- c := iter.buf[i]
- switch c {
- case ' ', '\n', '\t', '\r':
- continue
- }
- iter.head = i + 1
- return c
- }
- if !iter.loadMore() {
- return 0
- }
- }
-}
-
-// ReportError record a error in iterator instance with current position.
-func (iter *Iterator) ReportError(operation string, msg string) {
- if iter.Error != nil {
- if iter.Error != io.EOF {
- return
- }
- }
- peekStart := iter.head - 10
- if peekStart < 0 {
- peekStart = 0
- }
- peekEnd := iter.head + 10
- if peekEnd > iter.tail {
- peekEnd = iter.tail
- }
- parsing := string(iter.buf[peekStart:peekEnd])
- contextStart := iter.head - 50
- if contextStart < 0 {
- contextStart = 0
- }
- contextEnd := iter.head + 50
- if contextEnd > iter.tail {
- contextEnd = iter.tail
- }
- context := string(iter.buf[contextStart:contextEnd])
- iter.Error = fmt.Errorf("%s: %s, error found in #%v byte of ...|%s|..., bigger context ...|%s|...",
- operation, msg, iter.head-peekStart, parsing, context)
-}
-
-// CurrentBuffer gets current buffer as string for debugging purpose
-func (iter *Iterator) CurrentBuffer() string {
- peekStart := iter.head - 10
- if peekStart < 0 {
- peekStart = 0
- }
- return fmt.Sprintf("parsing #%v byte, around ...|%s|..., whole buffer ...|%s|...", iter.head,
- string(iter.buf[peekStart:iter.head]), string(iter.buf[0:iter.tail]))
-}
-
-func (iter *Iterator) readByte() (ret byte) {
- if iter.head == iter.tail {
- if iter.loadMore() {
- ret = iter.buf[iter.head]
- iter.head++
- return ret
- }
- return 0
- }
- ret = iter.buf[iter.head]
- iter.head++
- return ret
-}
-
-func (iter *Iterator) loadMore() bool {
- if iter.reader == nil {
- if iter.Error == nil {
- iter.head = iter.tail
- iter.Error = io.EOF
- }
- return false
- }
- if iter.captured != nil {
- iter.captured = append(iter.captured,
- iter.buf[iter.captureStartedAt:iter.tail]...)
- iter.captureStartedAt = 0
- }
- for {
- n, err := iter.reader.Read(iter.buf)
- if n == 0 {
- if err != nil {
- if iter.Error == nil {
- iter.Error = err
- }
- return false
- }
- } else {
- iter.head = 0
- iter.tail = n
- return true
- }
- }
-}
-
-func (iter *Iterator) unreadByte() {
- if iter.Error != nil {
- return
- }
- iter.head--
- return
-}
-
-// Read read the next JSON element as generic interface{}.
-func (iter *Iterator) Read() interface{} {
- valueType := iter.WhatIsNext()
- switch valueType {
- case StringValue:
- return iter.ReadString()
- case NumberValue:
- if iter.cfg.configBeforeFrozen.UseNumber {
- return json.Number(iter.readNumberAsString())
- }
- return iter.ReadFloat64()
- case NilValue:
- iter.skipFourBytes('n', 'u', 'l', 'l')
- return nil
- case BoolValue:
- return iter.ReadBool()
- case ArrayValue:
- arr := []interface{}{}
- iter.ReadArrayCB(func(iter *Iterator) bool {
- var elem interface{}
- iter.ReadVal(&elem)
- arr = append(arr, elem)
- return true
- })
- return arr
- case ObjectValue:
- obj := map[string]interface{}{}
- iter.ReadMapCB(func(Iter *Iterator, field string) bool {
- var elem interface{}
- iter.ReadVal(&elem)
- obj[field] = elem
- return true
- })
- return obj
- default:
- iter.ReportError("Read", fmt.Sprintf("unexpected value type: %v", valueType))
- return nil
- }
-}
diff --git a/vendor/github.com/json-iterator/go/iter_array.go b/vendor/github.com/json-iterator/go/iter_array.go
deleted file mode 100644
index 6188cb4..0000000
--- a/vendor/github.com/json-iterator/go/iter_array.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package jsoniter
-
-// ReadArray read array element, tells if the array has more element to read.
-func (iter *Iterator) ReadArray() (ret bool) {
- c := iter.nextToken()
- switch c {
- case 'n':
- iter.skipThreeBytes('u', 'l', 'l')
- return false // null
- case '[':
- c = iter.nextToken()
- if c != ']' {
- iter.unreadByte()
- return true
- }
- return false
- case ']':
- return false
- case ',':
- return true
- default:
- iter.ReportError("ReadArray", "expect [ or , or ] or n, but found "+string([]byte{c}))
- return
- }
-}
-
-// ReadArrayCB read array with callback
-func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool) {
- c := iter.nextToken()
- if c == '[' {
- c = iter.nextToken()
- if c != ']' {
- iter.unreadByte()
- if !callback(iter) {
- return false
- }
- c = iter.nextToken()
- for c == ',' {
- if !callback(iter) {
- return false
- }
- c = iter.nextToken()
- }
- if c != ']' {
- iter.ReportError("ReadArrayCB", "expect ] in the end, but found "+string([]byte{c}))
- return false
- }
- return true
- }
- return true
- }
- if c == 'n' {
- iter.skipThreeBytes('u', 'l', 'l')
- return true // null
- }
- iter.ReportError("ReadArrayCB", "expect [ or n, but found "+string([]byte{c}))
- return false
-}
diff --git a/vendor/github.com/json-iterator/go/iter_float.go b/vendor/github.com/json-iterator/go/iter_float.go
deleted file mode 100644
index 4f883c0..0000000
--- a/vendor/github.com/json-iterator/go/iter_float.go
+++ /dev/null
@@ -1,347 +0,0 @@
-package jsoniter
-
-import (
- "encoding/json"
- "io"
- "math/big"
- "strconv"
- "strings"
- "unsafe"
-)
-
-var floatDigits []int8
-
-const invalidCharForNumber = int8(-1)
-const endOfNumber = int8(-2)
-const dotInNumber = int8(-3)
-
-func init() {
- floatDigits = make([]int8, 256)
- for i := 0; i < len(floatDigits); i++ {
- floatDigits[i] = invalidCharForNumber
- }
- for i := int8('0'); i <= int8('9'); i++ {
- floatDigits[i] = i - int8('0')
- }
- floatDigits[','] = endOfNumber
- floatDigits[']'] = endOfNumber
- floatDigits['}'] = endOfNumber
- floatDigits[' '] = endOfNumber
- floatDigits['\t'] = endOfNumber
- floatDigits['\n'] = endOfNumber
- floatDigits['.'] = dotInNumber
-}
-
-// ReadBigFloat read big.Float
-func (iter *Iterator) ReadBigFloat() (ret *big.Float) {
- str := iter.readNumberAsString()
- if iter.Error != nil && iter.Error != io.EOF {
- return nil
- }
- prec := 64
- if len(str) > prec {
- prec = len(str)
- }
- val, _, err := big.ParseFloat(str, 10, uint(prec), big.ToZero)
- if err != nil {
- iter.Error = err
- return nil
- }
- return val
-}
-
-// ReadBigInt read big.Int
-func (iter *Iterator) ReadBigInt() (ret *big.Int) {
- str := iter.readNumberAsString()
- if iter.Error != nil && iter.Error != io.EOF {
- return nil
- }
- ret = big.NewInt(0)
- var success bool
- ret, success = ret.SetString(str, 10)
- if !success {
- iter.ReportError("ReadBigInt", "invalid big int")
- return nil
- }
- return ret
-}
-
-//ReadFloat32 read float32
-func (iter *Iterator) ReadFloat32() (ret float32) {
- c := iter.nextToken()
- if c == '-' {
- return -iter.readPositiveFloat32()
- }
- iter.unreadByte()
- return iter.readPositiveFloat32()
-}
-
-func (iter *Iterator) readPositiveFloat32() (ret float32) {
- value := uint64(0)
- c := byte(' ')
- i := iter.head
- // first char
- if i == iter.tail {
- return iter.readFloat32SlowPath()
- }
- c = iter.buf[i]
- i++
- ind := floatDigits[c]
- switch ind {
- case invalidCharForNumber:
- return iter.readFloat32SlowPath()
- case endOfNumber:
- iter.ReportError("readFloat32", "empty number")
- return
- case dotInNumber:
- iter.ReportError("readFloat32", "leading dot is invalid")
- return
- case 0:
- if i == iter.tail {
- return iter.readFloat32SlowPath()
- }
- c = iter.buf[i]
- switch c {
- case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- iter.ReportError("readFloat32", "leading zero is invalid")
- return
- }
- }
- value = uint64(ind)
- // chars before dot
-non_decimal_loop:
- for ; i < iter.tail; i++ {
- c = iter.buf[i]
- ind := floatDigits[c]
- switch ind {
- case invalidCharForNumber:
- return iter.readFloat32SlowPath()
- case endOfNumber:
- iter.head = i
- return float32(value)
- case dotInNumber:
- break non_decimal_loop
- }
- if value > uint64SafeToMultiple10 {
- return iter.readFloat32SlowPath()
- }
- value = (value << 3) + (value << 1) + uint64(ind) // value = value * 10 + ind;
- }
- // chars after dot
- if c == '.' {
- i++
- decimalPlaces := 0
- if i == iter.tail {
- return iter.readFloat32SlowPath()
- }
- for ; i < iter.tail; i++ {
- c = iter.buf[i]
- ind := floatDigits[c]
- switch ind {
- case endOfNumber:
- if decimalPlaces > 0 && decimalPlaces < len(pow10) {
- iter.head = i
- return float32(float64(value) / float64(pow10[decimalPlaces]))
- }
- // too many decimal places
- return iter.readFloat32SlowPath()
- case invalidCharForNumber:
- fallthrough
- case dotInNumber:
- return iter.readFloat32SlowPath()
- }
- decimalPlaces++
- if value > uint64SafeToMultiple10 {
- return iter.readFloat32SlowPath()
- }
- value = (value << 3) + (value << 1) + uint64(ind)
- }
- }
- return iter.readFloat32SlowPath()
-}
-
-func (iter *Iterator) readNumberAsString() (ret string) {
- strBuf := [16]byte{}
- str := strBuf[0:0]
-load_loop:
- for {
- for i := iter.head; i < iter.tail; i++ {
- c := iter.buf[i]
- switch c {
- case '+', '-', '.', 'e', 'E', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- str = append(str, c)
- continue
- default:
- iter.head = i
- break load_loop
- }
- }
- if !iter.loadMore() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- return
- }
- if len(str) == 0 {
- iter.ReportError("readNumberAsString", "invalid number")
- }
- return *(*string)(unsafe.Pointer(&str))
-}
-
-func (iter *Iterator) readFloat32SlowPath() (ret float32) {
- str := iter.readNumberAsString()
- if iter.Error != nil && iter.Error != io.EOF {
- return
- }
- errMsg := validateFloat(str)
- if errMsg != "" {
- iter.ReportError("readFloat32SlowPath", errMsg)
- return
- }
- val, err := strconv.ParseFloat(str, 32)
- if err != nil {
- iter.Error = err
- return
- }
- return float32(val)
-}
-
-// ReadFloat64 read float64
-func (iter *Iterator) ReadFloat64() (ret float64) {
- c := iter.nextToken()
- if c == '-' {
- return -iter.readPositiveFloat64()
- }
- iter.unreadByte()
- return iter.readPositiveFloat64()
-}
-
-func (iter *Iterator) readPositiveFloat64() (ret float64) {
- value := uint64(0)
- c := byte(' ')
- i := iter.head
- // first char
- if i == iter.tail {
- return iter.readFloat64SlowPath()
- }
- c = iter.buf[i]
- i++
- ind := floatDigits[c]
- switch ind {
- case invalidCharForNumber:
- return iter.readFloat64SlowPath()
- case endOfNumber:
- iter.ReportError("readFloat64", "empty number")
- return
- case dotInNumber:
- iter.ReportError("readFloat64", "leading dot is invalid")
- return
- case 0:
- if i == iter.tail {
- return iter.readFloat64SlowPath()
- }
- c = iter.buf[i]
- switch c {
- case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- iter.ReportError("readFloat64", "leading zero is invalid")
- return
- }
- }
- value = uint64(ind)
- // chars before dot
-non_decimal_loop:
- for ; i < iter.tail; i++ {
- c = iter.buf[i]
- ind := floatDigits[c]
- switch ind {
- case invalidCharForNumber:
- return iter.readFloat64SlowPath()
- case endOfNumber:
- iter.head = i
- return float64(value)
- case dotInNumber:
- break non_decimal_loop
- }
- if value > uint64SafeToMultiple10 {
- return iter.readFloat64SlowPath()
- }
- value = (value << 3) + (value << 1) + uint64(ind) // value = value * 10 + ind;
- }
- // chars after dot
- if c == '.' {
- i++
- decimalPlaces := 0
- if i == iter.tail {
- return iter.readFloat64SlowPath()
- }
- for ; i < iter.tail; i++ {
- c = iter.buf[i]
- ind := floatDigits[c]
- switch ind {
- case endOfNumber:
- if decimalPlaces > 0 && decimalPlaces < len(pow10) {
- iter.head = i
- return float64(value) / float64(pow10[decimalPlaces])
- }
- // too many decimal places
- return iter.readFloat64SlowPath()
- case invalidCharForNumber:
- fallthrough
- case dotInNumber:
- return iter.readFloat64SlowPath()
- }
- decimalPlaces++
- if value > uint64SafeToMultiple10 {
- return iter.readFloat64SlowPath()
- }
- value = (value << 3) + (value << 1) + uint64(ind)
- }
- }
- return iter.readFloat64SlowPath()
-}
-
-func (iter *Iterator) readFloat64SlowPath() (ret float64) {
- str := iter.readNumberAsString()
- if iter.Error != nil && iter.Error != io.EOF {
- return
- }
- errMsg := validateFloat(str)
- if errMsg != "" {
- iter.ReportError("readFloat64SlowPath", errMsg)
- return
- }
- val, err := strconv.ParseFloat(str, 64)
- if err != nil {
- iter.Error = err
- return
- }
- return val
-}
-
-func validateFloat(str string) string {
- // strconv.ParseFloat is not validating `1.` or `1.e1`
- if len(str) == 0 {
- return "empty number"
- }
- if str[0] == '-' {
- return "-- is not valid"
- }
- dotPos := strings.IndexByte(str, '.')
- if dotPos != -1 {
- if dotPos == len(str)-1 {
- return "dot can not be last character"
- }
- switch str[dotPos+1] {
- case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- default:
- return "missing digit after dot"
- }
- }
- return ""
-}
-
-// ReadNumber read json.Number
-func (iter *Iterator) ReadNumber() (ret json.Number) {
- return json.Number(iter.readNumberAsString())
-}
diff --git a/vendor/github.com/json-iterator/go/iter_int.go b/vendor/github.com/json-iterator/go/iter_int.go
deleted file mode 100644
index 2142320..0000000
--- a/vendor/github.com/json-iterator/go/iter_int.go
+++ /dev/null
@@ -1,345 +0,0 @@
-package jsoniter
-
-import (
- "math"
- "strconv"
-)
-
-var intDigits []int8
-
-const uint32SafeToMultiply10 = uint32(0xffffffff)/10 - 1
-const uint64SafeToMultiple10 = uint64(0xffffffffffffffff)/10 - 1
-
-func init() {
- intDigits = make([]int8, 256)
- for i := 0; i < len(intDigits); i++ {
- intDigits[i] = invalidCharForNumber
- }
- for i := int8('0'); i <= int8('9'); i++ {
- intDigits[i] = i - int8('0')
- }
-}
-
-// ReadUint read uint
-func (iter *Iterator) ReadUint() uint {
- if strconv.IntSize == 32 {
- return uint(iter.ReadUint32())
- }
- return uint(iter.ReadUint64())
-}
-
-// ReadInt read int
-func (iter *Iterator) ReadInt() int {
- if strconv.IntSize == 32 {
- return int(iter.ReadInt32())
- }
- return int(iter.ReadInt64())
-}
-
-// ReadInt8 read int8
-func (iter *Iterator) ReadInt8() (ret int8) {
- c := iter.nextToken()
- if c == '-' {
- val := iter.readUint32(iter.readByte())
- if val > math.MaxInt8+1 {
- iter.ReportError("ReadInt8", "overflow: "+strconv.FormatInt(int64(val), 10))
- return
- }
- return -int8(val)
- }
- val := iter.readUint32(c)
- if val > math.MaxInt8 {
- iter.ReportError("ReadInt8", "overflow: "+strconv.FormatInt(int64(val), 10))
- return
- }
- return int8(val)
-}
-
-// ReadUint8 read uint8
-func (iter *Iterator) ReadUint8() (ret uint8) {
- val := iter.readUint32(iter.nextToken())
- if val > math.MaxUint8 {
- iter.ReportError("ReadUint8", "overflow: "+strconv.FormatInt(int64(val), 10))
- return
- }
- return uint8(val)
-}
-
-// ReadInt16 read int16
-func (iter *Iterator) ReadInt16() (ret int16) {
- c := iter.nextToken()
- if c == '-' {
- val := iter.readUint32(iter.readByte())
- if val > math.MaxInt16+1 {
- iter.ReportError("ReadInt16", "overflow: "+strconv.FormatInt(int64(val), 10))
- return
- }
- return -int16(val)
- }
- val := iter.readUint32(c)
- if val > math.MaxInt16 {
- iter.ReportError("ReadInt16", "overflow: "+strconv.FormatInt(int64(val), 10))
- return
- }
- return int16(val)
-}
-
-// ReadUint16 read uint16
-func (iter *Iterator) ReadUint16() (ret uint16) {
- val := iter.readUint32(iter.nextToken())
- if val > math.MaxUint16 {
- iter.ReportError("ReadUint16", "overflow: "+strconv.FormatInt(int64(val), 10))
- return
- }
- return uint16(val)
-}
-
-// ReadInt32 read int32
-func (iter *Iterator) ReadInt32() (ret int32) {
- c := iter.nextToken()
- if c == '-' {
- val := iter.readUint32(iter.readByte())
- if val > math.MaxInt32+1 {
- iter.ReportError("ReadInt32", "overflow: "+strconv.FormatInt(int64(val), 10))
- return
- }
- return -int32(val)
- }
- val := iter.readUint32(c)
- if val > math.MaxInt32 {
- iter.ReportError("ReadInt32", "overflow: "+strconv.FormatInt(int64(val), 10))
- return
- }
- return int32(val)
-}
-
-// ReadUint32 read uint32
-func (iter *Iterator) ReadUint32() (ret uint32) {
- return iter.readUint32(iter.nextToken())
-}
-
-func (iter *Iterator) readUint32(c byte) (ret uint32) {
- ind := intDigits[c]
- if ind == 0 {
- iter.assertInteger()
- return 0 // single zero
- }
- if ind == invalidCharForNumber {
- iter.ReportError("readUint32", "unexpected character: "+string([]byte{byte(ind)}))
- return
- }
- value := uint32(ind)
- if iter.tail-iter.head > 10 {
- i := iter.head
- ind2 := intDigits[iter.buf[i]]
- if ind2 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value
- }
- i++
- ind3 := intDigits[iter.buf[i]]
- if ind3 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*10 + uint32(ind2)
- }
- //iter.head = i + 1
- //value = value * 100 + uint32(ind2) * 10 + uint32(ind3)
- i++
- ind4 := intDigits[iter.buf[i]]
- if ind4 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*100 + uint32(ind2)*10 + uint32(ind3)
- }
- i++
- ind5 := intDigits[iter.buf[i]]
- if ind5 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*1000 + uint32(ind2)*100 + uint32(ind3)*10 + uint32(ind4)
- }
- i++
- ind6 := intDigits[iter.buf[i]]
- if ind6 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*10000 + uint32(ind2)*1000 + uint32(ind3)*100 + uint32(ind4)*10 + uint32(ind5)
- }
- i++
- ind7 := intDigits[iter.buf[i]]
- if ind7 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*100000 + uint32(ind2)*10000 + uint32(ind3)*1000 + uint32(ind4)*100 + uint32(ind5)*10 + uint32(ind6)
- }
- i++
- ind8 := intDigits[iter.buf[i]]
- if ind8 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*1000000 + uint32(ind2)*100000 + uint32(ind3)*10000 + uint32(ind4)*1000 + uint32(ind5)*100 + uint32(ind6)*10 + uint32(ind7)
- }
- i++
- ind9 := intDigits[iter.buf[i]]
- value = value*10000000 + uint32(ind2)*1000000 + uint32(ind3)*100000 + uint32(ind4)*10000 + uint32(ind5)*1000 + uint32(ind6)*100 + uint32(ind7)*10 + uint32(ind8)
- iter.head = i
- if ind9 == invalidCharForNumber {
- iter.assertInteger()
- return value
- }
- }
- for {
- for i := iter.head; i < iter.tail; i++ {
- ind = intDigits[iter.buf[i]]
- if ind == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value
- }
- if value > uint32SafeToMultiply10 {
- value2 := (value << 3) + (value << 1) + uint32(ind)
- if value2 < value {
- iter.ReportError("readUint32", "overflow")
- return
- }
- value = value2
- continue
- }
- value = (value << 3) + (value << 1) + uint32(ind)
- }
- if !iter.loadMore() {
- iter.assertInteger()
- return value
- }
- }
-}
-
-// ReadInt64 read int64
-func (iter *Iterator) ReadInt64() (ret int64) {
- c := iter.nextToken()
- if c == '-' {
- val := iter.readUint64(iter.readByte())
- if val > math.MaxInt64+1 {
- iter.ReportError("ReadInt64", "overflow: "+strconv.FormatUint(uint64(val), 10))
- return
- }
- return -int64(val)
- }
- val := iter.readUint64(c)
- if val > math.MaxInt64 {
- iter.ReportError("ReadInt64", "overflow: "+strconv.FormatUint(uint64(val), 10))
- return
- }
- return int64(val)
-}
-
-// ReadUint64 read uint64
-func (iter *Iterator) ReadUint64() uint64 {
- return iter.readUint64(iter.nextToken())
-}
-
-func (iter *Iterator) readUint64(c byte) (ret uint64) {
- ind := intDigits[c]
- if ind == 0 {
- iter.assertInteger()
- return 0 // single zero
- }
- if ind == invalidCharForNumber {
- iter.ReportError("readUint64", "unexpected character: "+string([]byte{byte(ind)}))
- return
- }
- value := uint64(ind)
- if iter.tail-iter.head > 10 {
- i := iter.head
- ind2 := intDigits[iter.buf[i]]
- if ind2 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value
- }
- i++
- ind3 := intDigits[iter.buf[i]]
- if ind3 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*10 + uint64(ind2)
- }
- //iter.head = i + 1
- //value = value * 100 + uint32(ind2) * 10 + uint32(ind3)
- i++
- ind4 := intDigits[iter.buf[i]]
- if ind4 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*100 + uint64(ind2)*10 + uint64(ind3)
- }
- i++
- ind5 := intDigits[iter.buf[i]]
- if ind5 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*1000 + uint64(ind2)*100 + uint64(ind3)*10 + uint64(ind4)
- }
- i++
- ind6 := intDigits[iter.buf[i]]
- if ind6 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*10000 + uint64(ind2)*1000 + uint64(ind3)*100 + uint64(ind4)*10 + uint64(ind5)
- }
- i++
- ind7 := intDigits[iter.buf[i]]
- if ind7 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*100000 + uint64(ind2)*10000 + uint64(ind3)*1000 + uint64(ind4)*100 + uint64(ind5)*10 + uint64(ind6)
- }
- i++
- ind8 := intDigits[iter.buf[i]]
- if ind8 == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value*1000000 + uint64(ind2)*100000 + uint64(ind3)*10000 + uint64(ind4)*1000 + uint64(ind5)*100 + uint64(ind6)*10 + uint64(ind7)
- }
- i++
- ind9 := intDigits[iter.buf[i]]
- value = value*10000000 + uint64(ind2)*1000000 + uint64(ind3)*100000 + uint64(ind4)*10000 + uint64(ind5)*1000 + uint64(ind6)*100 + uint64(ind7)*10 + uint64(ind8)
- iter.head = i
- if ind9 == invalidCharForNumber {
- iter.assertInteger()
- return value
- }
- }
- for {
- for i := iter.head; i < iter.tail; i++ {
- ind = intDigits[iter.buf[i]]
- if ind == invalidCharForNumber {
- iter.head = i
- iter.assertInteger()
- return value
- }
- if value > uint64SafeToMultiple10 {
- value2 := (value << 3) + (value << 1) + uint64(ind)
- if value2 < value {
- iter.ReportError("readUint64", "overflow")
- return
- }
- value = value2
- continue
- }
- value = (value << 3) + (value << 1) + uint64(ind)
- }
- if !iter.loadMore() {
- iter.assertInteger()
- return value
- }
- }
-}
-
-func (iter *Iterator) assertInteger() {
- if iter.head < len(iter.buf) && iter.buf[iter.head] == '.' {
- iter.ReportError("assertInteger", "can not decode float as int")
- }
-}
diff --git a/vendor/github.com/json-iterator/go/iter_object.go b/vendor/github.com/json-iterator/go/iter_object.go
deleted file mode 100644
index 1c57576..0000000
--- a/vendor/github.com/json-iterator/go/iter_object.go
+++ /dev/null
@@ -1,251 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "strings"
-)
-
-// ReadObject read one field from object.
-// If object ended, returns empty string.
-// Otherwise, returns the field name.
-func (iter *Iterator) ReadObject() (ret string) {
- c := iter.nextToken()
- switch c {
- case 'n':
- iter.skipThreeBytes('u', 'l', 'l')
- return "" // null
- case '{':
- c = iter.nextToken()
- if c == '"' {
- iter.unreadByte()
- field := iter.ReadString()
- c = iter.nextToken()
- if c != ':' {
- iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
- }
- return field
- }
- if c == '}' {
- return "" // end of object
- }
- iter.ReportError("ReadObject", `expect " after {, but found `+string([]byte{c}))
- return
- case ',':
- field := iter.ReadString()
- c = iter.nextToken()
- if c != ':' {
- iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
- }
- return field
- case '}':
- return "" // end of object
- default:
- iter.ReportError("ReadObject", fmt.Sprintf(`expect { or , or } or n, but found %s`, string([]byte{c})))
- return
- }
-}
-
-// CaseInsensitive
-func (iter *Iterator) readFieldHash() int64 {
- hash := int64(0x811c9dc5)
- c := iter.nextToken()
- if c != '"' {
- iter.ReportError("readFieldHash", `expect ", but found `+string([]byte{c}))
- return 0
- }
- for {
- for i := iter.head; i < iter.tail; i++ {
- // require ascii string and no escape
- b := iter.buf[i]
- if b == '\\' {
- iter.head = i
- for _, b := range iter.readStringSlowPath() {
- if 'A' <= b && b <= 'Z' && !iter.cfg.caseSensitive {
- b += 'a' - 'A'
- }
- hash ^= int64(b)
- hash *= 0x1000193
- }
- c = iter.nextToken()
- if c != ':' {
- iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c}))
- return 0
- }
- return hash
- }
- if b == '"' {
- iter.head = i + 1
- c = iter.nextToken()
- if c != ':' {
- iter.ReportError("readFieldHash", `expect :, but found `+string([]byte{c}))
- return 0
- }
- return hash
- }
- if 'A' <= b && b <= 'Z' && !iter.cfg.caseSensitive {
- b += 'a' - 'A'
- }
- hash ^= int64(b)
- hash *= 0x1000193
- }
- if !iter.loadMore() {
- iter.ReportError("readFieldHash", `incomplete field name`)
- return 0
- }
- }
-}
-
-func calcHash(str string, caseSensitive bool) int64 {
- if !caseSensitive {
- str = strings.ToLower(str)
- }
- hash := int64(0x811c9dc5)
- for _, b := range []byte(str) {
- hash ^= int64(b)
- hash *= 0x1000193
- }
- return int64(hash)
-}
-
-// ReadObjectCB read object with callback, the key is ascii only and field name not copied
-func (iter *Iterator) ReadObjectCB(callback func(*Iterator, string) bool) bool {
- c := iter.nextToken()
- var field string
- if c == '{' {
- c = iter.nextToken()
- if c == '"' {
- iter.unreadByte()
- field = iter.ReadString()
- c = iter.nextToken()
- if c != ':' {
- iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
- }
- if !callback(iter, field) {
- return false
- }
- c = iter.nextToken()
- for c == ',' {
- field = iter.ReadString()
- c = iter.nextToken()
- if c != ':' {
- iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
- }
- if !callback(iter, field) {
- return false
- }
- c = iter.nextToken()
- }
- if c != '}' {
- iter.ReportError("ReadObjectCB", `object not ended with }`)
- return false
- }
- return true
- }
- if c == '}' {
- return true
- }
- iter.ReportError("ReadObjectCB", `expect " after }, but found `+string([]byte{c}))
- return false
- }
- if c == 'n' {
- iter.skipThreeBytes('u', 'l', 'l')
- return true // null
- }
- iter.ReportError("ReadObjectCB", `expect { or n, but found `+string([]byte{c}))
- return false
-}
-
-// ReadMapCB read map with callback, the key can be any string
-func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool {
- c := iter.nextToken()
- if c == '{' {
- c = iter.nextToken()
- if c == '"' {
- iter.unreadByte()
- field := iter.ReadString()
- if iter.nextToken() != ':' {
- iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c}))
- return false
- }
- if !callback(iter, field) {
- return false
- }
- c = iter.nextToken()
- for c == ',' {
- field = iter.ReadString()
- if iter.nextToken() != ':' {
- iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c}))
- return false
- }
- if !callback(iter, field) {
- return false
- }
- c = iter.nextToken()
- }
- if c != '}' {
- iter.ReportError("ReadMapCB", `object not ended with }`)
- return false
- }
- return true
- }
- if c == '}' {
- return true
- }
- iter.ReportError("ReadMapCB", `expect " after }, but found `+string([]byte{c}))
- return false
- }
- if c == 'n' {
- iter.skipThreeBytes('u', 'l', 'l')
- return true // null
- }
- iter.ReportError("ReadMapCB", `expect { or n, but found `+string([]byte{c}))
- return false
-}
-
-func (iter *Iterator) readObjectStart() bool {
- c := iter.nextToken()
- if c == '{' {
- c = iter.nextToken()
- if c == '}' {
- return false
- }
- iter.unreadByte()
- return true
- } else if c == 'n' {
- iter.skipThreeBytes('u', 'l', 'l')
- return false
- }
- iter.ReportError("readObjectStart", "expect { or n, but found "+string([]byte{c}))
- return false
-}
-
-func (iter *Iterator) readObjectFieldAsBytes() (ret []byte) {
- str := iter.ReadStringAsSlice()
- if iter.skipWhitespacesWithoutLoadMore() {
- if ret == nil {
- ret = make([]byte, len(str))
- copy(ret, str)
- }
- if !iter.loadMore() {
- return
- }
- }
- if iter.buf[iter.head] != ':' {
- iter.ReportError("readObjectFieldAsBytes", "expect : after object field, but found "+string([]byte{iter.buf[iter.head]}))
- return
- }
- iter.head++
- if iter.skipWhitespacesWithoutLoadMore() {
- if ret == nil {
- ret = make([]byte, len(str))
- copy(ret, str)
- }
- if !iter.loadMore() {
- return
- }
- }
- if ret == nil {
- return str
- }
- return ret
-}
diff --git a/vendor/github.com/json-iterator/go/iter_skip.go b/vendor/github.com/json-iterator/go/iter_skip.go
deleted file mode 100644
index f58beb9..0000000
--- a/vendor/github.com/json-iterator/go/iter_skip.go
+++ /dev/null
@@ -1,129 +0,0 @@
-package jsoniter
-
-import "fmt"
-
-// ReadNil reads a json object as nil and
-// returns whether it's a nil or not
-func (iter *Iterator) ReadNil() (ret bool) {
- c := iter.nextToken()
- if c == 'n' {
- iter.skipThreeBytes('u', 'l', 'l') // null
- return true
- }
- iter.unreadByte()
- return false
-}
-
-// ReadBool reads a json object as BoolValue
-func (iter *Iterator) ReadBool() (ret bool) {
- c := iter.nextToken()
- if c == 't' {
- iter.skipThreeBytes('r', 'u', 'e')
- return true
- }
- if c == 'f' {
- iter.skipFourBytes('a', 'l', 's', 'e')
- return false
- }
- iter.ReportError("ReadBool", "expect t or f, but found "+string([]byte{c}))
- return
-}
-
-// SkipAndReturnBytes skip next JSON element, and return its content as []byte.
-// The []byte can be kept, it is a copy of data.
-func (iter *Iterator) SkipAndReturnBytes() []byte {
- iter.startCapture(iter.head)
- iter.Skip()
- return iter.stopCapture()
-}
-
-type captureBuffer struct {
- startedAt int
- captured []byte
-}
-
-func (iter *Iterator) startCapture(captureStartedAt int) {
- if iter.captured != nil {
- panic("already in capture mode")
- }
- iter.captureStartedAt = captureStartedAt
- iter.captured = make([]byte, 0, 32)
-}
-
-func (iter *Iterator) stopCapture() []byte {
- if iter.captured == nil {
- panic("not in capture mode")
- }
- captured := iter.captured
- remaining := iter.buf[iter.captureStartedAt:iter.head]
- iter.captureStartedAt = -1
- iter.captured = nil
- if len(captured) == 0 {
- copied := make([]byte, len(remaining))
- copy(copied, remaining)
- return copied
- }
- captured = append(captured, remaining...)
- return captured
-}
-
-// Skip skips a json object and positions to relatively the next json object
-func (iter *Iterator) Skip() {
- c := iter.nextToken()
- switch c {
- case '"':
- iter.skipString()
- case 'n':
- iter.skipThreeBytes('u', 'l', 'l') // null
- case 't':
- iter.skipThreeBytes('r', 'u', 'e') // true
- case 'f':
- iter.skipFourBytes('a', 'l', 's', 'e') // false
- case '0':
- iter.unreadByte()
- iter.ReadFloat32()
- case '-', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- iter.skipNumber()
- case '[':
- iter.skipArray()
- case '{':
- iter.skipObject()
- default:
- iter.ReportError("Skip", fmt.Sprintf("do not know how to skip: %v", c))
- return
- }
-}
-
-func (iter *Iterator) skipFourBytes(b1, b2, b3, b4 byte) {
- if iter.readByte() != b1 {
- iter.ReportError("skipFourBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3, b4})))
- return
- }
- if iter.readByte() != b2 {
- iter.ReportError("skipFourBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3, b4})))
- return
- }
- if iter.readByte() != b3 {
- iter.ReportError("skipFourBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3, b4})))
- return
- }
- if iter.readByte() != b4 {
- iter.ReportError("skipFourBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3, b4})))
- return
- }
-}
-
-func (iter *Iterator) skipThreeBytes(b1, b2, b3 byte) {
- if iter.readByte() != b1 {
- iter.ReportError("skipThreeBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3})))
- return
- }
- if iter.readByte() != b2 {
- iter.ReportError("skipThreeBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3})))
- return
- }
- if iter.readByte() != b3 {
- iter.ReportError("skipThreeBytes", fmt.Sprintf("expect %s", string([]byte{b1, b2, b3})))
- return
- }
-}
diff --git a/vendor/github.com/json-iterator/go/iter_skip_sloppy.go b/vendor/github.com/json-iterator/go/iter_skip_sloppy.go
deleted file mode 100644
index 8fcdc3b..0000000
--- a/vendor/github.com/json-iterator/go/iter_skip_sloppy.go
+++ /dev/null
@@ -1,144 +0,0 @@
-//+build jsoniter_sloppy
-
-package jsoniter
-
-// sloppy but faster implementation, do not validate the input json
-
-func (iter *Iterator) skipNumber() {
- for {
- for i := iter.head; i < iter.tail; i++ {
- c := iter.buf[i]
- switch c {
- case ' ', '\n', '\r', '\t', ',', '}', ']':
- iter.head = i
- return
- }
- }
- if !iter.loadMore() {
- return
- }
- }
-}
-
-func (iter *Iterator) skipArray() {
- level := 1
- for {
- for i := iter.head; i < iter.tail; i++ {
- switch iter.buf[i] {
- case '"': // If inside string, skip it
- iter.head = i + 1
- iter.skipString()
- i = iter.head - 1 // it will be i++ soon
- case '[': // If open symbol, increase level
- level++
- case ']': // If close symbol, increase level
- level--
-
- // If we have returned to the original level, we're done
- if level == 0 {
- iter.head = i + 1
- return
- }
- }
- }
- if !iter.loadMore() {
- iter.ReportError("skipObject", "incomplete array")
- return
- }
- }
-}
-
-func (iter *Iterator) skipObject() {
- level := 1
- for {
- for i := iter.head; i < iter.tail; i++ {
- switch iter.buf[i] {
- case '"': // If inside string, skip it
- iter.head = i + 1
- iter.skipString()
- i = iter.head - 1 // it will be i++ soon
- case '{': // If open symbol, increase level
- level++
- case '}': // If close symbol, increase level
- level--
-
- // If we have returned to the original level, we're done
- if level == 0 {
- iter.head = i + 1
- return
- }
- }
- }
- if !iter.loadMore() {
- iter.ReportError("skipObject", "incomplete object")
- return
- }
- }
-}
-
-func (iter *Iterator) skipString() {
- for {
- end, escaped := iter.findStringEnd()
- if end == -1 {
- if !iter.loadMore() {
- iter.ReportError("skipString", "incomplete string")
- return
- }
- if escaped {
- iter.head = 1 // skip the first char as last char read is \
- }
- } else {
- iter.head = end
- return
- }
- }
-}
-
-// adapted from: https://github.com/buger/jsonparser/blob/master/parser.go
-// Tries to find the end of string
-// Support if string contains escaped quote symbols.
-func (iter *Iterator) findStringEnd() (int, bool) {
- escaped := false
- for i := iter.head; i < iter.tail; i++ {
- c := iter.buf[i]
- if c == '"' {
- if !escaped {
- return i + 1, false
- }
- j := i - 1
- for {
- if j < iter.head || iter.buf[j] != '\\' {
- // even number of backslashes
- // either end of buffer, or " found
- return i + 1, true
- }
- j--
- if j < iter.head || iter.buf[j] != '\\' {
- // odd number of backslashes
- // it is \" or \\\"
- break
- }
- j--
- }
- } else if c == '\\' {
- escaped = true
- }
- }
- j := iter.tail - 1
- for {
- if j < iter.head || iter.buf[j] != '\\' {
- // even number of backslashes
- // either end of buffer, or " found
- return -1, false // do not end with \
- }
- j--
- if j < iter.head || iter.buf[j] != '\\' {
- // odd number of backslashes
- // it is \" or \\\"
- break
- }
- j--
-
- }
- return -1, true // end with \
-}
diff --git a/vendor/github.com/json-iterator/go/iter_skip_strict.go b/vendor/github.com/json-iterator/go/iter_skip_strict.go
deleted file mode 100644
index f67bc2e..0000000
--- a/vendor/github.com/json-iterator/go/iter_skip_strict.go
+++ /dev/null
@@ -1,89 +0,0 @@
-//+build !jsoniter_sloppy
-
-package jsoniter
-
-import "fmt"
-
-func (iter *Iterator) skipNumber() {
- if !iter.trySkipNumber() {
- iter.unreadByte()
- iter.ReadFloat32()
- }
-}
-
-func (iter *Iterator) trySkipNumber() bool {
- dotFound := false
- for i := iter.head; i < iter.tail; i++ {
- c := iter.buf[i]
- switch c {
- case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- case '.':
- if dotFound {
- iter.ReportError("validateNumber", `more than one dot found in number`)
- return true // already failed
- }
- if i+1 == iter.tail {
- return false
- }
- c = iter.buf[i+1]
- switch c {
- case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
- default:
- iter.ReportError("validateNumber", `missing digit after dot`)
- return true // already failed
- }
- dotFound = true
- default:
- switch c {
- case ',', ']', '}', ' ', '\t', '\n', '\r':
- if iter.head == i {
- return false // if - without following digits
- }
- iter.head = i
- return true // must be valid
- }
- return false // may be invalid
- }
- }
- return false
-}
-
-func (iter *Iterator) skipString() {
- if !iter.trySkipString() {
- iter.unreadByte()
- iter.ReadString()
- }
-}
-
-func (iter *Iterator) trySkipString() bool {
- for i := iter.head; i < iter.tail; i++ {
- c := iter.buf[i]
- if c == '"' {
- iter.head = i + 1
- return true // valid
- } else if c == '\\' {
- return false
- } else if c < ' ' {
- iter.ReportError("trySkipString",
- fmt.Sprintf(`invalid control character found: %d`, c))
- return true // already failed
- }
- }
- return false
-}
-
-func (iter *Iterator) skipObject() {
- iter.unreadByte()
- iter.ReadObjectCB(func(iter *Iterator, field string) bool {
- iter.Skip()
- return true
- })
-}
-
-func (iter *Iterator) skipArray() {
- iter.unreadByte()
- iter.ReadArrayCB(func(iter *Iterator) bool {
- iter.Skip()
- return true
- })
-}
diff --git a/vendor/github.com/json-iterator/go/iter_str.go b/vendor/github.com/json-iterator/go/iter_str.go
deleted file mode 100644
index adc487e..0000000
--- a/vendor/github.com/json-iterator/go/iter_str.go
+++ /dev/null
@@ -1,215 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "unicode/utf16"
-)
-
-// ReadString read string from iterator
-func (iter *Iterator) ReadString() (ret string) {
- c := iter.nextToken()
- if c == '"' {
- for i := iter.head; i < iter.tail; i++ {
- c := iter.buf[i]
- if c == '"' {
- ret = string(iter.buf[iter.head:i])
- iter.head = i + 1
- return ret
- } else if c == '\\' {
- break
- } else if c < ' ' {
- iter.ReportError("ReadString",
- fmt.Sprintf(`invalid control character found: %d`, c))
- return
- }
- }
- return iter.readStringSlowPath()
- } else if c == 'n' {
- iter.skipThreeBytes('u', 'l', 'l')
- return ""
- }
- iter.ReportError("ReadString", `expects " or n, but found `+string([]byte{c}))
- return
-}
-
-func (iter *Iterator) readStringSlowPath() (ret string) {
- var str []byte
- var c byte
- for iter.Error == nil {
- c = iter.readByte()
- if c == '"' {
- return string(str)
- }
- if c == '\\' {
- c = iter.readByte()
- str = iter.readEscapedChar(c, str)
- } else {
- str = append(str, c)
- }
- }
- iter.ReportError("readStringSlowPath", "unexpected end of input")
- return
-}
-
-func (iter *Iterator) readEscapedChar(c byte, str []byte) []byte {
- switch c {
- case 'u':
- r := iter.readU4()
- if utf16.IsSurrogate(r) {
- c = iter.readByte()
- if iter.Error != nil {
- return nil
- }
- if c != '\\' {
- iter.unreadByte()
- str = appendRune(str, r)
- return str
- }
- c = iter.readByte()
- if iter.Error != nil {
- return nil
- }
- if c != 'u' {
- str = appendRune(str, r)
- return iter.readEscapedChar(c, str)
- }
- r2 := iter.readU4()
- if iter.Error != nil {
- return nil
- }
- combined := utf16.DecodeRune(r, r2)
- if combined == '\uFFFD' {
- str = appendRune(str, r)
- str = appendRune(str, r2)
- } else {
- str = appendRune(str, combined)
- }
- } else {
- str = appendRune(str, r)
- }
- case '"':
- str = append(str, '"')
- case '\\':
- str = append(str, '\\')
- case '/':
- str = append(str, '/')
- case 'b':
- str = append(str, '\b')
- case 'f':
- str = append(str, '\f')
- case 'n':
- str = append(str, '\n')
- case 'r':
- str = append(str, '\r')
- case 't':
- str = append(str, '\t')
- default:
- iter.ReportError("readEscapedChar",
- `invalid escape char after \`)
- return nil
- }
- return str
-}
-
-// ReadStringAsSlice read string from iterator without copying into string form.
-// The []byte can not be kept, as it will change after next iterator call.
-func (iter *Iterator) ReadStringAsSlice() (ret []byte) {
- c := iter.nextToken()
- if c == '"' {
- for i := iter.head; i < iter.tail; i++ {
- // require ascii string and no escape
- // for: field name, base64, number
- if iter.buf[i] == '"' {
- // fast path: reuse the underlying buffer
- ret = iter.buf[iter.head:i]
- iter.head = i + 1
- return ret
- }
- }
- readLen := iter.tail - iter.head
- copied := make([]byte, readLen, readLen*2)
- copy(copied, iter.buf[iter.head:iter.tail])
- iter.head = iter.tail
- for iter.Error == nil {
- c := iter.readByte()
- if c == '"' {
- return copied
- }
- copied = append(copied, c)
- }
- return copied
- }
- iter.ReportError("ReadStringAsSlice", `expects " or n, but found `+string([]byte{c}))
- return
-}
-
-func (iter *Iterator) readU4() (ret rune) {
- for i := 0; i < 4; i++ {
- c := iter.readByte()
- if iter.Error != nil {
- return
- }
- if c >= '0' && c <= '9' {
- ret = ret*16 + rune(c-'0')
- } else if c >= 'a' && c <= 'f' {
- ret = ret*16 + rune(c-'a'+10)
- } else if c >= 'A' && c <= 'F' {
- ret = ret*16 + rune(c-'A'+10)
- } else {
- iter.ReportError("readU4", "expects 0~9 or a~f, but found "+string([]byte{c}))
- return
- }
- }
- return ret
-}
-
-const (
- t1 = 0x00 // 0000 0000
- tx = 0x80 // 1000 0000
- t2 = 0xC0 // 1100 0000
- t3 = 0xE0 // 1110 0000
- t4 = 0xF0 // 1111 0000
- t5 = 0xF8 // 1111 1000
-
- maskx = 0x3F // 0011 1111
- mask2 = 0x1F // 0001 1111
- mask3 = 0x0F // 0000 1111
- mask4 = 0x07 // 0000 0111
-
- rune1Max = 1<<7 - 1
- rune2Max = 1<<11 - 1
- rune3Max = 1<<16 - 1
-
- surrogateMin = 0xD800
- surrogateMax = 0xDFFF
-
- maxRune = '\U0010FFFF' // Maximum valid Unicode code point.
- runeError = '\uFFFD' // the "error" Rune or "Unicode replacement character"
-)
-
-func appendRune(p []byte, r rune) []byte {
- // Negative values are erroneous. Making it unsigned addresses the problem.
- switch i := uint32(r); {
- case i <= rune1Max:
- p = append(p, byte(r))
- return p
- case i <= rune2Max:
- p = append(p, t2|byte(r>>6))
- p = append(p, tx|byte(r)&maskx)
- return p
- case i > maxRune, surrogateMin <= i && i <= surrogateMax:
- r = runeError
- fallthrough
- case i <= rune3Max:
- p = append(p, t3|byte(r>>12))
- p = append(p, tx|byte(r>>6)&maskx)
- p = append(p, tx|byte(r)&maskx)
- return p
- default:
- p = append(p, t4|byte(r>>18))
- p = append(p, tx|byte(r>>12)&maskx)
- p = append(p, tx|byte(r>>6)&maskx)
- p = append(p, tx|byte(r)&maskx)
- return p
- }
-}
diff --git a/vendor/github.com/json-iterator/go/jsoniter.go b/vendor/github.com/json-iterator/go/jsoniter.go
deleted file mode 100644
index c2934f9..0000000
--- a/vendor/github.com/json-iterator/go/jsoniter.go
+++ /dev/null
@@ -1,18 +0,0 @@
-// Package jsoniter implements encoding and decoding of JSON as defined in
-// RFC 4627 and provides interfaces with identical syntax of standard lib encoding/json.
-// Converting from encoding/json to jsoniter is no more than replacing the package with jsoniter
-// and variable type declarations (if any).
-// jsoniter interfaces gives 100% compatibility with code using standard lib.
-//
-// "JSON and Go"
-// (https://golang.org/doc/articles/json_and_go.html)
-// gives a description of how Marshal/Unmarshal operate
-// between arbitrary or predefined json objects and bytes,
-// and it applies to jsoniter.Marshal/Unmarshal as well.
-//
-// Besides, jsoniter.Iterator provides a different set of interfaces
-// iterating given bytes/string/reader
-// and yielding parsed elements one by one.
-// This set of interfaces reads input as required and gives
-// better performance.
-package jsoniter
diff --git a/vendor/github.com/json-iterator/go/pool.go b/vendor/github.com/json-iterator/go/pool.go
deleted file mode 100644
index e2389b5..0000000
--- a/vendor/github.com/json-iterator/go/pool.go
+++ /dev/null
@@ -1,42 +0,0 @@
-package jsoniter
-
-import (
- "io"
-)
-
-// IteratorPool a thread safe pool of iterators with same configuration
-type IteratorPool interface {
- BorrowIterator(data []byte) *Iterator
- ReturnIterator(iter *Iterator)
-}
-
-// StreamPool a thread safe pool of streams with same configuration
-type StreamPool interface {
- BorrowStream(writer io.Writer) *Stream
- ReturnStream(stream *Stream)
-}
-
-func (cfg *frozenConfig) BorrowStream(writer io.Writer) *Stream {
- stream := cfg.streamPool.Get().(*Stream)
- stream.Reset(writer)
- return stream
-}
-
-func (cfg *frozenConfig) ReturnStream(stream *Stream) {
- stream.out = nil
- stream.Error = nil
- stream.Attachment = nil
- cfg.streamPool.Put(stream)
-}
-
-func (cfg *frozenConfig) BorrowIterator(data []byte) *Iterator {
- iter := cfg.iteratorPool.Get().(*Iterator)
- iter.ResetBytes(data)
- return iter
-}
-
-func (cfg *frozenConfig) ReturnIterator(iter *Iterator) {
- iter.Error = nil
- iter.Attachment = nil
- cfg.iteratorPool.Put(iter)
-}
diff --git a/vendor/github.com/json-iterator/go/reflect.go b/vendor/github.com/json-iterator/go/reflect.go
deleted file mode 100644
index 4459e20..0000000
--- a/vendor/github.com/json-iterator/go/reflect.go
+++ /dev/null
@@ -1,332 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "reflect"
- "unsafe"
-
- "github.com/modern-go/reflect2"
-)
-
-// ValDecoder is an internal type registered to cache as needed.
-// Don't confuse jsoniter.ValDecoder with json.Decoder.
-// For json.Decoder's adapter, refer to jsoniter.AdapterDecoder(todo link).
-//
-// Reflection on type to create decoders, which is then cached
-// Reflection on value is avoided as we can, as the reflect.Value itself will allocate, with following exceptions
-// 1. create instance of new value, for example *int will need a int to be allocated
-// 2. append to slice, if the existing cap is not enough, allocate will be done using Reflect.New
-// 3. assignment to map, both key and value will be reflect.Value
-// For a simple struct binding, it will be reflect.Value free and allocation free
-type ValDecoder interface {
- Decode(ptr unsafe.Pointer, iter *Iterator)
-}
-
-// ValEncoder is an internal type registered to cache as needed.
-// Don't confuse jsoniter.ValEncoder with json.Encoder.
-// For json.Encoder's adapter, refer to jsoniter.AdapterEncoder(todo godoc link).
-type ValEncoder interface {
- IsEmpty(ptr unsafe.Pointer) bool
- Encode(ptr unsafe.Pointer, stream *Stream)
-}
-
-type checkIsEmpty interface {
- IsEmpty(ptr unsafe.Pointer) bool
-}
-
-type ctx struct {
- *frozenConfig
- prefix string
- encoders map[reflect2.Type]ValEncoder
- decoders map[reflect2.Type]ValDecoder
-}
-
-func (b *ctx) caseSensitive() bool {
- if b.frozenConfig == nil {
- // default is case-insensitive
- return false
- }
- return b.frozenConfig.caseSensitive
-}
-
-func (b *ctx) append(prefix string) *ctx {
- return &ctx{
- frozenConfig: b.frozenConfig,
- prefix: b.prefix + " " + prefix,
- encoders: b.encoders,
- decoders: b.decoders,
- }
-}
-
-// ReadVal copy the underlying JSON into go interface, same as json.Unmarshal
-func (iter *Iterator) ReadVal(obj interface{}) {
- cacheKey := reflect2.RTypeOf(obj)
- decoder := iter.cfg.getDecoderFromCache(cacheKey)
- if decoder == nil {
- typ := reflect2.TypeOf(obj)
- if typ.Kind() != reflect.Ptr {
- iter.ReportError("ReadVal", "can only unmarshal into pointer")
- return
- }
- decoder = iter.cfg.DecoderOf(typ)
- }
- ptr := reflect2.PtrOf(obj)
- if ptr == nil {
- iter.ReportError("ReadVal", "can not read into nil pointer")
- return
- }
- decoder.Decode(ptr, iter)
-}
-
-// WriteVal copy the go interface into underlying JSON, same as json.Marshal
-func (stream *Stream) WriteVal(val interface{}) {
- if nil == val {
- stream.WriteNil()
- return
- }
- cacheKey := reflect2.RTypeOf(val)
- encoder := stream.cfg.getEncoderFromCache(cacheKey)
- if encoder == nil {
- typ := reflect2.TypeOf(val)
- encoder = stream.cfg.EncoderOf(typ)
- }
- encoder.Encode(reflect2.PtrOf(val), stream)
-}
-
-func (cfg *frozenConfig) DecoderOf(typ reflect2.Type) ValDecoder {
- cacheKey := typ.RType()
- decoder := cfg.getDecoderFromCache(cacheKey)
- if decoder != nil {
- return decoder
- }
- ctx := &ctx{
- frozenConfig: cfg,
- prefix: "",
- decoders: map[reflect2.Type]ValDecoder{},
- encoders: map[reflect2.Type]ValEncoder{},
- }
- ptrType := typ.(*reflect2.UnsafePtrType)
- decoder = decoderOfType(ctx, ptrType.Elem())
- cfg.addDecoderToCache(cacheKey, decoder)
- return decoder
-}
-
-func decoderOfType(ctx *ctx, typ reflect2.Type) ValDecoder {
- decoder := getTypeDecoderFromExtension(ctx, typ)
- if decoder != nil {
- return decoder
- }
- decoder = createDecoderOfType(ctx, typ)
- for _, extension := range extensions {
- decoder = extension.DecorateDecoder(typ, decoder)
- }
- decoder = ctx.decoderExtension.DecorateDecoder(typ, decoder)
- for _, extension := range ctx.extraExtensions {
- decoder = extension.DecorateDecoder(typ, decoder)
- }
- return decoder
-}
-
-func createDecoderOfType(ctx *ctx, typ reflect2.Type) ValDecoder {
- decoder := ctx.decoders[typ]
- if decoder != nil {
- return decoder
- }
- placeholder := &placeholderDecoder{}
- ctx.decoders[typ] = placeholder
- decoder = _createDecoderOfType(ctx, typ)
- placeholder.decoder = decoder
- return decoder
-}
-
-func _createDecoderOfType(ctx *ctx, typ reflect2.Type) ValDecoder {
- decoder := createDecoderOfJsonRawMessage(ctx, typ)
- if decoder != nil {
- return decoder
- }
- decoder = createDecoderOfJsonNumber(ctx, typ)
- if decoder != nil {
- return decoder
- }
- decoder = createDecoderOfMarshaler(ctx, typ)
- if decoder != nil {
- return decoder
- }
- decoder = createDecoderOfAny(ctx, typ)
- if decoder != nil {
- return decoder
- }
- decoder = createDecoderOfNative(ctx, typ)
- if decoder != nil {
- return decoder
- }
- switch typ.Kind() {
- case reflect.Interface:
- ifaceType, isIFace := typ.(*reflect2.UnsafeIFaceType)
- if isIFace {
- return &ifaceDecoder{valType: ifaceType}
- }
- return &efaceDecoder{}
- case reflect.Struct:
- return decoderOfStruct(ctx, typ)
- case reflect.Array:
- return decoderOfArray(ctx, typ)
- case reflect.Slice:
- return decoderOfSlice(ctx, typ)
- case reflect.Map:
- return decoderOfMap(ctx, typ)
- case reflect.Ptr:
- return decoderOfOptional(ctx, typ)
- default:
- return &lazyErrorDecoder{err: fmt.Errorf("%s%s is unsupported type", ctx.prefix, typ.String())}
- }
-}
-
-func (cfg *frozenConfig) EncoderOf(typ reflect2.Type) ValEncoder {
- cacheKey := typ.RType()
- encoder := cfg.getEncoderFromCache(cacheKey)
- if encoder != nil {
- return encoder
- }
- ctx := &ctx{
- frozenConfig: cfg,
- prefix: "",
- decoders: map[reflect2.Type]ValDecoder{},
- encoders: map[reflect2.Type]ValEncoder{},
- }
- encoder = encoderOfType(ctx, typ)
- if typ.LikePtr() {
- encoder = &onePtrEncoder{encoder}
- }
- cfg.addEncoderToCache(cacheKey, encoder)
- return encoder
-}
-
-type onePtrEncoder struct {
- encoder ValEncoder
-}
-
-func (encoder *onePtrEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.encoder.IsEmpty(unsafe.Pointer(&ptr))
-}
-
-func (encoder *onePtrEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- encoder.encoder.Encode(unsafe.Pointer(&ptr), stream)
-}
-
-func encoderOfType(ctx *ctx, typ reflect2.Type) ValEncoder {
- encoder := getTypeEncoderFromExtension(ctx, typ)
- if encoder != nil {
- return encoder
- }
- encoder = createEncoderOfType(ctx, typ)
- for _, extension := range extensions {
- encoder = extension.DecorateEncoder(typ, encoder)
- }
- encoder = ctx.encoderExtension.DecorateEncoder(typ, encoder)
- for _, extension := range ctx.extraExtensions {
- encoder = extension.DecorateEncoder(typ, encoder)
- }
- return encoder
-}
-
-func createEncoderOfType(ctx *ctx, typ reflect2.Type) ValEncoder {
- encoder := ctx.encoders[typ]
- if encoder != nil {
- return encoder
- }
- placeholder := &placeholderEncoder{}
- ctx.encoders[typ] = placeholder
- encoder = _createEncoderOfType(ctx, typ)
- placeholder.encoder = encoder
- return encoder
-}
-func _createEncoderOfType(ctx *ctx, typ reflect2.Type) ValEncoder {
- encoder := createEncoderOfJsonRawMessage(ctx, typ)
- if encoder != nil {
- return encoder
- }
- encoder = createEncoderOfJsonNumber(ctx, typ)
- if encoder != nil {
- return encoder
- }
- encoder = createEncoderOfMarshaler(ctx, typ)
- if encoder != nil {
- return encoder
- }
- encoder = createEncoderOfAny(ctx, typ)
- if encoder != nil {
- return encoder
- }
- encoder = createEncoderOfNative(ctx, typ)
- if encoder != nil {
- return encoder
- }
- kind := typ.Kind()
- switch kind {
- case reflect.Interface:
- return &dynamicEncoder{typ}
- case reflect.Struct:
- return encoderOfStruct(ctx, typ)
- case reflect.Array:
- return encoderOfArray(ctx, typ)
- case reflect.Slice:
- return encoderOfSlice(ctx, typ)
- case reflect.Map:
- return encoderOfMap(ctx, typ)
- case reflect.Ptr:
- return encoderOfOptional(ctx, typ)
- default:
- return &lazyErrorEncoder{err: fmt.Errorf("%s%s is unsupported type", ctx.prefix, typ.String())}
- }
-}
-
-type lazyErrorDecoder struct {
- err error
-}
-
-func (decoder *lazyErrorDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if iter.WhatIsNext() != NilValue {
- if iter.Error == nil {
- iter.Error = decoder.err
- }
- } else {
- iter.Skip()
- }
-}
-
-type lazyErrorEncoder struct {
- err error
-}
-
-func (encoder *lazyErrorEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- if ptr == nil {
- stream.WriteNil()
- } else if stream.Error == nil {
- stream.Error = encoder.err
- }
-}
-
-func (encoder *lazyErrorEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return false
-}
-
-type placeholderDecoder struct {
- decoder ValDecoder
-}
-
-func (decoder *placeholderDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- decoder.decoder.Decode(ptr, iter)
-}
-
-type placeholderEncoder struct {
- encoder ValEncoder
-}
-
-func (encoder *placeholderEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- encoder.encoder.Encode(ptr, stream)
-}
-
-func (encoder *placeholderEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.encoder.IsEmpty(ptr)
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_array.go b/vendor/github.com/json-iterator/go/reflect_array.go
deleted file mode 100644
index 13a0b7b..0000000
--- a/vendor/github.com/json-iterator/go/reflect_array.go
+++ /dev/null
@@ -1,104 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "github.com/modern-go/reflect2"
- "io"
- "unsafe"
-)
-
-func decoderOfArray(ctx *ctx, typ reflect2.Type) ValDecoder {
- arrayType := typ.(*reflect2.UnsafeArrayType)
- decoder := decoderOfType(ctx.append("[arrayElem]"), arrayType.Elem())
- return &arrayDecoder{arrayType, decoder}
-}
-
-func encoderOfArray(ctx *ctx, typ reflect2.Type) ValEncoder {
- arrayType := typ.(*reflect2.UnsafeArrayType)
- if arrayType.Len() == 0 {
- return emptyArrayEncoder{}
- }
- encoder := encoderOfType(ctx.append("[arrayElem]"), arrayType.Elem())
- return &arrayEncoder{arrayType, encoder}
-}
-
-type emptyArrayEncoder struct{}
-
-func (encoder emptyArrayEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteEmptyArray()
-}
-
-func (encoder emptyArrayEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return true
-}
-
-type arrayEncoder struct {
- arrayType *reflect2.UnsafeArrayType
- elemEncoder ValEncoder
-}
-
-func (encoder *arrayEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteArrayStart()
- elemPtr := unsafe.Pointer(ptr)
- encoder.elemEncoder.Encode(elemPtr, stream)
- for i := 1; i < encoder.arrayType.Len(); i++ {
- stream.WriteMore()
- elemPtr = encoder.arrayType.UnsafeGetIndex(ptr, i)
- encoder.elemEncoder.Encode(elemPtr, stream)
- }
- stream.WriteArrayEnd()
- if stream.Error != nil && stream.Error != io.EOF {
- stream.Error = fmt.Errorf("%v: %s", encoder.arrayType, stream.Error.Error())
- }
-}
-
-func (encoder *arrayEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return false
-}
-
-type arrayDecoder struct {
- arrayType *reflect2.UnsafeArrayType
- elemDecoder ValDecoder
-}
-
-func (decoder *arrayDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- decoder.doDecode(ptr, iter)
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v: %s", decoder.arrayType, iter.Error.Error())
- }
-}
-
-func (decoder *arrayDecoder) doDecode(ptr unsafe.Pointer, iter *Iterator) {
- c := iter.nextToken()
- arrayType := decoder.arrayType
- if c == 'n' {
- iter.skipThreeBytes('u', 'l', 'l')
- return
- }
- if c != '[' {
- iter.ReportError("decode array", "expect [ or n, but found "+string([]byte{c}))
- return
- }
- c = iter.nextToken()
- if c == ']' {
- return
- }
- iter.unreadByte()
- elemPtr := arrayType.UnsafeGetIndex(ptr, 0)
- decoder.elemDecoder.Decode(elemPtr, iter)
- length := 1
- for c = iter.nextToken(); c == ','; c = iter.nextToken() {
- if length >= arrayType.Len() {
- iter.Skip()
- continue
- }
- idx := length
- length += 1
- elemPtr = arrayType.UnsafeGetIndex(ptr, idx)
- decoder.elemDecoder.Decode(elemPtr, iter)
- }
- if c != ']' {
- iter.ReportError("decode array", "expect ], but found "+string([]byte{c}))
- return
- }
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_dynamic.go b/vendor/github.com/json-iterator/go/reflect_dynamic.go
deleted file mode 100644
index 8b6bc8b..0000000
--- a/vendor/github.com/json-iterator/go/reflect_dynamic.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package jsoniter
-
-import (
- "github.com/modern-go/reflect2"
- "reflect"
- "unsafe"
-)
-
-type dynamicEncoder struct {
- valType reflect2.Type
-}
-
-func (encoder *dynamicEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- obj := encoder.valType.UnsafeIndirect(ptr)
- stream.WriteVal(obj)
-}
-
-func (encoder *dynamicEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.valType.UnsafeIndirect(ptr) == nil
-}
-
-type efaceDecoder struct {
-}
-
-func (decoder *efaceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- pObj := (*interface{})(ptr)
- obj := *pObj
- if obj == nil {
- *pObj = iter.Read()
- return
- }
- typ := reflect2.TypeOf(obj)
- if typ.Kind() != reflect.Ptr {
- *pObj = iter.Read()
- return
- }
- ptrType := typ.(*reflect2.UnsafePtrType)
- ptrElemType := ptrType.Elem()
- if iter.WhatIsNext() == NilValue {
- if ptrElemType.Kind() != reflect.Ptr {
- iter.skipFourBytes('n', 'u', 'l', 'l')
- *pObj = nil
- return
- }
- }
- if reflect2.IsNil(obj) {
- obj := ptrElemType.New()
- iter.ReadVal(obj)
- *pObj = obj
- return
- }
- iter.ReadVal(obj)
-}
-
-type ifaceDecoder struct {
- valType *reflect2.UnsafeIFaceType
-}
-
-func (decoder *ifaceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if iter.ReadNil() {
- decoder.valType.UnsafeSet(ptr, decoder.valType.UnsafeNew())
- return
- }
- obj := decoder.valType.UnsafeIndirect(ptr)
- if reflect2.IsNil(obj) {
- iter.ReportError("decode non empty interface", "can not unmarshal into nil")
- return
- }
- iter.ReadVal(obj)
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_extension.go b/vendor/github.com/json-iterator/go/reflect_extension.go
deleted file mode 100644
index 04f6875..0000000
--- a/vendor/github.com/json-iterator/go/reflect_extension.go
+++ /dev/null
@@ -1,483 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "github.com/modern-go/reflect2"
- "reflect"
- "sort"
- "strings"
- "unicode"
- "unsafe"
-)
-
-var typeDecoders = map[string]ValDecoder{}
-var fieldDecoders = map[string]ValDecoder{}
-var typeEncoders = map[string]ValEncoder{}
-var fieldEncoders = map[string]ValEncoder{}
-var extensions = []Extension{}
-
-// StructDescriptor describe how should we encode/decode the struct
-type StructDescriptor struct {
- Type reflect2.Type
- Fields []*Binding
-}
-
-// GetField get one field from the descriptor by its name.
-// Can not use map here to keep field orders.
-func (structDescriptor *StructDescriptor) GetField(fieldName string) *Binding {
- for _, binding := range structDescriptor.Fields {
- if binding.Field.Name() == fieldName {
- return binding
- }
- }
- return nil
-}
-
-// Binding describe how should we encode/decode the struct field
-type Binding struct {
- levels []int
- Field reflect2.StructField
- FromNames []string
- ToNames []string
- Encoder ValEncoder
- Decoder ValDecoder
-}
-
-// Extension the one for all SPI. Customize encoding/decoding by specifying alternate encoder/decoder.
-// Can also rename fields by UpdateStructDescriptor.
-type Extension interface {
- UpdateStructDescriptor(structDescriptor *StructDescriptor)
- CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
- CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
- CreateDecoder(typ reflect2.Type) ValDecoder
- CreateEncoder(typ reflect2.Type) ValEncoder
- DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder
- DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder
-}
-
-// DummyExtension embed this type get dummy implementation for all methods of Extension
-type DummyExtension struct {
-}
-
-// UpdateStructDescriptor No-op
-func (extension *DummyExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) {
-}
-
-// CreateMapKeyDecoder No-op
-func (extension *DummyExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder {
- return nil
-}
-
-// CreateMapKeyEncoder No-op
-func (extension *DummyExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder {
- return nil
-}
-
-// CreateDecoder No-op
-func (extension *DummyExtension) CreateDecoder(typ reflect2.Type) ValDecoder {
- return nil
-}
-
-// CreateEncoder No-op
-func (extension *DummyExtension) CreateEncoder(typ reflect2.Type) ValEncoder {
- return nil
-}
-
-// DecorateDecoder No-op
-func (extension *DummyExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder {
- return decoder
-}
-
-// DecorateEncoder No-op
-func (extension *DummyExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder {
- return encoder
-}
-
-type EncoderExtension map[reflect2.Type]ValEncoder
-
-// UpdateStructDescriptor No-op
-func (extension EncoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) {
-}
-
-// CreateDecoder No-op
-func (extension EncoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder {
- return nil
-}
-
-// CreateEncoder get encoder from map
-func (extension EncoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder {
- return extension[typ]
-}
-
-// CreateMapKeyDecoder No-op
-func (extension EncoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder {
- return nil
-}
-
-// CreateMapKeyEncoder No-op
-func (extension EncoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder {
- return nil
-}
-
-// DecorateDecoder No-op
-func (extension EncoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder {
- return decoder
-}
-
-// DecorateEncoder No-op
-func (extension EncoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder {
- return encoder
-}
-
-type DecoderExtension map[reflect2.Type]ValDecoder
-
-// UpdateStructDescriptor No-op
-func (extension DecoderExtension) UpdateStructDescriptor(structDescriptor *StructDescriptor) {
-}
-
-// CreateMapKeyDecoder No-op
-func (extension DecoderExtension) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder {
- return nil
-}
-
-// CreateMapKeyEncoder No-op
-func (extension DecoderExtension) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder {
- return nil
-}
-
-// CreateDecoder get decoder from map
-func (extension DecoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder {
- return extension[typ]
-}
-
-// CreateEncoder No-op
-func (extension DecoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder {
- return nil
-}
-
-// DecorateDecoder No-op
-func (extension DecoderExtension) DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder {
- return decoder
-}
-
-// DecorateEncoder No-op
-func (extension DecoderExtension) DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder {
- return encoder
-}
-
-type funcDecoder struct {
- fun DecoderFunc
-}
-
-func (decoder *funcDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- decoder.fun(ptr, iter)
-}
-
-type funcEncoder struct {
- fun EncoderFunc
- isEmptyFunc func(ptr unsafe.Pointer) bool
-}
-
-func (encoder *funcEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- encoder.fun(ptr, stream)
-}
-
-func (encoder *funcEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- if encoder.isEmptyFunc == nil {
- return false
- }
- return encoder.isEmptyFunc(ptr)
-}
-
-// DecoderFunc the function form of TypeDecoder
-type DecoderFunc func(ptr unsafe.Pointer, iter *Iterator)
-
-// EncoderFunc the function form of TypeEncoder
-type EncoderFunc func(ptr unsafe.Pointer, stream *Stream)
-
-// RegisterTypeDecoderFunc register TypeDecoder for a type with function
-func RegisterTypeDecoderFunc(typ string, fun DecoderFunc) {
- typeDecoders[typ] = &funcDecoder{fun}
-}
-
-// RegisterTypeDecoder register TypeDecoder for a typ
-func RegisterTypeDecoder(typ string, decoder ValDecoder) {
- typeDecoders[typ] = decoder
-}
-
-// RegisterFieldDecoderFunc register TypeDecoder for a struct field with function
-func RegisterFieldDecoderFunc(typ string, field string, fun DecoderFunc) {
- RegisterFieldDecoder(typ, field, &funcDecoder{fun})
-}
-
-// RegisterFieldDecoder register TypeDecoder for a struct field
-func RegisterFieldDecoder(typ string, field string, decoder ValDecoder) {
- fieldDecoders[fmt.Sprintf("%s/%s", typ, field)] = decoder
-}
-
-// RegisterTypeEncoderFunc register TypeEncoder for a type with encode/isEmpty function
-func RegisterTypeEncoderFunc(typ string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool) {
- typeEncoders[typ] = &funcEncoder{fun, isEmptyFunc}
-}
-
-// RegisterTypeEncoder register TypeEncoder for a type
-func RegisterTypeEncoder(typ string, encoder ValEncoder) {
- typeEncoders[typ] = encoder
-}
-
-// RegisterFieldEncoderFunc register TypeEncoder for a struct field with encode/isEmpty function
-func RegisterFieldEncoderFunc(typ string, field string, fun EncoderFunc, isEmptyFunc func(unsafe.Pointer) bool) {
- RegisterFieldEncoder(typ, field, &funcEncoder{fun, isEmptyFunc})
-}
-
-// RegisterFieldEncoder register TypeEncoder for a struct field
-func RegisterFieldEncoder(typ string, field string, encoder ValEncoder) {
- fieldEncoders[fmt.Sprintf("%s/%s", typ, field)] = encoder
-}
-
-// RegisterExtension register extension
-func RegisterExtension(extension Extension) {
- extensions = append(extensions, extension)
-}
-
-func getTypeDecoderFromExtension(ctx *ctx, typ reflect2.Type) ValDecoder {
- decoder := _getTypeDecoderFromExtension(ctx, typ)
- if decoder != nil {
- for _, extension := range extensions {
- decoder = extension.DecorateDecoder(typ, decoder)
- }
- decoder = ctx.decoderExtension.DecorateDecoder(typ, decoder)
- for _, extension := range ctx.extraExtensions {
- decoder = extension.DecorateDecoder(typ, decoder)
- }
- }
- return decoder
-}
-func _getTypeDecoderFromExtension(ctx *ctx, typ reflect2.Type) ValDecoder {
- for _, extension := range extensions {
- decoder := extension.CreateDecoder(typ)
- if decoder != nil {
- return decoder
- }
- }
- decoder := ctx.decoderExtension.CreateDecoder(typ)
- if decoder != nil {
- return decoder
- }
- for _, extension := range ctx.extraExtensions {
- decoder := extension.CreateDecoder(typ)
- if decoder != nil {
- return decoder
- }
- }
- typeName := typ.String()
- decoder = typeDecoders[typeName]
- if decoder != nil {
- return decoder
- }
- if typ.Kind() == reflect.Ptr {
- ptrType := typ.(*reflect2.UnsafePtrType)
- decoder := typeDecoders[ptrType.Elem().String()]
- if decoder != nil {
- return &OptionalDecoder{ptrType.Elem(), decoder}
- }
- }
- return nil
-}
-
-func getTypeEncoderFromExtension(ctx *ctx, typ reflect2.Type) ValEncoder {
- encoder := _getTypeEncoderFromExtension(ctx, typ)
- if encoder != nil {
- for _, extension := range extensions {
- encoder = extension.DecorateEncoder(typ, encoder)
- }
- encoder = ctx.encoderExtension.DecorateEncoder(typ, encoder)
- for _, extension := range ctx.extraExtensions {
- encoder = extension.DecorateEncoder(typ, encoder)
- }
- }
- return encoder
-}
-
-func _getTypeEncoderFromExtension(ctx *ctx, typ reflect2.Type) ValEncoder {
- for _, extension := range extensions {
- encoder := extension.CreateEncoder(typ)
- if encoder != nil {
- return encoder
- }
- }
- encoder := ctx.encoderExtension.CreateEncoder(typ)
- if encoder != nil {
- return encoder
- }
- for _, extension := range ctx.extraExtensions {
- encoder := extension.CreateEncoder(typ)
- if encoder != nil {
- return encoder
- }
- }
- typeName := typ.String()
- encoder = typeEncoders[typeName]
- if encoder != nil {
- return encoder
- }
- if typ.Kind() == reflect.Ptr {
- typePtr := typ.(*reflect2.UnsafePtrType)
- encoder := typeEncoders[typePtr.Elem().String()]
- if encoder != nil {
- return &OptionalEncoder{encoder}
- }
- }
- return nil
-}
-
-func describeStruct(ctx *ctx, typ reflect2.Type) *StructDescriptor {
- structType := typ.(*reflect2.UnsafeStructType)
- embeddedBindings := []*Binding{}
- bindings := []*Binding{}
- for i := 0; i < structType.NumField(); i++ {
- field := structType.Field(i)
- tag, hastag := field.Tag().Lookup(ctx.getTagKey())
- if ctx.onlyTaggedField && !hastag {
- continue
- }
- tagParts := strings.Split(tag, ",")
- if tag == "-" {
- continue
- }
- if field.Anonymous() && (tag == "" || tagParts[0] == "") {
- if field.Type().Kind() == reflect.Struct {
- structDescriptor := describeStruct(ctx, field.Type())
- for _, binding := range structDescriptor.Fields {
- binding.levels = append([]int{i}, binding.levels...)
- omitempty := binding.Encoder.(*structFieldEncoder).omitempty
- binding.Encoder = &structFieldEncoder{field, binding.Encoder, omitempty}
- binding.Decoder = &structFieldDecoder{field, binding.Decoder}
- embeddedBindings = append(embeddedBindings, binding)
- }
- continue
- } else if field.Type().Kind() == reflect.Ptr {
- ptrType := field.Type().(*reflect2.UnsafePtrType)
- if ptrType.Elem().Kind() == reflect.Struct {
- structDescriptor := describeStruct(ctx, ptrType.Elem())
- for _, binding := range structDescriptor.Fields {
- binding.levels = append([]int{i}, binding.levels...)
- omitempty := binding.Encoder.(*structFieldEncoder).omitempty
- binding.Encoder = &dereferenceEncoder{binding.Encoder}
- binding.Encoder = &structFieldEncoder{field, binding.Encoder, omitempty}
- binding.Decoder = &dereferenceDecoder{ptrType.Elem(), binding.Decoder}
- binding.Decoder = &structFieldDecoder{field, binding.Decoder}
- embeddedBindings = append(embeddedBindings, binding)
- }
- continue
- }
- }
- }
- fieldNames := calcFieldNames(field.Name(), tagParts[0], tag)
- fieldCacheKey := fmt.Sprintf("%s/%s", typ.String(), field.Name())
- decoder := fieldDecoders[fieldCacheKey]
- if decoder == nil {
- decoder = decoderOfType(ctx.append(field.Name()), field.Type())
- }
- encoder := fieldEncoders[fieldCacheKey]
- if encoder == nil {
- encoder = encoderOfType(ctx.append(field.Name()), field.Type())
- }
- binding := &Binding{
- Field: field,
- FromNames: fieldNames,
- ToNames: fieldNames,
- Decoder: decoder,
- Encoder: encoder,
- }
- binding.levels = []int{i}
- bindings = append(bindings, binding)
- }
- return createStructDescriptor(ctx, typ, bindings, embeddedBindings)
-}
-func createStructDescriptor(ctx *ctx, typ reflect2.Type, bindings []*Binding, embeddedBindings []*Binding) *StructDescriptor {
- structDescriptor := &StructDescriptor{
- Type: typ,
- Fields: bindings,
- }
- for _, extension := range extensions {
- extension.UpdateStructDescriptor(structDescriptor)
- }
- ctx.encoderExtension.UpdateStructDescriptor(structDescriptor)
- ctx.decoderExtension.UpdateStructDescriptor(structDescriptor)
- for _, extension := range ctx.extraExtensions {
- extension.UpdateStructDescriptor(structDescriptor)
- }
- processTags(structDescriptor, ctx.frozenConfig)
- // merge normal & embedded bindings & sort with original order
- allBindings := sortableBindings(append(embeddedBindings, structDescriptor.Fields...))
- sort.Sort(allBindings)
- structDescriptor.Fields = allBindings
- return structDescriptor
-}
-
-type sortableBindings []*Binding
-
-func (bindings sortableBindings) Len() int {
- return len(bindings)
-}
-
-func (bindings sortableBindings) Less(i, j int) bool {
- left := bindings[i].levels
- right := bindings[j].levels
- k := 0
- for {
- if left[k] < right[k] {
- return true
- } else if left[k] > right[k] {
- return false
- }
- k++
- }
-}
-
-func (bindings sortableBindings) Swap(i, j int) {
- bindings[i], bindings[j] = bindings[j], bindings[i]
-}
-
-func processTags(structDescriptor *StructDescriptor, cfg *frozenConfig) {
- for _, binding := range structDescriptor.Fields {
- shouldOmitEmpty := false
- tagParts := strings.Split(binding.Field.Tag().Get(cfg.getTagKey()), ",")
- for _, tagPart := range tagParts[1:] {
- if tagPart == "omitempty" {
- shouldOmitEmpty = true
- } else if tagPart == "string" {
- if binding.Field.Type().Kind() == reflect.String {
- binding.Decoder = &stringModeStringDecoder{binding.Decoder, cfg}
- binding.Encoder = &stringModeStringEncoder{binding.Encoder, cfg}
- } else {
- binding.Decoder = &stringModeNumberDecoder{binding.Decoder}
- binding.Encoder = &stringModeNumberEncoder{binding.Encoder}
- }
- }
- }
- binding.Decoder = &structFieldDecoder{binding.Field, binding.Decoder}
- binding.Encoder = &structFieldEncoder{binding.Field, binding.Encoder, shouldOmitEmpty}
- }
-}
-
-func calcFieldNames(originalFieldName string, tagProvidedFieldName string, wholeTag string) []string {
- // ignore?
- if wholeTag == "-" {
- return []string{}
- }
- // rename?
- var fieldNames []string
- if tagProvidedFieldName == "" {
- fieldNames = []string{originalFieldName}
- } else {
- fieldNames = []string{tagProvidedFieldName}
- }
- // private?
- isNotExported := unicode.IsLower(rune(originalFieldName[0]))
- if isNotExported {
- fieldNames = []string{}
- }
- return fieldNames
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_json_number.go b/vendor/github.com/json-iterator/go/reflect_json_number.go
deleted file mode 100644
index 98d45c1..0000000
--- a/vendor/github.com/json-iterator/go/reflect_json_number.go
+++ /dev/null
@@ -1,112 +0,0 @@
-package jsoniter
-
-import (
- "encoding/json"
- "github.com/modern-go/reflect2"
- "strconv"
- "unsafe"
-)
-
-type Number string
-
-// String returns the literal text of the number.
-func (n Number) String() string { return string(n) }
-
-// Float64 returns the number as a float64.
-func (n Number) Float64() (float64, error) {
- return strconv.ParseFloat(string(n), 64)
-}
-
-// Int64 returns the number as an int64.
-func (n Number) Int64() (int64, error) {
- return strconv.ParseInt(string(n), 10, 64)
-}
-
-func CastJsonNumber(val interface{}) (string, bool) {
- switch typedVal := val.(type) {
- case json.Number:
- return string(typedVal), true
- case Number:
- return string(typedVal), true
- }
- return "", false
-}
-
-var jsonNumberType = reflect2.TypeOfPtr((*json.Number)(nil)).Elem()
-var jsoniterNumberType = reflect2.TypeOfPtr((*Number)(nil)).Elem()
-
-func createDecoderOfJsonNumber(ctx *ctx, typ reflect2.Type) ValDecoder {
- if typ.AssignableTo(jsonNumberType) {
- return &jsonNumberCodec{}
- }
- if typ.AssignableTo(jsoniterNumberType) {
- return &jsoniterNumberCodec{}
- }
- return nil
-}
-
-func createEncoderOfJsonNumber(ctx *ctx, typ reflect2.Type) ValEncoder {
- if typ.AssignableTo(jsonNumberType) {
- return &jsonNumberCodec{}
- }
- if typ.AssignableTo(jsoniterNumberType) {
- return &jsoniterNumberCodec{}
- }
- return nil
-}
-
-type jsonNumberCodec struct {
-}
-
-func (codec *jsonNumberCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- switch iter.WhatIsNext() {
- case StringValue:
- *((*json.Number)(ptr)) = json.Number(iter.ReadString())
- case NilValue:
- iter.skipFourBytes('n', 'u', 'l', 'l')
- *((*json.Number)(ptr)) = ""
- default:
- *((*json.Number)(ptr)) = json.Number([]byte(iter.readNumberAsString()))
- }
-}
-
-func (codec *jsonNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
- number := *((*json.Number)(ptr))
- if len(number) == 0 {
- stream.writeByte('0')
- } else {
- stream.WriteRaw(string(number))
- }
-}
-
-func (codec *jsonNumberCodec) IsEmpty(ptr unsafe.Pointer) bool {
- return len(*((*json.Number)(ptr))) == 0
-}
-
-type jsoniterNumberCodec struct {
-}
-
-func (codec *jsoniterNumberCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- switch iter.WhatIsNext() {
- case StringValue:
- *((*Number)(ptr)) = Number(iter.ReadString())
- case NilValue:
- iter.skipFourBytes('n', 'u', 'l', 'l')
- *((*Number)(ptr)) = ""
- default:
- *((*Number)(ptr)) = Number([]byte(iter.readNumberAsString()))
- }
-}
-
-func (codec *jsoniterNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
- number := *((*Number)(ptr))
- if len(number) == 0 {
- stream.writeByte('0')
- } else {
- stream.WriteRaw(string(number))
- }
-}
-
-func (codec *jsoniterNumberCodec) IsEmpty(ptr unsafe.Pointer) bool {
- return len(*((*Number)(ptr))) == 0
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_json_raw_message.go b/vendor/github.com/json-iterator/go/reflect_json_raw_message.go
deleted file mode 100644
index f261993..0000000
--- a/vendor/github.com/json-iterator/go/reflect_json_raw_message.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package jsoniter
-
-import (
- "encoding/json"
- "github.com/modern-go/reflect2"
- "unsafe"
-)
-
-var jsonRawMessageType = reflect2.TypeOfPtr((*json.RawMessage)(nil)).Elem()
-var jsoniterRawMessageType = reflect2.TypeOfPtr((*RawMessage)(nil)).Elem()
-
-func createEncoderOfJsonRawMessage(ctx *ctx, typ reflect2.Type) ValEncoder {
- if typ == jsonRawMessageType {
- return &jsonRawMessageCodec{}
- }
- if typ == jsoniterRawMessageType {
- return &jsoniterRawMessageCodec{}
- }
- return nil
-}
-
-func createDecoderOfJsonRawMessage(ctx *ctx, typ reflect2.Type) ValDecoder {
- if typ == jsonRawMessageType {
- return &jsonRawMessageCodec{}
- }
- if typ == jsoniterRawMessageType {
- return &jsoniterRawMessageCodec{}
- }
- return nil
-}
-
-type jsonRawMessageCodec struct {
-}
-
-func (codec *jsonRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- *((*json.RawMessage)(ptr)) = json.RawMessage(iter.SkipAndReturnBytes())
-}
-
-func (codec *jsonRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteRaw(string(*((*json.RawMessage)(ptr))))
-}
-
-func (codec *jsonRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool {
- return len(*((*json.RawMessage)(ptr))) == 0
-}
-
-type jsoniterRawMessageCodec struct {
-}
-
-func (codec *jsoniterRawMessageCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- *((*RawMessage)(ptr)) = RawMessage(iter.SkipAndReturnBytes())
-}
-
-func (codec *jsoniterRawMessageCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteRaw(string(*((*RawMessage)(ptr))))
-}
-
-func (codec *jsoniterRawMessageCodec) IsEmpty(ptr unsafe.Pointer) bool {
- return len(*((*RawMessage)(ptr))) == 0
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_map.go b/vendor/github.com/json-iterator/go/reflect_map.go
deleted file mode 100644
index 7f66a88..0000000
--- a/vendor/github.com/json-iterator/go/reflect_map.go
+++ /dev/null
@@ -1,326 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "github.com/modern-go/reflect2"
- "io"
- "reflect"
- "sort"
- "unsafe"
-)
-
-func decoderOfMap(ctx *ctx, typ reflect2.Type) ValDecoder {
- mapType := typ.(*reflect2.UnsafeMapType)
- keyDecoder := decoderOfMapKey(ctx.append("[mapKey]"), mapType.Key())
- elemDecoder := decoderOfType(ctx.append("[mapElem]"), mapType.Elem())
- return &mapDecoder{
- mapType: mapType,
- keyType: mapType.Key(),
- elemType: mapType.Elem(),
- keyDecoder: keyDecoder,
- elemDecoder: elemDecoder,
- }
-}
-
-func encoderOfMap(ctx *ctx, typ reflect2.Type) ValEncoder {
- mapType := typ.(*reflect2.UnsafeMapType)
- if ctx.sortMapKeys {
- return &sortKeysMapEncoder{
- mapType: mapType,
- keyEncoder: encoderOfMapKey(ctx.append("[mapKey]"), mapType.Key()),
- elemEncoder: encoderOfType(ctx.append("[mapElem]"), mapType.Elem()),
- }
- }
- return &mapEncoder{
- mapType: mapType,
- keyEncoder: encoderOfMapKey(ctx.append("[mapKey]"), mapType.Key()),
- elemEncoder: encoderOfType(ctx.append("[mapElem]"), mapType.Elem()),
- }
-}
-
-func decoderOfMapKey(ctx *ctx, typ reflect2.Type) ValDecoder {
- decoder := ctx.decoderExtension.CreateMapKeyDecoder(typ)
- if decoder != nil {
- return decoder
- }
- for _, extension := range ctx.extraExtensions {
- decoder := extension.CreateMapKeyDecoder(typ)
- if decoder != nil {
- return decoder
- }
- }
- switch typ.Kind() {
- case reflect.String:
- return decoderOfType(ctx, reflect2.DefaultTypeOfKind(reflect.String))
- case reflect.Bool,
- reflect.Uint8, reflect.Int8,
- reflect.Uint16, reflect.Int16,
- reflect.Uint32, reflect.Int32,
- reflect.Uint64, reflect.Int64,
- reflect.Uint, reflect.Int,
- reflect.Float32, reflect.Float64,
- reflect.Uintptr:
- typ = reflect2.DefaultTypeOfKind(typ.Kind())
- return &numericMapKeyDecoder{decoderOfType(ctx, typ)}
- default:
- ptrType := reflect2.PtrTo(typ)
- if ptrType.Implements(textMarshalerType) {
- return &referenceDecoder{
- &textUnmarshalerDecoder{
- valType: ptrType,
- },
- }
- }
- if typ.Implements(textMarshalerType) {
- return &textUnmarshalerDecoder{
- valType: typ,
- }
- }
- return &lazyErrorDecoder{err: fmt.Errorf("unsupported map key type: %v", typ)}
- }
-}
-
-func encoderOfMapKey(ctx *ctx, typ reflect2.Type) ValEncoder {
- encoder := ctx.encoderExtension.CreateMapKeyEncoder(typ)
- if encoder != nil {
- return encoder
- }
- for _, extension := range ctx.extraExtensions {
- encoder := extension.CreateMapKeyEncoder(typ)
- if encoder != nil {
- return encoder
- }
- }
- switch typ.Kind() {
- case reflect.String:
- return encoderOfType(ctx, reflect2.DefaultTypeOfKind(reflect.String))
- case reflect.Bool,
- reflect.Uint8, reflect.Int8,
- reflect.Uint16, reflect.Int16,
- reflect.Uint32, reflect.Int32,
- reflect.Uint64, reflect.Int64,
- reflect.Uint, reflect.Int,
- reflect.Float32, reflect.Float64,
- reflect.Uintptr:
- typ = reflect2.DefaultTypeOfKind(typ.Kind())
- return &numericMapKeyEncoder{encoderOfType(ctx, typ)}
- default:
- if typ == textMarshalerType {
- return &directTextMarshalerEncoder{
- stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
- }
- }
- if typ.Implements(textMarshalerType) {
- return &textMarshalerEncoder{
- valType: typ,
- stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
- }
- }
- if typ.Kind() == reflect.Interface {
- return &dynamicMapKeyEncoder{ctx, typ}
- }
- return &lazyErrorEncoder{err: fmt.Errorf("unsupported map key type: %v", typ)}
- }
-}
-
-type mapDecoder struct {
- mapType *reflect2.UnsafeMapType
- keyType reflect2.Type
- elemType reflect2.Type
- keyDecoder ValDecoder
- elemDecoder ValDecoder
-}
-
-func (decoder *mapDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- mapType := decoder.mapType
- c := iter.nextToken()
- if c == 'n' {
- iter.skipThreeBytes('u', 'l', 'l')
- *(*unsafe.Pointer)(ptr) = nil
- mapType.UnsafeSet(ptr, mapType.UnsafeNew())
- return
- }
- if mapType.UnsafeIsNil(ptr) {
- mapType.UnsafeSet(ptr, mapType.UnsafeMakeMap(0))
- }
- if c != '{' {
- iter.ReportError("ReadMapCB", `expect { or n, but found `+string([]byte{c}))
- return
- }
- c = iter.nextToken()
- if c == '}' {
- return
- }
- if c != '"' {
- iter.ReportError("ReadMapCB", `expect " after }, but found `+string([]byte{c}))
- return
- }
- iter.unreadByte()
- key := decoder.keyType.UnsafeNew()
- decoder.keyDecoder.Decode(key, iter)
- c = iter.nextToken()
- if c != ':' {
- iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c}))
- return
- }
- elem := decoder.elemType.UnsafeNew()
- decoder.elemDecoder.Decode(elem, iter)
- decoder.mapType.UnsafeSetIndex(ptr, key, elem)
- for c = iter.nextToken(); c == ','; c = iter.nextToken() {
- key := decoder.keyType.UnsafeNew()
- decoder.keyDecoder.Decode(key, iter)
- c = iter.nextToken()
- if c != ':' {
- iter.ReportError("ReadMapCB", "expect : after object field, but found "+string([]byte{c}))
- return
- }
- elem := decoder.elemType.UnsafeNew()
- decoder.elemDecoder.Decode(elem, iter)
- decoder.mapType.UnsafeSetIndex(ptr, key, elem)
- }
- if c != '}' {
- iter.ReportError("ReadMapCB", `expect }, but found `+string([]byte{c}))
- }
-}
-
-type numericMapKeyDecoder struct {
- decoder ValDecoder
-}
-
-func (decoder *numericMapKeyDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- c := iter.nextToken()
- if c != '"' {
- iter.ReportError("ReadMapCB", `expect ", but found `+string([]byte{c}))
- return
- }
- decoder.decoder.Decode(ptr, iter)
- c = iter.nextToken()
- if c != '"' {
- iter.ReportError("ReadMapCB", `expect ", but found `+string([]byte{c}))
- return
- }
-}
-
-type numericMapKeyEncoder struct {
- encoder ValEncoder
-}
-
-func (encoder *numericMapKeyEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.writeByte('"')
- encoder.encoder.Encode(ptr, stream)
- stream.writeByte('"')
-}
-
-func (encoder *numericMapKeyEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return false
-}
-
-type dynamicMapKeyEncoder struct {
- ctx *ctx
- valType reflect2.Type
-}
-
-func (encoder *dynamicMapKeyEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- obj := encoder.valType.UnsafeIndirect(ptr)
- encoderOfMapKey(encoder.ctx, reflect2.TypeOf(obj)).Encode(reflect2.PtrOf(obj), stream)
-}
-
-func (encoder *dynamicMapKeyEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- obj := encoder.valType.UnsafeIndirect(ptr)
- return encoderOfMapKey(encoder.ctx, reflect2.TypeOf(obj)).IsEmpty(reflect2.PtrOf(obj))
-}
-
-type mapEncoder struct {
- mapType *reflect2.UnsafeMapType
- keyEncoder ValEncoder
- elemEncoder ValEncoder
-}
-
-func (encoder *mapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteObjectStart()
- iter := encoder.mapType.UnsafeIterate(ptr)
- for i := 0; iter.HasNext(); i++ {
- if i != 0 {
- stream.WriteMore()
- }
- key, elem := iter.UnsafeNext()
- encoder.keyEncoder.Encode(key, stream)
- if stream.indention > 0 {
- stream.writeTwoBytes(byte(':'), byte(' '))
- } else {
- stream.writeByte(':')
- }
- encoder.elemEncoder.Encode(elem, stream)
- }
- stream.WriteObjectEnd()
-}
-
-func (encoder *mapEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- iter := encoder.mapType.UnsafeIterate(ptr)
- return !iter.HasNext()
-}
-
-type sortKeysMapEncoder struct {
- mapType *reflect2.UnsafeMapType
- keyEncoder ValEncoder
- elemEncoder ValEncoder
-}
-
-func (encoder *sortKeysMapEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- if *(*unsafe.Pointer)(ptr) == nil {
- stream.WriteNil()
- return
- }
- stream.WriteObjectStart()
- mapIter := encoder.mapType.UnsafeIterate(ptr)
- subStream := stream.cfg.BorrowStream(nil)
- subIter := stream.cfg.BorrowIterator(nil)
- keyValues := encodedKeyValues{}
- for mapIter.HasNext() {
- subStream.buf = make([]byte, 0, 64)
- key, elem := mapIter.UnsafeNext()
- encoder.keyEncoder.Encode(key, subStream)
- if subStream.Error != nil && subStream.Error != io.EOF && stream.Error == nil {
- stream.Error = subStream.Error
- }
- encodedKey := subStream.Buffer()
- subIter.ResetBytes(encodedKey)
- decodedKey := subIter.ReadString()
- if stream.indention > 0 {
- subStream.writeTwoBytes(byte(':'), byte(' '))
- } else {
- subStream.writeByte(':')
- }
- encoder.elemEncoder.Encode(elem, subStream)
- keyValues = append(keyValues, encodedKV{
- key: decodedKey,
- keyValue: subStream.Buffer(),
- })
- }
- sort.Sort(keyValues)
- for i, keyValue := range keyValues {
- if i != 0 {
- stream.WriteMore()
- }
- stream.Write(keyValue.keyValue)
- }
- stream.WriteObjectEnd()
- stream.cfg.ReturnStream(subStream)
- stream.cfg.ReturnIterator(subIter)
-}
-
-func (encoder *sortKeysMapEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- iter := encoder.mapType.UnsafeIterate(ptr)
- return !iter.HasNext()
-}
-
-type encodedKeyValues []encodedKV
-
-type encodedKV struct {
- key string
- keyValue []byte
-}
-
-func (sv encodedKeyValues) Len() int { return len(sv) }
-func (sv encodedKeyValues) Swap(i, j int) { sv[i], sv[j] = sv[j], sv[i] }
-func (sv encodedKeyValues) Less(i, j int) bool { return sv[i].key < sv[j].key }
diff --git a/vendor/github.com/json-iterator/go/reflect_marshaler.go b/vendor/github.com/json-iterator/go/reflect_marshaler.go
deleted file mode 100644
index 58ac959..0000000
--- a/vendor/github.com/json-iterator/go/reflect_marshaler.go
+++ /dev/null
@@ -1,218 +0,0 @@
-package jsoniter
-
-import (
- "encoding"
- "encoding/json"
- "github.com/modern-go/reflect2"
- "unsafe"
-)
-
-var marshalerType = reflect2.TypeOfPtr((*json.Marshaler)(nil)).Elem()
-var unmarshalerType = reflect2.TypeOfPtr((*json.Unmarshaler)(nil)).Elem()
-var textMarshalerType = reflect2.TypeOfPtr((*encoding.TextMarshaler)(nil)).Elem()
-var textUnmarshalerType = reflect2.TypeOfPtr((*encoding.TextUnmarshaler)(nil)).Elem()
-
-func createDecoderOfMarshaler(ctx *ctx, typ reflect2.Type) ValDecoder {
- ptrType := reflect2.PtrTo(typ)
- if ptrType.Implements(unmarshalerType) {
- return &referenceDecoder{
- &unmarshalerDecoder{ptrType},
- }
- }
- if ptrType.Implements(textUnmarshalerType) {
- return &referenceDecoder{
- &textUnmarshalerDecoder{ptrType},
- }
- }
- return nil
-}
-
-func createEncoderOfMarshaler(ctx *ctx, typ reflect2.Type) ValEncoder {
- if typ == marshalerType {
- checkIsEmpty := createCheckIsEmpty(ctx, typ)
- var encoder ValEncoder = &directMarshalerEncoder{
- checkIsEmpty: checkIsEmpty,
- }
- return encoder
- }
- if typ.Implements(marshalerType) {
- checkIsEmpty := createCheckIsEmpty(ctx, typ)
- var encoder ValEncoder = &marshalerEncoder{
- valType: typ,
- checkIsEmpty: checkIsEmpty,
- }
- return encoder
- }
- ptrType := reflect2.PtrTo(typ)
- if ctx.prefix != "" && ptrType.Implements(marshalerType) {
- checkIsEmpty := createCheckIsEmpty(ctx, ptrType)
- var encoder ValEncoder = &marshalerEncoder{
- valType: ptrType,
- checkIsEmpty: checkIsEmpty,
- }
- return &referenceEncoder{encoder}
- }
- if typ == textMarshalerType {
- checkIsEmpty := createCheckIsEmpty(ctx, typ)
- var encoder ValEncoder = &directTextMarshalerEncoder{
- checkIsEmpty: checkIsEmpty,
- stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
- }
- return encoder
- }
- if typ.Implements(textMarshalerType) {
- checkIsEmpty := createCheckIsEmpty(ctx, typ)
- var encoder ValEncoder = &textMarshalerEncoder{
- valType: typ,
- stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
- checkIsEmpty: checkIsEmpty,
- }
- return encoder
- }
- // if prefix is empty, the type is the root type
- if ctx.prefix != "" && ptrType.Implements(textMarshalerType) {
- checkIsEmpty := createCheckIsEmpty(ctx, ptrType)
- var encoder ValEncoder = &textMarshalerEncoder{
- valType: ptrType,
- stringEncoder: ctx.EncoderOf(reflect2.TypeOf("")),
- checkIsEmpty: checkIsEmpty,
- }
- return &referenceEncoder{encoder}
- }
- return nil
-}
-
-type marshalerEncoder struct {
- checkIsEmpty checkIsEmpty
- valType reflect2.Type
-}
-
-func (encoder *marshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- obj := encoder.valType.UnsafeIndirect(ptr)
- if encoder.valType.IsNullable() && reflect2.IsNil(obj) {
- stream.WriteNil()
- return
- }
- marshaler := obj.(json.Marshaler)
- bytes, err := marshaler.MarshalJSON()
- if err != nil {
- stream.Error = err
- } else {
- stream.Write(bytes)
- }
-}
-
-func (encoder *marshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.checkIsEmpty.IsEmpty(ptr)
-}
-
-type directMarshalerEncoder struct {
- checkIsEmpty checkIsEmpty
-}
-
-func (encoder *directMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- marshaler := *(*json.Marshaler)(ptr)
- if marshaler == nil {
- stream.WriteNil()
- return
- }
- bytes, err := marshaler.MarshalJSON()
- if err != nil {
- stream.Error = err
- } else {
- stream.Write(bytes)
- }
-}
-
-func (encoder *directMarshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.checkIsEmpty.IsEmpty(ptr)
-}
-
-type textMarshalerEncoder struct {
- valType reflect2.Type
- stringEncoder ValEncoder
- checkIsEmpty checkIsEmpty
-}
-
-func (encoder *textMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- obj := encoder.valType.UnsafeIndirect(ptr)
- if encoder.valType.IsNullable() && reflect2.IsNil(obj) {
- stream.WriteNil()
- return
- }
- marshaler := (obj).(encoding.TextMarshaler)
- bytes, err := marshaler.MarshalText()
- if err != nil {
- stream.Error = err
- } else {
- str := string(bytes)
- encoder.stringEncoder.Encode(unsafe.Pointer(&str), stream)
- }
-}
-
-func (encoder *textMarshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.checkIsEmpty.IsEmpty(ptr)
-}
-
-type directTextMarshalerEncoder struct {
- stringEncoder ValEncoder
- checkIsEmpty checkIsEmpty
-}
-
-func (encoder *directTextMarshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- marshaler := *(*encoding.TextMarshaler)(ptr)
- if marshaler == nil {
- stream.WriteNil()
- return
- }
- bytes, err := marshaler.MarshalText()
- if err != nil {
- stream.Error = err
- } else {
- str := string(bytes)
- encoder.stringEncoder.Encode(unsafe.Pointer(&str), stream)
- }
-}
-
-func (encoder *directTextMarshalerEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.checkIsEmpty.IsEmpty(ptr)
-}
-
-type unmarshalerDecoder struct {
- valType reflect2.Type
-}
-
-func (decoder *unmarshalerDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- valType := decoder.valType
- obj := valType.UnsafeIndirect(ptr)
- unmarshaler := obj.(json.Unmarshaler)
- iter.nextToken()
- iter.unreadByte() // skip spaces
- bytes := iter.SkipAndReturnBytes()
- err := unmarshaler.UnmarshalJSON(bytes)
- if err != nil {
- iter.ReportError("unmarshalerDecoder", err.Error())
- }
-}
-
-type textUnmarshalerDecoder struct {
- valType reflect2.Type
-}
-
-func (decoder *textUnmarshalerDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- valType := decoder.valType
- obj := valType.UnsafeIndirect(ptr)
- if reflect2.IsNil(obj) {
- ptrType := valType.(*reflect2.UnsafePtrType)
- elemType := ptrType.Elem()
- elem := elemType.UnsafeNew()
- ptrType.UnsafeSet(ptr, unsafe.Pointer(&elem))
- obj = valType.UnsafeIndirect(ptr)
- }
- unmarshaler := (obj).(encoding.TextUnmarshaler)
- str := iter.ReadString()
- err := unmarshaler.UnmarshalText([]byte(str))
- if err != nil {
- iter.ReportError("textUnmarshalerDecoder", err.Error())
- }
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_native.go b/vendor/github.com/json-iterator/go/reflect_native.go
deleted file mode 100644
index 9042eb0..0000000
--- a/vendor/github.com/json-iterator/go/reflect_native.go
+++ /dev/null
@@ -1,451 +0,0 @@
-package jsoniter
-
-import (
- "encoding/base64"
- "reflect"
- "strconv"
- "unsafe"
-
- "github.com/modern-go/reflect2"
-)
-
-const ptrSize = 32 << uintptr(^uintptr(0)>>63)
-
-func createEncoderOfNative(ctx *ctx, typ reflect2.Type) ValEncoder {
- if typ.Kind() == reflect.Slice && typ.(reflect2.SliceType).Elem().Kind() == reflect.Uint8 {
- sliceDecoder := decoderOfSlice(ctx, typ)
- return &base64Codec{sliceDecoder: sliceDecoder}
- }
- typeName := typ.String()
- kind := typ.Kind()
- switch kind {
- case reflect.String:
- if typeName != "string" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*string)(nil)).Elem())
- }
- return &stringCodec{}
- case reflect.Int:
- if typeName != "int" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*int)(nil)).Elem())
- }
- if strconv.IntSize == 32 {
- return &int32Codec{}
- }
- return &int64Codec{}
- case reflect.Int8:
- if typeName != "int8" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*int8)(nil)).Elem())
- }
- return &int8Codec{}
- case reflect.Int16:
- if typeName != "int16" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*int16)(nil)).Elem())
- }
- return &int16Codec{}
- case reflect.Int32:
- if typeName != "int32" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*int32)(nil)).Elem())
- }
- return &int32Codec{}
- case reflect.Int64:
- if typeName != "int64" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*int64)(nil)).Elem())
- }
- return &int64Codec{}
- case reflect.Uint:
- if typeName != "uint" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*uint)(nil)).Elem())
- }
- if strconv.IntSize == 32 {
- return &uint32Codec{}
- }
- return &uint64Codec{}
- case reflect.Uint8:
- if typeName != "uint8" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*uint8)(nil)).Elem())
- }
- return &uint8Codec{}
- case reflect.Uint16:
- if typeName != "uint16" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*uint16)(nil)).Elem())
- }
- return &uint16Codec{}
- case reflect.Uint32:
- if typeName != "uint32" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*uint32)(nil)).Elem())
- }
- return &uint32Codec{}
- case reflect.Uintptr:
- if typeName != "uintptr" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*uintptr)(nil)).Elem())
- }
- if ptrSize == 32 {
- return &uint32Codec{}
- }
- return &uint64Codec{}
- case reflect.Uint64:
- if typeName != "uint64" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*uint64)(nil)).Elem())
- }
- return &uint64Codec{}
- case reflect.Float32:
- if typeName != "float32" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*float32)(nil)).Elem())
- }
- return &float32Codec{}
- case reflect.Float64:
- if typeName != "float64" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*float64)(nil)).Elem())
- }
- return &float64Codec{}
- case reflect.Bool:
- if typeName != "bool" {
- return encoderOfType(ctx, reflect2.TypeOfPtr((*bool)(nil)).Elem())
- }
- return &boolCodec{}
- }
- return nil
-}
-
-func createDecoderOfNative(ctx *ctx, typ reflect2.Type) ValDecoder {
- if typ.Kind() == reflect.Slice && typ.(reflect2.SliceType).Elem().Kind() == reflect.Uint8 {
- sliceDecoder := decoderOfSlice(ctx, typ)
- return &base64Codec{sliceDecoder: sliceDecoder}
- }
- typeName := typ.String()
- switch typ.Kind() {
- case reflect.String:
- if typeName != "string" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*string)(nil)).Elem())
- }
- return &stringCodec{}
- case reflect.Int:
- if typeName != "int" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*int)(nil)).Elem())
- }
- if strconv.IntSize == 32 {
- return &int32Codec{}
- }
- return &int64Codec{}
- case reflect.Int8:
- if typeName != "int8" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*int8)(nil)).Elem())
- }
- return &int8Codec{}
- case reflect.Int16:
- if typeName != "int16" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*int16)(nil)).Elem())
- }
- return &int16Codec{}
- case reflect.Int32:
- if typeName != "int32" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*int32)(nil)).Elem())
- }
- return &int32Codec{}
- case reflect.Int64:
- if typeName != "int64" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*int64)(nil)).Elem())
- }
- return &int64Codec{}
- case reflect.Uint:
- if typeName != "uint" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*uint)(nil)).Elem())
- }
- if strconv.IntSize == 32 {
- return &uint32Codec{}
- }
- return &uint64Codec{}
- case reflect.Uint8:
- if typeName != "uint8" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*uint8)(nil)).Elem())
- }
- return &uint8Codec{}
- case reflect.Uint16:
- if typeName != "uint16" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*uint16)(nil)).Elem())
- }
- return &uint16Codec{}
- case reflect.Uint32:
- if typeName != "uint32" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*uint32)(nil)).Elem())
- }
- return &uint32Codec{}
- case reflect.Uintptr:
- if typeName != "uintptr" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*uintptr)(nil)).Elem())
- }
- if ptrSize == 32 {
- return &uint32Codec{}
- }
- return &uint64Codec{}
- case reflect.Uint64:
- if typeName != "uint64" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*uint64)(nil)).Elem())
- }
- return &uint64Codec{}
- case reflect.Float32:
- if typeName != "float32" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*float32)(nil)).Elem())
- }
- return &float32Codec{}
- case reflect.Float64:
- if typeName != "float64" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*float64)(nil)).Elem())
- }
- return &float64Codec{}
- case reflect.Bool:
- if typeName != "bool" {
- return decoderOfType(ctx, reflect2.TypeOfPtr((*bool)(nil)).Elem())
- }
- return &boolCodec{}
- }
- return nil
-}
-
-type stringCodec struct {
-}
-
-func (codec *stringCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- *((*string)(ptr)) = iter.ReadString()
-}
-
-func (codec *stringCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
- str := *((*string)(ptr))
- stream.WriteString(str)
-}
-
-func (codec *stringCodec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*string)(ptr)) == ""
-}
-
-type int8Codec struct {
-}
-
-func (codec *int8Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*int8)(ptr)) = iter.ReadInt8()
- }
-}
-
-func (codec *int8Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteInt8(*((*int8)(ptr)))
-}
-
-func (codec *int8Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*int8)(ptr)) == 0
-}
-
-type int16Codec struct {
-}
-
-func (codec *int16Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*int16)(ptr)) = iter.ReadInt16()
- }
-}
-
-func (codec *int16Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteInt16(*((*int16)(ptr)))
-}
-
-func (codec *int16Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*int16)(ptr)) == 0
-}
-
-type int32Codec struct {
-}
-
-func (codec *int32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*int32)(ptr)) = iter.ReadInt32()
- }
-}
-
-func (codec *int32Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteInt32(*((*int32)(ptr)))
-}
-
-func (codec *int32Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*int32)(ptr)) == 0
-}
-
-type int64Codec struct {
-}
-
-func (codec *int64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*int64)(ptr)) = iter.ReadInt64()
- }
-}
-
-func (codec *int64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteInt64(*((*int64)(ptr)))
-}
-
-func (codec *int64Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*int64)(ptr)) == 0
-}
-
-type uint8Codec struct {
-}
-
-func (codec *uint8Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*uint8)(ptr)) = iter.ReadUint8()
- }
-}
-
-func (codec *uint8Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteUint8(*((*uint8)(ptr)))
-}
-
-func (codec *uint8Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*uint8)(ptr)) == 0
-}
-
-type uint16Codec struct {
-}
-
-func (codec *uint16Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*uint16)(ptr)) = iter.ReadUint16()
- }
-}
-
-func (codec *uint16Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteUint16(*((*uint16)(ptr)))
-}
-
-func (codec *uint16Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*uint16)(ptr)) == 0
-}
-
-type uint32Codec struct {
-}
-
-func (codec *uint32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*uint32)(ptr)) = iter.ReadUint32()
- }
-}
-
-func (codec *uint32Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteUint32(*((*uint32)(ptr)))
-}
-
-func (codec *uint32Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*uint32)(ptr)) == 0
-}
-
-type uint64Codec struct {
-}
-
-func (codec *uint64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*uint64)(ptr)) = iter.ReadUint64()
- }
-}
-
-func (codec *uint64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteUint64(*((*uint64)(ptr)))
-}
-
-func (codec *uint64Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*uint64)(ptr)) == 0
-}
-
-type float32Codec struct {
-}
-
-func (codec *float32Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*float32)(ptr)) = iter.ReadFloat32()
- }
-}
-
-func (codec *float32Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteFloat32(*((*float32)(ptr)))
-}
-
-func (codec *float32Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*float32)(ptr)) == 0
-}
-
-type float64Codec struct {
-}
-
-func (codec *float64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*float64)(ptr)) = iter.ReadFloat64()
- }
-}
-
-func (codec *float64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteFloat64(*((*float64)(ptr)))
-}
-
-func (codec *float64Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*float64)(ptr)) == 0
-}
-
-type boolCodec struct {
-}
-
-func (codec *boolCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.ReadNil() {
- *((*bool)(ptr)) = iter.ReadBool()
- }
-}
-
-func (codec *boolCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteBool(*((*bool)(ptr)))
-}
-
-func (codec *boolCodec) IsEmpty(ptr unsafe.Pointer) bool {
- return !(*((*bool)(ptr)))
-}
-
-type base64Codec struct {
- sliceType *reflect2.UnsafeSliceType
- sliceDecoder ValDecoder
-}
-
-func (codec *base64Codec) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if iter.ReadNil() {
- codec.sliceType.UnsafeSetNil(ptr)
- return
- }
- switch iter.WhatIsNext() {
- case StringValue:
- src := iter.ReadString()
- dst, err := base64.StdEncoding.DecodeString(src)
- if err != nil {
- iter.ReportError("decode base64", err.Error())
- } else {
- codec.sliceType.UnsafeSet(ptr, unsafe.Pointer(&dst))
- }
- case ArrayValue:
- codec.sliceDecoder.Decode(ptr, iter)
- default:
- iter.ReportError("base64Codec", "invalid input")
- }
-}
-
-func (codec *base64Codec) Encode(ptr unsafe.Pointer, stream *Stream) {
- src := *((*[]byte)(ptr))
- if len(src) == 0 {
- stream.WriteNil()
- return
- }
- encoding := base64.StdEncoding
- stream.writeByte('"')
- size := encoding.EncodedLen(len(src))
- buf := make([]byte, size)
- encoding.Encode(buf, src)
- stream.buf = append(stream.buf, buf...)
- stream.writeByte('"')
-}
-
-func (codec *base64Codec) IsEmpty(ptr unsafe.Pointer) bool {
- return len(*((*[]byte)(ptr))) == 0
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_optional.go b/vendor/github.com/json-iterator/go/reflect_optional.go
deleted file mode 100644
index 43ec71d..0000000
--- a/vendor/github.com/json-iterator/go/reflect_optional.go
+++ /dev/null
@@ -1,133 +0,0 @@
-package jsoniter
-
-import (
- "github.com/modern-go/reflect2"
- "reflect"
- "unsafe"
-)
-
-func decoderOfOptional(ctx *ctx, typ reflect2.Type) ValDecoder {
- ptrType := typ.(*reflect2.UnsafePtrType)
- elemType := ptrType.Elem()
- decoder := decoderOfType(ctx, elemType)
- if ctx.prefix == "" && elemType.Kind() == reflect.Ptr {
- return &dereferenceDecoder{elemType, decoder}
- }
- return &OptionalDecoder{elemType, decoder}
-}
-
-func encoderOfOptional(ctx *ctx, typ reflect2.Type) ValEncoder {
- ptrType := typ.(*reflect2.UnsafePtrType)
- elemType := ptrType.Elem()
- elemEncoder := encoderOfType(ctx, elemType)
- encoder := &OptionalEncoder{elemEncoder}
- return encoder
-}
-
-type OptionalDecoder struct {
- ValueType reflect2.Type
- ValueDecoder ValDecoder
-}
-
-func (decoder *OptionalDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if iter.ReadNil() {
- *((*unsafe.Pointer)(ptr)) = nil
- } else {
- if *((*unsafe.Pointer)(ptr)) == nil {
- //pointer to null, we have to allocate memory to hold the value
- newPtr := decoder.ValueType.UnsafeNew()
- decoder.ValueDecoder.Decode(newPtr, iter)
- *((*unsafe.Pointer)(ptr)) = newPtr
- } else {
- //reuse existing instance
- decoder.ValueDecoder.Decode(*((*unsafe.Pointer)(ptr)), iter)
- }
- }
-}
-
-type dereferenceDecoder struct {
- // only to deference a pointer
- valueType reflect2.Type
- valueDecoder ValDecoder
-}
-
-func (decoder *dereferenceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if *((*unsafe.Pointer)(ptr)) == nil {
- //pointer to null, we have to allocate memory to hold the value
- newPtr := decoder.valueType.UnsafeNew()
- decoder.valueDecoder.Decode(newPtr, iter)
- *((*unsafe.Pointer)(ptr)) = newPtr
- } else {
- //reuse existing instance
- decoder.valueDecoder.Decode(*((*unsafe.Pointer)(ptr)), iter)
- }
-}
-
-type OptionalEncoder struct {
- ValueEncoder ValEncoder
-}
-
-func (encoder *OptionalEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- if *((*unsafe.Pointer)(ptr)) == nil {
- stream.WriteNil()
- } else {
- encoder.ValueEncoder.Encode(*((*unsafe.Pointer)(ptr)), stream)
- }
-}
-
-func (encoder *OptionalEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return *((*unsafe.Pointer)(ptr)) == nil
-}
-
-type dereferenceEncoder struct {
- ValueEncoder ValEncoder
-}
-
-func (encoder *dereferenceEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- if *((*unsafe.Pointer)(ptr)) == nil {
- stream.WriteNil()
- } else {
- encoder.ValueEncoder.Encode(*((*unsafe.Pointer)(ptr)), stream)
- }
-}
-
-func (encoder *dereferenceEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- dePtr := *((*unsafe.Pointer)(ptr))
- if dePtr == nil {
- return true
- }
- return encoder.ValueEncoder.IsEmpty(dePtr)
-}
-
-func (encoder *dereferenceEncoder) IsEmbeddedPtrNil(ptr unsafe.Pointer) bool {
- deReferenced := *((*unsafe.Pointer)(ptr))
- if deReferenced == nil {
- return true
- }
- isEmbeddedPtrNil, converted := encoder.ValueEncoder.(IsEmbeddedPtrNil)
- if !converted {
- return false
- }
- fieldPtr := unsafe.Pointer(deReferenced)
- return isEmbeddedPtrNil.IsEmbeddedPtrNil(fieldPtr)
-}
-
-type referenceEncoder struct {
- encoder ValEncoder
-}
-
-func (encoder *referenceEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- encoder.encoder.Encode(unsafe.Pointer(&ptr), stream)
-}
-
-func (encoder *referenceEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.encoder.IsEmpty(unsafe.Pointer(&ptr))
-}
-
-type referenceDecoder struct {
- decoder ValDecoder
-}
-
-func (decoder *referenceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- decoder.decoder.Decode(unsafe.Pointer(&ptr), iter)
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_slice.go b/vendor/github.com/json-iterator/go/reflect_slice.go
deleted file mode 100644
index 9441d79..0000000
--- a/vendor/github.com/json-iterator/go/reflect_slice.go
+++ /dev/null
@@ -1,99 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "github.com/modern-go/reflect2"
- "io"
- "unsafe"
-)
-
-func decoderOfSlice(ctx *ctx, typ reflect2.Type) ValDecoder {
- sliceType := typ.(*reflect2.UnsafeSliceType)
- decoder := decoderOfType(ctx.append("[sliceElem]"), sliceType.Elem())
- return &sliceDecoder{sliceType, decoder}
-}
-
-func encoderOfSlice(ctx *ctx, typ reflect2.Type) ValEncoder {
- sliceType := typ.(*reflect2.UnsafeSliceType)
- encoder := encoderOfType(ctx.append("[sliceElem]"), sliceType.Elem())
- return &sliceEncoder{sliceType, encoder}
-}
-
-type sliceEncoder struct {
- sliceType *reflect2.UnsafeSliceType
- elemEncoder ValEncoder
-}
-
-func (encoder *sliceEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- if encoder.sliceType.UnsafeIsNil(ptr) {
- stream.WriteNil()
- return
- }
- length := encoder.sliceType.UnsafeLengthOf(ptr)
- if length == 0 {
- stream.WriteEmptyArray()
- return
- }
- stream.WriteArrayStart()
- encoder.elemEncoder.Encode(encoder.sliceType.UnsafeGetIndex(ptr, 0), stream)
- for i := 1; i < length; i++ {
- stream.WriteMore()
- elemPtr := encoder.sliceType.UnsafeGetIndex(ptr, i)
- encoder.elemEncoder.Encode(elemPtr, stream)
- }
- stream.WriteArrayEnd()
- if stream.Error != nil && stream.Error != io.EOF {
- stream.Error = fmt.Errorf("%v: %s", encoder.sliceType, stream.Error.Error())
- }
-}
-
-func (encoder *sliceEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.sliceType.UnsafeLengthOf(ptr) == 0
-}
-
-type sliceDecoder struct {
- sliceType *reflect2.UnsafeSliceType
- elemDecoder ValDecoder
-}
-
-func (decoder *sliceDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- decoder.doDecode(ptr, iter)
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v: %s", decoder.sliceType, iter.Error.Error())
- }
-}
-
-func (decoder *sliceDecoder) doDecode(ptr unsafe.Pointer, iter *Iterator) {
- c := iter.nextToken()
- sliceType := decoder.sliceType
- if c == 'n' {
- iter.skipThreeBytes('u', 'l', 'l')
- sliceType.UnsafeSetNil(ptr)
- return
- }
- if c != '[' {
- iter.ReportError("decode slice", "expect [ or n, but found "+string([]byte{c}))
- return
- }
- c = iter.nextToken()
- if c == ']' {
- sliceType.UnsafeSet(ptr, sliceType.UnsafeMakeSlice(0, 0))
- return
- }
- iter.unreadByte()
- sliceType.UnsafeGrow(ptr, 1)
- elemPtr := sliceType.UnsafeGetIndex(ptr, 0)
- decoder.elemDecoder.Decode(elemPtr, iter)
- length := 1
- for c = iter.nextToken(); c == ','; c = iter.nextToken() {
- idx := length
- length += 1
- sliceType.UnsafeGrow(ptr, length)
- elemPtr = sliceType.UnsafeGetIndex(ptr, idx)
- decoder.elemDecoder.Decode(elemPtr, iter)
- }
- if c != ']' {
- iter.ReportError("decode slice", "expect ], but found "+string([]byte{c}))
- return
- }
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_struct_decoder.go b/vendor/github.com/json-iterator/go/reflect_struct_decoder.go
deleted file mode 100644
index 355d2d1..0000000
--- a/vendor/github.com/json-iterator/go/reflect_struct_decoder.go
+++ /dev/null
@@ -1,1048 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "io"
- "strings"
- "unsafe"
-
- "github.com/modern-go/reflect2"
-)
-
-func decoderOfStruct(ctx *ctx, typ reflect2.Type) ValDecoder {
- bindings := map[string]*Binding{}
- structDescriptor := describeStruct(ctx, typ)
- for _, binding := range structDescriptor.Fields {
- for _, fromName := range binding.FromNames {
- old := bindings[fromName]
- if old == nil {
- bindings[fromName] = binding
- continue
- }
- ignoreOld, ignoreNew := resolveConflictBinding(ctx.frozenConfig, old, binding)
- if ignoreOld {
- delete(bindings, fromName)
- }
- if !ignoreNew {
- bindings[fromName] = binding
- }
- }
- }
- fields := map[string]*structFieldDecoder{}
- for k, binding := range bindings {
- fields[k] = binding.Decoder.(*structFieldDecoder)
- }
-
- if !ctx.caseSensitive() {
- for k, binding := range bindings {
- if _, found := fields[strings.ToLower(k)]; !found {
- fields[strings.ToLower(k)] = binding.Decoder.(*structFieldDecoder)
- }
- }
- }
-
- return createStructDecoder(ctx, typ, fields)
-}
-
-func createStructDecoder(ctx *ctx, typ reflect2.Type, fields map[string]*structFieldDecoder) ValDecoder {
- if ctx.disallowUnknownFields {
- return &generalStructDecoder{typ: typ, fields: fields, disallowUnknownFields: true}
- }
- knownHash := map[int64]struct{}{
- 0: {},
- }
-
- switch len(fields) {
- case 0:
- return &skipObjectDecoder{typ}
- case 1:
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- return &oneFieldStructDecoder{typ, fieldHash, fieldDecoder}
- }
- case 2:
- var fieldHash1 int64
- var fieldHash2 int64
- var fieldDecoder1 *structFieldDecoder
- var fieldDecoder2 *structFieldDecoder
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- if fieldHash1 == 0 {
- fieldHash1 = fieldHash
- fieldDecoder1 = fieldDecoder
- } else {
- fieldHash2 = fieldHash
- fieldDecoder2 = fieldDecoder
- }
- }
- return &twoFieldsStructDecoder{typ, fieldHash1, fieldDecoder1, fieldHash2, fieldDecoder2}
- case 3:
- var fieldName1 int64
- var fieldName2 int64
- var fieldName3 int64
- var fieldDecoder1 *structFieldDecoder
- var fieldDecoder2 *structFieldDecoder
- var fieldDecoder3 *structFieldDecoder
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- if fieldName1 == 0 {
- fieldName1 = fieldHash
- fieldDecoder1 = fieldDecoder
- } else if fieldName2 == 0 {
- fieldName2 = fieldHash
- fieldDecoder2 = fieldDecoder
- } else {
- fieldName3 = fieldHash
- fieldDecoder3 = fieldDecoder
- }
- }
- return &threeFieldsStructDecoder{typ,
- fieldName1, fieldDecoder1,
- fieldName2, fieldDecoder2,
- fieldName3, fieldDecoder3}
- case 4:
- var fieldName1 int64
- var fieldName2 int64
- var fieldName3 int64
- var fieldName4 int64
- var fieldDecoder1 *structFieldDecoder
- var fieldDecoder2 *structFieldDecoder
- var fieldDecoder3 *structFieldDecoder
- var fieldDecoder4 *structFieldDecoder
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- if fieldName1 == 0 {
- fieldName1 = fieldHash
- fieldDecoder1 = fieldDecoder
- } else if fieldName2 == 0 {
- fieldName2 = fieldHash
- fieldDecoder2 = fieldDecoder
- } else if fieldName3 == 0 {
- fieldName3 = fieldHash
- fieldDecoder3 = fieldDecoder
- } else {
- fieldName4 = fieldHash
- fieldDecoder4 = fieldDecoder
- }
- }
- return &fourFieldsStructDecoder{typ,
- fieldName1, fieldDecoder1,
- fieldName2, fieldDecoder2,
- fieldName3, fieldDecoder3,
- fieldName4, fieldDecoder4}
- case 5:
- var fieldName1 int64
- var fieldName2 int64
- var fieldName3 int64
- var fieldName4 int64
- var fieldName5 int64
- var fieldDecoder1 *structFieldDecoder
- var fieldDecoder2 *structFieldDecoder
- var fieldDecoder3 *structFieldDecoder
- var fieldDecoder4 *structFieldDecoder
- var fieldDecoder5 *structFieldDecoder
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- if fieldName1 == 0 {
- fieldName1 = fieldHash
- fieldDecoder1 = fieldDecoder
- } else if fieldName2 == 0 {
- fieldName2 = fieldHash
- fieldDecoder2 = fieldDecoder
- } else if fieldName3 == 0 {
- fieldName3 = fieldHash
- fieldDecoder3 = fieldDecoder
- } else if fieldName4 == 0 {
- fieldName4 = fieldHash
- fieldDecoder4 = fieldDecoder
- } else {
- fieldName5 = fieldHash
- fieldDecoder5 = fieldDecoder
- }
- }
- return &fiveFieldsStructDecoder{typ,
- fieldName1, fieldDecoder1,
- fieldName2, fieldDecoder2,
- fieldName3, fieldDecoder3,
- fieldName4, fieldDecoder4,
- fieldName5, fieldDecoder5}
- case 6:
- var fieldName1 int64
- var fieldName2 int64
- var fieldName3 int64
- var fieldName4 int64
- var fieldName5 int64
- var fieldName6 int64
- var fieldDecoder1 *structFieldDecoder
- var fieldDecoder2 *structFieldDecoder
- var fieldDecoder3 *structFieldDecoder
- var fieldDecoder4 *structFieldDecoder
- var fieldDecoder5 *structFieldDecoder
- var fieldDecoder6 *structFieldDecoder
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- if fieldName1 == 0 {
- fieldName1 = fieldHash
- fieldDecoder1 = fieldDecoder
- } else if fieldName2 == 0 {
- fieldName2 = fieldHash
- fieldDecoder2 = fieldDecoder
- } else if fieldName3 == 0 {
- fieldName3 = fieldHash
- fieldDecoder3 = fieldDecoder
- } else if fieldName4 == 0 {
- fieldName4 = fieldHash
- fieldDecoder4 = fieldDecoder
- } else if fieldName5 == 0 {
- fieldName5 = fieldHash
- fieldDecoder5 = fieldDecoder
- } else {
- fieldName6 = fieldHash
- fieldDecoder6 = fieldDecoder
- }
- }
- return &sixFieldsStructDecoder{typ,
- fieldName1, fieldDecoder1,
- fieldName2, fieldDecoder2,
- fieldName3, fieldDecoder3,
- fieldName4, fieldDecoder4,
- fieldName5, fieldDecoder5,
- fieldName6, fieldDecoder6}
- case 7:
- var fieldName1 int64
- var fieldName2 int64
- var fieldName3 int64
- var fieldName4 int64
- var fieldName5 int64
- var fieldName6 int64
- var fieldName7 int64
- var fieldDecoder1 *structFieldDecoder
- var fieldDecoder2 *structFieldDecoder
- var fieldDecoder3 *structFieldDecoder
- var fieldDecoder4 *structFieldDecoder
- var fieldDecoder5 *structFieldDecoder
- var fieldDecoder6 *structFieldDecoder
- var fieldDecoder7 *structFieldDecoder
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- if fieldName1 == 0 {
- fieldName1 = fieldHash
- fieldDecoder1 = fieldDecoder
- } else if fieldName2 == 0 {
- fieldName2 = fieldHash
- fieldDecoder2 = fieldDecoder
- } else if fieldName3 == 0 {
- fieldName3 = fieldHash
- fieldDecoder3 = fieldDecoder
- } else if fieldName4 == 0 {
- fieldName4 = fieldHash
- fieldDecoder4 = fieldDecoder
- } else if fieldName5 == 0 {
- fieldName5 = fieldHash
- fieldDecoder5 = fieldDecoder
- } else if fieldName6 == 0 {
- fieldName6 = fieldHash
- fieldDecoder6 = fieldDecoder
- } else {
- fieldName7 = fieldHash
- fieldDecoder7 = fieldDecoder
- }
- }
- return &sevenFieldsStructDecoder{typ,
- fieldName1, fieldDecoder1,
- fieldName2, fieldDecoder2,
- fieldName3, fieldDecoder3,
- fieldName4, fieldDecoder4,
- fieldName5, fieldDecoder5,
- fieldName6, fieldDecoder6,
- fieldName7, fieldDecoder7}
- case 8:
- var fieldName1 int64
- var fieldName2 int64
- var fieldName3 int64
- var fieldName4 int64
- var fieldName5 int64
- var fieldName6 int64
- var fieldName7 int64
- var fieldName8 int64
- var fieldDecoder1 *structFieldDecoder
- var fieldDecoder2 *structFieldDecoder
- var fieldDecoder3 *structFieldDecoder
- var fieldDecoder4 *structFieldDecoder
- var fieldDecoder5 *structFieldDecoder
- var fieldDecoder6 *structFieldDecoder
- var fieldDecoder7 *structFieldDecoder
- var fieldDecoder8 *structFieldDecoder
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- if fieldName1 == 0 {
- fieldName1 = fieldHash
- fieldDecoder1 = fieldDecoder
- } else if fieldName2 == 0 {
- fieldName2 = fieldHash
- fieldDecoder2 = fieldDecoder
- } else if fieldName3 == 0 {
- fieldName3 = fieldHash
- fieldDecoder3 = fieldDecoder
- } else if fieldName4 == 0 {
- fieldName4 = fieldHash
- fieldDecoder4 = fieldDecoder
- } else if fieldName5 == 0 {
- fieldName5 = fieldHash
- fieldDecoder5 = fieldDecoder
- } else if fieldName6 == 0 {
- fieldName6 = fieldHash
- fieldDecoder6 = fieldDecoder
- } else if fieldName7 == 0 {
- fieldName7 = fieldHash
- fieldDecoder7 = fieldDecoder
- } else {
- fieldName8 = fieldHash
- fieldDecoder8 = fieldDecoder
- }
- }
- return &eightFieldsStructDecoder{typ,
- fieldName1, fieldDecoder1,
- fieldName2, fieldDecoder2,
- fieldName3, fieldDecoder3,
- fieldName4, fieldDecoder4,
- fieldName5, fieldDecoder5,
- fieldName6, fieldDecoder6,
- fieldName7, fieldDecoder7,
- fieldName8, fieldDecoder8}
- case 9:
- var fieldName1 int64
- var fieldName2 int64
- var fieldName3 int64
- var fieldName4 int64
- var fieldName5 int64
- var fieldName6 int64
- var fieldName7 int64
- var fieldName8 int64
- var fieldName9 int64
- var fieldDecoder1 *structFieldDecoder
- var fieldDecoder2 *structFieldDecoder
- var fieldDecoder3 *structFieldDecoder
- var fieldDecoder4 *structFieldDecoder
- var fieldDecoder5 *structFieldDecoder
- var fieldDecoder6 *structFieldDecoder
- var fieldDecoder7 *structFieldDecoder
- var fieldDecoder8 *structFieldDecoder
- var fieldDecoder9 *structFieldDecoder
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- if fieldName1 == 0 {
- fieldName1 = fieldHash
- fieldDecoder1 = fieldDecoder
- } else if fieldName2 == 0 {
- fieldName2 = fieldHash
- fieldDecoder2 = fieldDecoder
- } else if fieldName3 == 0 {
- fieldName3 = fieldHash
- fieldDecoder3 = fieldDecoder
- } else if fieldName4 == 0 {
- fieldName4 = fieldHash
- fieldDecoder4 = fieldDecoder
- } else if fieldName5 == 0 {
- fieldName5 = fieldHash
- fieldDecoder5 = fieldDecoder
- } else if fieldName6 == 0 {
- fieldName6 = fieldHash
- fieldDecoder6 = fieldDecoder
- } else if fieldName7 == 0 {
- fieldName7 = fieldHash
- fieldDecoder7 = fieldDecoder
- } else if fieldName8 == 0 {
- fieldName8 = fieldHash
- fieldDecoder8 = fieldDecoder
- } else {
- fieldName9 = fieldHash
- fieldDecoder9 = fieldDecoder
- }
- }
- return &nineFieldsStructDecoder{typ,
- fieldName1, fieldDecoder1,
- fieldName2, fieldDecoder2,
- fieldName3, fieldDecoder3,
- fieldName4, fieldDecoder4,
- fieldName5, fieldDecoder5,
- fieldName6, fieldDecoder6,
- fieldName7, fieldDecoder7,
- fieldName8, fieldDecoder8,
- fieldName9, fieldDecoder9}
- case 10:
- var fieldName1 int64
- var fieldName2 int64
- var fieldName3 int64
- var fieldName4 int64
- var fieldName5 int64
- var fieldName6 int64
- var fieldName7 int64
- var fieldName8 int64
- var fieldName9 int64
- var fieldName10 int64
- var fieldDecoder1 *structFieldDecoder
- var fieldDecoder2 *structFieldDecoder
- var fieldDecoder3 *structFieldDecoder
- var fieldDecoder4 *structFieldDecoder
- var fieldDecoder5 *structFieldDecoder
- var fieldDecoder6 *structFieldDecoder
- var fieldDecoder7 *structFieldDecoder
- var fieldDecoder8 *structFieldDecoder
- var fieldDecoder9 *structFieldDecoder
- var fieldDecoder10 *structFieldDecoder
- for fieldName, fieldDecoder := range fields {
- fieldHash := calcHash(fieldName, ctx.caseSensitive())
- _, known := knownHash[fieldHash]
- if known {
- return &generalStructDecoder{typ, fields, false}
- }
- knownHash[fieldHash] = struct{}{}
- if fieldName1 == 0 {
- fieldName1 = fieldHash
- fieldDecoder1 = fieldDecoder
- } else if fieldName2 == 0 {
- fieldName2 = fieldHash
- fieldDecoder2 = fieldDecoder
- } else if fieldName3 == 0 {
- fieldName3 = fieldHash
- fieldDecoder3 = fieldDecoder
- } else if fieldName4 == 0 {
- fieldName4 = fieldHash
- fieldDecoder4 = fieldDecoder
- } else if fieldName5 == 0 {
- fieldName5 = fieldHash
- fieldDecoder5 = fieldDecoder
- } else if fieldName6 == 0 {
- fieldName6 = fieldHash
- fieldDecoder6 = fieldDecoder
- } else if fieldName7 == 0 {
- fieldName7 = fieldHash
- fieldDecoder7 = fieldDecoder
- } else if fieldName8 == 0 {
- fieldName8 = fieldHash
- fieldDecoder8 = fieldDecoder
- } else if fieldName9 == 0 {
- fieldName9 = fieldHash
- fieldDecoder9 = fieldDecoder
- } else {
- fieldName10 = fieldHash
- fieldDecoder10 = fieldDecoder
- }
- }
- return &tenFieldsStructDecoder{typ,
- fieldName1, fieldDecoder1,
- fieldName2, fieldDecoder2,
- fieldName3, fieldDecoder3,
- fieldName4, fieldDecoder4,
- fieldName5, fieldDecoder5,
- fieldName6, fieldDecoder6,
- fieldName7, fieldDecoder7,
- fieldName8, fieldDecoder8,
- fieldName9, fieldDecoder9,
- fieldName10, fieldDecoder10}
- }
- return &generalStructDecoder{typ, fields, false}
-}
-
-type generalStructDecoder struct {
- typ reflect2.Type
- fields map[string]*structFieldDecoder
- disallowUnknownFields bool
-}
-
-func (decoder *generalStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- var c byte
- for c = ','; c == ','; c = iter.nextToken() {
- decoder.decodeOneField(ptr, iter)
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
- if c != '}' {
- iter.ReportError("struct Decode", `expect }, but found `+string([]byte{c}))
- }
-}
-
-func (decoder *generalStructDecoder) decodeOneField(ptr unsafe.Pointer, iter *Iterator) {
- var field string
- var fieldDecoder *structFieldDecoder
- if iter.cfg.objectFieldMustBeSimpleString {
- fieldBytes := iter.ReadStringAsSlice()
- field = *(*string)(unsafe.Pointer(&fieldBytes))
- fieldDecoder = decoder.fields[field]
- if fieldDecoder == nil && !iter.cfg.caseSensitive {
- fieldDecoder = decoder.fields[strings.ToLower(field)]
- }
- } else {
- field = iter.ReadString()
- fieldDecoder = decoder.fields[field]
- if fieldDecoder == nil && !iter.cfg.caseSensitive {
- fieldDecoder = decoder.fields[strings.ToLower(field)]
- }
- }
- if fieldDecoder == nil {
- msg := "found unknown field: " + field
- if decoder.disallowUnknownFields {
- iter.ReportError("ReadObject", msg)
- }
- c := iter.nextToken()
- if c != ':' {
- iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
- }
- iter.Skip()
- return
- }
- c := iter.nextToken()
- if c != ':' {
- iter.ReportError("ReadObject", "expect : after object field, but found "+string([]byte{c}))
- }
- fieldDecoder.Decode(ptr, iter)
-}
-
-type skipObjectDecoder struct {
- typ reflect2.Type
-}
-
-func (decoder *skipObjectDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- valueType := iter.WhatIsNext()
- if valueType != ObjectValue && valueType != NilValue {
- iter.ReportError("skipObjectDecoder", "expect object or null")
- return
- }
- iter.Skip()
-}
-
-type oneFieldStructDecoder struct {
- typ reflect2.Type
- fieldHash int64
- fieldDecoder *structFieldDecoder
-}
-
-func (decoder *oneFieldStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- if iter.readFieldHash() == decoder.fieldHash {
- decoder.fieldDecoder.Decode(ptr, iter)
- } else {
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type twoFieldsStructDecoder struct {
- typ reflect2.Type
- fieldHash1 int64
- fieldDecoder1 *structFieldDecoder
- fieldHash2 int64
- fieldDecoder2 *structFieldDecoder
-}
-
-func (decoder *twoFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- switch iter.readFieldHash() {
- case decoder.fieldHash1:
- decoder.fieldDecoder1.Decode(ptr, iter)
- case decoder.fieldHash2:
- decoder.fieldDecoder2.Decode(ptr, iter)
- default:
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type threeFieldsStructDecoder struct {
- typ reflect2.Type
- fieldHash1 int64
- fieldDecoder1 *structFieldDecoder
- fieldHash2 int64
- fieldDecoder2 *structFieldDecoder
- fieldHash3 int64
- fieldDecoder3 *structFieldDecoder
-}
-
-func (decoder *threeFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- switch iter.readFieldHash() {
- case decoder.fieldHash1:
- decoder.fieldDecoder1.Decode(ptr, iter)
- case decoder.fieldHash2:
- decoder.fieldDecoder2.Decode(ptr, iter)
- case decoder.fieldHash3:
- decoder.fieldDecoder3.Decode(ptr, iter)
- default:
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type fourFieldsStructDecoder struct {
- typ reflect2.Type
- fieldHash1 int64
- fieldDecoder1 *structFieldDecoder
- fieldHash2 int64
- fieldDecoder2 *structFieldDecoder
- fieldHash3 int64
- fieldDecoder3 *structFieldDecoder
- fieldHash4 int64
- fieldDecoder4 *structFieldDecoder
-}
-
-func (decoder *fourFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- switch iter.readFieldHash() {
- case decoder.fieldHash1:
- decoder.fieldDecoder1.Decode(ptr, iter)
- case decoder.fieldHash2:
- decoder.fieldDecoder2.Decode(ptr, iter)
- case decoder.fieldHash3:
- decoder.fieldDecoder3.Decode(ptr, iter)
- case decoder.fieldHash4:
- decoder.fieldDecoder4.Decode(ptr, iter)
- default:
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type fiveFieldsStructDecoder struct {
- typ reflect2.Type
- fieldHash1 int64
- fieldDecoder1 *structFieldDecoder
- fieldHash2 int64
- fieldDecoder2 *structFieldDecoder
- fieldHash3 int64
- fieldDecoder3 *structFieldDecoder
- fieldHash4 int64
- fieldDecoder4 *structFieldDecoder
- fieldHash5 int64
- fieldDecoder5 *structFieldDecoder
-}
-
-func (decoder *fiveFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- switch iter.readFieldHash() {
- case decoder.fieldHash1:
- decoder.fieldDecoder1.Decode(ptr, iter)
- case decoder.fieldHash2:
- decoder.fieldDecoder2.Decode(ptr, iter)
- case decoder.fieldHash3:
- decoder.fieldDecoder3.Decode(ptr, iter)
- case decoder.fieldHash4:
- decoder.fieldDecoder4.Decode(ptr, iter)
- case decoder.fieldHash5:
- decoder.fieldDecoder5.Decode(ptr, iter)
- default:
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type sixFieldsStructDecoder struct {
- typ reflect2.Type
- fieldHash1 int64
- fieldDecoder1 *structFieldDecoder
- fieldHash2 int64
- fieldDecoder2 *structFieldDecoder
- fieldHash3 int64
- fieldDecoder3 *structFieldDecoder
- fieldHash4 int64
- fieldDecoder4 *structFieldDecoder
- fieldHash5 int64
- fieldDecoder5 *structFieldDecoder
- fieldHash6 int64
- fieldDecoder6 *structFieldDecoder
-}
-
-func (decoder *sixFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- switch iter.readFieldHash() {
- case decoder.fieldHash1:
- decoder.fieldDecoder1.Decode(ptr, iter)
- case decoder.fieldHash2:
- decoder.fieldDecoder2.Decode(ptr, iter)
- case decoder.fieldHash3:
- decoder.fieldDecoder3.Decode(ptr, iter)
- case decoder.fieldHash4:
- decoder.fieldDecoder4.Decode(ptr, iter)
- case decoder.fieldHash5:
- decoder.fieldDecoder5.Decode(ptr, iter)
- case decoder.fieldHash6:
- decoder.fieldDecoder6.Decode(ptr, iter)
- default:
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type sevenFieldsStructDecoder struct {
- typ reflect2.Type
- fieldHash1 int64
- fieldDecoder1 *structFieldDecoder
- fieldHash2 int64
- fieldDecoder2 *structFieldDecoder
- fieldHash3 int64
- fieldDecoder3 *structFieldDecoder
- fieldHash4 int64
- fieldDecoder4 *structFieldDecoder
- fieldHash5 int64
- fieldDecoder5 *structFieldDecoder
- fieldHash6 int64
- fieldDecoder6 *structFieldDecoder
- fieldHash7 int64
- fieldDecoder7 *structFieldDecoder
-}
-
-func (decoder *sevenFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- switch iter.readFieldHash() {
- case decoder.fieldHash1:
- decoder.fieldDecoder1.Decode(ptr, iter)
- case decoder.fieldHash2:
- decoder.fieldDecoder2.Decode(ptr, iter)
- case decoder.fieldHash3:
- decoder.fieldDecoder3.Decode(ptr, iter)
- case decoder.fieldHash4:
- decoder.fieldDecoder4.Decode(ptr, iter)
- case decoder.fieldHash5:
- decoder.fieldDecoder5.Decode(ptr, iter)
- case decoder.fieldHash6:
- decoder.fieldDecoder6.Decode(ptr, iter)
- case decoder.fieldHash7:
- decoder.fieldDecoder7.Decode(ptr, iter)
- default:
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type eightFieldsStructDecoder struct {
- typ reflect2.Type
- fieldHash1 int64
- fieldDecoder1 *structFieldDecoder
- fieldHash2 int64
- fieldDecoder2 *structFieldDecoder
- fieldHash3 int64
- fieldDecoder3 *structFieldDecoder
- fieldHash4 int64
- fieldDecoder4 *structFieldDecoder
- fieldHash5 int64
- fieldDecoder5 *structFieldDecoder
- fieldHash6 int64
- fieldDecoder6 *structFieldDecoder
- fieldHash7 int64
- fieldDecoder7 *structFieldDecoder
- fieldHash8 int64
- fieldDecoder8 *structFieldDecoder
-}
-
-func (decoder *eightFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- switch iter.readFieldHash() {
- case decoder.fieldHash1:
- decoder.fieldDecoder1.Decode(ptr, iter)
- case decoder.fieldHash2:
- decoder.fieldDecoder2.Decode(ptr, iter)
- case decoder.fieldHash3:
- decoder.fieldDecoder3.Decode(ptr, iter)
- case decoder.fieldHash4:
- decoder.fieldDecoder4.Decode(ptr, iter)
- case decoder.fieldHash5:
- decoder.fieldDecoder5.Decode(ptr, iter)
- case decoder.fieldHash6:
- decoder.fieldDecoder6.Decode(ptr, iter)
- case decoder.fieldHash7:
- decoder.fieldDecoder7.Decode(ptr, iter)
- case decoder.fieldHash8:
- decoder.fieldDecoder8.Decode(ptr, iter)
- default:
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type nineFieldsStructDecoder struct {
- typ reflect2.Type
- fieldHash1 int64
- fieldDecoder1 *structFieldDecoder
- fieldHash2 int64
- fieldDecoder2 *structFieldDecoder
- fieldHash3 int64
- fieldDecoder3 *structFieldDecoder
- fieldHash4 int64
- fieldDecoder4 *structFieldDecoder
- fieldHash5 int64
- fieldDecoder5 *structFieldDecoder
- fieldHash6 int64
- fieldDecoder6 *structFieldDecoder
- fieldHash7 int64
- fieldDecoder7 *structFieldDecoder
- fieldHash8 int64
- fieldDecoder8 *structFieldDecoder
- fieldHash9 int64
- fieldDecoder9 *structFieldDecoder
-}
-
-func (decoder *nineFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- switch iter.readFieldHash() {
- case decoder.fieldHash1:
- decoder.fieldDecoder1.Decode(ptr, iter)
- case decoder.fieldHash2:
- decoder.fieldDecoder2.Decode(ptr, iter)
- case decoder.fieldHash3:
- decoder.fieldDecoder3.Decode(ptr, iter)
- case decoder.fieldHash4:
- decoder.fieldDecoder4.Decode(ptr, iter)
- case decoder.fieldHash5:
- decoder.fieldDecoder5.Decode(ptr, iter)
- case decoder.fieldHash6:
- decoder.fieldDecoder6.Decode(ptr, iter)
- case decoder.fieldHash7:
- decoder.fieldDecoder7.Decode(ptr, iter)
- case decoder.fieldHash8:
- decoder.fieldDecoder8.Decode(ptr, iter)
- case decoder.fieldHash9:
- decoder.fieldDecoder9.Decode(ptr, iter)
- default:
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type tenFieldsStructDecoder struct {
- typ reflect2.Type
- fieldHash1 int64
- fieldDecoder1 *structFieldDecoder
- fieldHash2 int64
- fieldDecoder2 *structFieldDecoder
- fieldHash3 int64
- fieldDecoder3 *structFieldDecoder
- fieldHash4 int64
- fieldDecoder4 *structFieldDecoder
- fieldHash5 int64
- fieldDecoder5 *structFieldDecoder
- fieldHash6 int64
- fieldDecoder6 *structFieldDecoder
- fieldHash7 int64
- fieldDecoder7 *structFieldDecoder
- fieldHash8 int64
- fieldDecoder8 *structFieldDecoder
- fieldHash9 int64
- fieldDecoder9 *structFieldDecoder
- fieldHash10 int64
- fieldDecoder10 *structFieldDecoder
-}
-
-func (decoder *tenFieldsStructDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- if !iter.readObjectStart() {
- return
- }
- for {
- switch iter.readFieldHash() {
- case decoder.fieldHash1:
- decoder.fieldDecoder1.Decode(ptr, iter)
- case decoder.fieldHash2:
- decoder.fieldDecoder2.Decode(ptr, iter)
- case decoder.fieldHash3:
- decoder.fieldDecoder3.Decode(ptr, iter)
- case decoder.fieldHash4:
- decoder.fieldDecoder4.Decode(ptr, iter)
- case decoder.fieldHash5:
- decoder.fieldDecoder5.Decode(ptr, iter)
- case decoder.fieldHash6:
- decoder.fieldDecoder6.Decode(ptr, iter)
- case decoder.fieldHash7:
- decoder.fieldDecoder7.Decode(ptr, iter)
- case decoder.fieldHash8:
- decoder.fieldDecoder8.Decode(ptr, iter)
- case decoder.fieldHash9:
- decoder.fieldDecoder9.Decode(ptr, iter)
- case decoder.fieldHash10:
- decoder.fieldDecoder10.Decode(ptr, iter)
- default:
- iter.Skip()
- }
- if iter.isObjectEnd() {
- break
- }
- }
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%v.%s", decoder.typ, iter.Error.Error())
- }
-}
-
-type structFieldDecoder struct {
- field reflect2.StructField
- fieldDecoder ValDecoder
-}
-
-func (decoder *structFieldDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- fieldPtr := decoder.field.UnsafeGet(ptr)
- decoder.fieldDecoder.Decode(fieldPtr, iter)
- if iter.Error != nil && iter.Error != io.EOF {
- iter.Error = fmt.Errorf("%s: %s", decoder.field.Name(), iter.Error.Error())
- }
-}
-
-type stringModeStringDecoder struct {
- elemDecoder ValDecoder
- cfg *frozenConfig
-}
-
-func (decoder *stringModeStringDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- decoder.elemDecoder.Decode(ptr, iter)
- str := *((*string)(ptr))
- tempIter := decoder.cfg.BorrowIterator([]byte(str))
- defer decoder.cfg.ReturnIterator(tempIter)
- *((*string)(ptr)) = tempIter.ReadString()
-}
-
-type stringModeNumberDecoder struct {
- elemDecoder ValDecoder
-}
-
-func (decoder *stringModeNumberDecoder) Decode(ptr unsafe.Pointer, iter *Iterator) {
- c := iter.nextToken()
- if c != '"' {
- iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c}))
- return
- }
- decoder.elemDecoder.Decode(ptr, iter)
- if iter.Error != nil {
- return
- }
- c = iter.readByte()
- if c != '"' {
- iter.ReportError("stringModeNumberDecoder", `expect ", but found `+string([]byte{c}))
- return
- }
-}
diff --git a/vendor/github.com/json-iterator/go/reflect_struct_encoder.go b/vendor/github.com/json-iterator/go/reflect_struct_encoder.go
deleted file mode 100644
index d0759cf..0000000
--- a/vendor/github.com/json-iterator/go/reflect_struct_encoder.go
+++ /dev/null
@@ -1,210 +0,0 @@
-package jsoniter
-
-import (
- "fmt"
- "github.com/modern-go/reflect2"
- "io"
- "reflect"
- "unsafe"
-)
-
-func encoderOfStruct(ctx *ctx, typ reflect2.Type) ValEncoder {
- type bindingTo struct {
- binding *Binding
- toName string
- ignored bool
- }
- orderedBindings := []*bindingTo{}
- structDescriptor := describeStruct(ctx, typ)
- for _, binding := range structDescriptor.Fields {
- for _, toName := range binding.ToNames {
- new := &bindingTo{
- binding: binding,
- toName: toName,
- }
- for _, old := range orderedBindings {
- if old.toName != toName {
- continue
- }
- old.ignored, new.ignored = resolveConflictBinding(ctx.frozenConfig, old.binding, new.binding)
- }
- orderedBindings = append(orderedBindings, new)
- }
- }
- if len(orderedBindings) == 0 {
- return &emptyStructEncoder{}
- }
- finalOrderedFields := []structFieldTo{}
- for _, bindingTo := range orderedBindings {
- if !bindingTo.ignored {
- finalOrderedFields = append(finalOrderedFields, structFieldTo{
- encoder: bindingTo.binding.Encoder.(*structFieldEncoder),
- toName: bindingTo.toName,
- })
- }
- }
- return &structEncoder{typ, finalOrderedFields}
-}
-
-func createCheckIsEmpty(ctx *ctx, typ reflect2.Type) checkIsEmpty {
- encoder := createEncoderOfNative(ctx, typ)
- if encoder != nil {
- return encoder
- }
- kind := typ.Kind()
- switch kind {
- case reflect.Interface:
- return &dynamicEncoder{typ}
- case reflect.Struct:
- return &structEncoder{typ: typ}
- case reflect.Array:
- return &arrayEncoder{}
- case reflect.Slice:
- return &sliceEncoder{}
- case reflect.Map:
- return encoderOfMap(ctx, typ)
- case reflect.Ptr:
- return &OptionalEncoder{}
- default:
- return &lazyErrorEncoder{err: fmt.Errorf("unsupported type: %v", typ)}
- }
-}
-
-func resolveConflictBinding(cfg *frozenConfig, old, new *Binding) (ignoreOld, ignoreNew bool) {
- newTagged := new.Field.Tag().Get(cfg.getTagKey()) != ""
- oldTagged := old.Field.Tag().Get(cfg.getTagKey()) != ""
- if newTagged {
- if oldTagged {
- if len(old.levels) > len(new.levels) {
- return true, false
- } else if len(new.levels) > len(old.levels) {
- return false, true
- } else {
- return true, true
- }
- } else {
- return true, false
- }
- } else {
- if oldTagged {
- return true, false
- }
- if len(old.levels) > len(new.levels) {
- return true, false
- } else if len(new.levels) > len(old.levels) {
- return false, true
- } else {
- return true, true
- }
- }
-}
-
-type structFieldEncoder struct {
- field reflect2.StructField
- fieldEncoder ValEncoder
- omitempty bool
-}
-
-func (encoder *structFieldEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- fieldPtr := encoder.field.UnsafeGet(ptr)
- encoder.fieldEncoder.Encode(fieldPtr, stream)
- if stream.Error != nil && stream.Error != io.EOF {
- stream.Error = fmt.Errorf("%s: %s", encoder.field.Name(), stream.Error.Error())
- }
-}
-
-func (encoder *structFieldEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- fieldPtr := encoder.field.UnsafeGet(ptr)
- return encoder.fieldEncoder.IsEmpty(fieldPtr)
-}
-
-func (encoder *structFieldEncoder) IsEmbeddedPtrNil(ptr unsafe.Pointer) bool {
- isEmbeddedPtrNil, converted := encoder.fieldEncoder.(IsEmbeddedPtrNil)
- if !converted {
- return false
- }
- fieldPtr := encoder.field.UnsafeGet(ptr)
- return isEmbeddedPtrNil.IsEmbeddedPtrNil(fieldPtr)
-}
-
-type IsEmbeddedPtrNil interface {
- IsEmbeddedPtrNil(ptr unsafe.Pointer) bool
-}
-
-type structEncoder struct {
- typ reflect2.Type
- fields []structFieldTo
-}
-
-type structFieldTo struct {
- encoder *structFieldEncoder
- toName string
-}
-
-func (encoder *structEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteObjectStart()
- isNotFirst := false
- for _, field := range encoder.fields {
- if field.encoder.omitempty && field.encoder.IsEmpty(ptr) {
- continue
- }
- if field.encoder.IsEmbeddedPtrNil(ptr) {
- continue
- }
- if isNotFirst {
- stream.WriteMore()
- }
- stream.WriteObjectField(field.toName)
- field.encoder.Encode(ptr, stream)
- isNotFirst = true
- }
- stream.WriteObjectEnd()
- if stream.Error != nil && stream.Error != io.EOF {
- stream.Error = fmt.Errorf("%v.%s", encoder.typ, stream.Error.Error())
- }
-}
-
-func (encoder *structEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return false
-}
-
-type emptyStructEncoder struct {
-}
-
-func (encoder *emptyStructEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.WriteEmptyObject()
-}
-
-func (encoder *emptyStructEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return false
-}
-
-type stringModeNumberEncoder struct {
- elemEncoder ValEncoder
-}
-
-func (encoder *stringModeNumberEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- stream.writeByte('"')
- encoder.elemEncoder.Encode(ptr, stream)
- stream.writeByte('"')
-}
-
-func (encoder *stringModeNumberEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.elemEncoder.IsEmpty(ptr)
-}
-
-type stringModeStringEncoder struct {
- elemEncoder ValEncoder
- cfg *frozenConfig
-}
-
-func (encoder *stringModeStringEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
- tempStream := encoder.cfg.BorrowStream(nil)
- defer encoder.cfg.ReturnStream(tempStream)
- encoder.elemEncoder.Encode(ptr, tempStream)
- stream.WriteString(string(tempStream.Buffer()))
-}
-
-func (encoder *stringModeStringEncoder) IsEmpty(ptr unsafe.Pointer) bool {
- return encoder.elemEncoder.IsEmpty(ptr)
-}
diff --git a/vendor/github.com/json-iterator/go/stream.go b/vendor/github.com/json-iterator/go/stream.go
deleted file mode 100644
index 17662fd..0000000
--- a/vendor/github.com/json-iterator/go/stream.go
+++ /dev/null
@@ -1,211 +0,0 @@
-package jsoniter
-
-import (
- "io"
-)
-
-// stream is a io.Writer like object, with JSON specific write functions.
-// Error is not returned as return value, but stored as Error member on this stream instance.
-type Stream struct {
- cfg *frozenConfig
- out io.Writer
- buf []byte
- Error error
- indention int
- Attachment interface{} // open for customized encoder
-}
-
-// NewStream create new stream instance.
-// cfg can be jsoniter.ConfigDefault.
-// out can be nil if write to internal buffer.
-// bufSize is the initial size for the internal buffer in bytes.
-func NewStream(cfg API, out io.Writer, bufSize int) *Stream {
- return &Stream{
- cfg: cfg.(*frozenConfig),
- out: out,
- buf: make([]byte, 0, bufSize),
- Error: nil,
- indention: 0,
- }
-}
-
-// Pool returns a pool can provide more stream with same configuration
-func (stream *Stream) Pool() StreamPool {
- return stream.cfg
-}
-
-// Reset reuse this stream instance by assign a new writer
-func (stream *Stream) Reset(out io.Writer) {
- stream.out = out
- stream.buf = stream.buf[:0]
-}
-
-// Available returns how many bytes are unused in the buffer.
-func (stream *Stream) Available() int {
- return cap(stream.buf) - len(stream.buf)
-}
-
-// Buffered returns the number of bytes that have been written into the current buffer.
-func (stream *Stream) Buffered() int {
- return len(stream.buf)
-}
-
-// Buffer if writer is nil, use this method to take the result
-func (stream *Stream) Buffer() []byte {
- return stream.buf
-}
-
-// SetBuffer allows to append to the internal buffer directly
-func (stream *Stream) SetBuffer(buf []byte) {
- stream.buf = buf
-}
-
-// Write writes the contents of p into the buffer.
-// It returns the number of bytes written.
-// If nn < len(p), it also returns an error explaining
-// why the write is short.
-func (stream *Stream) Write(p []byte) (nn int, err error) {
- stream.buf = append(stream.buf, p...)
- if stream.out != nil {
- nn, err = stream.out.Write(stream.buf)
- stream.buf = stream.buf[nn:]
- return
- }
- return len(p), nil
-}
-
-// WriteByte writes a single byte.
-func (stream *Stream) writeByte(c byte) {
- stream.buf = append(stream.buf, c)
-}
-
-func (stream *Stream) writeTwoBytes(c1 byte, c2 byte) {
- stream.buf = append(stream.buf, c1, c2)
-}
-
-func (stream *Stream) writeThreeBytes(c1 byte, c2 byte, c3 byte) {
- stream.buf = append(stream.buf, c1, c2, c3)
-}
-
-func (stream *Stream) writeFourBytes(c1 byte, c2 byte, c3 byte, c4 byte) {
- stream.buf = append(stream.buf, c1, c2, c3, c4)
-}
-
-func (stream *Stream) writeFiveBytes(c1 byte, c2 byte, c3 byte, c4 byte, c5 byte) {
- stream.buf = append(stream.buf, c1, c2, c3, c4, c5)
-}
-
-// Flush writes any buffered data to the underlying io.Writer.
-func (stream *Stream) Flush() error {
- if stream.out == nil {
- return nil
- }
- if stream.Error != nil {
- return stream.Error
- }
- n, err := stream.out.Write(stream.buf)
- if err != nil {
- if stream.Error == nil {
- stream.Error = err
- }
- return err
- }
- stream.buf = stream.buf[n:]
- return nil
-}
-
-// WriteRaw write string out without quotes, just like []byte
-func (stream *Stream) WriteRaw(s string) {
- stream.buf = append(stream.buf, s...)
-}
-
-// WriteNil write null to stream
-func (stream *Stream) WriteNil() {
- stream.writeFourBytes('n', 'u', 'l', 'l')
-}
-
-// WriteTrue write true to stream
-func (stream *Stream) WriteTrue() {
- stream.writeFourBytes('t', 'r', 'u', 'e')
-}
-
-// WriteFalse write false to stream
-func (stream *Stream) WriteFalse() {
- stream.writeFiveBytes('f', 'a', 'l', 's', 'e')
-}
-
-// WriteBool write true or false into stream
-func (stream *Stream) WriteBool(val bool) {
- if val {
- stream.WriteTrue()
- } else {
- stream.WriteFalse()
- }
-}
-
-// WriteObjectStart write { with possible indention
-func (stream *Stream) WriteObjectStart() {
- stream.indention += stream.cfg.indentionStep
- stream.writeByte('{')
- stream.writeIndention(0)
-}
-
-// WriteObjectField write "field": with possible indention
-func (stream *Stream) WriteObjectField(field string) {
- stream.WriteString(field)
- if stream.indention > 0 {
- stream.writeTwoBytes(':', ' ')
- } else {
- stream.writeByte(':')
- }
-}
-
-// WriteObjectEnd write } with possible indention
-func (stream *Stream) WriteObjectEnd() {
- stream.writeIndention(stream.cfg.indentionStep)
- stream.indention -= stream.cfg.indentionStep
- stream.writeByte('}')
-}
-
-// WriteEmptyObject write {}
-func (stream *Stream) WriteEmptyObject() {
- stream.writeByte('{')
- stream.writeByte('}')
-}
-
-// WriteMore write , with possible indention
-func (stream *Stream) WriteMore() {
- stream.writeByte(',')
- stream.writeIndention(0)
- stream.Flush()
-}
-
-// WriteArrayStart write [ with possible indention
-func (stream *Stream) WriteArrayStart() {
- stream.indention += stream.cfg.indentionStep
- stream.writeByte('[')
- stream.writeIndention(0)
-}
-
-// WriteEmptyArray write []
-func (stream *Stream) WriteEmptyArray() {
- stream.writeTwoBytes('[', ']')
-}
-
-// WriteArrayEnd write ] with possible indention
-func (stream *Stream) WriteArrayEnd() {
- stream.writeIndention(stream.cfg.indentionStep)
- stream.indention -= stream.cfg.indentionStep
- stream.writeByte(']')
-}
-
-func (stream *Stream) writeIndention(delta int) {
- if stream.indention == 0 {
- return
- }
- stream.writeByte('\n')
- toWrite := stream.indention - delta
- for i := 0; i < toWrite; i++ {
- stream.buf = append(stream.buf, ' ')
- }
-}
diff --git a/vendor/github.com/json-iterator/go/stream_float.go b/vendor/github.com/json-iterator/go/stream_float.go
deleted file mode 100644
index f318d2c..0000000
--- a/vendor/github.com/json-iterator/go/stream_float.go
+++ /dev/null
@@ -1,94 +0,0 @@
-package jsoniter
-
-import (
- "math"
- "strconv"
-)
-
-var pow10 []uint64
-
-func init() {
- pow10 = []uint64{1, 10, 100, 1000, 10000, 100000, 1000000}
-}
-
-// WriteFloat32 write float32 to stream
-func (stream *Stream) WriteFloat32(val float32) {
- abs := math.Abs(float64(val))
- fmt := byte('f')
- // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right.
- if abs != 0 {
- if float32(abs) < 1e-6 || float32(abs) >= 1e21 {
- fmt = 'e'
- }
- }
- stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 32)
-}
-
-// WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster
-func (stream *Stream) WriteFloat32Lossy(val float32) {
- if val < 0 {
- stream.writeByte('-')
- val = -val
- }
- if val > 0x4ffffff {
- stream.WriteFloat32(val)
- return
- }
- precision := 6
- exp := uint64(1000000) // 6
- lval := uint64(float64(val)*float64(exp) + 0.5)
- stream.WriteUint64(lval / exp)
- fval := lval % exp
- if fval == 0 {
- return
- }
- stream.writeByte('.')
- for p := precision - 1; p > 0 && fval < pow10[p]; p-- {
- stream.writeByte('0')
- }
- stream.WriteUint64(fval)
- for stream.buf[len(stream.buf)-1] == '0' {
- stream.buf = stream.buf[:len(stream.buf)-1]
- }
-}
-
-// WriteFloat64 write float64 to stream
-func (stream *Stream) WriteFloat64(val float64) {
- abs := math.Abs(val)
- fmt := byte('f')
- // Note: Must use float32 comparisons for underlying float32 value to get precise cutoffs right.
- if abs != 0 {
- if abs < 1e-6 || abs >= 1e21 {
- fmt = 'e'
- }
- }
- stream.buf = strconv.AppendFloat(stream.buf, float64(val), fmt, -1, 64)
-}
-
-// WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster
-func (stream *Stream) WriteFloat64Lossy(val float64) {
- if val < 0 {
- stream.writeByte('-')
- val = -val
- }
- if val > 0x4ffffff {
- stream.WriteFloat64(val)
- return
- }
- precision := 6
- exp := uint64(1000000) // 6
- lval := uint64(val*float64(exp) + 0.5)
- stream.WriteUint64(lval / exp)
- fval := lval % exp
- if fval == 0 {
- return
- }
- stream.writeByte('.')
- for p := precision - 1; p > 0 && fval < pow10[p]; p-- {
- stream.writeByte('0')
- }
- stream.WriteUint64(fval)
- for stream.buf[len(stream.buf)-1] == '0' {
- stream.buf = stream.buf[:len(stream.buf)-1]
- }
-}
diff --git a/vendor/github.com/json-iterator/go/stream_int.go b/vendor/github.com/json-iterator/go/stream_int.go
deleted file mode 100644
index d1059ee..0000000
--- a/vendor/github.com/json-iterator/go/stream_int.go
+++ /dev/null
@@ -1,190 +0,0 @@
-package jsoniter
-
-var digits []uint32
-
-func init() {
- digits = make([]uint32, 1000)
- for i := uint32(0); i < 1000; i++ {
- digits[i] = (((i / 100) + '0') << 16) + ((((i / 10) % 10) + '0') << 8) + i%10 + '0'
- if i < 10 {
- digits[i] += 2 << 24
- } else if i < 100 {
- digits[i] += 1 << 24
- }
- }
-}
-
-func writeFirstBuf(space []byte, v uint32) []byte {
- start := v >> 24
- if start == 0 {
- space = append(space, byte(v>>16), byte(v>>8))
- } else if start == 1 {
- space = append(space, byte(v>>8))
- }
- space = append(space, byte(v))
- return space
-}
-
-func writeBuf(buf []byte, v uint32) []byte {
- return append(buf, byte(v>>16), byte(v>>8), byte(v))
-}
-
-// WriteUint8 write uint8 to stream
-func (stream *Stream) WriteUint8(val uint8) {
- stream.buf = writeFirstBuf(stream.buf, digits[val])
-}
-
-// WriteInt8 write int8 to stream
-func (stream *Stream) WriteInt8(nval int8) {
- var val uint8
- if nval < 0 {
- val = uint8(-nval)
- stream.buf = append(stream.buf, '-')
- } else {
- val = uint8(nval)
- }
- stream.buf = writeFirstBuf(stream.buf, digits[val])
-}
-
-// WriteUint16 write uint16 to stream
-func (stream *Stream) WriteUint16(val uint16) {
- q1 := val / 1000
- if q1 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[val])
- return
- }
- r1 := val - q1*1000
- stream.buf = writeFirstBuf(stream.buf, digits[q1])
- stream.buf = writeBuf(stream.buf, digits[r1])
- return
-}
-
-// WriteInt16 write int16 to stream
-func (stream *Stream) WriteInt16(nval int16) {
- var val uint16
- if nval < 0 {
- val = uint16(-nval)
- stream.buf = append(stream.buf, '-')
- } else {
- val = uint16(nval)
- }
- stream.WriteUint16(val)
-}
-
-// WriteUint32 write uint32 to stream
-func (stream *Stream) WriteUint32(val uint32) {
- q1 := val / 1000
- if q1 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[val])
- return
- }
- r1 := val - q1*1000
- q2 := q1 / 1000
- if q2 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[q1])
- stream.buf = writeBuf(stream.buf, digits[r1])
- return
- }
- r2 := q1 - q2*1000
- q3 := q2 / 1000
- if q3 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[q2])
- } else {
- r3 := q2 - q3*1000
- stream.buf = append(stream.buf, byte(q3+'0'))
- stream.buf = writeBuf(stream.buf, digits[r3])
- }
- stream.buf = writeBuf(stream.buf, digits[r2])
- stream.buf = writeBuf(stream.buf, digits[r1])
-}
-
-// WriteInt32 write int32 to stream
-func (stream *Stream) WriteInt32(nval int32) {
- var val uint32
- if nval < 0 {
- val = uint32(-nval)
- stream.buf = append(stream.buf, '-')
- } else {
- val = uint32(nval)
- }
- stream.WriteUint32(val)
-}
-
-// WriteUint64 write uint64 to stream
-func (stream *Stream) WriteUint64(val uint64) {
- q1 := val / 1000
- if q1 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[val])
- return
- }
- r1 := val - q1*1000
- q2 := q1 / 1000
- if q2 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[q1])
- stream.buf = writeBuf(stream.buf, digits[r1])
- return
- }
- r2 := q1 - q2*1000
- q3 := q2 / 1000
- if q3 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[q2])
- stream.buf = writeBuf(stream.buf, digits[r2])
- stream.buf = writeBuf(stream.buf, digits[r1])
- return
- }
- r3 := q2 - q3*1000
- q4 := q3 / 1000
- if q4 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[q3])
- stream.buf = writeBuf(stream.buf, digits[r3])
- stream.buf = writeBuf(stream.buf, digits[r2])
- stream.buf = writeBuf(stream.buf, digits[r1])
- return
- }
- r4 := q3 - q4*1000
- q5 := q4 / 1000
- if q5 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[q4])
- stream.buf = writeBuf(stream.buf, digits[r4])
- stream.buf = writeBuf(stream.buf, digits[r3])
- stream.buf = writeBuf(stream.buf, digits[r2])
- stream.buf = writeBuf(stream.buf, digits[r1])
- return
- }
- r5 := q4 - q5*1000
- q6 := q5 / 1000
- if q6 == 0 {
- stream.buf = writeFirstBuf(stream.buf, digits[q5])
- } else {
- stream.buf = writeFirstBuf(stream.buf, digits[q6])
- r6 := q5 - q6*1000
- stream.buf = writeBuf(stream.buf, digits[r6])
- }
- stream.buf = writeBuf(stream.buf, digits[r5])
- stream.buf = writeBuf(stream.buf, digits[r4])
- stream.buf = writeBuf(stream.buf, digits[r3])
- stream.buf = writeBuf(stream.buf, digits[r2])
- stream.buf = writeBuf(stream.buf, digits[r1])
-}
-
-// WriteInt64 write int64 to stream
-func (stream *Stream) WriteInt64(nval int64) {
- var val uint64
- if nval < 0 {
- val = uint64(-nval)
- stream.buf = append(stream.buf, '-')
- } else {
- val = uint64(nval)
- }
- stream.WriteUint64(val)
-}
-
-// WriteInt write int to stream
-func (stream *Stream) WriteInt(val int) {
- stream.WriteInt64(int64(val))
-}
-
-// WriteUint write uint to stream
-func (stream *Stream) WriteUint(val uint) {
- stream.WriteUint64(uint64(val))
-}
diff --git a/vendor/github.com/json-iterator/go/stream_str.go b/vendor/github.com/json-iterator/go/stream_str.go
deleted file mode 100644
index 54c2ba0..0000000
--- a/vendor/github.com/json-iterator/go/stream_str.go
+++ /dev/null
@@ -1,372 +0,0 @@
-package jsoniter
-
-import (
- "unicode/utf8"
-)
-
-// htmlSafeSet holds the value true if the ASCII character with the given
-// array position can be safely represented inside a JSON string, embedded
-// inside of HTML " that closes the next token. If
- // non-empty, the subsequent call to Next will return a raw or RCDATA text
- // token: one that treats "
" as text instead of an element.
- // rawTag's contents are lower-cased.
- rawTag string
- // textIsRaw is whether the current text token's data is not escaped.
- textIsRaw bool
- // convertNUL is whether NUL bytes in the current token's data should
- // be converted into \ufffd replacement characters.
- convertNUL bool
- // allowCDATA is whether CDATA sections are allowed in the current context.
- allowCDATA bool
-}
-
-// AllowCDATA sets whether or not the tokenizer recognizes as
-// the text "foo". The default value is false, which means to recognize it as
-// a bogus comment "" instead.
-//
-// Strictly speaking, an HTML5 compliant tokenizer should allow CDATA if and
-// only if tokenizing foreign content, such as MathML and SVG. However,
-// tracking foreign-contentness is difficult to do purely in the tokenizer,
-// as opposed to the parser, due to HTML integration points: an