diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d46c5400 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +.data \ No newline at end of file diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index cff67273..00000000 --- a/Gopkg.lock +++ /dev/null @@ -1,121 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/aliyun/alibaba-cloud-sdk-go" - packages = [ - "sdk", - "sdk/auth", - "sdk/auth/credentials", - "sdk/auth/credentials/provider", - "sdk/auth/signers", - "sdk/endpoints", - "sdk/errors", - "sdk/requests", - "sdk/responses", - "sdk/utils", - "services/kms" - ] - revision = "e6958b522d6f315a3585561bca1f87f6a41fd0c3" - -[[projects]] - branch = "master" - name = "github.com/buger/jsonparser" - packages = ["."] - revision = "bf1c66bbce23153d89b23f8960071a680dbef54b" - -[[projects]] - name = "github.com/davecgh/go-spew" - packages = ["spew"] - revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" - version = "v1.1.1" - -[[projects]] - name = "github.com/go-errors/errors" - packages = ["."] - revision = "a6af135bd4e28680facf08a3d206b454abc877a4" - version = "v1.0.1" - -[[projects]] - name = "github.com/golang/mock" - packages = ["gomock"] - revision = "9fa652df1129bef0e734c9cf9bf6dbae9ef3b9fa" - version = "1.3.1" - -[[projects]] - name = "github.com/jmespath/go-jmespath" - packages = ["."] - revision = "c2b33e84" - -[[projects]] - name = "github.com/json-iterator/go" - packages = ["."] - revision = "0ff49de124c6f76f8494e194af75bde0f1a49a29" - version = "v1.1.6" - -[[projects]] - branch = "master" - name = "github.com/lestrrat/go-file-rotatelogs" - packages = ["."] - revision = "d3151e2a480fdcd05fb97102f5310a47d96274c4" - -[[projects]] - branch = "master" - name = "github.com/lestrrat/go-strftime" - packages = ["."] - revision = "ba3bf9c1d0421aa146564a632931730344f1f9f1" - -[[projects]] - name = "github.com/modern-go/concurrent" - packages = ["."] - revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" - version = "1.0.3" - -[[projects]] - name = "github.com/modern-go/reflect2" - packages = ["."] - revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" - version = "1.0.1" - -[[projects]] - name = "github.com/pkg/errors" - packages = ["."] - revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4" - version = "v0.8.1" - -[[projects]] - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - name = "github.com/satori/go.uuid" - packages = ["."] - revision = "f58768cc1a7a7e77a3bd49e98cdd21419399b6a3" - version = "v1.2.0" - -[[projects]] - name = "github.com/stretchr/testify" - packages = ["assert"] - revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" - version = "v1.3.0" - -[[projects]] - branch = "master" - name = "github.com/toolkits/concurrent" - packages = ["semaphore"] - revision = "a4371d70e3e308db0d5f90c2b1f5efaa84add725" - -[[projects]] - name = "gopkg.in/ini.v1" - packages = ["."] - revision = "8659100d2d9ecf3760a41838b1886db49426d001" - version = "v1.44.0" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "5f9193892ff6610740b5d7993fe17737c26a52df0ed97a9ed0d4b662aa71455e" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 2a3873d4..00000000 --- a/Gopkg.toml +++ /dev/null @@ -1,58 +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" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[[constraint]] - branch = "master" - name = "github.com/buger/jsonparser" - -[[constraint]] - name = "github.com/go-errors/errors" - version = "1.0.1" - -[[constraint]] - name = "github.com/golang/mock" - version = "1.3.1" - -[[constraint]] - name = "github.com/pkg/errors" - version = "0.8.1" - -[[constraint]] - name = "github.com/stretchr/testify" - version = "1.3.0" - -[[constraint]] - branch = "master" - name = "github.com/toolkits/concurrent" - -[[constraint]] - name = "github.com/aliyun/alibaba-cloud-sdk-go" - revision = "e6958b522d6f315a3585561bca1f87f6a41fd0c3" - -[prune] - go-tests = true - unused-packages = true diff --git a/clients/client_factory.go b/clients/client_factory.go index 41a0318c..45bad9fa 100644 --- a/clients/client_factory.go +++ b/clients/client_factory.go @@ -50,7 +50,7 @@ func setConfig(properties map[string]interface{}) (iClient nacos_client.INacosCl if clientConfig, ok := clientConfigTmp.(constant.ClientConfig); ok { err = client.SetClientConfig(clientConfig) if err != nil { - return + return nil, err } } } else { @@ -65,7 +65,7 @@ func setConfig(properties map[string]interface{}) (iClient nacos_client.INacosCl if serverConfigs, ok := serverConfigTmp.([]constant.ServerConfig); ok { err = client.SetServerConfig(serverConfigs) if err != nil { - return + return nil, err } } } else { diff --git a/clients/config_client/config_client_test.go b/clients/config_client/config_client_test.go index e73a627c..d46ee00c 100644 --- a/clients/config_client/config_client_test.go +++ b/clients/config_client/config_client_test.go @@ -144,7 +144,7 @@ func Test_GetConfigWithErrorResponse_401(t *testing.T) { gomock.AssignableToTypeOf(http.Header{}), gomock.Eq(clientConfigTest.TimeoutMs), gomock.Eq(configParamMapTest), - ).Times(3).Return(http_agent.FakeHttpResponse(401, "no auth"), nil) + ).Times(3).Return(http_agent.FakeHttpResponse(401, "no security"), nil) result, err := client.GetConfig(configParamTest) assert.Nil(t, err) fmt.Printf("result:%s \n", result) @@ -206,7 +206,7 @@ func Test_GetConfigWithCache(t *testing.T) { gomock.AssignableToTypeOf(http.Header{}), gomock.Eq(clientConfigTest.TimeoutMs), gomock.Eq(configParamMapTest), - ).Times(3).Return(http_agent.FakeHttpResponse(401, "no auth"), nil) + ).Times(3).Return(http_agent.FakeHttpResponse(401, "no security"), nil) content, err = client.GetConfig(configParamTest) assert.Nil(t, err) assert.Equal(t, "content", content) @@ -268,7 +268,7 @@ func Test_PublishConfigWithErrorResponse(t *testing.T) { gomock.AssignableToTypeOf(http.Header{}), gomock.Eq(clientConfigTest.TimeoutMs), gomock.Eq(localConfigMapTest), - ).Times(3).Return(http_agent.FakeHttpResponse(401, "no auth"), nil) + ).Times(3).Return(http_agent.FakeHttpResponse(401, "no security"), nil) success, err := client.PublishConfig(localConfigTest) assert.NotNil(t, err) assert.True(t, !success) @@ -343,7 +343,7 @@ func Test_DeleteConfigWithErrorResponse_401(t *testing.T) { gomock.AssignableToTypeOf(http.Header{}), gomock.Eq(clientConfigTest.TimeoutMs), gomock.Eq(configParamMapTest), - ).Times(3).Return(http_agent.FakeHttpResponse(401, "no auth"), nil) + ).Times(3).Return(http_agent.FakeHttpResponse(401, "no security"), nil) success, err := client.DeleteConfig(configParamTest) assert.NotNil(t, err) assert.Equal(t, false, success) @@ -581,7 +581,7 @@ func Test_listenWithErrorResponse_401(t *testing.T) { gomock.AssignableToTypeOf(headerTest), gomock.Eq(clientConfigTest.TimeoutMs), gomock.Eq(param), - ).Times(1).Return(http_agent.FakeHttpResponse(401, "no auth"), nil) + ).Times(1).Return(http_agent.FakeHttpResponse(401, "no security"), nil) _ = client.SetHttpAgent(mockHttpAgent) diff --git a/clients/config_client/config_proxy.go b/clients/config_client/config_proxy.go index f09053cd..acde591d 100644 --- a/clients/config_client/config_proxy.go +++ b/clients/config_client/config_proxy.go @@ -18,7 +18,7 @@ type ConfigProxy struct { func NewConfigProxy(serverConfig []constant.ServerConfig, clientConfig constant.ClientConfig, httpAgent http_agent.IHttpAgent) (ConfigProxy, error) { proxy := ConfigProxy{} var err error - proxy.nacosServer, err = nacos_server.NewNacosServer(serverConfig, httpAgent, clientConfig.TimeoutMs, clientConfig.Endpoint) + proxy.nacosServer, err = nacos_server.NewNacosServer(serverConfig, clientConfig, httpAgent, clientConfig.TimeoutMs, clientConfig.Endpoint) return proxy, err } diff --git a/clients/naming_client/host_reator.go b/clients/naming_client/host_reator.go index b391a01b..a8563a2e 100644 --- a/clients/naming_client/host_reator.go +++ b/clients/naming_client/host_reator.go @@ -5,7 +5,6 @@ import ( "github.com/nacos-group/nacos-sdk-go/clients/cache" "github.com/nacos-group/nacos-sdk-go/model" "github.com/nacos-group/nacos-sdk-go/utils" - nsema "github.com/toolkits/concurrent/semaphore" "log" "reflect" "time" @@ -131,7 +130,7 @@ func (hr *HostReactor) updateServiceNow(serviceName string, clusters string) { } func (hr *HostReactor) asyncUpdateService() { - sema := nsema.NewSemaphore(hr.updateThreadNum) + sema := utils.NewSemaphore(hr.updateThreadNum) for { for _, v := range hr.serviceInfoMap.Items() { service := v.(model.Service) diff --git a/clients/naming_client/naming_client_test.go b/clients/naming_client/naming_client_test.go index 1b375365..9fa21bea 100644 --- a/clients/naming_client/naming_client_test.go +++ b/clients/naming_client/naming_client_test.go @@ -46,9 +46,9 @@ func Test_RegisterServiceInstance_withoutGroupeName(t *testing.T) { mockIHttpAgent.EXPECT().Request(gomock.Eq("POST"), gomock.Eq("http://console.nacos.io:80/nacos/v1/ns/instance"), gomock.AssignableToTypeOf(http.Header{}), - gomock.Eq(uint64(20*1000)), + gomock.Eq(uint64(10*1000)), gomock.Eq(map[string]string{ - "namespaceId": "public", + "namespaceId": "", "serviceName": "DEFAULT_GROUP@@DEMO", "groupName": "DEFAULT_GROUP", "clusterName": "", @@ -71,6 +71,7 @@ func Test_RegisterServiceInstance_withoutGroupeName(t *testing.T) { ServiceName: "DEMO", Ip: "10.0.0.10", Port: 80, + Ephemeral: true, }) assert.Equal(t, nil, err) assert.Equal(t, true, success) @@ -112,6 +113,7 @@ func Test_RegisterServiceInstance_withGroupeName(t *testing.T) { Ip: "10.0.0.10", Port: 80, GroupName: "test_group", + Ephemeral: true, }) assert.Equal(t, nil, err) assert.Equal(t, true, success) @@ -127,9 +129,9 @@ func Test_RegisterServiceInstance_withCluster(t *testing.T) { mockIHttpAgent.EXPECT().Request(gomock.Eq("POST"), gomock.Eq("http://console.nacos.io:80/nacos/v1/ns/instance"), gomock.AssignableToTypeOf(http.Header{}), - gomock.Eq(uint64(20*1000)), + gomock.Eq(uint64(10*1000)), gomock.Eq(map[string]string{ - "namespaceId": "public", + "namespaceId": "", "serviceName": "test_group@@DEMO", "groupName": "test_group", "clusterName": "test", @@ -154,6 +156,7 @@ func Test_RegisterServiceInstance_withCluster(t *testing.T) { Port: 80, GroupName: "test_group", ClusterName: "test", + Ephemeral: true, }) assert.Equal(t, nil, err) assert.Equal(t, true, success) @@ -169,9 +172,9 @@ func Test_RegisterServiceInstance_401(t *testing.T) { mockIHttpAgent.EXPECT().Request(gomock.Eq("POST"), gomock.Eq("http://console.nacos.io:80/nacos/v1/ns/instance"), gomock.AssignableToTypeOf(http.Header{}), - gomock.Eq(uint64(20*1000)), + gomock.Eq(uint64(10*1000)), gomock.Eq(map[string]string{ - "namespaceId": "public", + "namespaceId": "", "serviceName": "test_group@@DEMO", "groupName": "test_group", "clusterName": "", @@ -183,7 +186,7 @@ func Test_RegisterServiceInstance_401(t *testing.T) { "metadata": "null", "ephemeral": "true", })).Times(3). - Return(http_agent.FakeHttpResponse(401, `no auth`), nil) + Return(http_agent.FakeHttpResponse(401, `no security`), nil) nc := nacos_client.NacosClient{} nc.SetServerConfig([]constant.ServerConfig{serverConfigTest}) @@ -195,6 +198,7 @@ func Test_RegisterServiceInstance_401(t *testing.T) { Ip: "10.0.0.10", Port: 80, GroupName: "test_group", + Ephemeral: true, }) assert.Equal(t, false, result) assert.NotNil(t, err) @@ -210,9 +214,9 @@ func TestNamingProxy_DeristerService_WithoutGroupName(t *testing.T) { mockIHttpAgent.EXPECT().Request(gomock.Eq("DELETE"), gomock.Eq("http://console.nacos.io:80/nacos/v1/ns/instance"), gomock.AssignableToTypeOf(http.Header{}), - gomock.Eq(uint64(20*1000)), + gomock.Eq(uint64(10*1000)), gomock.Eq(map[string]string{ - "namespaceId": "public", + "namespaceId": "", "serviceName": "DEFAULT_GROUP@@DEMO", "clusterName": "", "ip": "10.0.0.10", @@ -229,6 +233,7 @@ func TestNamingProxy_DeristerService_WithoutGroupName(t *testing.T) { ServiceName: "DEMO", Ip: "10.0.0.10", Port: 80, + Ephemeral: true, }) } @@ -242,9 +247,9 @@ func TestNamingProxy_DeristerService_WithGroupName(t *testing.T) { mockIHttpAgent.EXPECT().Request(gomock.Eq("DELETE"), gomock.Eq("http://console.nacos.io:80/nacos/v1/ns/instance"), gomock.AssignableToTypeOf(http.Header{}), - gomock.Eq(uint64(20*1000)), + gomock.Eq(uint64(10*1000)), gomock.Eq(map[string]string{ - "namespaceId": "public", + "namespaceId": "", "serviceName": "test_group@@DEMO", "clusterName": "", "ip": "10.0.0.10", @@ -262,6 +267,7 @@ func TestNamingProxy_DeristerService_WithGroupName(t *testing.T) { Ip: "10.0.0.10", Port: 80, GroupName: "test_group", + Ephemeral: true, }) } @@ -275,16 +281,16 @@ func TestNamingProxy_DeristerService_401(t *testing.T) { mockIHttpAgent.EXPECT().Request(gomock.Eq("DELETE"), gomock.Eq("http://console.nacos.io:80/nacos/v1/ns/instance"), gomock.AssignableToTypeOf(http.Header{}), - gomock.Eq(uint64(20*1000)), + gomock.Eq(uint64(10*1000)), gomock.Eq(map[string]string{ - "namespaceId": "public", + "namespaceId": "", "serviceName": "test_group@@DEMO", "clusterName": "", "ip": "10.0.0.10", "port": "80", "ephemeral": "true", })).Times(3). - Return(http_agent.FakeHttpResponse(401, `no auth`), nil) + Return(http_agent.FakeHttpResponse(401, `no security`), nil) nc := nacos_client.NacosClient{} nc.SetServerConfig([]constant.ServerConfig{serverConfigTest}) nc.SetClientConfig(clientConfigTest) @@ -295,6 +301,7 @@ func TestNamingProxy_DeristerService_401(t *testing.T) { Ip: "10.0.0.10", Port: 80, GroupName: "test_group", + Ephemeral: true, }) } @@ -374,7 +381,7 @@ func TestNamingProxy_GetService_WithoutGroupName(t *testing.T) { mockIHttpAgent.EXPECT().Request(gomock.Eq("GET"), gomock.Eq("http://console.nacos.io:80/nacos/v1/ns/instance/list"), gomock.AssignableToTypeOf(http.Header{}), - gomock.Eq(uint64(20*1000)), + gomock.Eq(uint64(10*1000)), gomock.Any()).Times(2). Return(http_agent.FakeHttpResponse(200, serviceJsonTest), nil) @@ -402,7 +409,7 @@ func TestNamingClient_SelectAllInstancs(t *testing.T) { mockIHttpAgent.EXPECT().Request(gomock.Eq("GET"), gomock.Eq("http://console.nacos.io:80/nacos/v1/ns/instance/list"), gomock.AssignableToTypeOf(http.Header{}), - gomock.Eq(uint64(20*1000)), + gomock.Eq(uint64(10*1000)), gomock.Any()).Times(2). Return(http_agent.FakeHttpResponse(200, serviceJsonTest), nil) diff --git a/clients/naming_client/naming_proxy.go b/clients/naming_client/naming_proxy.go index eeb9cf59..0e262614 100644 --- a/clients/naming_client/naming_proxy.go +++ b/clients/naming_client/naming_proxy.go @@ -15,18 +15,20 @@ import ( ) type NamingProxy struct { - clientConfig constant.ClientConfig - nacosServer nacos_server.NacosServer + clientConfig constant.ClientConfig + nacosServer nacos_server.NacosServer } func NewNamingProxy(clientCfg constant.ClientConfig, serverCfgs []constant.ServerConfig, httpAgent http_agent.IHttpAgent) (NamingProxy, error) { srvProxy := NamingProxy{} srvProxy.clientConfig = clientCfg + var err error - srvProxy.nacosServer, err = nacos_server.NewNacosServer(serverCfgs, httpAgent, clientCfg.TimeoutMs, clientCfg.Endpoint) + srvProxy.nacosServer, err = nacos_server.NewNacosServer(serverCfgs, clientCfg, httpAgent, clientCfg.TimeoutMs, clientCfg.Endpoint) if err != nil { return srvProxy, err } + return srvProxy, nil } @@ -164,3 +166,4 @@ func (proxy *NamingProxy) GetAllServiceInfoList(namespace string, groupName stri api := constant.SERVICE_INFO_PATH + "/getAll" return proxy.nacosServer.ReqApi(api, param, http.MethodGet) } + diff --git a/common/constant/config.go b/common/constant/config.go index e9d64967..a4215310 100644 --- a/common/constant/config.go +++ b/common/constant/config.go @@ -30,4 +30,6 @@ type ClientConfig struct { UpdateCacheWhenEmpty bool OpenKMS bool RegionId string + Username string + Password string } diff --git a/common/constant/const.go b/common/constant/const.go index 1c5d6673..bb34a4dd 100644 --- a/common/constant/const.go +++ b/common/constant/const.go @@ -10,6 +10,8 @@ package constant **/ const ( + KEY_USERNAME = "username" + KEY_PASSWORD = "password" KEY_ENDPOINT = "endpoint" KEY_NAME_SPACE = "namespace" KEY_ACCESS_KEY = "accessKey" @@ -27,6 +29,11 @@ const ( KEY_LISTEN_INTERVAL = "listenInterval" KEY_SERVER_CONFIGS = "serverConfigs" KEY_CLIENT_CONFIG = "clientConfig" + KEY_TOKEN = "token" + KEY_ACCESS_TOKEN = "accessToken" + KEY_TOKEN_TTL = "tokenTtl" + KEY_GLOBAL_ADMIN = "globalAdmin" + KEY_TOKEN_REFRESH_WINDOW = "tokenRefreshWindow" WEB_CONTEXT = "/nacos" CONFIG_BASE_PATH = "/v1/cs" CONFIG_PATH = CONFIG_BASE_PATH + "/configs" diff --git a/common/nacos_server/nacos_server.go b/common/nacos_server/nacos_server.go index 25b4732f..8350fc44 100644 --- a/common/nacos_server/nacos_server.go +++ b/common/nacos_server/nacos_server.go @@ -9,6 +9,7 @@ import ( "github.com/nacos-group/nacos-sdk-go/common/constant" "github.com/nacos-group/nacos-sdk-go/common/http_agent" "github.com/nacos-group/nacos-sdk-go/common/nacos_error" + "github.com/nacos-group/nacos-sdk-go/common/security" "github.com/nacos-group/nacos-sdk-go/utils" "github.com/satori/go.uuid" "io/ioutil" @@ -24,6 +25,7 @@ import ( type NacosServer struct { sync.RWMutex + securityLogin security.AuthClient serverList []constant.ServerConfig httpAgent http_agent.IHttpAgent timeoutMs uint64 @@ -32,18 +34,29 @@ type NacosServer struct { vipSrvRefInterMills int64 } -func NewNacosServer(serverList []constant.ServerConfig, httpAgent http_agent.IHttpAgent, timeoutMs uint64, endpoint string) (NacosServer, error) { +func NewNacosServer(serverList []constant.ServerConfig, clientCfg constant.ClientConfig, httpAgent http_agent.IHttpAgent, timeoutMs uint64, endpoint string) (NacosServer, error) { if len(serverList) == 0 && endpoint == "" { return NacosServer{}, errors.New("both serverlist and endpoint are empty") } + + securityLogin := security.NewAuthClient(clientCfg, serverList, httpAgent) + ns := NacosServer{ serverList: serverList, + securityLogin: securityLogin, httpAgent: httpAgent, timeoutMs: timeoutMs, endpoint: endpoint, vipSrvRefInterMills: 10000, } ns.initRefreshSrvIfNeed() + _, err := securityLogin.Login() + + if err != nil { + return ns, err + } + + securityLogin.AutoRefresh() return ns, nil } @@ -68,6 +81,8 @@ func (server *NacosServer) callConfigServer(api string, params map[string]string headers["Timestamp"] = []string{signHeaders["timeStamp"]} headers["Spas-Signature"] = []string{signHeaders["Spas-Signature"]} + injectSecurityInfo(server, params) + var response *http.Response response, err = server.httpAgent.Request(method, url, headers, server.timeoutMs, params) if err != nil { @@ -103,6 +118,8 @@ func (server *NacosServer) callServer(api string, params map[string]string, meth headers["Request-Module"] = []string{"Naming"} headers["Content-Type"] = []string{"application/x-www-form-urlencoded;charset=UTF8"} + injectSecurityInfo(server, params) + var response *http.Response response, err = server.httpAgent.Request(method, url, headers, server.timeoutMs, params) if err != nil { @@ -128,6 +145,9 @@ func (server *NacosServer) ReqConfigApi(api string, params map[string]string, he if srvs == nil || len(srvs) == 0 { return "", errors.New("server list is empty") } + + injectSecurityInfo(server, params) + //only one server,retry request when error var err error var result string @@ -160,6 +180,9 @@ func (server *NacosServer) ReqApi(api string, params map[string]string, method s if srvs == nil || len(srvs) == 0 { return "", errors.New("server list is empty") } + + injectSecurityInfo(server, params) + //only one server,retry request when error if len(srvs) == 1 { for i := 0; i < constant.REQUEST_DOMAIN_RETRY_TIME; i++ { @@ -242,6 +265,13 @@ func (server *NacosServer) GetServerList() []constant.ServerConfig { return server.serverList } +func injectSecurityInfo(server *NacosServer, param map[string]string) { + accessToken := server.securityLogin.GetAccessToken() + if accessToken != "" { + param[constant.KEY_ACCESS_TOKEN] = accessToken + } +} + func getAddress(cfg constant.ServerConfig) string { return cfg.IpAddr + ":" + strconv.Itoa(int(cfg.Port)) } diff --git a/common/security/security_proxy.go b/common/security/security_proxy.go new file mode 100644 index 00000000..aaf0373d --- /dev/null +++ b/common/security/security_proxy.go @@ -0,0 +1,146 @@ +package security + +import ( + "encoding/json" + "errors" + "github.com/nacos-group/nacos-sdk-go/common/constant" + "github.com/nacos-group/nacos-sdk-go/common/http_agent" + "io/ioutil" + "log" + "net/http" + "strconv" + "strings" + "sync/atomic" + "time" +) + +type AuthClient struct { + username string + password string + accessToken *atomic.Value + tokenTtl int64 + lastRefreshTime int64 + tokenRefreshWindow int64 + agent http_agent.IHttpAgent + clientCfg constant.ClientConfig + serverCfgs []constant.ServerConfig +} + +func NewAuthClient(clientCfg constant.ClientConfig, serverCfgs []constant.ServerConfig, agent http_agent.IHttpAgent) AuthClient { + client := AuthClient{ + username: clientCfg.Username, + password: clientCfg.Password, + serverCfgs: serverCfgs, + clientCfg: clientCfg, + agent: agent, + accessToken: &atomic.Value{}, + } + + return client +} + +func (ac *AuthClient) GetAccessToken() string { + v := ac.accessToken.Load() + if v == nil { + return "" + } + return v.(string) +} + +func (ac *AuthClient) AutoRefresh() { + + // If the username is not set, the automatic refresh Token is not enabled + + if ac.username == "" { + return + } + + go func() { + ticker := time.NewTicker(time.Millisecond * 5) + + for range ticker.C { + _, err := ac.Login() + if err != nil { + log.Printf("[ERROR]: login has error %s", err) + } + } + }() +} + +func (ac *AuthClient) Login() (bool, error) { + var throwable error = nil + for i := 0; i < len(ac.serverCfgs); i++ { + result, err := ac.login(ac.serverCfgs[i]) + throwable = err + if result { + return true, nil + } + } + return false, throwable +} + +func (ac *AuthClient) login(server constant.ServerConfig) (bool, error) { + if ac.username != "" { + query := map[string]string{"username": ac.username, "password": ac.password} + + contextPath := server.ContextPath + + if !strings.HasPrefix(contextPath, "/") { + contextPath = "/" + contextPath + } + + if strings.HasSuffix(contextPath, "/") { + contextPath = contextPath[0 : len(contextPath)-1] + } + + reqUrl := "http://" + server.IpAddr + ":" + strconv.FormatInt(int64(server.Port), 10) + contextPath + "/v1/auth/users/login" + + queryInfo := "" + + for key, value := range query { + if len(value) > 0 { + queryInfo += key + "=" + value + "&" + } + } + if strings.HasSuffix(queryInfo, "&") { + queryInfo = queryInfo[:len(queryInfo)-1] + } + + reqUrl += "?" + queryInfo + + header := http.Header{} + resp, err := ac.agent.Post(reqUrl, header, ac.clientCfg.TimeoutMs, map[string]string{}) + + if err != nil { + return false, err + } + + var bytes []byte + bytes, err = ioutil.ReadAll(resp.Body) + defer resp.Body.Close() + if err != nil { + return false, err + } + + if resp.StatusCode != 200 { + errMsg := string(bytes) + return false, errors.New(errMsg) + } + + var result map[string]interface{} + + err = json.Unmarshal(bytes, &result) + + if err != nil { + return false, err + } + + if val, ok := result[constant.KEY_ACCESS_TOKEN]; ok { + ac.accessToken.Store(val) + ac.tokenTtl = int64(result[constant.KEY_TOKEN_TTL].(float64)) + ac.lastRefreshTime = ac.tokenTtl / 10 + } + } + return true, nil + +} diff --git a/example/main/main.go b/example/main/main.go index b8397c0f..df6ff5f7 100644 --- a/example/main/main.go +++ b/example/main/main.go @@ -12,7 +12,7 @@ import ( ) func main() { - client, _ := clients.CreateNamingClient(map[string]interface{}{ + client, err := clients.CreateNamingClient(map[string]interface{}{ "serverConfigs": []constant.ServerConfig{ { IpAddr: "console.nacos.io", @@ -20,13 +20,19 @@ func main() { }, }, "clientConfig": constant.ClientConfig{ - TimeoutMs: 20000, + TimeoutMs: 5000, ListenInterval: 10000, NotLoadCacheAtStart: true, LogDir: "data/nacos/log", + Username: "nacos", + Password: "nacos", }, }) + if err != nil { + panic(err) + } + example.ExampleServiceClient_RegisterServiceInstance(client, vo.RegisterInstanceParam{ Ip: "10.0.0.11", Port: 8848, diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..32cf9d7f --- /dev/null +++ b/go.mod @@ -0,0 +1,22 @@ +module github.com/nacos-group/nacos-sdk-go + +go 1.12 + +require ( + github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 + github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 + github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239 // indirect + github.com/go-errors/errors v1.0.1 + github.com/golang/mock v1.3.1 + github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect + github.com/jonboulle/clockwork v0.1.0 // indirect + github.com/json-iterator/go v1.1.6 // indirect + github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570 // indirect + github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f + github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 // indirect + github.com/pkg/errors v0.9.1 + github.com/satori/go.uuid v1.2.0 + github.com/stretchr/testify v1.5.1 + github.com/tebeka/strftime v0.1.3 // indirect + github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3 +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..905893a9 --- /dev/null +++ b/go.sum @@ -0,0 +1,69 @@ +github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 h1:zOVTBdCKFd9JbCKz9/nt+FovbjPFmb7mUnp8nH9fQBA= +github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDHxfTGEciD+yhvOU/5s1Rfk= +github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 h1:D21IyuvjDCshj1/qq+pCNd3VZOAEI9jy6Bi131YlXgI= +github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= +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/fastly/go-utils v0.0.0-20180712184237-d95a45783239 h1:Ghm4eQYC0nEPnSJdVkTrXpu9KtoVCSo1hg7mtI7G9KU= +github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0yfBxPvZrHkprdPPTTS3N5rwmLE8T22KBXlw= +github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w= +github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= +github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= +github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4= +github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +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/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570 h1:0iQektZGS248WXmGIYOwRXSQhD4qn3icjMpuxwO7qlo= +github.com/lestrrat/go-envload v0.0.0-20180220120943-6ed08b54a570/go.mod h1:BLt8L9ld7wVsvEWQbuLrUZnCMnUmLZ+CGDzKtclrTlE= +github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f h1:sgUSP4zdTUZYZgAGGtN5Lxk92rK+JUFOwf+FT99EEI4= +github.com/lestrrat/go-file-rotatelogs v0.0.0-20180223000712-d3151e2a480f/go.mod h1:UGmTpUd3rjbtfIpwAPrcfmGf/Z1HS95TATB+m57TPB8= +github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042 h1:Bvq8AziQ5jFF4BHGAEDSqwPW1NJS3XshxbRCxtjFAZc= +github.com/lestrrat/go-strftime v0.0.0-20180220042222-ba3bf9c1d042/go.mod h1:TPpsiPUEh0zFL1Snz4crhMlBe60PYxRHr5oFF3rRYg0= +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 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.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/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs= +github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/tebeka/strftime v0.1.3 h1:5HQXOqWKYRFfNyBMNVc9z5+QzuBtIXy03psIhtdJYto= +github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ= +github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3 h1:kF/7m/ZU+0D4Jj5eZ41Zm3IH/J8OElK1Qtd7tVKAwLk= +github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3/go.mod h1:QDlpd3qS71vYtakd2hmdpqhJ9nwv6mD6A30bQ1BPBFE= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +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/ini.v1 v1.42.0 h1:7N3gPTt50s8GuLortA00n8AqRTk75qOP98+mTPpgzRk= +gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +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/toolkits/concurrent/semaphore/semaphore.go b/utils/semaphore.go similarity index 94% rename from vendor/github.com/toolkits/concurrent/semaphore/semaphore.go rename to utils/semaphore.go index a760bc37..2f48de34 100644 --- a/vendor/github.com/toolkits/concurrent/semaphore/semaphore.go +++ b/utils/semaphore.go @@ -1,6 +1,4 @@ -package semaphore - -import () +package utils type Semaphore struct { bufSize int diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/LICENSE b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/LICENSE deleted file mode 100644 index 261eeb9e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/LICENSE +++ /dev/null @@ -1,201 +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. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credential.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credential.go deleted file mode 100644 index 7f20b7a4..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credential.go +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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 auth - -type Credential interface { -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/access_key_credential.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/access_key_credential.go deleted file mode 100644 index 68f82263..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/access_key_credential.go +++ /dev/null @@ -1,34 +0,0 @@ -package credentials - -// Deprecated: Use AccessKeyCredential in this package instead. -type BaseCredential struct { - AccessKeyId string - AccessKeySecret string -} - -type AccessKeyCredential struct { - AccessKeyId string - AccessKeySecret string -} - -// Deprecated: Use NewAccessKeyCredential in this package instead. -func NewBaseCredential(accessKeyId, accessKeySecret string) *BaseCredential { - return &BaseCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - } -} - -func (baseCred *BaseCredential) ToAccessKeyCredential() *AccessKeyCredential { - return &AccessKeyCredential{ - AccessKeyId: baseCred.AccessKeyId, - AccessKeySecret: baseCred.AccessKeySecret, - } -} - -func NewAccessKeyCredential(accessKeyId, accessKeySecret string) *AccessKeyCredential { - return &AccessKeyCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/bearer_token_credential.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/bearer_token_credential.go deleted file mode 100644 index 6d4763e6..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/bearer_token_credential.go +++ /dev/null @@ -1,12 +0,0 @@ -package credentials - -type BearerTokenCredential struct { - BearerToken string -} - -// NewBearerTokenCredential return a BearerTokenCredential object -func NewBearerTokenCredential(token string) *BearerTokenCredential { - return &BearerTokenCredential{ - BearerToken: token, - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/ecs_ram_role.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/ecs_ram_role.go deleted file mode 100644 index 55a5c2da..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/ecs_ram_role.go +++ /dev/null @@ -1,29 +0,0 @@ -package credentials - -func (oldCred *StsRoleNameOnEcsCredential) ToEcsRamRoleCredential() *EcsRamRoleCredential { - return &EcsRamRoleCredential{ - RoleName: oldCred.RoleName, - } -} - -type EcsRamRoleCredential struct { - RoleName string -} - -func NewEcsRamRoleCredential(roleName string) *EcsRamRoleCredential { - return &EcsRamRoleCredential{ - RoleName: roleName, - } -} - -// Deprecated: Use EcsRamRoleCredential in this package instead. -type StsRoleNameOnEcsCredential struct { - RoleName string -} - -// Deprecated: Use NewEcsRamRoleCredential in this package instead. -func NewStsRoleNameOnEcsCredential(roleName string) *StsRoleNameOnEcsCredential { - return &StsRoleNameOnEcsCredential{ - RoleName: roleName, - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/env.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/env.go deleted file mode 100644 index 3cd0d020..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/env.go +++ /dev/null @@ -1,30 +0,0 @@ -package provider - -import ( - "errors" - "os" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth" -) - -type EnvProvider struct{} - -var ProviderEnv = new(EnvProvider) - -func NewEnvProvider() Provider { - return &EnvProvider{} -} - -func (p *EnvProvider) Resolve() (auth.Credential, error) { - accessKeyID, ok1 := os.LookupEnv(ENVAccessKeyID) - accessKeySecret, ok2 := os.LookupEnv(ENVAccessKeySecret) - if !ok1 || !ok2 { - return nil, nil - } - if accessKeyID == "" || accessKeySecret == "" { - return nil, errors.New("Environmental variable (ALIBABACLOUD_ACCESS_KEY_ID or ALIBABACLOUD_ACCESS_KEY_SECRET) is empty") - } - return credentials.NewAccessKeyCredential(accessKeyID, accessKeySecret), nil -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/instance_credentials.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/instance_credentials.go deleted file mode 100644 index 1906d21f..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/instance_credentials.go +++ /dev/null @@ -1,92 +0,0 @@ -package provider - -import ( - "encoding/json" - "errors" - "fmt" - "io/ioutil" - "net/http" - "os" - "time" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" -) - -var securityCredURL = "http://100.100.100.200/latest/meta-data/ram/security-credentials/" - -type InstanceCredentialsProvider struct{} - -var ProviderInstance = new(InstanceCredentialsProvider) - -var HookGet = func(fn func(string) (int, []byte, error)) func(string) (int, []byte, error) { - return fn -} - -func NewInstanceCredentialsProvider() Provider { - return &InstanceCredentialsProvider{} -} - -func (p *InstanceCredentialsProvider) Resolve() (auth.Credential, error) { - roleName, ok := os.LookupEnv(ENVEcsMetadata) - if !ok { - return nil, nil - } - if roleName == "" { - return nil, errors.New("Environmental variable 'ALIBABA_CLOUD_ECS_METADATA' are empty") - } - status, content, err := HookGet(get)(securityCredURL + roleName) - if err != nil { - return nil, err - } - if status != 200 { - if status == 404 { - return nil, fmt.Errorf("The role was not found in the instance") - } - return nil, fmt.Errorf("Received %d when getting security credentials for %s", status, roleName) - } - body := make(map[string]interface{}) - - if err := json.Unmarshal(content, &body); err != nil { - return nil, err - } - - accessKeyID, err := extractString(body, "AccessKeyId") - if err != nil { - return nil, err - } - accessKeySecret, err := extractString(body, "AccessKeySecret") - if err != nil { - return nil, err - } - securityToken, err := extractString(body, "SecurityToken") - if err != nil { - return nil, err - } - - return credentials.NewStsTokenCredential(accessKeyID, accessKeySecret, securityToken), nil -} - -func get(url string) (status int, content []byte, err error) { - httpClient := http.DefaultClient - httpClient.Timeout = time.Second * 1 - resp, err := httpClient.Get(url) - if err != nil { - return - } - defer resp.Body.Close() - content, err = ioutil.ReadAll(resp.Body) - return resp.StatusCode, content, err -} - -func extractString(m map[string]interface{}, key string) (string, error) { - raw, ok := m[key] - if !ok { - return "", fmt.Errorf("%s not in map", key) - } - str, ok := raw.(string) - if !ok { - return "", fmt.Errorf("%s is not a string in map", key) - } - return str, nil -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/profile_credentials.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/profile_credentials.go deleted file mode 100644 index 8d525c37..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/profile_credentials.go +++ /dev/null @@ -1,158 +0,0 @@ -package provider - -import ( - "bufio" - "errors" - "os" - "runtime" - "strings" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" - - ini "gopkg.in/ini.v1" -) - -type ProfileProvider struct { - Profile string -} - -var ProviderProfile = NewProfileProvider() - -// NewProfileProvider receive zero or more parameters, -// when length of name is 0, the value of field Profile will be "default", -// and when there are multiple inputs, the function will take the -// first one and discard the other values. -func NewProfileProvider(name ...string) Provider { - p := new(ProfileProvider) - if len(name) == 0 { - p.Profile = "default" - } else { - p.Profile = name[0] - } - return p -} - -// Resolve implements the Provider interface -// when credential type is rsa_key_pair, the content of private_key file -// must be able to be parsed directly into the required string -// that NewRsaKeyPairCredential function needed -func (p *ProfileProvider) Resolve() (auth.Credential, error) { - path, ok := os.LookupEnv(ENVCredentialFile) - if !ok { - path, err := checkDefaultPath() - if err != nil { - return nil, err - } - if path == "" { - return nil, nil - } - } else if path == "" { - return nil, errors.New("Environment variable '" + ENVCredentialFile + "' cannot be empty") - } - - ini, err := ini.Load(path) - if err != nil { - return nil, errors.New("ERROR: Can not open file" + err.Error()) - } - - section, err := ini.GetSection(p.Profile) - if err != nil { - return nil, errors.New("ERROR: Can not load section" + err.Error()) - } - - value, err := section.GetKey("type") - if err != nil { - return nil, errors.New("ERROR: Can not find credential type" + err.Error()) - } - - switch value.String() { - case "access_key": - value1, err1 := section.GetKey("access_key_id") - value2, err2 := section.GetKey("access_key_secret") - if err1 != nil || err2 != nil { - return nil, errors.New("ERROR: Failed to get value") - } - if value1.String() == "" || value2.String() == "" { - return nil, errors.New("ERROR: Value can't be empty") - } - return credentials.NewAccessKeyCredential(value1.String(), value2.String()), nil - case "ecs_ram_role": - value1, err1 := section.GetKey("role_name") - if err1 != nil { - return nil, errors.New("ERROR: Failed to get value") - } - if value1.String() == "" { - return nil, errors.New("ERROR: Value can't be empty") - } - return credentials.NewEcsRamRoleCredential(value1.String()), nil - case "ram_role_arn": - value1, err1 := section.GetKey("access_key_id") - value2, err2 := section.GetKey("access_key_secret") - value3, err3 := section.GetKey("role_arn") - value4, err4 := section.GetKey("role_session_name") - if err1 != nil || err2 != nil || err3 != nil || err4 != nil { - return nil, errors.New("ERROR: Failed to get value") - } - if value1.String() == "" || value2.String() == "" || value3.String() == "" || value4.String() == "" { - return nil, errors.New("ERROR: Value can't be empty") - } - return credentials.NewRamRoleArnCredential(value1.String(), value2.String(), value3.String(), value4.String(), 3600), nil - case "rsa_key_pair": - value1, err1 := section.GetKey("public_key_id") - value2, err2 := section.GetKey("private_key_file") - if err1 != nil || err2 != nil { - return nil, errors.New("ERROR: Failed to get value") - } - if value1.String() == "" || value2.String() == "" { - return nil, errors.New("ERROR: Value can't be empty") - } - file, err := os.Open(value2.String()) - if err != nil { - return nil, errors.New("ERROR: Can not get private_key") - } - defer file.Close() - var privateKey string - scan := bufio.NewScanner(file) - var data string - for scan.Scan() { - if strings.HasPrefix(scan.Text(), "----") { - continue - } - data += scan.Text() + "\n" - } - return credentials.NewRsaKeyPairCredential(privateKey, value1.String(), 3600), nil - default: - return nil, errors.New("ERROR: Failed to get credential") - } -} - -// GetHomePath return home directory according to the system. -// if the environmental virables does not exist, will return empty -func GetHomePath() string { - if runtime.GOOS == "windows" { - path, ok := os.LookupEnv("USERPROFILE") - if !ok { - return "" - } - return path - } - path, ok := os.LookupEnv("HOME") - if !ok { - return "" - } - return path -} - -func checkDefaultPath() (path string, err error) { - path = GetHomePath() - if path == "" { - return "", errors.New("The default credential file path is invalid") - } - path = strings.Replace("~/.alibabacloud/credentials", "~", path, 1) - _, err = os.Stat(path) - if err != nil { - return "", nil - } - return path, nil -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/provider.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/provider.go deleted file mode 100644 index ae4e168e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/provider.go +++ /dev/null @@ -1,19 +0,0 @@ -package provider - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth" -) - -//Environmental virables that may be used by the provider -const ( - ENVAccessKeyID = "ALIBABA_CLOUD_ACCESS_KEY_ID" - ENVAccessKeySecret = "ALIBABA_CLOUD_ACCESS_KEY_SECRET" - ENVCredentialFile = "ALIBABA_CLOUD_CREDENTIALS_FILE" - ENVEcsMetadata = "ALIBABA_CLOUD_ECS_METADATA" - PATHCredentialFile = "~/.alibabacloud/credentials" -) - -// When you want to customize the provider, you only need to implement the method of the interface. -type Provider interface { - Resolve() (auth.Credential, error) -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/provider_chain.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/provider_chain.go deleted file mode 100644 index 3f9315d1..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider/provider_chain.go +++ /dev/null @@ -1,34 +0,0 @@ -package provider - -import ( - "errors" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth" -) - -type ProviderChain struct { - Providers []Provider -} - -var defaultproviders = []Provider{ProviderEnv, ProviderProfile, ProviderInstance} -var DefaultChain = NewProviderChain(defaultproviders) - -func NewProviderChain(providers []Provider) Provider { - return &ProviderChain{ - Providers: providers, - } -} - -func (p *ProviderChain) Resolve() (auth.Credential, error) { - for _, provider := range p.Providers { - creds, err := provider.Resolve() - if err != nil { - return nil, err - } else if err == nil && creds == nil { - continue - } - return creds, err - } - return nil, errors.New("No credential found") - -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/rsa_key_pair_credential.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/rsa_key_pair_credential.go deleted file mode 100644 index 00d688eb..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/rsa_key_pair_credential.go +++ /dev/null @@ -1,15 +0,0 @@ -package credentials - -type RsaKeyPairCredential struct { - PrivateKey string - PublicKeyId string - SessionExpiration int -} - -func NewRsaKeyPairCredential(privateKey, publicKeyId string, sessionExpiration int) *RsaKeyPairCredential { - return &RsaKeyPairCredential{ - PrivateKey: privateKey, - PublicKeyId: publicKeyId, - SessionExpiration: sessionExpiration, - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/sts_credential.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/sts_credential.go deleted file mode 100644 index 554431ff..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/sts_credential.go +++ /dev/null @@ -1,15 +0,0 @@ -package credentials - -type StsTokenCredential struct { - AccessKeyId string - AccessKeySecret string - AccessKeyStsToken string -} - -func NewStsTokenCredential(accessKeyId, accessKeySecret, accessKeyStsToken string) *StsTokenCredential { - return &StsTokenCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - AccessKeyStsToken: accessKeyStsToken, - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/sts_role_arn_credential.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/sts_role_arn_credential.go deleted file mode 100644 index 27602fd7..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/sts_role_arn_credential.go +++ /dev/null @@ -1,61 +0,0 @@ -package credentials - -// Deprecated: Use RamRoleArnCredential in this package instead. -type StsRoleArnCredential struct { - AccessKeyId string - AccessKeySecret string - RoleArn string - RoleSessionName string - RoleSessionExpiration int -} - -type RamRoleArnCredential struct { - AccessKeyId string - AccessKeySecret string - RoleArn string - RoleSessionName string - RoleSessionExpiration int - Policy string -} - -// Deprecated: Use RamRoleArnCredential in this package instead. -func NewStsRoleArnCredential(accessKeyId, accessKeySecret, roleArn, roleSessionName string, roleSessionExpiration int) *StsRoleArnCredential { - return &StsRoleArnCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - RoleArn: roleArn, - RoleSessionName: roleSessionName, - RoleSessionExpiration: roleSessionExpiration, - } -} - -func (oldCred *StsRoleArnCredential) ToRamRoleArnCredential() *RamRoleArnCredential { - return &RamRoleArnCredential{ - AccessKeyId: oldCred.AccessKeyId, - AccessKeySecret: oldCred.AccessKeySecret, - RoleArn: oldCred.RoleArn, - RoleSessionName: oldCred.RoleSessionName, - RoleSessionExpiration: oldCred.RoleSessionExpiration, - } -} - -func NewRamRoleArnCredential(accessKeyId, accessKeySecret, roleArn, roleSessionName string, roleSessionExpiration int) *RamRoleArnCredential { - return &RamRoleArnCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - RoleArn: roleArn, - RoleSessionName: roleSessionName, - RoleSessionExpiration: roleSessionExpiration, - } -} - -func NewRamRoleArnWithPolicyCredential(accessKeyId, accessKeySecret, roleArn, roleSessionName, policy string, roleSessionExpiration int) *RamRoleArnCredential { - return &RamRoleArnCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - RoleArn: roleArn, - RoleSessionName: roleSessionName, - RoleSessionExpiration: roleSessionExpiration, - Policy: policy, - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/roa_signature_composer.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/roa_signature_composer.go deleted file mode 100644 index 8b4037a0..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/roa_signature_composer.go +++ /dev/null @@ -1,136 +0,0 @@ -/* - * 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 auth - -import ( - "bytes" - "sort" - "strings" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" -) - -var debug utils.Debug - -var hookGetDate = func(fn func() string) string { - return fn() -} - -func init() { - debug = utils.Init("sdk") -} - -func signRoaRequest(request requests.AcsRequest, signer Signer, regionId string) (err error) { - completeROASignParams(request, signer, regionId) - stringToSign := buildRoaStringToSign(request) - request.SetStringToSign(stringToSign) - accessKeyId, err := signer.GetAccessKeyId() - if err != nil { - return err - } - - signature := signer.Sign(stringToSign, "") - request.GetHeaders()["Authorization"] = "acs " + accessKeyId + ":" + signature - - return -} - -func completeROASignParams(request requests.AcsRequest, signer Signer, regionId string) { - headerParams := request.GetHeaders() - - // complete query params - queryParams := request.GetQueryParams() - //if _, ok := queryParams["RegionId"]; !ok { - // queryParams["RegionId"] = regionId - //} - if extraParam := signer.GetExtraParam(); extraParam != nil { - for key, value := range extraParam { - if key == "SecurityToken" { - headerParams["x-acs-security-token"] = value - continue - } - if key == "BearerToken" { - headerParams["x-acs-bearer-token"] = value - continue - } - queryParams[key] = value - } - } - - // complete header params - headerParams["Date"] = hookGetDate(utils.GetTimeInFormatRFC2616) - headerParams["x-acs-signature-method"] = signer.GetName() - headerParams["x-acs-signature-version"] = signer.GetVersion() - if request.GetFormParams() != nil && len(request.GetFormParams()) > 0 { - formString := utils.GetUrlFormedMap(request.GetFormParams()) - request.SetContent([]byte(formString)) - headerParams["Content-Type"] = requests.Form - } - contentMD5 := utils.GetMD5Base64(request.GetContent()) - headerParams["Content-MD5"] = contentMD5 - if _, contains := headerParams["Content-Type"]; !contains { - headerParams["Content-Type"] = requests.Raw - } - switch format := request.GetAcceptFormat(); format { - case "JSON": - headerParams["Accept"] = requests.Json - case "XML": - headerParams["Accept"] = requests.Xml - default: - headerParams["Accept"] = requests.Raw - } -} - -func buildRoaStringToSign(request requests.AcsRequest) (stringToSign string) { - - headers := request.GetHeaders() - - stringToSignBuilder := bytes.Buffer{} - stringToSignBuilder.WriteString(request.GetMethod()) - stringToSignBuilder.WriteString(requests.HeaderSeparator) - - // append header keys for sign - appendIfContain(headers, &stringToSignBuilder, "Accept", requests.HeaderSeparator) - appendIfContain(headers, &stringToSignBuilder, "Content-MD5", requests.HeaderSeparator) - appendIfContain(headers, &stringToSignBuilder, "Content-Type", requests.HeaderSeparator) - appendIfContain(headers, &stringToSignBuilder, "Date", requests.HeaderSeparator) - - // sort and append headers witch starts with 'x-acs-' - var acsHeaders []string - for key := range headers { - if strings.HasPrefix(key, "x-acs-") { - acsHeaders = append(acsHeaders, key) - } - } - sort.Strings(acsHeaders) - for _, key := range acsHeaders { - stringToSignBuilder.WriteString(key + ":" + headers[key]) - stringToSignBuilder.WriteString(requests.HeaderSeparator) - } - - // append query params - stringToSignBuilder.WriteString(request.BuildQueries()) - stringToSign = stringToSignBuilder.String() - debug("stringToSign: %s", stringToSign) - return -} - -func appendIfContain(sourceMap map[string]string, target *bytes.Buffer, key, separator string) { - if value, contain := sourceMap[key]; contain && len(value) > 0 { - target.WriteString(sourceMap[key]) - target.WriteString(separator) - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/rpc_signature_composer.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/rpc_signature_composer.go deleted file mode 100644 index 33967b9e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/rpc_signature_composer.go +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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 auth - -import ( - "net/url" - "strings" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" -) - -var hookGetNonce = func(fn func() string) string { - return fn() -} - -func signRpcRequest(request requests.AcsRequest, signer Signer, regionId string) (err error) { - err = completeRpcSignParams(request, signer, regionId) - if err != nil { - return - } - // remove while retry - if _, containsSign := request.GetQueryParams()["Signature"]; containsSign { - delete(request.GetQueryParams(), "Signature") - } - stringToSign := buildRpcStringToSign(request) - request.SetStringToSign(stringToSign) - signature := signer.Sign(stringToSign, "&") - request.GetQueryParams()["Signature"] = signature - - return -} - -func completeRpcSignParams(request requests.AcsRequest, signer Signer, regionId string) (err error) { - queryParams := request.GetQueryParams() - queryParams["Version"] = request.GetVersion() - queryParams["Action"] = request.GetActionName() - queryParams["Format"] = request.GetAcceptFormat() - queryParams["Timestamp"] = hookGetDate(utils.GetTimeInFormatISO8601) - queryParams["SignatureMethod"] = signer.GetName() - queryParams["SignatureType"] = signer.GetType() - queryParams["SignatureVersion"] = signer.GetVersion() - queryParams["SignatureNonce"] = hookGetNonce(utils.GetUUID) - queryParams["AccessKeyId"], err = signer.GetAccessKeyId() - - if err != nil { - return - } - - if _, contains := queryParams["RegionId"]; !contains { - queryParams["RegionId"] = regionId - } - if extraParam := signer.GetExtraParam(); extraParam != nil { - for key, value := range extraParam { - queryParams[key] = value - } - } - - request.GetHeaders()["Content-Type"] = requests.Form - formString := utils.GetUrlFormedMap(request.GetFormParams()) - request.SetContent([]byte(formString)) - - return -} - -func buildRpcStringToSign(request requests.AcsRequest) (stringToSign string) { - signParams := make(map[string]string) - for key, value := range request.GetQueryParams() { - signParams[key] = value - } - for key, value := range request.GetFormParams() { - signParams[key] = value - } - - stringToSign = utils.GetUrlFormedMap(signParams) - stringToSign = strings.Replace(stringToSign, "+", "%20", -1) - stringToSign = strings.Replace(stringToSign, "*", "%2A", -1) - stringToSign = strings.Replace(stringToSign, "%7E", "~", -1) - stringToSign = url.QueryEscape(stringToSign) - stringToSign = request.GetMethod() + "&%2F&" + stringToSign - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signer.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signer.go deleted file mode 100644 index cbbc3cef..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signer.go +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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 auth - -import ( - "fmt" - "reflect" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -type Signer interface { - GetName() string - GetType() string - GetVersion() string - GetAccessKeyId() (string, error) - GetExtraParam() map[string]string - Sign(stringToSign, secretSuffix string) string -} - -func NewSignerWithCredential(credential Credential, commonApi func(request *requests.CommonRequest, signer interface{}) (response *responses.CommonResponse, err error)) (signer Signer, err error) { - switch instance := credential.(type) { - case *credentials.AccessKeyCredential: - { - signer = signers.NewAccessKeySigner(instance) - } - case *credentials.StsTokenCredential: - { - signer = signers.NewStsTokenSigner(instance) - } - case *credentials.BearerTokenCredential: - { - signer = signers.NewBearerTokenSigner(instance) - } - case *credentials.RamRoleArnCredential: - { - signer, err = signers.NewRamRoleArnSigner(instance, commonApi) - } - case *credentials.RsaKeyPairCredential: - { - signer, err = signers.NewSignerKeyPair(instance, commonApi) - } - case *credentials.EcsRamRoleCredential: - { - signer = signers.NewEcsRamRoleSigner(instance, commonApi) - } - case *credentials.BaseCredential: // deprecated user interface - { - signer = signers.NewAccessKeySigner(instance.ToAccessKeyCredential()) - } - case *credentials.StsRoleArnCredential: // deprecated user interface - { - signer, err = signers.NewRamRoleArnSigner(instance.ToRamRoleArnCredential(), commonApi) - } - case *credentials.StsRoleNameOnEcsCredential: // deprecated user interface - { - signer = signers.NewEcsRamRoleSigner(instance.ToEcsRamRoleCredential(), commonApi) - } - default: - message := fmt.Sprintf(errors.UnsupportedCredentialErrorMessage, reflect.TypeOf(credential)) - err = errors.NewClientError(errors.UnsupportedCredentialErrorCode, message, nil) - } - return -} - -func Sign(request requests.AcsRequest, signer Signer, regionId string) (err error) { - switch request.GetStyle() { - case requests.ROA: - { - err = signRoaRequest(request, signer, regionId) - } - case requests.RPC: - { - err = signRpcRequest(request, signer, regionId) - } - default: - message := fmt.Sprintf(errors.UnknownRequestTypeErrorMessage, reflect.TypeOf(request)) - err = errors.NewClientError(errors.UnknownRequestTypeErrorCode, message, nil) - } - - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/algorithms.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/algorithms.go deleted file mode 100644 index 887f5020..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/algorithms.go +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 signers - -import ( - "crypto" - "crypto/hmac" - "crypto/rand" - "crypto/rsa" - "crypto/sha1" - "crypto/x509" - "encoding/base64" -) - -func ShaHmac1(source, secret string) string { - key := []byte(secret) - hmac := hmac.New(sha1.New, key) - hmac.Write([]byte(source)) - signedBytes := hmac.Sum(nil) - signedString := base64.StdEncoding.EncodeToString(signedBytes) - return signedString -} - -func Sha256WithRsa(source, secret string) string { - // block, _ := pem.Decode([]byte(secret)) - decodeString, err := base64.StdEncoding.DecodeString(secret) - if err != nil { - panic(err) - } - private, err := x509.ParsePKCS8PrivateKey(decodeString) - if err != nil { - panic(err) - } - - h := crypto.Hash.New(crypto.SHA256) - h.Write([]byte(source)) - hashed := h.Sum(nil) - signature, err := rsa.SignPKCS1v15(rand.Reader, private.(*rsa.PrivateKey), - crypto.SHA256, hashed) - if err != nil { - panic(err) - } - - return base64.StdEncoding.EncodeToString(signature) -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/credential_updater.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/credential_updater.go deleted file mode 100644 index ba291a41..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/credential_updater.go +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 signers - -import ( - "time" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -const defaultInAdvanceScale = 0.95 - -type credentialUpdater struct { - credentialExpiration int - lastUpdateTimestamp int64 - inAdvanceScale float64 - buildRequestMethod func() (*requests.CommonRequest, error) - responseCallBack func(response *responses.CommonResponse) error - refreshApi func(request *requests.CommonRequest) (response *responses.CommonResponse, err error) -} - -func (updater *credentialUpdater) needUpdateCredential() (result bool) { - if updater.inAdvanceScale == 0 { - updater.inAdvanceScale = defaultInAdvanceScale - } - return time.Now().Unix()-updater.lastUpdateTimestamp >= int64(float64(updater.credentialExpiration)*updater.inAdvanceScale) -} - -func (updater *credentialUpdater) updateCredential() (err error) { - request, err := updater.buildRequestMethod() - if err != nil { - return - } - response, err := updater.refreshApi(request) - if err != nil { - return - } - updater.lastUpdateTimestamp = time.Now().Unix() - err = updater.responseCallBack(response) - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/session_credential.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/session_credential.go deleted file mode 100644 index 99c624c8..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/session_credential.go +++ /dev/null @@ -1,7 +0,0 @@ -package signers - -type SessionCredential struct { - AccessKeyId string - AccessKeySecret string - StsToken string -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_access_key.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_access_key.go deleted file mode 100644 index bc4f35b8..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_access_key.go +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 signers - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" -) - -type AccessKeySigner struct { - credential *credentials.AccessKeyCredential -} - -func (signer *AccessKeySigner) GetExtraParam() map[string]string { - return nil -} - -func NewAccessKeySigner(credential *credentials.AccessKeyCredential) *AccessKeySigner { - return &AccessKeySigner{ - credential: credential, - } -} - -func (*AccessKeySigner) GetName() string { - return "HMAC-SHA1" -} - -func (*AccessKeySigner) GetType() string { - return "" -} - -func (*AccessKeySigner) GetVersion() string { - return "1.0" -} - -func (signer *AccessKeySigner) GetAccessKeyId() (accessKeyId string, err error) { - return signer.credential.AccessKeyId, nil -} - -func (signer *AccessKeySigner) Sign(stringToSign, secretSuffix string) string { - secret := signer.credential.AccessKeySecret + secretSuffix - return ShaHmac1(stringToSign, secret) -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_bearer_token.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_bearer_token.go deleted file mode 100644 index 75b78433..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_bearer_token.go +++ /dev/null @@ -1,35 +0,0 @@ -package signers - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" -) - -type BearerTokenSigner struct { - credential *credentials.BearerTokenCredential -} - -func NewBearerTokenSigner(credential *credentials.BearerTokenCredential) *BearerTokenSigner { - return &BearerTokenSigner{ - credential: credential, - } -} - -func (signer *BearerTokenSigner) GetExtraParam() map[string]string { - return map[string]string{"BearerToken": signer.credential.BearerToken} -} - -func (*BearerTokenSigner) GetName() string { - return "" -} -func (*BearerTokenSigner) GetType() string { - return "BEARERTOKEN" -} -func (*BearerTokenSigner) GetVersion() string { - return "1.0" -} -func (signer *BearerTokenSigner) GetAccessKeyId() (accessKeyId string, err error) { - return "", nil -} -func (signer *BearerTokenSigner) Sign(stringToSign, secretSuffix string) string { - return "" -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_ecs_ram_role.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_ecs_ram_role.go deleted file mode 100644 index 73788429..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_ecs_ram_role.go +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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 signers - -import ( - "encoding/json" - "fmt" - "net/http" - "strings" - "time" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" - jmespath "github.com/jmespath/go-jmespath" -) - -var securityCredURL = "http://100.100.100.200/latest/meta-data/ram/security-credentials/" - -type EcsRamRoleSigner struct { - *credentialUpdater - sessionCredential *SessionCredential - credential *credentials.EcsRamRoleCredential - commonApi func(request *requests.CommonRequest, signer interface{}) (response *responses.CommonResponse, err error) -} - -func NewEcsRamRoleSigner(credential *credentials.EcsRamRoleCredential, commonApi func(*requests.CommonRequest, interface{}) (response *responses.CommonResponse, err error)) (signer *EcsRamRoleSigner) { - signer = &EcsRamRoleSigner{ - credential: credential, - commonApi: commonApi, - } - - signer.credentialUpdater = &credentialUpdater{ - credentialExpiration: defaultDurationSeconds / 60, - buildRequestMethod: signer.buildCommonRequest, - responseCallBack: signer.refreshCredential, - refreshApi: signer.refreshApi, - } - - return signer -} - -func (*EcsRamRoleSigner) GetName() string { - return "HMAC-SHA1" -} - -func (*EcsRamRoleSigner) GetType() string { - return "" -} - -func (*EcsRamRoleSigner) GetVersion() string { - return "1.0" -} - -func (signer *EcsRamRoleSigner) GetAccessKeyId() (accessKeyId string, err error) { - if signer.sessionCredential == nil || signer.needUpdateCredential() { - err = signer.updateCredential() - if err != nil { - return - } - } - if signer.sessionCredential == nil || len(signer.sessionCredential.AccessKeyId) <= 0 { - return "", nil - } - return signer.sessionCredential.AccessKeyId, nil -} - -func (signer *EcsRamRoleSigner) GetExtraParam() map[string]string { - if signer.sessionCredential == nil { - return make(map[string]string) - } - if len(signer.sessionCredential.StsToken) <= 0 { - return make(map[string]string) - } - return map[string]string{"SecurityToken": signer.sessionCredential.StsToken} -} - -func (signer *EcsRamRoleSigner) Sign(stringToSign, secretSuffix string) string { - secret := signer.sessionCredential.AccessKeySecret + secretSuffix - return ShaHmac1(stringToSign, secret) -} - -func (signer *EcsRamRoleSigner) buildCommonRequest() (request *requests.CommonRequest, err error) { - return -} - -func (signer *EcsRamRoleSigner) refreshApi(request *requests.CommonRequest) (response *responses.CommonResponse, err error) { - requestUrl := securityCredURL + signer.credential.RoleName - httpRequest, err := http.NewRequest(requests.GET, requestUrl, strings.NewReader("")) - if err != nil { - err = fmt.Errorf("refresh Ecs sts token err: %s", err.Error()) - return - } - httpClient := &http.Client{} - httpResponse, err := httpClient.Do(httpRequest) - if err != nil { - err = fmt.Errorf("refresh Ecs sts token err: %s", err.Error()) - return - } - - response = responses.NewCommonResponse() - err = responses.Unmarshal(response, httpResponse, "") - return -} - -func (signer *EcsRamRoleSigner) refreshCredential(response *responses.CommonResponse) (err error) { - if response.GetHttpStatus() != http.StatusOK { - return fmt.Errorf("refresh Ecs sts token err, httpStatus: %d, message = %s", response.GetHttpStatus(), response.GetHttpContentString()) - } - var data interface{} - err = json.Unmarshal(response.GetHttpContentBytes(), &data) - if err != nil { - return fmt.Errorf("refresh Ecs sts token err, json.Unmarshal fail: %s", err.Error()) - } - code, err := jmespath.Search("Code", data) - if err != nil { - return fmt.Errorf("refresh Ecs sts token err, fail to get Code: %s", err.Error()) - } - if code.(string) != "Success" { - return fmt.Errorf("refresh Ecs sts token err, Code is not Success") - } - accessKeyId, err := jmespath.Search("AccessKeyId", data) - if err != nil { - return fmt.Errorf("refresh Ecs sts token err, fail to get AccessKeyId: %s", err.Error()) - } - accessKeySecret, err := jmespath.Search("AccessKeySecret", data) - if err != nil { - return fmt.Errorf("refresh Ecs sts token err, fail to get AccessKeySecret: %s", err.Error()) - } - securityToken, err := jmespath.Search("SecurityToken", data) - if err != nil { - return fmt.Errorf("refresh Ecs sts token err, fail to get SecurityToken: %s", err.Error()) - } - expiration, err := jmespath.Search("Expiration", data) - if err != nil { - return fmt.Errorf("refresh Ecs sts token err, fail to get Expiration: %s", err.Error()) - } - if accessKeyId == nil || accessKeySecret == nil || securityToken == nil || expiration == nil { - return - } - - expirationTime, err := time.Parse("2006-01-02T15:04:05Z", expiration.(string)) - signer.credentialExpiration = int(expirationTime.Unix() - time.Now().Unix()) - signer.sessionCredential = &SessionCredential{ - AccessKeyId: accessKeyId.(string), - AccessKeySecret: accessKeySecret.(string), - StsToken: securityToken.(string), - } - - return -} - -func (signer *EcsRamRoleSigner) GetSessionCredential() *SessionCredential { - return signer.sessionCredential -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_key_pair.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_key_pair.go deleted file mode 100644 index 19273d5a..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_key_pair.go +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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 signers - -import ( - "encoding/json" - "fmt" - "net/http" - "strconv" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" - jmespath "github.com/jmespath/go-jmespath" -) - -type SignerKeyPair struct { - *credentialUpdater - sessionCredential *SessionCredential - credential *credentials.RsaKeyPairCredential - commonApi func(request *requests.CommonRequest, signer interface{}) (response *responses.CommonResponse, err error) -} - -func NewSignerKeyPair(credential *credentials.RsaKeyPairCredential, commonApi func(*requests.CommonRequest, interface{}) (response *responses.CommonResponse, err error)) (signer *SignerKeyPair, err error) { - signer = &SignerKeyPair{ - credential: credential, - commonApi: commonApi, - } - - signer.credentialUpdater = &credentialUpdater{ - credentialExpiration: credential.SessionExpiration, - buildRequestMethod: signer.buildCommonRequest, - responseCallBack: signer.refreshCredential, - refreshApi: signer.refreshApi, - } - - if credential.SessionExpiration > 0 { - if credential.SessionExpiration >= 900 && credential.SessionExpiration <= 3600 { - signer.credentialExpiration = credential.SessionExpiration - } else { - err = errors.NewClientError(errors.InvalidParamErrorCode, "Key Pair session duration should be in the range of 15min - 1Hr", nil) - } - } else { - signer.credentialExpiration = defaultDurationSeconds - } - return -} - -func (*SignerKeyPair) GetName() string { - return "HMAC-SHA1" -} - -func (*SignerKeyPair) GetType() string { - return "" -} - -func (*SignerKeyPair) GetVersion() string { - return "1.0" -} - -func (signer *SignerKeyPair) ensureCredential() error { - if signer.sessionCredential == nil || signer.needUpdateCredential() { - return signer.updateCredential() - } - return nil -} - -func (signer *SignerKeyPair) GetAccessKeyId() (accessKeyId string, err error) { - err = signer.ensureCredential() - if err != nil { - return - } - if signer.sessionCredential == nil || len(signer.sessionCredential.AccessKeyId) <= 0 { - accessKeyId = "" - return - } - - accessKeyId = signer.sessionCredential.AccessKeyId - return -} - -func (signer *SignerKeyPair) GetExtraParam() map[string]string { - return make(map[string]string) -} - -func (signer *SignerKeyPair) Sign(stringToSign, secretSuffix string) string { - secret := signer.sessionCredential.AccessKeySecret + secretSuffix - return ShaHmac1(stringToSign, secret) -} - -func (signer *SignerKeyPair) buildCommonRequest() (request *requests.CommonRequest, err error) { - request = requests.NewCommonRequest() - request.Product = "Sts" - request.Version = "2015-04-01" - request.ApiName = "GenerateSessionAccessKey" - request.Scheme = requests.HTTPS - request.SetDomain("sts.ap-northeast-1.aliyuncs.com") - request.QueryParams["PublicKeyId"] = signer.credential.PublicKeyId - request.QueryParams["DurationSeconds"] = strconv.Itoa(signer.credentialExpiration) - return -} - -func (signer *SignerKeyPair) refreshApi(request *requests.CommonRequest) (response *responses.CommonResponse, err error) { - signerV2 := NewSignerV2(signer.credential) - return signer.commonApi(request, signerV2) -} - -func (signer *SignerKeyPair) refreshCredential(response *responses.CommonResponse) (err error) { - if response.GetHttpStatus() != http.StatusOK { - message := "refresh session AccessKey failed" - err = errors.NewServerError(response.GetHttpStatus(), response.GetHttpContentString(), message) - return - } - var data interface{} - err = json.Unmarshal(response.GetHttpContentBytes(), &data) - if err != nil { - return fmt.Errorf("refresh KeyPair err, json.Unmarshal fail: %s", err.Error()) - } - accessKeyId, err := jmespath.Search("SessionAccessKey.SessionAccessKeyId", data) - if err != nil { - return fmt.Errorf("refresh KeyPair err, fail to get SessionAccessKeyId: %s", err.Error()) - } - accessKeySecret, err := jmespath.Search("SessionAccessKey.SessionAccessKeySecret", data) - if err != nil { - return fmt.Errorf("refresh KeyPair err, fail to get SessionAccessKeySecret: %s", err.Error()) - } - if accessKeyId == nil || accessKeySecret == nil { - return - } - signer.sessionCredential = &SessionCredential{ - AccessKeyId: accessKeyId.(string), - AccessKeySecret: accessKeySecret.(string), - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_ram_role_arn.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_ram_role_arn.go deleted file mode 100644 index c945c8ae..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_ram_role_arn.go +++ /dev/null @@ -1,175 +0,0 @@ -/* - * 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 signers - -import ( - "encoding/json" - "fmt" - "net/http" - "strconv" - "time" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" - jmespath "github.com/jmespath/go-jmespath" -) - -const ( - defaultDurationSeconds = 3600 -) - -type RamRoleArnSigner struct { - *credentialUpdater - roleSessionName string - sessionCredential *SessionCredential - credential *credentials.RamRoleArnCredential - commonApi func(request *requests.CommonRequest, signer interface{}) (response *responses.CommonResponse, err error) -} - -func NewRamRoleArnSigner(credential *credentials.RamRoleArnCredential, commonApi func(request *requests.CommonRequest, signer interface{}) (response *responses.CommonResponse, err error)) (signer *RamRoleArnSigner, err error) { - signer = &RamRoleArnSigner{ - credential: credential, - commonApi: commonApi, - } - - signer.credentialUpdater = &credentialUpdater{ - credentialExpiration: credential.RoleSessionExpiration, - buildRequestMethod: signer.buildCommonRequest, - responseCallBack: signer.refreshCredential, - refreshApi: signer.refreshApi, - } - - if len(credential.RoleSessionName) > 0 { - signer.roleSessionName = credential.RoleSessionName - } else { - signer.roleSessionName = "aliyun-go-sdk-" + strconv.FormatInt(time.Now().UnixNano()/1000, 10) - } - if credential.RoleSessionExpiration > 0 { - if credential.RoleSessionExpiration >= 900 && credential.RoleSessionExpiration <= 3600 { - signer.credentialExpiration = credential.RoleSessionExpiration - } else { - err = errors.NewClientError(errors.InvalidParamErrorCode, "Assume Role session duration should be in the range of 15min - 1Hr", nil) - } - } else { - signer.credentialExpiration = defaultDurationSeconds - } - return -} - -func (*RamRoleArnSigner) GetName() string { - return "HMAC-SHA1" -} - -func (*RamRoleArnSigner) GetType() string { - return "" -} - -func (*RamRoleArnSigner) GetVersion() string { - return "1.0" -} - -func (signer *RamRoleArnSigner) GetAccessKeyId() (accessKeyId string, err error) { - if signer.sessionCredential == nil || signer.needUpdateCredential() { - err = signer.updateCredential() - if err != nil { - return - } - } - - if signer.sessionCredential == nil || len(signer.sessionCredential.AccessKeyId) <= 0 { - return "", err - } - - return signer.sessionCredential.AccessKeyId, nil -} - -func (signer *RamRoleArnSigner) GetExtraParam() map[string]string { - if signer.sessionCredential == nil || signer.needUpdateCredential() { - signer.updateCredential() - } - if signer.sessionCredential == nil || len(signer.sessionCredential.StsToken) <= 0 { - return make(map[string]string) - } - return map[string]string{"SecurityToken": signer.sessionCredential.StsToken} -} - -func (signer *RamRoleArnSigner) Sign(stringToSign, secretSuffix string) string { - secret := signer.sessionCredential.AccessKeySecret + secretSuffix - return ShaHmac1(stringToSign, secret) -} - -func (signer *RamRoleArnSigner) buildCommonRequest() (request *requests.CommonRequest, err error) { - request = requests.NewCommonRequest() - request.Product = "Sts" - request.Version = "2015-04-01" - request.ApiName = "AssumeRole" - request.Scheme = requests.HTTPS - request.QueryParams["RoleArn"] = signer.credential.RoleArn - if signer.credential.Policy != "" { - request.QueryParams["Policy"] = signer.credential.Policy - } - request.QueryParams["RoleSessionName"] = signer.credential.RoleSessionName - request.QueryParams["DurationSeconds"] = strconv.Itoa(signer.credentialExpiration) - return -} - -func (signer *RamRoleArnSigner) refreshApi(request *requests.CommonRequest) (response *responses.CommonResponse, err error) { - credential := &credentials.AccessKeyCredential{ - AccessKeyId: signer.credential.AccessKeyId, - AccessKeySecret: signer.credential.AccessKeySecret, - } - signerV1 := NewAccessKeySigner(credential) - return signer.commonApi(request, signerV1) -} - -func (signer *RamRoleArnSigner) refreshCredential(response *responses.CommonResponse) (err error) { - if response.GetHttpStatus() != http.StatusOK { - message := "refresh session token failed" - err = errors.NewServerError(response.GetHttpStatus(), response.GetHttpContentString(), message) - return - } - var data interface{} - err = json.Unmarshal(response.GetHttpContentBytes(), &data) - if err != nil { - return fmt.Errorf("refresh RoleArn sts token err, json.Unmarshal fail: %s", err.Error()) - } - accessKeyId, err := jmespath.Search("Credentials.AccessKeyId", data) - if err != nil { - return fmt.Errorf("refresh RoleArn sts token err, fail to get AccessKeyId: %s", err.Error()) - } - accessKeySecret, err := jmespath.Search("Credentials.AccessKeySecret", data) - if err != nil { - return fmt.Errorf("refresh RoleArn sts token err, fail to get AccessKeySecret: %s", err.Error()) - } - securityToken, err := jmespath.Search("Credentials.SecurityToken", data) - if err != nil { - return fmt.Errorf("refresh RoleArn sts token err, fail to get SecurityToken: %s", err.Error()) - } - if accessKeyId == nil || accessKeySecret == nil || securityToken == nil { - return - } - signer.sessionCredential = &SessionCredential{ - AccessKeyId: accessKeyId.(string), - AccessKeySecret: accessKeySecret.(string), - StsToken: securityToken.(string), - } - return -} - -func (signer *RamRoleArnSigner) GetSessionCredential() *SessionCredential { - return signer.sessionCredential -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_sts_token.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_sts_token.go deleted file mode 100644 index d0ce36c3..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_sts_token.go +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 signers - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" -) - -type StsTokenSigner struct { - credential *credentials.StsTokenCredential -} - -func NewStsTokenSigner(credential *credentials.StsTokenCredential) *StsTokenSigner { - return &StsTokenSigner{ - credential: credential, - } -} - -func (*StsTokenSigner) GetName() string { - return "HMAC-SHA1" -} - -func (*StsTokenSigner) GetType() string { - return "" -} - -func (*StsTokenSigner) GetVersion() string { - return "1.0" -} - -func (signer *StsTokenSigner) GetAccessKeyId() (accessKeyId string, err error) { - return signer.credential.AccessKeyId, nil -} - -func (signer *StsTokenSigner) GetExtraParam() map[string]string { - return map[string]string{"SecurityToken": signer.credential.AccessKeyStsToken} -} - -func (signer *StsTokenSigner) Sign(stringToSign, secretSuffix string) string { - secret := signer.credential.AccessKeySecret + secretSuffix - return ShaHmac1(stringToSign, secret) -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_v2.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_v2.go deleted file mode 100644 index 97348529..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/signers/signer_v2.go +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 signers - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" -) - -type SignerV2 struct { - credential *credentials.RsaKeyPairCredential -} - -func (signer *SignerV2) GetExtraParam() map[string]string { - return nil -} - -func NewSignerV2(credential *credentials.RsaKeyPairCredential) *SignerV2 { - return &SignerV2{ - credential: credential, - } -} - -func (*SignerV2) GetName() string { - return "SHA256withRSA" -} - -func (*SignerV2) GetType() string { - return "PRIVATEKEY" -} - -func (*SignerV2) GetVersion() string { - return "1.0" -} - -func (signer *SignerV2) GetAccessKeyId() (accessKeyId string, err error) { - return signer.credential.PublicKeyId, err -} - -func (signer *SignerV2) Sign(stringToSign, secretSuffix string) string { - secret := signer.credential.PrivateKey - return Sha256WithRsa(stringToSign, secret) -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/client.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/client.go deleted file mode 100644 index 01c2f93b..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/client.go +++ /dev/null @@ -1,725 +0,0 @@ -/* - * 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 sdk - -import ( - "context" - "crypto/tls" - "fmt" - "net" - "net/http" - "net/url" - "os" - "runtime" - "strconv" - "strings" - "sync" - "time" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials/provider" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" -) - -var debug utils.Debug - -func init() { - debug = utils.Init("sdk") -} - -// Version this value will be replaced while build: -ldflags="-X sdk.version=x.x.x" -var Version = "0.0.1" -var defaultConnectTimeout = 5 * time.Second -var defaultReadTimeout = 10 * time.Second - -var DefaultUserAgent = fmt.Sprintf("AlibabaCloud (%s; %s) Golang/%s Core/%s", runtime.GOOS, runtime.GOARCH, strings.Trim(runtime.Version(), "go"), Version) - -var hookDo = func(fn func(req *http.Request) (*http.Response, error)) func(req *http.Request) (*http.Response, error) { - return fn -} - -// Client the type Client -type Client struct { - isInsecure bool - regionId string - config *Config - httpProxy string - httpsProxy string - noProxy string - logger *Logger - userAgent map[string]string - signer auth.Signer - httpClient *http.Client - asyncTaskQueue chan func() - readTimeout time.Duration - connectTimeout time.Duration - - debug bool - isRunning bool - // void "panic(write to close channel)" cause of addAsync() after Shutdown() - asyncChanLock *sync.RWMutex -} - -func (client *Client) Init() (err error) { - panic("not support yet") -} - -func (client *Client) SetHTTPSInsecure(isInsecure bool) { - client.isInsecure = isInsecure -} - -func (client *Client) GetHTTPSInsecure() bool { - return client.isInsecure -} - -func (client *Client) SetHttpsProxy(httpsProxy string) { - client.httpsProxy = httpsProxy -} - -func (client *Client) GetHttpsProxy() string { - return client.httpsProxy -} - -func (client *Client) SetHttpProxy(httpProxy string) { - client.httpProxy = httpProxy -} - -func (client *Client) GetHttpProxy() string { - return client.httpProxy -} - -func (client *Client) SetNoProxy(noProxy string) { - client.noProxy = noProxy -} - -func (client *Client) GetNoProxy() string { - return client.noProxy -} - -// InitWithProviderChain will get credential from the providerChain, -// the RsaKeyPairCredential Only applicable to regionID `ap-northeast-1`, -// if your providerChain may return a credential type with RsaKeyPairCredential, -// please ensure your regionID is `ap-northeast-1`. -func (client *Client) InitWithProviderChain(regionId string, provider provider.Provider) (err error) { - config := client.InitClientConfig() - credential, err := provider.Resolve() - if err != nil { - return - } - return client.InitWithOptions(regionId, config, credential) -} - -func (client *Client) InitWithOptions(regionId string, config *Config, credential auth.Credential) (err error) { - client.isRunning = true - client.asyncChanLock = new(sync.RWMutex) - client.regionId = regionId - client.config = config - client.httpClient = &http.Client{} - - if config.HttpTransport != nil { - client.httpClient.Transport = config.HttpTransport - } - - if config.Timeout > 0 { - client.httpClient.Timeout = config.Timeout - } - - if config.EnableAsync { - client.EnableAsync(config.GoRoutinePoolSize, config.MaxTaskQueueSize) - } - - client.signer, err = auth.NewSignerWithCredential(credential, client.ProcessCommonRequestWithSigner) - - return -} - -func (client *Client) SetReadTimeout(readTimeout time.Duration) { - client.readTimeout = readTimeout -} - -func (client *Client) SetConnectTimeout(connectTimeout time.Duration) { - client.connectTimeout = connectTimeout -} - -func (client *Client) GetReadTimeout() time.Duration { - return client.readTimeout -} - -func (client *Client) GetConnectTimeout() time.Duration { - return client.connectTimeout -} - -func (client *Client) getHttpProxy(scheme string) (proxy *url.URL, err error) { - if scheme == "https" { - if client.GetHttpsProxy() != "" { - proxy, err = url.Parse(client.httpsProxy) - } else if rawurl := os.Getenv("HTTPS_PROXY"); rawurl != "" { - proxy, err = url.Parse(rawurl) - } else if rawurl := os.Getenv("https_proxy"); rawurl != "" { - proxy, err = url.Parse(rawurl) - } - } else { - if client.GetHttpProxy() != "" { - proxy, err = url.Parse(client.httpProxy) - } else if rawurl := os.Getenv("HTTP_PROXY"); rawurl != "" { - proxy, err = url.Parse(rawurl) - } else if rawurl := os.Getenv("http_proxy"); rawurl != "" { - proxy, err = url.Parse(rawurl) - } - } - - return proxy, err -} - -func (client *Client) getNoProxy(scheme string) []string { - var urls []string - if client.GetNoProxy() != "" { - urls = strings.Split(client.noProxy, ",") - } else if rawurl := os.Getenv("NO_PROXY"); rawurl != "" { - urls = strings.Split(rawurl, ",") - } else if rawurl := os.Getenv("no_proxy"); rawurl != "" { - urls = strings.Split(rawurl, ",") - } - - return urls -} - -// EnableAsync enable the async task queue -func (client *Client) EnableAsync(routinePoolSize, maxTaskQueueSize int) { - client.asyncTaskQueue = make(chan func(), maxTaskQueueSize) - for i := 0; i < routinePoolSize; i++ { - go func() { - for client.isRunning { - select { - case task, notClosed := <-client.asyncTaskQueue: - if notClosed { - task() - } - } - } - }() - } -} - -func (client *Client) InitWithAccessKey(regionId, accessKeyId, accessKeySecret string) (err error) { - config := client.InitClientConfig() - credential := &credentials.BaseCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - } - return client.InitWithOptions(regionId, config, credential) -} - -func (client *Client) InitWithStsToken(regionId, accessKeyId, accessKeySecret, securityToken string) (err error) { - config := client.InitClientConfig() - credential := &credentials.StsTokenCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - AccessKeyStsToken: securityToken, - } - return client.InitWithOptions(regionId, config, credential) -} - -func (client *Client) InitWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (err error) { - config := client.InitClientConfig() - credential := &credentials.RamRoleArnCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - RoleArn: roleArn, - RoleSessionName: roleSessionName, - } - return client.InitWithOptions(regionId, config, credential) -} - -func (client *Client) InitWithRamRoleArnAndPolicy(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy string) (err error) { - config := client.InitClientConfig() - credential := &credentials.RamRoleArnCredential{ - AccessKeyId: accessKeyId, - AccessKeySecret: accessKeySecret, - RoleArn: roleArn, - RoleSessionName: roleSessionName, - Policy: policy, - } - return client.InitWithOptions(regionId, config, credential) -} - -func (client *Client) InitWithRsaKeyPair(regionId, publicKeyId, privateKey string, sessionExpiration int) (err error) { - config := client.InitClientConfig() - credential := &credentials.RsaKeyPairCredential{ - PrivateKey: privateKey, - PublicKeyId: publicKeyId, - SessionExpiration: sessionExpiration, - } - return client.InitWithOptions(regionId, config, credential) -} - -func (client *Client) InitWithEcsRamRole(regionId, roleName string) (err error) { - config := client.InitClientConfig() - credential := &credentials.EcsRamRoleCredential{ - RoleName: roleName, - } - return client.InitWithOptions(regionId, config, credential) -} - -func (client *Client) InitWithBearerToken(regionId, bearerToken string) (err error) { - config := client.InitClientConfig() - credential := &credentials.BearerTokenCredential{ - BearerToken: bearerToken, - } - return client.InitWithOptions(regionId, config, credential) -} - -func (client *Client) InitClientConfig() (config *Config) { - if client.config != nil { - return client.config - } else { - return NewConfig() - } -} - -func (client *Client) DoAction(request requests.AcsRequest, response responses.AcsResponse) (err error) { - return client.DoActionWithSigner(request, response, nil) -} - -func (client *Client) buildRequestWithSigner(request requests.AcsRequest, signer auth.Signer) (httpRequest *http.Request, err error) { - // add clientVersion - request.GetHeaders()["x-sdk-core-version"] = Version - - regionId := client.regionId - if len(request.GetRegionId()) > 0 { - regionId = request.GetRegionId() - } - - // resolve endpoint - resolveParam := &endpoints.ResolveParam{ - Domain: request.GetDomain(), - Product: request.GetProduct(), - RegionId: regionId, - LocationProduct: request.GetLocationServiceCode(), - LocationEndpointType: request.GetLocationEndpointType(), - CommonApi: client.ProcessCommonRequest, - } - endpoint, err := endpoints.Resolve(resolveParam) - if err != nil { - return - } - request.SetDomain(endpoint) - if request.GetScheme() == "" { - request.SetScheme(client.config.Scheme) - } - // init request params - err = requests.InitParams(request) - if err != nil { - return - } - - // signature - var finalSigner auth.Signer - if signer != nil { - finalSigner = signer - } else { - finalSigner = client.signer - } - httpRequest, err = buildHttpRequest(request, finalSigner, regionId) - if err == nil { - userAgent := DefaultUserAgent + getSendUserAgent(client.config.UserAgent, client.userAgent, request.GetUserAgent()) - httpRequest.Header.Set("User-Agent", userAgent) - } - - return -} - -func getSendUserAgent(configUserAgent string, clientUserAgent, requestUserAgent map[string]string) string { - realUserAgent := "" - for key1, value1 := range clientUserAgent { - for key2, _ := range requestUserAgent { - if key1 == key2 { - key1 = "" - } - } - if key1 != "" { - realUserAgent += fmt.Sprintf(" %s/%s", key1, value1) - - } - } - for key, value := range requestUserAgent { - realUserAgent += fmt.Sprintf(" %s/%s", key, value) - } - if configUserAgent != "" { - return realUserAgent + fmt.Sprintf(" Extra/%s", configUserAgent) - } - return realUserAgent -} - -func (client *Client) AppendUserAgent(key, value string) { - newkey := true - - if client.userAgent == nil { - client.userAgent = make(map[string]string) - } - if strings.ToLower(key) != "core" && strings.ToLower(key) != "go" { - for tag, _ := range client.userAgent { - if tag == key { - client.userAgent[tag] = value - newkey = false - } - } - if newkey { - client.userAgent[key] = value - } - } -} - -func (client *Client) BuildRequestWithSigner(request requests.AcsRequest, signer auth.Signer) (err error) { - _, err = client.buildRequestWithSigner(request, signer) - return -} - -func (client *Client) getTimeout(request requests.AcsRequest) (time.Duration, time.Duration) { - readTimeout := defaultReadTimeout - connectTimeout := defaultConnectTimeout - - reqReadTimeout := request.GetReadTimeout() - reqConnectTimeout := request.GetConnectTimeout() - if reqReadTimeout != 0*time.Millisecond { - readTimeout = reqReadTimeout - } else if client.readTimeout != 0*time.Millisecond { - readTimeout = client.readTimeout - } else if client.httpClient.Timeout != 0 && client.httpClient.Timeout != 10000000000 { - readTimeout = client.httpClient.Timeout - } - - if reqConnectTimeout != 0*time.Millisecond { - connectTimeout = reqConnectTimeout - } else if client.connectTimeout != 0*time.Millisecond { - connectTimeout = client.connectTimeout - } - return readTimeout, connectTimeout -} - -func Timeout(connectTimeout time.Duration) func(cxt context.Context, net, addr string) (c net.Conn, err error) { - return func(ctx context.Context, network, address string) (net.Conn, error) { - return (&net.Dialer{ - Timeout: connectTimeout, - DualStack: true, - }).DialContext(ctx, network, address) - } -} - -func (client *Client) setTimeout(request requests.AcsRequest) { - readTimeout, connectTimeout := client.getTimeout(request) - client.httpClient.Timeout = readTimeout - if trans, ok := client.httpClient.Transport.(*http.Transport); ok && trans != nil { - trans.DialContext = Timeout(connectTimeout) - client.httpClient.Transport = trans - } else { - client.httpClient.Transport = &http.Transport{ - DialContext: Timeout(connectTimeout), - } - } -} - -func (client *Client) getHTTPSInsecure(request requests.AcsRequest) (insecure bool) { - if request.GetHTTPSInsecure() != nil { - insecure = *request.GetHTTPSInsecure() - } else { - insecure = client.GetHTTPSInsecure() - } - return insecure -} - -func (client *Client) DoActionWithSigner(request requests.AcsRequest, response responses.AcsResponse, signer auth.Signer) (err error) { - - fieldMap := make(map[string]string) - initLogMsg(fieldMap) - defer func() { - client.printLog(fieldMap, err) - }() - httpRequest, err := client.buildRequestWithSigner(request, signer) - if err != nil { - return - } - - client.setTimeout(request) - proxy, err := client.getHttpProxy(httpRequest.URL.Scheme) - if err != nil { - return err - } - - noProxy := client.getNoProxy(httpRequest.URL.Scheme) - - var flag bool - for _, value := range noProxy { - if value == httpRequest.Host { - flag = true - break - } - } - - // Set whether to ignore certificate validation. - // Default InsecureSkipVerify is false. - if trans, ok := client.httpClient.Transport.(*http.Transport); ok && trans != nil { - trans.TLSClientConfig = &tls.Config{ - InsecureSkipVerify: client.getHTTPSInsecure(request), - } - if proxy != nil && !flag { - trans.Proxy = http.ProxyURL(proxy) - } - client.httpClient.Transport = trans - } - - var httpResponse *http.Response - for retryTimes := 0; retryTimes <= client.config.MaxRetryTime; retryTimes++ { - if proxy != nil && proxy.User != nil { - if password, passwordSet := proxy.User.Password(); passwordSet { - httpRequest.SetBasicAuth(proxy.User.Username(), password) - } - } - if retryTimes > 0 { - client.printLog(fieldMap, err) - initLogMsg(fieldMap) - } - putMsgToMap(fieldMap, httpRequest) - debug("> %s %s %s", httpRequest.Method, httpRequest.URL.RequestURI(), httpRequest.Proto) - debug("> Host: %s", httpRequest.Host) - for key, value := range httpRequest.Header { - debug("> %s: %v", key, strings.Join(value, "")) - } - debug(">") - debug(" Retry Times: %d.", retryTimes) - - startTime := time.Now() - fieldMap["{start_time}"] = startTime.Format("2006-01-02 15:04:05") - httpResponse, err = hookDo(client.httpClient.Do)(httpRequest) - fieldMap["{cost}"] = time.Now().Sub(startTime).String() - if err == nil { - fieldMap["{code}"] = strconv.Itoa(httpResponse.StatusCode) - fieldMap["{res_headers}"] = TransToString(httpResponse.Header) - debug("< %s %s", httpResponse.Proto, httpResponse.Status) - for key, value := range httpResponse.Header { - debug("< %s: %v", key, strings.Join(value, "")) - } - } - debug("<") - // receive error - if err != nil { - debug(" Error: %s.", err.Error()) - if !client.config.AutoRetry { - return - } else if retryTimes >= client.config.MaxRetryTime { - // timeout but reached the max retry times, return - times := strconv.Itoa(retryTimes + 1) - timeoutErrorMsg := fmt.Sprintf(errors.TimeoutErrorMessage, times, times) - if strings.Contains(err.Error(), "Client.Timeout") { - timeoutErrorMsg += " Read timeout. Please set a valid ReadTimeout." - } else { - timeoutErrorMsg += " Connect timeout. Please set a valid ConnectTimeout." - } - err = errors.NewClientError(errors.TimeoutErrorCode, timeoutErrorMsg, err) - return - } - } - // if status code >= 500 or timeout, will trigger retry - if client.config.AutoRetry && (err != nil || isServerError(httpResponse)) { - client.setTimeout(request) - // rewrite signatureNonce and signature - httpRequest, err = client.buildRequestWithSigner(request, signer) - // buildHttpRequest(request, finalSigner, regionId) - if err != nil { - return - } - continue - } - break - } - - err = responses.Unmarshal(response, httpResponse, request.GetAcceptFormat()) - // wrap server errors - if serverErr, ok := err.(*errors.ServerError); ok { - var wrapInfo = map[string]string{} - wrapInfo["StringToSign"] = request.GetStringToSign() - err = errors.WrapServerError(serverErr, wrapInfo) - } - return -} - -func putMsgToMap(fieldMap map[string]string, request *http.Request) { - fieldMap["{host}"] = request.Host - fieldMap["{method}"] = request.Method - fieldMap["{uri}"] = request.URL.RequestURI() - fieldMap["{pid}"] = strconv.Itoa(os.Getpid()) - fieldMap["{version}"] = strings.Split(request.Proto, "/")[1] - hostname, _ := os.Hostname() - fieldMap["{hostname}"] = hostname - fieldMap["{req_headers}"] = TransToString(request.Header) - fieldMap["{target}"] = request.URL.Path + request.URL.RawQuery -} - -func buildHttpRequest(request requests.AcsRequest, singer auth.Signer, regionId string) (httpRequest *http.Request, err error) { - err = auth.Sign(request, singer, regionId) - if err != nil { - return - } - requestMethod := request.GetMethod() - requestUrl := request.BuildUrl() - body := request.GetBodyReader() - httpRequest, err = http.NewRequest(requestMethod, requestUrl, body) - if err != nil { - return - } - for key, value := range request.GetHeaders() { - httpRequest.Header[key] = []string{value} - } - // host is a special case - if host, containsHost := request.GetHeaders()["Host"]; containsHost { - httpRequest.Host = host - } - return -} - -func isServerError(httpResponse *http.Response) bool { - return httpResponse.StatusCode >= http.StatusInternalServerError -} - -/** -only block when any one of the following occurs: -1. the asyncTaskQueue is full, increase the queue size to avoid this -2. Shutdown() in progressing, the client is being closed -**/ -func (client *Client) AddAsyncTask(task func()) (err error) { - if client.asyncTaskQueue != nil { - client.asyncChanLock.RLock() - defer client.asyncChanLock.RUnlock() - if client.isRunning { - client.asyncTaskQueue <- task - } - } else { - err = errors.NewClientError(errors.AsyncFunctionNotEnabledCode, errors.AsyncFunctionNotEnabledMessage, nil) - } - return -} - -func (client *Client) GetConfig() *Config { - return client.config -} - -func NewClient() (client *Client, err error) { - client = &Client{} - err = client.Init() - return -} - -func NewClientWithProvider(regionId string, providers ...provider.Provider) (client *Client, err error) { - client = &Client{} - var pc provider.Provider - if len(providers) == 0 { - pc = provider.DefaultChain - } else { - pc = provider.NewProviderChain(providers) - } - err = client.InitWithProviderChain(regionId, pc) - return -} - -func NewClientWithOptions(regionId string, config *Config, credential auth.Credential) (client *Client, err error) { - client = &Client{} - err = client.InitWithOptions(regionId, config, credential) - return -} - -func NewClientWithAccessKey(regionId, accessKeyId, accessKeySecret string) (client *Client, err error) { - client = &Client{} - err = client.InitWithAccessKey(regionId, accessKeyId, accessKeySecret) - return -} - -func NewClientWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken string) (client *Client, err error) { - client = &Client{} - err = client.InitWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken) - return -} - -func NewClientWithRamRoleArn(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (client *Client, err error) { - client = &Client{} - err = client.InitWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName) - return -} - -func NewClientWithRamRoleArnAndPolicy(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy string) (client *Client, err error) { - client = &Client{} - err = client.InitWithRamRoleArnAndPolicy(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName, policy) - return -} - -func NewClientWithEcsRamRole(regionId string, roleName string) (client *Client, err error) { - client = &Client{} - err = client.InitWithEcsRamRole(regionId, roleName) - return -} - -func NewClientWithRsaKeyPair(regionId string, publicKeyId, privateKey string, sessionExpiration int) (client *Client, err error) { - client = &Client{} - err = client.InitWithRsaKeyPair(regionId, publicKeyId, privateKey, sessionExpiration) - return -} - -func NewClientWithBearerToken(regionId, bearerToken string) (client *Client, err error) { - client = &Client{} - err = client.InitWithBearerToken(regionId, bearerToken) - return -} - -func (client *Client) ProcessCommonRequest(request *requests.CommonRequest) (response *responses.CommonResponse, err error) { - request.TransToAcsRequest() - response = responses.NewCommonResponse() - err = client.DoAction(request, response) - return -} - -func (client *Client) ProcessCommonRequestWithSigner(request *requests.CommonRequest, signerInterface interface{}) (response *responses.CommonResponse, err error) { - if signer, isSigner := signerInterface.(auth.Signer); isSigner { - request.TransToAcsRequest() - response = responses.NewCommonResponse() - err = client.DoActionWithSigner(request, response, signer) - return - } - panic("should not be here") -} - -func (client *Client) Shutdown() { - // lock the addAsync() - client.asyncChanLock.Lock() - defer client.asyncChanLock.Unlock() - if client.asyncTaskQueue != nil { - close(client.asyncTaskQueue) - } - client.isRunning = false -} - -// Deprecated: Use NewClientWithRamRoleArn in this package instead. -func NewClientWithStsRoleArn(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (client *Client, err error) { - return NewClientWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName) -} - -// Deprecated: Use NewClientWithEcsRamRole in this package instead. -func NewClientWithStsRoleNameOnEcs(regionId string, roleName string) (client *Client, err error) { - return NewClientWithEcsRamRole(regionId, roleName) -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/config.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/config.go deleted file mode 100644 index e8862e0c..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/config.go +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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 sdk - -import ( - "net/http" - "time" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" -) - -type Config struct { - AutoRetry bool `default:"true"` - MaxRetryTime int `default:"3"` - UserAgent string `default:""` - Debug bool `default:"false"` - Timeout time.Duration `default:"10000000000"` - HttpTransport *http.Transport `default:""` - EnableAsync bool `default:"false"` - MaxTaskQueueSize int `default:"1000"` - GoRoutinePoolSize int `default:"5"` - Scheme string `default:"HTTP"` -} - -func NewConfig() (config *Config) { - config = &Config{} - utils.InitStructWithDefaultTag(config) - return -} - -func (c *Config) WithAutoRetry(isAutoRetry bool) *Config { - c.AutoRetry = isAutoRetry - return c -} - -func (c *Config) WithMaxRetryTime(maxRetryTime int) *Config { - c.MaxRetryTime = maxRetryTime - return c -} - -func (c *Config) WithUserAgent(userAgent string) *Config { - c.UserAgent = userAgent - return c -} - -func (c *Config) WithDebug(isDebug bool) *Config { - c.Debug = isDebug - return c -} - -func (c *Config) WithTimeout(timeout time.Duration) *Config { - c.Timeout = timeout - return c -} - -func (c *Config) WithHttpTransport(httpTransport *http.Transport) *Config { - c.HttpTransport = httpTransport - return c -} - -func (c *Config) WithEnableAsync(isEnableAsync bool) *Config { - c.EnableAsync = isEnableAsync - return c -} - -func (c *Config) WithMaxTaskQueueSize(maxTaskQueueSize int) *Config { - c.MaxTaskQueueSize = maxTaskQueueSize - return c -} - -func (c *Config) WithGoRoutinePoolSize(goRoutinePoolSize int) *Config { - c.GoRoutinePoolSize = goRoutinePoolSize - return c -} - -func (c *Config) WithScheme(scheme string) *Config { - c.Scheme = scheme - return c -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/endpoints_config.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/endpoints_config.go deleted file mode 100644 index d1409844..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/endpoints_config.go +++ /dev/null @@ -1,4126 +0,0 @@ -package endpoints - -import ( - "encoding/json" - "fmt" - "sync" -) - -const endpointsJson = `{ - "products": [ - { - "code": "emr", - "document_id": "28140", - "location_service_code": "emr", - "regional_endpoints": [ - { - "region": "cn-qingdao", - "endpoint": "emr.cn-qingdao.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "emr.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "emr.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "emr.eu-west-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "emr.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "emr.me-east-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "emr.ap-northeast-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "emr.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "emr.cn-huhehaote.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "emr.ap-south-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "emr.us-east-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "emr.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "emr.cn-hongkong.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "emr.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "emr.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "emr.ap-southeast-3.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "emr.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "emr.ap-southeast-5.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "emr.aliyuncs.com" - } - ], - "global_endpoint": "emr.aliyuncs.com", - "regional_endpoint_pattern": "emr.[RegionId].aliyuncs.com" - }, - { - "code": "petadata", - "document_id": "", - "location_service_code": "petadata", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "petadata.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "petadata.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "petadata.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "petadata.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "petadata.me-east-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "petadata.ap-southeast-2.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "petadata.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "petadata.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "petadata.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "petadata.ap-southeast-5.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "petadata.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "petadata.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "petadata.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "petadata.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "petadata.aliyuncs.com" - } - ], - "global_endpoint": "petadata.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "dbs", - "document_id": "", - "location_service_code": "dbs", - "regional_endpoints": [ - { - "region": "cn-shenzhen", - "endpoint": "dbs-api.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "dbs-api.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "dbs-api.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "dbs-api.ap-northeast-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "dbs-api.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "dbs-api.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "dbs-api.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "dbs-api.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "alidnsgtm", - "document_id": "", - "location_service_code": "alidnsgtm", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "alidns.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "alidns.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "elasticsearch", - "document_id": "", - "location_service_code": "elasticsearch", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "elasticsearch.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "elasticsearch.cn-shenzhen.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "elasticsearch.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "elasticsearch.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "elasticsearch.cn-hongkong.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "elasticsearch.ap-southeast-3.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "elasticsearch.us-west-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "elasticsearch.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "elasticsearch.ap-southeast-5.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "elasticsearch.eu-central-1.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "elasticsearch.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "elasticsearch.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "elasticsearch.cn-qingdao.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "elasticsearch.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "elasticsearch.ap-northeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "baas", - "document_id": "", - "location_service_code": "baas", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "baas.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "baas.ap-northeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "baas.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "baas.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "baas.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "baas.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "cr", - "document_id": "60716", - "location_service_code": "cr", - "regional_endpoints": null, - "global_endpoint": "cr.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "cloudap", - "document_id": "", - "location_service_code": "cloudap", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "cloudwf.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "imagesearch", - "document_id": "", - "location_service_code": "imagesearch", - "regional_endpoints": [ - { - "region": "ap-southeast-2", - "endpoint": "imagesearch.ap-southeast-2.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "imagesearch.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "imagesearch.ap-northeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "imagesearch.ap-southeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "pts", - "document_id": "", - "location_service_code": "pts", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "pts.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ehs", - "document_id": "", - "location_service_code": "ehs", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "ehpc.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "ehpc.cn-hongkong.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "ehpc.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "ehpc.cn-qingdao.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "ehpc.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "ehpc.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "ehpc.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "ehpc.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "ehpc.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "ehpc.cn-shenzhen.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "ehpc.ap-southeast-2.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "polardb", - "document_id": "58764", - "location_service_code": "polardb", - "regional_endpoints": [ - { - "region": "ap-south-1", - "endpoint": "polardb.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "polardb.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "polardb.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "polardb.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "polardb.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "polardb.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "polardb.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "polardb.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "polardb.ap-southeast-5.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "polardb.aliyuncs.com" - }, - { - "code": "r-kvstore", - "document_id": "60831", - "location_service_code": "redisa", - "regional_endpoints": [ - { - "region": "cn-shenzhen", - "endpoint": "r-kvstore.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "r-kvstore.cn-huhehaote.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "r-kvstore.ap-southeast-3.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "r-kvstore.ap-southeast-2.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "r-kvstore.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "r-kvstore.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "r-kvstore.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "r-kvstore.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "r-kvstore.cn-hongkong.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "r-kvstore.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "r-kvstore.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "r-kvstore.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "r-kvstore.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "r-kvstore.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "r-kvstore.eu-west-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "r-kvstore.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "r-kvstore.me-east-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "r-kvstore.ap-northeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "r-kvstore.ap-southeast-5.aliyuncs.com" - } - ], - "global_endpoint": "r-kvstore.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "xianzhi", - "document_id": "", - "location_service_code": "xianzhi", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "xianzhi.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "pcdn", - "document_id": "", - "location_service_code": "pcdn", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "pcdn.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "cdn", - "document_id": "27148", - "location_service_code": "cdn", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "cdn.aliyuncs.com" - } - ], - "global_endpoint": "cdn.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "cloudauth", - "document_id": "60687", - "location_service_code": "cloudauth", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "cloudauth.aliyuncs.com" - } - ], - "global_endpoint": "cloudauth.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "nas", - "document_id": "62598", - "location_service_code": "nas", - "regional_endpoints": [ - { - "region": "ap-southeast-2", - "endpoint": "nas.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "nas.ap-south-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "nas.eu-central-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "nas.us-west-1.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "nas.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "nas.cn-qingdao.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "nas.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "nas.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "nas.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "nas.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "nas.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "nas.ap-northeast-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "nas.us-east-1.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "nas.cn-shenzhen.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "nas.ap-southeast-5.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "nas.cn-hongkong.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "nas.ap-southeast-3.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "alidns", - "document_id": "29739", - "location_service_code": "alidns", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "alidns.aliyuncs.com" - } - ], - "global_endpoint": "alidns.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "dts", - "document_id": "", - "location_service_code": "dts", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "dts.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "dts.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "dts.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "dts.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "dts.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "dts.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "dts.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "dts.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "dts.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "emas", - "document_id": "", - "location_service_code": "emas", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "mhub.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "mhub.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "dysmsapi", - "document_id": "", - "location_service_code": "dysmsapi", - "regional_endpoints": [ - { - "region": "ap-southeast-3", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "dysmsapi.aliyuncs.com" - }, - { - "region": "cn-chengdu", - "endpoint": "dysmsapi.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "dysmsapi.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "dysmsapi.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "dysmsapi.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "dysmsapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "dysmsapi.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "dysmsapi.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "dysmsapi.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "cloudwf", - "document_id": "58111", - "location_service_code": "cloudwf", - "regional_endpoints": null, - "global_endpoint": "cloudwf.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "fc", - "document_id": "", - "location_service_code": "fc", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "cn-beijing.fc.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "ap-southeast-2.fc.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "cn-huhehaote.fc.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "cn-shanghai.fc.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "cn-hangzhou.fc.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "cn-shenzhen.fc.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "saf", - "document_id": "", - "location_service_code": "saf", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "saf.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "saf.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "saf.cn-shenzhen.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "rds", - "document_id": "26223", - "location_service_code": "rds", - "regional_endpoints": [ - { - "region": "ap-northeast-1", - "endpoint": "rds.ap-northeast-1.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "rds.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "rds.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "rds.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "rds.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "rds.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "rds.eu-west-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "rds.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "rds.ap-southeast-3.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "rds.ap-southeast-2.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "rds.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "rds.cn-huhehaote.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "rds.ap-southeast-5.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "rds.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "rds.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "rds.me-east-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "rds.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "rds.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "rds.aliyuncs.com" - } - ], - "global_endpoint": "rds.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "vpc", - "document_id": "34962", - "location_service_code": "vpc", - "regional_endpoints": [ - { - "region": "ap-south-1", - "endpoint": "vpc.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "vpc.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "vpc.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "vpc.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "vpc.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "vpc.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "vpc.ap-northeast-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "vpc.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "vpc.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "vpc.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "vpc.cn-huhehaote.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "vpc.me-east-1.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "vpc.ap-southeast-5.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "vpc.ap-southeast-3.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "vpc.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "vpc.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "vpc.eu-west-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "vpc.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "vpc.aliyuncs.com" - } - ], - "global_endpoint": "vpc.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "gpdb", - "document_id": "", - "location_service_code": "gpdb", - "regional_endpoints": [ - { - "region": "ap-southeast-3", - "endpoint": "gpdb.ap-southeast-3.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "gpdb.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "gpdb.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "gpdb.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "gpdb.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "gpdb.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "gpdb.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "gpdb.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "gpdb.ap-southeast-5.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "gpdb.ap-southeast-2.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "gpdb.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "gpdb.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "gpdb.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "gpdb.ap-northeast-1.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "gpdb.eu-west-1.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "gpdb.ap-south-1.aliyuncs.com" - } - ], - "global_endpoint": "gpdb.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "yunmarket", - "document_id": "", - "location_service_code": "yunmarket", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "market.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "pvtz", - "document_id": "", - "location_service_code": "pvtz", - "regional_endpoints": [ - { - "region": "ap-southeast-1", - "endpoint": "pvtz.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "pvtz.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "oss", - "document_id": "", - "location_service_code": "oss", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "oss-cn-beijing.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "oss-cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "oss-cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "oss-cn-hongkong.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "oss-cn-shenzhen.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "oss-ap-southeast-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "oss-us-west-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "oss-cn-qingdao.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "foas", - "document_id": "", - "location_service_code": "foas", - "regional_endpoints": [ - { - "region": "cn-qingdao", - "endpoint": "foas.cn-qingdao.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "foas.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "foas.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "foas.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "foas.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "foas.cn-shenzhen.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "foas.ap-northeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ddos", - "document_id": "", - "location_service_code": "ddos", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ddospro.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "ddospro.cn-hongkong.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "cbn", - "document_id": "", - "location_service_code": "cbn", - "regional_endpoints": [ - { - "region": "ap-southeast-1", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "cbn.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "cbn.aliyuncs.com" - } - ], - "global_endpoint": "cbn.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "nlp", - "document_id": "", - "location_service_code": "nlp", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "nlp.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "hsm", - "document_id": "", - "location_service_code": "hsm", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "hsm.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "hsm.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "hsm.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "hsm.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "hsm.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "hsm.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ons", - "document_id": "44416", - "location_service_code": "ons", - "regional_endpoints": [ - { - "region": "ap-southeast-1", - "endpoint": "ons.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "ons.cn-huhehaote.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "ons.us-east-1.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "ons.cn-hongkong.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "ons.cn-shenzhen.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "ons.ap-southeast-3.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "ons.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "ons.cn-qingdao.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "ons.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "ons.me-east-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "ons.ap-northeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "ons.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "ons.cn-hangzhou.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "ons.eu-central-1.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "ons.eu-west-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "ons.us-west-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "ons.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "ons.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "kms", - "document_id": "", - "location_service_code": "kms", - "regional_endpoints": [ - { - "region": "cn-hongkong", - "endpoint": "kms.cn-hongkong.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "kms.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "kms.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "kms.cn-qingdao.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "kms.eu-west-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "kms.us-east-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "kms.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "kms.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "kms.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "kms.ap-southeast-5.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "kms.cn-huhehaote.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "kms.me-east-1.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "kms.cn-shenzhen.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "kms.ap-southeast-3.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "kms.us-west-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "kms.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "kms.ap-southeast-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "kms.eu-central-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "kms.ap-northeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "cps", - "document_id": "", - "location_service_code": "cps", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "cloudpush.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ensdisk", - "document_id": "", - "location_service_code": "ensdisk", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ens.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "cloudapi", - "document_id": "43590", - "location_service_code": "apigateway", - "regional_endpoints": [ - { - "region": "ap-southeast-2", - "endpoint": "apigateway.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "apigateway.ap-south-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "apigateway.us-east-1.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "apigateway.me-east-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "apigateway.cn-qingdao.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "apigateway.cn-beijing.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "apigateway.ap-southeast-5.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "apigateway.ap-southeast-3.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "apigateway.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "apigateway.cn-huhehaote.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "apigateway.ap-southeast-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "apigateway.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "apigateway.cn-hangzhou.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "apigateway.us-west-1.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "apigateway.cn-shenzhen.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "apigateway.eu-west-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "apigateway.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "apigateway.ap-northeast-1.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "apigateway.cn-hongkong.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "apigateway.[RegionId].aliyuncs.com" - }, - { - "code": "eci", - "document_id": "", - "location_service_code": "eci", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "eci.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "eci.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "eci.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "eci.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "eci.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "eci.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "onsvip", - "document_id": "", - "location_service_code": "onsvip", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "ons.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "ons.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "ons.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "ons.cn-shenzhen.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "ons.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "ons.cn-qingdao.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "linkwan", - "document_id": "", - "location_service_code": "linkwan", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "linkwan.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "linkwan.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ddosdip", - "document_id": "", - "location_service_code": "ddosdip", - "regional_endpoints": [ - { - "region": "ap-southeast-1", - "endpoint": "ddosdip.ap-southeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "batchcompute", - "document_id": "44717", - "location_service_code": "batchcompute", - "regional_endpoints": [ - { - "region": "us-west-1", - "endpoint": "batchcompute.us-west-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "batchcompute.cn-qingdao.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "batchcompute.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "batchcompute.cn-shenzhen.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "batchcompute.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "batchcompute.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "batchcompute.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "batchcompute.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "batchcompute.ap-southeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "batchcompute.[RegionId].aliyuncs.com" - }, - { - "code": "aegis", - "document_id": "28449", - "location_service_code": "vipaegis", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "aegis.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "aegis.ap-southeast-3.aliyuncs.com" - } - ], - "global_endpoint": "aegis.cn-hangzhou.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "arms", - "document_id": "42924", - "location_service_code": "arms", - "regional_endpoints": [ - { - "region": "cn-hongkong", - "endpoint": "arms.cn-hongkong.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "arms.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "arms.cn-shenzhen.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "arms.cn-qingdao.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "arms.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "arms.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "arms.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "arms.[RegionId].aliyuncs.com" - }, - { - "code": "live", - "document_id": "48207", - "location_service_code": "live", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "live.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "live.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "live.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "live.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "live.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "live.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "live.aliyuncs.com" - } - ], - "global_endpoint": "live.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "alimt", - "document_id": "", - "location_service_code": "alimt", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "mt.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "actiontrail", - "document_id": "", - "location_service_code": "actiontrail", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "actiontrail.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "actiontrail.cn-qingdao.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "actiontrail.us-east-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "actiontrail.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "actiontrail.ap-southeast-3.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "actiontrail.ap-southeast-5.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "actiontrail.ap-south-1.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "actiontrail.me-east-1.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "actiontrail.cn-hongkong.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "actiontrail.cn-shenzhen.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "actiontrail.cn-hangzhou.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "actiontrail.eu-west-1.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "actiontrail.cn-huhehaote.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "actiontrail.ap-northeast-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "actiontrail.us-west-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "actiontrail.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "actiontrail.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "actiontrail.cn-beijing.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "actiontrail.ap-southeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "smartag", - "document_id": "", - "location_service_code": "smartag", - "regional_endpoints": [ - { - "region": "ap-southeast-3", - "endpoint": "smartag.ap-southeast-3.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "smartag.ap-southeast-5.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "smartag.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "smartag.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "smartag.cn-hongkong.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "smartag.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "smartag.ap-southeast-2.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "vod", - "document_id": "60574", - "location_service_code": "vod", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "vod.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "vod.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "vod.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "vod.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "vod.ap-southeast-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "vod.eu-central-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "domain", - "document_id": "42875", - "location_service_code": "domain", - "regional_endpoints": [ - { - "region": "ap-southeast-1", - "endpoint": "domain-intl.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "domain.aliyuncs.com" - } - ], - "global_endpoint": "domain.aliyuncs.com", - "regional_endpoint_pattern": "domain.aliyuncs.com" - }, - { - "code": "ros", - "document_id": "28899", - "location_service_code": "ros", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ros.aliyuncs.com" - } - ], - "global_endpoint": "ros.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "cloudphoto", - "document_id": "59902", - "location_service_code": "cloudphoto", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "cloudphoto.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "cloudphoto.[RegionId].aliyuncs.com" - }, - { - "code": "rtc", - "document_id": "", - "location_service_code": "rtc", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "rtc.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "odpsmayi", - "document_id": "", - "location_service_code": "odpsmayi", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "bsb.cloud.alipay.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "bsb.cloud.alipay.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ims", - "document_id": "", - "location_service_code": "ims", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ims.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "csb", - "document_id": "64837", - "location_service_code": "csb", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "csb.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "csb.cn-beijing.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "csb.[RegionId].aliyuncs.com" - }, - { - "code": "cds", - "document_id": "62887", - "location_service_code": "codepipeline", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "cds.cn-beijing.aliyuncs.com" - } - ], - "global_endpoint": "cds.cn-beijing.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "ddosbgp", - "document_id": "", - "location_service_code": "ddosbgp", - "regional_endpoints": [ - { - "region": "cn-huhehaote", - "endpoint": "ddosbgp.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "ddosbgp.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "ddosbgp.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "ddosbgp.cn-hongkong.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "ddosbgp.cn-hangzhou.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "ddosbgp.us-west-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "ddosbgp.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "ddosbgp.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "ddosbgp.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "dybaseapi", - "document_id": "", - "location_service_code": "dybaseapi", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "dybaseapi.aliyuncs.com" - }, - { - "region": "cn-chengdu", - "endpoint": "dybaseapi.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "dybaseapi.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "dybaseapi.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "dybaseapi.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "dybaseapi.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "dybaseapi.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "dybaseapi.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "dybaseapi.ap-southeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ecs", - "document_id": "25484", - "location_service_code": "ecs", - "regional_endpoints": [ - { - "region": "cn-huhehaote", - "endpoint": "ecs.cn-huhehaote.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "ecs.ap-northeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "ecs.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "ecs.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "ecs-cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "ecs-cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "ecs.ap-southeast-3.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "ecs.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "ecs.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "ecs-cn-hangzhou.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "ecs.eu-west-1.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "ecs.me-east-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "ecs-cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "ecs-cn-hangzhou.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "ecs-cn-hangzhou.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "ecs-cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "ecs.ap-southeast-5.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "ecs-cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "ecs-cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "ecs-cn-hangzhou.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "ccc", - "document_id": "63027", - "location_service_code": "ccc", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ccc.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "ccc.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "ccc.[RegionId].aliyuncs.com" - }, - { - "code": "cs", - "document_id": "26043", - "location_service_code": "cs", - "regional_endpoints": null, - "global_endpoint": "cs.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "drdspre", - "document_id": "", - "location_service_code": "drdspre", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "drds.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "drds.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "drds.cn-shenzhen.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "drds.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "drds.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "drds.cn-qingdao.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "drds.cn-beijing.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "dcdn", - "document_id": "", - "location_service_code": "dcdn", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "dcdn.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "dcdn.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "linkedmall", - "document_id": "", - "location_service_code": "linkedmall", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "linkedmall.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "linkedmall.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "trademark", - "document_id": "", - "location_service_code": "trademark", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "trademark.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "openanalytics", - "document_id": "", - "location_service_code": "openanalytics", - "regional_endpoints": [ - { - "region": "cn-shenzhen", - "endpoint": "openanalytics.cn-shenzhen.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "openanalytics.eu-west-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "openanalytics.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "openanalytics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "openanalytics.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "openanalytics.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "openanalytics.ap-southeast-3.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "openanalytics.cn-zhangjiakou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "sts", - "document_id": "28756", - "location_service_code": "sts", - "regional_endpoints": null, - "global_endpoint": "sts.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "waf", - "document_id": "62847", - "location_service_code": "waf", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "wafopenapi.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ots", - "document_id": "", - "location_service_code": "ots", - "regional_endpoints": [ - { - "region": "me-east-1", - "endpoint": "ots.me-east-1.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "ots.ap-southeast-5.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "ots.eu-west-1.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "ots.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "ots.cn-beijing.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "ots.ap-southeast-2.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "ots.us-west-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "ots.us-east-1.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "ots.ap-south-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "ots.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "ots.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "ots.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "ots.ap-northeast-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "ots.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "ots.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "ots.ap-southeast-3.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "cloudfirewall", - "document_id": "", - "location_service_code": "cloudfirewall", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "cloudfw.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "dm", - "document_id": "29434", - "location_service_code": "dm", - "regional_endpoints": [ - { - "region": "ap-southeast-2", - "endpoint": "dm.ap-southeast-2.aliyuncs.com" - } - ], - "global_endpoint": "dm.aliyuncs.com", - "regional_endpoint_pattern": "dm.[RegionId].aliyuncs.com" - }, - { - "code": "oas", - "document_id": "", - "location_service_code": "oas", - "regional_endpoints": [ - { - "region": "cn-shenzhen", - "endpoint": "cn-shenzhen.oas.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "cn-beijing.oas.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "cn-hangzhou.oas.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ddoscoo", - "document_id": "", - "location_service_code": "ddoscoo", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ddoscoo.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "jaq", - "document_id": "35037", - "location_service_code": "jaq", - "regional_endpoints": null, - "global_endpoint": "jaq.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "iovcc", - "document_id": "", - "location_service_code": "iovcc", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "iovcc.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "sas-api", - "document_id": "28498", - "location_service_code": "sas", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "sas.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "chatbot", - "document_id": "60760", - "location_service_code": "beebot", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "chatbot.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "chatbot.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "chatbot.[RegionId].aliyuncs.com" - }, - { - "code": "airec", - "document_id": "", - "location_service_code": "airec", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "airec.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "airec.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "airec.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "dmsenterprise", - "document_id": "", - "location_service_code": "dmsenterprise", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "dms-enterprise.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "dms-enterprise.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "dms-enterprise.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "dms-enterprise.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "dms-enterprise.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "dms-enterprise.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ivision", - "document_id": "", - "location_service_code": "ivision", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ivision.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "ivision.cn-beijing.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "odpsplusmayi", - "document_id": "", - "location_service_code": "odpsplusmayi", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "bsb.cloud.alipay.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "bsb.cloud.alipay.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "bsb.cloud.alipay.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "gameshield", - "document_id": "", - "location_service_code": "gameshield", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "gameshield.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "gameshield.cn-zhangjiakou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "scdn", - "document_id": "", - "location_service_code": "scdn", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "scdn.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "hitsdb", - "document_id": "", - "location_service_code": "hitsdb", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "hitsdb.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "hdm", - "document_id": "", - "location_service_code": "hdm", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "hdm-api.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "slb", - "document_id": "27565", - "location_service_code": "slb", - "regional_endpoints": [ - { - "region": "cn-shenzhen", - "endpoint": "slb.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "slb.eu-west-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "slb.ap-northeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "slb.ap-southeast-2.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "slb.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "slb.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "slb.cn-huhehaote.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "slb.ap-south-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "slb.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "slb.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "slb.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "slb.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "slb.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "slb.ap-southeast-5.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "slb.ap-southeast-3.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "slb.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "slb.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "slb.me-east-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "slb.cn-zhangjiakou.aliyuncs.com" - } - ], - "global_endpoint": "slb.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "green", - "document_id": "28427", - "location_service_code": "green", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "green.cn-beijing.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "green.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "green.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "green.cn-hangzhou.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "green.us-west-1.aliyuncs.com" - } - ], - "global_endpoint": "green.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "cccvn", - "document_id": "", - "location_service_code": "cccvn", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "voicenavigator.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ddosrewards", - "document_id": "", - "location_service_code": "ddosrewards", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ddosright.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "iot", - "document_id": "30557", - "location_service_code": "iot", - "regional_endpoints": [ - { - "region": "us-east-1", - "endpoint": "iot.us-east-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "iot.ap-northeast-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "iot.us-west-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "iot.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "iot.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "iot.ap-southeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "iot.[RegionId].aliyuncs.com" - }, - { - "code": "bssopenapi", - "document_id": "", - "location_service_code": "bssopenapi", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "business.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "business.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "business.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "business.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "business.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "business.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "business.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "business.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "business.ap-southeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "sca", - "document_id": "", - "location_service_code": "sca", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "qualitycheck.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "luban", - "document_id": "", - "location_service_code": "luban", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "luban.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "luban.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "drdspost", - "document_id": "", - "location_service_code": "drdspost", - "regional_endpoints": [ - { - "region": "cn-shanghai", - "endpoint": "drds.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "drds.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "drds.ap-southeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "drds", - "document_id": "51111", - "location_service_code": "drds", - "regional_endpoints": [ - { - "region": "ap-southeast-1", - "endpoint": "drds.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "drds.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "drds.aliyuncs.com", - "regional_endpoint_pattern": "drds.aliyuncs.com" - }, - { - "code": "httpdns", - "document_id": "52679", - "location_service_code": "httpdns", - "regional_endpoints": null, - "global_endpoint": "httpdns-api.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "cas", - "document_id": "", - "location_service_code": "cas", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "cas.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "cas.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "cas.ap-northeast-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "cas.eu-central-1.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "cas.me-east-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "hpc", - "document_id": "35201", - "location_service_code": "hpc", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "hpc.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "hpc.aliyuncs.com" - } - ], - "global_endpoint": "hpc.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "ddosbasic", - "document_id": "", - "location_service_code": "ddosbasic", - "regional_endpoints": [ - { - "region": "ap-south-1", - "endpoint": "antiddos-openapi.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "antiddos-openapi.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "antiddos.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "antiddos.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "antiddos-openapi.ap-southeast-3.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "antiddos-openapi.me-east-1.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "antiddos-openapi.ap-southeast-5.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "antiddos-openapi.ap-southeast-2.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "antiddos.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "antiddos.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "antiddos.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "antiddos-openapi.eu-west-1.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "antiddos-openapi.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "antiddos.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "antiddos.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "antiddos.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "antiddos-openapi.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "antiddos.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "antiddos-openapi.ap-northeast-1.aliyuncs.com" - } - ], - "global_endpoint": "antiddos.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "clouddesktop", - "document_id": "", - "location_service_code": "clouddesktop", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "clouddesktop.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "clouddesktop.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "clouddesktop.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "clouddesktop.cn-shenzhen.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "uis", - "document_id": "", - "location_service_code": "uis", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "uis.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "imm", - "document_id": "", - "location_service_code": "imm", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "imm.cn-beijing.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "imm.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "imm.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "imm.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "imm.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "imm.cn-shenzhen.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ens", - "document_id": "", - "location_service_code": "ens", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ens.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ram", - "document_id": "28672", - "location_service_code": "ram", - "regional_endpoints": null, - "global_endpoint": "ram.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "hcs_mgw", - "document_id": "", - "location_service_code": "hcs_mgw", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "mgw.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "mgw.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "mgw.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "itaas", - "document_id": "55759", - "location_service_code": "itaas", - "regional_endpoints": null, - "global_endpoint": "itaas.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "qualitycheck", - "document_id": "50807", - "location_service_code": "qualitycheck", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "qualitycheck.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "alikafka", - "document_id": "", - "location_service_code": "alikafka", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "alikafka.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "alikafka.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "alikafka.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "alikafka.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "alikafka.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "alikafka.cn-shenzhen.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "alikafka.cn-hongkong.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "alikafka.cn-qingdao.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "faas", - "document_id": "", - "location_service_code": "faas", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "faas.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "faas.cn-shenzhen.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "faas.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "faas.cn-beijing.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "alidfs", - "document_id": "", - "location_service_code": "alidfs", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "dfs.cn-beijing.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "dfs.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "cms", - "document_id": "28615", - "location_service_code": "cms", - "regional_endpoints": [ - { - "region": "ap-southeast-3", - "endpoint": "metrics.ap-southeast-3.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "metrics.ap-southeast-5.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "metrics.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "metrics.eu-west-1.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "metrics.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "metrics.ap-northeast-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "metrics.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "metrics.cn-hangzhou.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "domain-intl", - "document_id": "", - "location_service_code": "domain-intl", - "regional_endpoints": null, - "global_endpoint": "domain-intl.aliyuncs.com", - "regional_endpoint_pattern": "domain-intl.aliyuncs.com" - }, - { - "code": "kvstore", - "document_id": "", - "location_service_code": "kvstore", - "regional_endpoints": [ - { - "region": "ap-northeast-1", - "endpoint": "r-kvstore.ap-northeast-1.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ccs", - "document_id": "", - "location_service_code": "ccs", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "ccs.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "ess", - "document_id": "25925", - "location_service_code": "ess", - "regional_endpoints": [ - { - "region": "cn-huhehaote", - "endpoint": "ess.cn-huhehaote.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "ess.ap-southeast-2.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "ess.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "ess.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "ess.eu-west-1.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "ess.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "ess.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "ess.ap-southeast-5.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "ess.ap-southeast-3.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "ess.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "ess.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "ess.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "ess.me-east-1.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "ess.ap-northeast-1.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "ess.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "ess.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "ess.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "ess.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "ess.aliyuncs.com" - } - ], - "global_endpoint": "ess.aliyuncs.com", - "regional_endpoint_pattern": "ess.[RegionId].aliyuncs.com" - }, - { - "code": "dds", - "document_id": "61715", - "location_service_code": "dds", - "regional_endpoints": [ - { - "region": "me-east-1", - "endpoint": "mongodb.me-east-1.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "mongodb.ap-southeast-3.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "mongodb.ap-southeast-5.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "mongodb.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "mongodb.ap-northeast-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "mongodb.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "mongodb.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "mongodb.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "mongodb.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "mongodb.eu-west-1.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "mongodb.aliyuncs.com" - }, - { - "region": "cn-huhehaote", - "endpoint": "mongodb.cn-huhehaote.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "mongodb.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "mongodb.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "mongodb.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "mongodb.ap-southeast-2.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "mongodb.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "mongodb.ap-south-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "mongodb.aliyuncs.com" - } - ], - "global_endpoint": "mongodb.aliyuncs.com", - "regional_endpoint_pattern": "mongodb.[RegionId].aliyuncs.com" - }, - { - "code": "mts", - "document_id": "29212", - "location_service_code": "mts", - "regional_endpoints": [ - { - "region": "cn-beijing", - "endpoint": "mts.cn-beijing.aliyuncs.com" - }, - { - "region": "ap-northeast-1", - "endpoint": "mts.ap-northeast-1.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "mts.cn-hongkong.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "mts.cn-shenzhen.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "mts.cn-zhangjiakou.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "mts.ap-south-1.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "mts.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "mts.ap-southeast-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "mts.us-west-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "mts.eu-central-1.aliyuncs.com" - }, - { - "region": "eu-west-1", - "endpoint": "mts.eu-west-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "mts.cn-hangzhou.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "push", - "document_id": "30074", - "location_service_code": "push", - "regional_endpoints": null, - "global_endpoint": "cloudpush.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "hcs_sgw", - "document_id": "", - "location_service_code": "hcs_sgw", - "regional_endpoints": [ - { - "region": "eu-central-1", - "endpoint": "sgw.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "sgw.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-zhangjiakou", - "endpoint": "sgw.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "sgw.ap-southeast-1.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "sgw.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-hongkong", - "endpoint": "sgw.cn-shanghai.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "sgw.ap-southeast-2.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "sgw.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "sgw.cn-shanghai.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "sgw.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "hbase", - "document_id": "", - "location_service_code": "hbase", - "regional_endpoints": [ - { - "region": "cn-huhehaote", - "endpoint": "hbase.cn-huhehaote.aliyuncs.com" - }, - { - "region": "ap-south-1", - "endpoint": "hbase.ap-south-1.aliyuncs.com" - }, - { - "region": "us-west-1", - "endpoint": "hbase.aliyuncs.com" - }, - { - "region": "me-east-1", - "endpoint": "hbase.me-east-1.aliyuncs.com" - }, - { - "region": "eu-central-1", - "endpoint": "hbase.eu-central-1.aliyuncs.com" - }, - { - "region": "cn-qingdao", - "endpoint": "hbase.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "hbase.aliyuncs.com" - }, - { - "region": "cn-shenzhen", - "endpoint": "hbase.aliyuncs.com" - }, - { - "region": "ap-southeast-2", - "endpoint": "hbase.ap-southeast-2.aliyuncs.com" - }, - { - "region": "ap-southeast-3", - "endpoint": "hbase.ap-southeast-3.aliyuncs.com" - }, - { - "region": "cn-hangzhou", - "endpoint": "hbase.aliyuncs.com" - }, - { - "region": "us-east-1", - "endpoint": "hbase.aliyuncs.com" - }, - { - "region": "ap-southeast-5", - "endpoint": "hbase.ap-southeast-5.aliyuncs.com" - }, - { - "region": "cn-beijing", - "endpoint": "hbase.aliyuncs.com" - }, - { - "region": "ap-southeast-1", - "endpoint": "hbase.aliyuncs.com" - } - ], - "global_endpoint": "hbase.aliyuncs.com", - "regional_endpoint_pattern": "" - }, - { - "code": "bastionhost", - "document_id": "", - "location_service_code": "bastionhost", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "yundun-bastionhost.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - }, - { - "code": "vs", - "document_id": "", - "location_service_code": "vs", - "regional_endpoints": [ - { - "region": "cn-hangzhou", - "endpoint": "vs.cn-hangzhou.aliyuncs.com" - }, - { - "region": "cn-shanghai", - "endpoint": "vs.cn-shanghai.aliyuncs.com" - } - ], - "global_endpoint": "", - "regional_endpoint_pattern": "" - } - ] -}` - -var initOnce sync.Once -var data interface{} - -func getEndpointConfigData() interface{} { - initOnce.Do(func() { - err := json.Unmarshal([]byte(endpointsJson), &data) - if err != nil { - panic(fmt.Sprintf("init endpoint config data failed. %s", err)) - } - }) - return data -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/local_global_resolver.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/local_global_resolver.go deleted file mode 100644 index 160e62cb..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/local_global_resolver.go +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 endpoints - -import ( - "fmt" - "strings" - - "github.com/jmespath/go-jmespath" -) - -type LocalGlobalResolver struct { -} - -func (resolver *LocalGlobalResolver) GetName() (name string) { - name = "local global resolver" - return -} - -func (resolver *LocalGlobalResolver) TryResolve(param *ResolveParam) (endpoint string, support bool, err error) { - // get the global endpoints configs - endpointExpression := fmt.Sprintf("products[?code=='%s'].global_endpoint", strings.ToLower(param.Product)) - endpointData, err := jmespath.Search(endpointExpression, getEndpointConfigData()) - if err == nil && endpointData != nil && len(endpointData.([]interface{})) > 0 { - endpoint = endpointData.([]interface{})[0].(string) - support = len(endpoint) > 0 - return - } - support = false - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/local_regional_resolver.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/local_regional_resolver.go deleted file mode 100644 index 7fee64d4..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/local_regional_resolver.go +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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 endpoints - -import ( - "fmt" - "strings" - - "github.com/jmespath/go-jmespath" -) - -type LocalRegionalResolver struct { -} - -func (resolver *LocalRegionalResolver) GetName() (name string) { - name = "local regional resolver" - return -} - -func (resolver *LocalRegionalResolver) TryResolve(param *ResolveParam) (endpoint string, support bool, err error) { - // get the regional endpoints configs - regionalExpression := fmt.Sprintf("products[?code=='%s'].regional_endpoints", strings.ToLower(param.Product)) - regionalData, err := jmespath.Search(regionalExpression, getEndpointConfigData()) - if err == nil && regionalData != nil && len(regionalData.([]interface{})) > 0 { - endpointExpression := fmt.Sprintf("[0][?region=='%s'].endpoint", strings.ToLower(param.RegionId)) - var endpointData interface{} - endpointData, err = jmespath.Search(endpointExpression, regionalData) - if err == nil && endpointData != nil && len(endpointData.([]interface{})) > 0 { - endpoint = endpointData.([]interface{})[0].(string) - support = len(endpoint) > 0 - return - } - } - support = false - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/location_resolver.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/location_resolver.go deleted file mode 100644 index cc354cc4..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/location_resolver.go +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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 endpoints - -import ( - "encoding/json" - "sync" - "time" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" -) - -const ( - // EndpointCacheExpireTime ... - EndpointCacheExpireTime = 3600 //Seconds -) - -// Cache caches endpoint for specific product and region -type Cache struct { - sync.RWMutex - cache map[string]interface{} -} - -// Get ... -func (c *Cache) Get(k string) (v interface{}) { - c.RLock() - v = c.cache[k] - c.RUnlock() - return -} - -// Set ... -func (c *Cache) Set(k string, v interface{}) { - c.Lock() - c.cache[k] = v - c.Unlock() -} - -var lastClearTimePerProduct = &Cache{cache: make(map[string]interface{})} -var endpointCache = &Cache{cache: make(map[string]interface{})} - -// LocationResolver ... -type LocationResolver struct { -} - -func (resolver *LocationResolver) GetName() (name string) { - name = "location resolver" - return -} - -// TryResolve resolves endpoint giving product and region -func (resolver *LocationResolver) TryResolve(param *ResolveParam) (endpoint string, support bool, err error) { - if len(param.LocationProduct) <= 0 { - support = false - return - } - - //get from cache - cacheKey := param.Product + "#" + param.RegionId - var ok bool - endpoint, ok = endpointCache.Get(cacheKey).(string) - - if ok && len(endpoint) > 0 && !CheckCacheIsExpire(cacheKey) { - support = true - return - } - - //get from remote - getEndpointRequest := requests.NewCommonRequest() - - getEndpointRequest.Product = "Location" - getEndpointRequest.Version = "2015-06-12" - getEndpointRequest.ApiName = "DescribeEndpoints" - getEndpointRequest.Domain = "location-readonly.aliyuncs.com" - getEndpointRequest.Method = "GET" - getEndpointRequest.Scheme = requests.HTTPS - - getEndpointRequest.QueryParams["Id"] = param.RegionId - getEndpointRequest.QueryParams["ServiceCode"] = param.LocationProduct - if len(param.LocationEndpointType) > 0 { - getEndpointRequest.QueryParams["Type"] = param.LocationEndpointType - } else { - getEndpointRequest.QueryParams["Type"] = "openAPI" - } - - response, err := param.CommonApi(getEndpointRequest) - if err != nil { - support = false - return - } - - if !response.IsSuccess() { - support = false - return - } - - var getEndpointResponse GetEndpointResponse - err = json.Unmarshal([]byte(response.GetHttpContentString()), &getEndpointResponse) - if err != nil { - support = false - return - } - - if !getEndpointResponse.Success || getEndpointResponse.Endpoints == nil { - support = false - return - } - if len(getEndpointResponse.Endpoints.Endpoint) <= 0 { - support = false - return - } - if len(getEndpointResponse.Endpoints.Endpoint[0].Endpoint) > 0 { - endpoint = getEndpointResponse.Endpoints.Endpoint[0].Endpoint - endpointCache.Set(cacheKey, endpoint) - lastClearTimePerProduct.Set(cacheKey, time.Now().Unix()) - support = true - return - } - - support = false - return -} - -// CheckCacheIsExpire ... -func CheckCacheIsExpire(cacheKey string) bool { - lastClearTime, ok := lastClearTimePerProduct.Get(cacheKey).(int64) - if !ok { - return true - } - - if lastClearTime <= 0 { - lastClearTime = time.Now().Unix() - lastClearTimePerProduct.Set(cacheKey, lastClearTime) - } - - now := time.Now().Unix() - elapsedTime := now - lastClearTime - if elapsedTime > EndpointCacheExpireTime { - return true - } - - return false -} - -// GetEndpointResponse ... -type GetEndpointResponse struct { - Endpoints *EndpointsObj - RequestId string - Success bool -} - -// EndpointsObj ... -type EndpointsObj struct { - Endpoint []EndpointObj -} - -// EndpointObj ... -type EndpointObj struct { - // Protocols map[string]string - Type string - Namespace string - Id string - SerivceCode string - Endpoint string -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/mapping_resolver.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/mapping_resolver.go deleted file mode 100644 index e39f5336..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/mapping_resolver.go +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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 endpoints - -import ( - "fmt" - "strings" -) - -const keyFormatter = "%s::%s" - -var endpointMapping = make(map[string]string) - -// AddEndpointMapping Use product id and region id as key to store the endpoint into inner map -func AddEndpointMapping(regionId, productId, endpoint string) (err error) { - key := fmt.Sprintf(keyFormatter, strings.ToLower(regionId), strings.ToLower(productId)) - endpointMapping[key] = endpoint - return nil -} - -// MappingResolver the mapping resolver type -type MappingResolver struct { -} - -// GetName get the resolver name: "mapping resolver" -func (resolver *MappingResolver) GetName() (name string) { - name = "mapping resolver" - return -} - -// TryResolve use Product and RegionId as key to find endpoint from inner map -func (resolver *MappingResolver) TryResolve(param *ResolveParam) (endpoint string, support bool, err error) { - key := fmt.Sprintf(keyFormatter, strings.ToLower(param.RegionId), strings.ToLower(param.Product)) - endpoint, contains := endpointMapping[key] - return endpoint, contains, nil -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/resolver.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/resolver.go deleted file mode 100644 index 5e1e3053..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/resolver.go +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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 endpoints - -import ( - "encoding/json" - "fmt" - "sync" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" -) - -var debug utils.Debug - -func init() { - debug = utils.Init("sdk") -} - -const ( - ResolveEndpointUserGuideLink = "" -) - -var once sync.Once -var resolvers []Resolver - -type Resolver interface { - TryResolve(param *ResolveParam) (endpoint string, support bool, err error) - GetName() (name string) -} - -// Resolve resolve endpoint with params -// It will resolve with each supported resolver until anyone resolved -func Resolve(param *ResolveParam) (endpoint string, err error) { - supportedResolvers := getAllResolvers() - var lastErr error - for _, resolver := range supportedResolvers { - endpoint, supported, resolveErr := resolver.TryResolve(param) - if resolveErr != nil { - lastErr = resolveErr - } - - if supported { - debug("resolve endpoint with %s\n", param) - debug("\t%s by resolver(%s)\n", endpoint, resolver.GetName()) - return endpoint, nil - } - } - - // not support - errorMsg := fmt.Sprintf(errors.CanNotResolveEndpointErrorMessage, param, ResolveEndpointUserGuideLink) - err = errors.NewClientError(errors.CanNotResolveEndpointErrorCode, errorMsg, lastErr) - return -} - -func getAllResolvers() []Resolver { - once.Do(func() { - resolvers = []Resolver{ - &SimpleHostResolver{}, - &MappingResolver{}, - &LocationResolver{}, - &LocalRegionalResolver{}, - &LocalGlobalResolver{}, - } - }) - return resolvers -} - -type ResolveParam struct { - Domain string - Product string - RegionId string - LocationProduct string - LocationEndpointType string - CommonApi func(request *requests.CommonRequest) (response *responses.CommonResponse, err error) `json:"-"` -} - -func (param *ResolveParam) String() string { - jsonBytes, err := json.Marshal(param) - if err != nil { - return fmt.Sprint("ResolveParam.String() process error:", err) - } - return string(jsonBytes) -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/simple_host_resolver.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/simple_host_resolver.go deleted file mode 100644 index 9ba2346c..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/endpoints/simple_host_resolver.go +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 endpoints - -// SimpleHostResolver the simple host resolver type -type SimpleHostResolver struct { -} - -// GetName get the resolver name: "simple host resolver" -func (resolver *SimpleHostResolver) GetName() (name string) { - name = "simple host resolver" - return -} - -// TryResolve if the Domain exist in param, use it as endpoint -func (resolver *SimpleHostResolver) TryResolve(param *ResolveParam) (endpoint string, support bool, err error) { - if support = len(param.Domain) > 0; support { - endpoint = param.Domain - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/client_error.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/client_error.go deleted file mode 100644 index 1e2d9c00..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/client_error.go +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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 errors - -import "fmt" - -const ( - DefaultClientErrorStatus = 400 - DefaultClientErrorCode = "SDK.ClientError" - - UnsupportedCredentialErrorCode = "SDK.UnsupportedCredential" - UnsupportedCredentialErrorMessage = "Specified credential (type = %s) is not supported, please check" - - CanNotResolveEndpointErrorCode = "SDK.CanNotResolveEndpoint" - CanNotResolveEndpointErrorMessage = "Can not resolve endpoint(param = %s), please check your accessKey with secret, and read the user guide\n %s" - - UnsupportedParamPositionErrorCode = "SDK.UnsupportedParamPosition" - UnsupportedParamPositionErrorMessage = "Specified param position (%s) is not supported, please upgrade sdk and retry" - - AsyncFunctionNotEnabledCode = "SDK.AsyncFunctionNotEnabled" - AsyncFunctionNotEnabledMessage = "Async function is not enabled in client, please invoke 'client.EnableAsync' function" - - UnknownRequestTypeErrorCode = "SDK.UnknownRequestType" - UnknownRequestTypeErrorMessage = "Unknown Request Type: %s" - - MissingParamErrorCode = "SDK.MissingParam" - InvalidParamErrorCode = "SDK.InvalidParam" - - JsonUnmarshalErrorCode = "SDK.JsonUnmarshalError" - JsonUnmarshalErrorMessage = "Failed to unmarshal response, but you can get the data via response.GetHttpStatusCode() and response.GetHttpContentString()" - - TimeoutErrorCode = "SDK.TimeoutError" - TimeoutErrorMessage = "The request timed out %s times(%s for retry), perhaps we should have the threshold raised a little?" -) - -type ClientError struct { - errorCode string - message string - originError error -} - -func NewClientError(errorCode, message string, originErr error) Error { - return &ClientError{ - errorCode: errorCode, - message: message, - originError: originErr, - } -} - -func (err *ClientError) Error() string { - clientErrMsg := fmt.Sprintf("[%s] %s", err.ErrorCode(), err.message) - if err.originError != nil { - return clientErrMsg + "\ncaused by:\n" + err.originError.Error() - } - return clientErrMsg -} - -func (err *ClientError) OriginError() error { - return err.originError -} - -func (*ClientError) HttpStatus() int { - return DefaultClientErrorStatus -} - -func (err *ClientError) ErrorCode() string { - if err.errorCode == "" { - return DefaultClientErrorCode - } else { - return err.errorCode - } -} - -func (err *ClientError) Message() string { - return err.message -} - -func (err *ClientError) String() string { - return err.Error() -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/error.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/error.go deleted file mode 100644 index 49962f3b..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/error.go +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 errors - -type Error interface { - error - HttpStatus() int - ErrorCode() string - Message() string - OriginError() error -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/server_error.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/server_error.go deleted file mode 100644 index 1b781041..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/server_error.go +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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 errors - -import ( - "encoding/json" - "fmt" - - "github.com/jmespath/go-jmespath" -) - -var wrapperList = []ServerErrorWrapper{ - &SignatureDostNotMatchWrapper{}, -} - -type ServerError struct { - httpStatus int - requestId string - hostId string - errorCode string - recommend string - message string - comment string -} - -type ServerErrorWrapper interface { - tryWrap(error *ServerError, wrapInfo map[string]string) bool -} - -func (err *ServerError) Error() string { - return fmt.Sprintf("SDK.ServerError\nErrorCode: %s\nRecommend: %s\nRequestId: %s\nMessage: %s", - err.errorCode, err.comment+err.recommend, err.requestId, err.message) -} - -func NewServerError(httpStatus int, responseContent, comment string) Error { - result := &ServerError{ - httpStatus: httpStatus, - message: responseContent, - comment: comment, - } - - var data interface{} - err := json.Unmarshal([]byte(responseContent), &data) - if err == nil { - requestId, _ := jmespath.Search("RequestId", data) - hostId, _ := jmespath.Search("HostId", data) - errorCode, _ := jmespath.Search("Code", data) - recommend, _ := jmespath.Search("Recommend", data) - message, _ := jmespath.Search("Message", data) - - if requestId != nil { - result.requestId = requestId.(string) - } - if hostId != nil { - result.hostId = hostId.(string) - } - if errorCode != nil { - result.errorCode = errorCode.(string) - } - if recommend != nil { - result.recommend = recommend.(string) - } - if message != nil { - result.message = message.(string) - } - } - - return result -} - -func WrapServerError(originError *ServerError, wrapInfo map[string]string) *ServerError { - for _, wrapper := range wrapperList { - ok := wrapper.tryWrap(originError, wrapInfo) - if ok { - return originError - } - } - return originError -} - -func (err *ServerError) HttpStatus() int { - return err.httpStatus -} - -func (err *ServerError) ErrorCode() string { - return err.errorCode -} - -func (err *ServerError) Message() string { - return err.message -} - -func (err *ServerError) OriginError() error { - return nil -} - -func (err *ServerError) HostId() string { - return err.hostId -} - -func (err *ServerError) RequestId() string { - return err.requestId -} - -func (err *ServerError) Recommend() string { - return err.recommend -} - -func (err *ServerError) Comment() string { - return err.comment -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/signature_does_not_match_wrapper.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/signature_does_not_match_wrapper.go deleted file mode 100644 index 4b09d7d7..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors/signature_does_not_match_wrapper.go +++ /dev/null @@ -1,45 +0,0 @@ -package errors - -import ( - "strings" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" -) - -const SignatureDostNotMatchErrorCode = "SignatureDoesNotMatch" -const IncompleteSignatureErrorCode = "IncompleteSignature" -const MessageContain = "server string to sign is:" - -var debug utils.Debug - -func init() { - debug = utils.Init("sdk") -} - -type SignatureDostNotMatchWrapper struct { -} - -func (*SignatureDostNotMatchWrapper) tryWrap(error *ServerError, wrapInfo map[string]string) (ok bool) { - clientStringToSign := wrapInfo["StringToSign"] - if (error.errorCode == SignatureDostNotMatchErrorCode || error.errorCode == IncompleteSignatureErrorCode) && clientStringToSign != "" { - message := error.message - if strings.Contains(message, MessageContain) { - str := strings.Split(message, MessageContain) - serverStringToSign := str[1] - - if clientStringToSign == serverStringToSign { - // user secret is error - error.recommend = "InvalidAccessKeySecret: Please check you AccessKeySecret" - } else { - debug("Client StringToSign: %s", clientStringToSign) - debug("Server StringToSign: %s", serverStringToSign) - error.recommend = "This may be a bug with the SDK and we hope you can submit this question in the " + - "github issue(https://github.com/aliyun/alibaba-cloud-sdk-go/issues), thanks very much" - } - } - ok = true - return - } - ok = false - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/logger.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/logger.go deleted file mode 100644 index 04f03393..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/logger.go +++ /dev/null @@ -1,116 +0,0 @@ -package sdk - -import ( - "encoding/json" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" - "io" - "log" - "os" - "strings" - "time" -) - -var logChannel string -var defaultChannel = "AlibabaCloud" - -type Logger struct { - *log.Logger - formatTemplate string - isOpen bool - lastLogMsg string -} - -var defaultLoggerTemplate = `{time} {channel}: "{method} {uri} HTTP/{version}" {code} {cost} {hostname}` -var loggerParam = []string{"{time}", "{start_time}", "{ts}", "{channel}", "{pid}", "{host}", "{method}", "{uri}", "{version}", "{target}", "{hostname}", "{code}", "{error}", "{req_headers}", "{res_headers}", "{cost}"} - -func initLogMsg(fieldMap map[string]string) { - for _, value := range loggerParam { - fieldMap[value] = "" - } -} - -func (client *Client) GetLogger() *Logger { - return client.logger -} - -func (client *Client) GetLoggerMsg() string { - if client.logger == nil { - client.SetLogger("", "", os.Stdout, "") - } - return client.logger.lastLogMsg -} - -func (client *Client) SetLogger(level string, channel string, out io.Writer, template string) { - if level == "" { - level = "info" - } - - logChannel = "AlibabaCloud" - if channel != "" { - logChannel = channel - } - log := log.New(out, "["+strings.ToUpper(level)+"]", log.Lshortfile) - if template == "" { - template = defaultLoggerTemplate - } - - client.logger = &Logger{ - Logger: log, - formatTemplate: template, - isOpen: true, - } -} - -func (client *Client) OpenLogger() { - if client.logger == nil { - client.SetLogger("", "", os.Stdout, "") - } - client.logger.isOpen = true -} - -func (client *Client) CloseLogger() { - if client.logger != nil { - client.logger.isOpen = false - } -} - -func (client *Client) SetTemplate(template string) { - if client.logger == nil { - client.SetLogger("", "", os.Stdout, "") - } - client.logger.formatTemplate = template -} - -func (client *Client) GetTemplate() string { - if client.logger == nil { - client.SetLogger("", "", os.Stdout, "") - } - return client.logger.formatTemplate -} - -func TransToString(object interface{}) string { - byt, err := json.Marshal(object) - if err != nil { - return "" - } - return string(byt) -} - -func (client *Client) printLog(fieldMap map[string]string, err error) { - if err != nil { - fieldMap["{error}"] = err.Error() - } - fieldMap["{time}"] = time.Now().Format("2006-01-02 15:04:05") - fieldMap["{ts}"] = utils.GetTimeInFormatISO8601() - fieldMap["{channel}"] = logChannel - if client.logger != nil { - logMsg := client.logger.formatTemplate - for key, value := range fieldMap { - logMsg = strings.Replace(logMsg, key, value, -1) - } - client.logger.lastLogMsg = logMsg - if client.logger.isOpen == true { - client.logger.Output(2, logMsg) - } - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/acs_request.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/acs_request.go deleted file mode 100644 index fa22db1f..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/acs_request.go +++ /dev/null @@ -1,378 +0,0 @@ -/* - * 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 requests - -import ( - "encoding/json" - "fmt" - "io" - "reflect" - "strconv" - "strings" - "time" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors" -) - -const ( - RPC = "RPC" - ROA = "ROA" - - HTTP = "HTTP" - HTTPS = "HTTPS" - - DefaultHttpPort = "80" - - GET = "GET" - PUT = "PUT" - POST = "POST" - DELETE = "DELETE" - HEAD = "HEAD" - OPTIONS = "OPTIONS" - - Json = "application/json" - Xml = "application/xml" - Raw = "application/octet-stream" - Form = "application/x-www-form-urlencoded" - - Header = "Header" - Query = "Query" - Body = "Body" - Path = "Path" - - HeaderSeparator = "\n" -) - -// interface -type AcsRequest interface { - GetScheme() string - GetMethod() string - GetDomain() string - GetPort() string - GetRegionId() string - GetHeaders() map[string]string - GetQueryParams() map[string]string - GetFormParams() map[string]string - GetContent() []byte - GetBodyReader() io.Reader - GetStyle() string - GetProduct() string - GetVersion() string - SetVersion(version string) - GetActionName() string - GetAcceptFormat() string - GetLocationServiceCode() string - GetLocationEndpointType() string - GetReadTimeout() time.Duration - GetConnectTimeout() time.Duration - SetReadTimeout(readTimeout time.Duration) - SetConnectTimeout(connectTimeout time.Duration) - SetHTTPSInsecure(isInsecure bool) - GetHTTPSInsecure() *bool - - GetUserAgent() map[string]string - - SetStringToSign(stringToSign string) - GetStringToSign() string - - SetDomain(domain string) - SetContent(content []byte) - SetScheme(scheme string) - BuildUrl() string - BuildQueries() string - - addHeaderParam(key, value string) - addQueryParam(key, value string) - addFormParam(key, value string) - addPathParam(key, value string) -} - -// base class -type baseRequest struct { - Scheme string - Method string - Domain string - Port string - RegionId string - ReadTimeout time.Duration - ConnectTimeout time.Duration - isInsecure *bool - - userAgent map[string]string - product string - version string - - actionName string - - AcceptFormat string - - QueryParams map[string]string - Headers map[string]string - FormParams map[string]string - Content []byte - - locationServiceCode string - locationEndpointType string - - queries string - - stringToSign string -} - -func (request *baseRequest) GetQueryParams() map[string]string { - return request.QueryParams -} - -func (request *baseRequest) GetFormParams() map[string]string { - return request.FormParams -} - -func (request *baseRequest) GetReadTimeout() time.Duration { - return request.ReadTimeout -} - -func (request *baseRequest) GetConnectTimeout() time.Duration { - return request.ConnectTimeout -} - -func (request *baseRequest) SetReadTimeout(readTimeout time.Duration) { - request.ReadTimeout = readTimeout -} - -func (request *baseRequest) SetConnectTimeout(connectTimeout time.Duration) { - request.ConnectTimeout = connectTimeout -} - -func (request *baseRequest) GetHTTPSInsecure() *bool { - return request.isInsecure -} - -func (request *baseRequest) SetHTTPSInsecure(isInsecure bool) { - request.isInsecure = &isInsecure -} - -func (request *baseRequest) GetContent() []byte { - return request.Content -} - -func (request *baseRequest) SetVersion(version string) { - request.version = version -} - -func (request *baseRequest) GetVersion() string { - return request.version -} - -func (request *baseRequest) GetActionName() string { - return request.actionName -} - -func (request *baseRequest) SetContent(content []byte) { - request.Content = content -} - -func (request *baseRequest) GetUserAgent() map[string]string { - return request.userAgent -} - -func (request *baseRequest) AppendUserAgent(key, value string) { - newkey := true - if request.userAgent == nil { - request.userAgent = make(map[string]string) - } - if strings.ToLower(key) != "core" && strings.ToLower(key) != "go" { - for tag, _ := range request.userAgent { - if tag == key { - request.userAgent[tag] = value - newkey = false - } - } - if newkey { - request.userAgent[key] = value - } - } -} - -func (request *baseRequest) addHeaderParam(key, value string) { - request.Headers[key] = value -} - -func (request *baseRequest) addQueryParam(key, value string) { - request.QueryParams[key] = value -} - -func (request *baseRequest) addFormParam(key, value string) { - request.FormParams[key] = value -} - -func (request *baseRequest) GetAcceptFormat() string { - return request.AcceptFormat -} - -func (request *baseRequest) GetLocationServiceCode() string { - return request.locationServiceCode -} - -func (request *baseRequest) GetLocationEndpointType() string { - return request.locationEndpointType -} - -func (request *baseRequest) GetProduct() string { - return request.product -} - -func (request *baseRequest) GetScheme() string { - return request.Scheme -} - -func (request *baseRequest) SetScheme(scheme string) { - request.Scheme = scheme -} - -func (request *baseRequest) GetMethod() string { - return request.Method -} - -func (request *baseRequest) GetDomain() string { - return request.Domain -} - -func (request *baseRequest) SetDomain(host string) { - request.Domain = host -} - -func (request *baseRequest) GetPort() string { - return request.Port -} - -func (request *baseRequest) GetRegionId() string { - return request.RegionId -} - -func (request *baseRequest) GetHeaders() map[string]string { - return request.Headers -} - -func (request *baseRequest) SetContentType(contentType string) { - request.addHeaderParam("Content-Type", contentType) -} - -func (request *baseRequest) GetContentType() (contentType string, contains bool) { - contentType, contains = request.Headers["Content-Type"] - return -} - -func (request *baseRequest) SetStringToSign(stringToSign string) { - request.stringToSign = stringToSign -} - -func (request *baseRequest) GetStringToSign() string { - return request.stringToSign -} - -func defaultBaseRequest() (request *baseRequest) { - request = &baseRequest{ - Scheme: "", - AcceptFormat: "JSON", - Method: GET, - QueryParams: make(map[string]string), - Headers: map[string]string{ - "x-sdk-client": "golang/1.0.0", - "x-sdk-invoke-type": "normal", - "Accept-Encoding": "identity", - }, - FormParams: make(map[string]string), - } - return -} - -func InitParams(request AcsRequest) (err error) { - requestValue := reflect.ValueOf(request).Elem() - err = flatRepeatedList(requestValue, request, "", "") - return -} - -func flatRepeatedList(dataValue reflect.Value, request AcsRequest, position, prefix string) (err error) { - dataType := dataValue.Type() - for i := 0; i < dataType.NumField(); i++ { - field := dataType.Field(i) - name, containsNameTag := field.Tag.Lookup("name") - fieldPosition := position - if fieldPosition == "" { - fieldPosition, _ = field.Tag.Lookup("position") - } - typeTag, containsTypeTag := field.Tag.Lookup("type") - if containsNameTag { - if !containsTypeTag { - // simple param - key := prefix + name - value := dataValue.Field(i).String() - if dataValue.Field(i).Kind().String() == "map" { - byt, _ := json.Marshal(dataValue.Field(i).Interface()) - value = string(byt) - } - err = addParam(request, fieldPosition, key, value) - if err != nil { - return - } - } else if typeTag == "Repeated" { - // repeated param - repeatedFieldValue := dataValue.Field(i) - if repeatedFieldValue.Kind() != reflect.Slice { - // possible value: {"[]string", "*[]struct"}, we must call Elem() in the last condition - repeatedFieldValue = repeatedFieldValue.Elem() - } - if repeatedFieldValue.IsValid() && !repeatedFieldValue.IsNil() { - for m := 0; m < repeatedFieldValue.Len(); m++ { - elementValue := repeatedFieldValue.Index(m) - key := prefix + name + "." + strconv.Itoa(m+1) - if elementValue.Type().Kind().String() == "string" { - value := elementValue.String() - err = addParam(request, fieldPosition, key, value) - if err != nil { - return - } - } else { - err = flatRepeatedList(elementValue, request, fieldPosition, key+".") - if err != nil { - return - } - } - } - } - } - } - } - return -} - -func addParam(request AcsRequest, position, name, value string) (err error) { - if len(value) > 0 { - switch position { - case Header: - request.addHeaderParam(name, value) - case Query: - request.addQueryParam(name, value) - case Path: - request.addPathParam(name, value) - case Body: - request.addFormParam(name, value) - default: - errMsg := fmt.Sprintf(errors.UnsupportedParamPositionErrorMessage, position) - err = errors.NewClientError(errors.UnsupportedParamPositionErrorCode, errMsg, nil) - } - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/common_request.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/common_request.go deleted file mode 100644 index 80c17009..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/common_request.go +++ /dev/null @@ -1,108 +0,0 @@ -package requests - -import ( - "bytes" - "fmt" - "io" - "sort" - "strings" -) - -type CommonRequest struct { - *baseRequest - - Version string - ApiName string - Product string - ServiceCode string - - // roa params - PathPattern string - PathParams map[string]string - - Ontology AcsRequest -} - -func NewCommonRequest() (request *CommonRequest) { - request = &CommonRequest{ - baseRequest: defaultBaseRequest(), - } - request.Headers["x-sdk-invoke-type"] = "common" - request.PathParams = make(map[string]string) - return -} - -func (request *CommonRequest) String() string { - request.TransToAcsRequest() - - resultBuilder := bytes.Buffer{} - - mapOutput := func(m map[string]string) { - if len(m) > 0 { - sortedKeys := make([]string, 0) - for k := range m { - sortedKeys = append(sortedKeys, k) - } - - // sort 'string' key in increasing order - sort.Strings(sortedKeys) - - for _, key := range sortedKeys { - resultBuilder.WriteString(key + ": " + m[key] + "\n") - } - } - } - - // Request Line - resultBuilder.WriteString(fmt.Sprintf("%s %s %s/1.1\n", request.Method, request.BuildQueries(), strings.ToUpper(request.Scheme))) - - // Headers - resultBuilder.WriteString("Host" + ": " + request.Domain + "\n") - mapOutput(request.Headers) - - resultBuilder.WriteString("\n") - // Body - if len(request.Content) > 0 { - resultBuilder.WriteString(string(request.Content) + "\n") - } else { - mapOutput(request.FormParams) - } - - return resultBuilder.String() -} - -func (request *CommonRequest) TransToAcsRequest() { - if len(request.PathPattern) > 0 { - roaRequest := &RoaRequest{} - roaRequest.initWithCommonRequest(request) - request.Ontology = roaRequest - } else { - rpcRequest := &RpcRequest{} - rpcRequest.baseRequest = request.baseRequest - rpcRequest.product = request.Product - rpcRequest.version = request.Version - rpcRequest.locationServiceCode = request.ServiceCode - rpcRequest.actionName = request.ApiName - request.Ontology = rpcRequest - } -} - -func (request *CommonRequest) BuildUrl() string { - return request.Ontology.BuildUrl() -} - -func (request *CommonRequest) BuildQueries() string { - return request.Ontology.BuildQueries() -} - -func (request *CommonRequest) GetBodyReader() io.Reader { - return request.Ontology.GetBodyReader() -} - -func (request *CommonRequest) GetStyle() string { - return request.Ontology.GetStyle() -} - -func (request *CommonRequest) addPathParam(key, value string) { - request.PathParams[key] = value -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/roa_request.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/roa_request.go deleted file mode 100644 index 70b856e3..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/roa_request.go +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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 requests - -import ( - "bytes" - "fmt" - "io" - "net/url" - "sort" - "strings" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" -) - -type RoaRequest struct { - *baseRequest - pathPattern string - PathParams map[string]string -} - -func (*RoaRequest) GetStyle() string { - return ROA -} - -func (request *RoaRequest) GetBodyReader() io.Reader { - if request.FormParams != nil && len(request.FormParams) > 0 { - formString := utils.GetUrlFormedMap(request.FormParams) - return strings.NewReader(formString) - } else if len(request.Content) > 0 { - return bytes.NewReader(request.Content) - } else { - return nil - } -} - -// for sign method, need not url encoded -func (request *RoaRequest) BuildQueries() string { - return request.buildQueries() -} - -func (request *RoaRequest) buildPath() string { - path := request.pathPattern - for key, value := range request.PathParams { - path = strings.Replace(path, "["+key+"]", value, 1) - } - return path -} - -func (request *RoaRequest) buildQueries() string { - // replace path params with value - path := request.buildPath() - queryParams := request.QueryParams - // sort QueryParams by key - var queryKeys []string - for key := range queryParams { - queryKeys = append(queryKeys, key) - } - sort.Strings(queryKeys) - - // append urlBuilder - urlBuilder := bytes.Buffer{} - urlBuilder.WriteString(path) - if len(queryKeys) > 0 { - urlBuilder.WriteString("?") - } - for i := 0; i < len(queryKeys); i++ { - queryKey := queryKeys[i] - urlBuilder.WriteString(queryKey) - if value := queryParams[queryKey]; len(value) > 0 { - urlBuilder.WriteString("=") - urlBuilder.WriteString(value) - } - if i < len(queryKeys)-1 { - urlBuilder.WriteString("&") - } - } - result := urlBuilder.String() - result = popStandardUrlencode(result) - return result -} - -func (request *RoaRequest) buildQueryString() string { - queryParams := request.QueryParams - // sort QueryParams by key - q := url.Values{} - for key, value := range queryParams { - q.Add(key, value) - } - return q.Encode() -} - -func popStandardUrlencode(stringToSign string) (result string) { - result = strings.Replace(stringToSign, "+", "%20", -1) - result = strings.Replace(result, "*", "%2A", -1) - result = strings.Replace(result, "%7E", "~", -1) - return -} - -func (request *RoaRequest) BuildUrl() string { - // for network trans, need url encoded - scheme := strings.ToLower(request.Scheme) - domain := request.Domain - port := request.Port - path := request.buildPath() - url := fmt.Sprintf("%s://%s:%s%s", scheme, domain, port, path) - querystring := request.buildQueryString() - if len(querystring) > 0 { - url = fmt.Sprintf("%s?%s", url, querystring) - } - return url -} - -func (request *RoaRequest) addPathParam(key, value string) { - request.PathParams[key] = value -} - -func (request *RoaRequest) InitWithApiInfo(product, version, action, uriPattern, serviceCode, endpointType string) { - request.baseRequest = defaultBaseRequest() - request.PathParams = make(map[string]string) - request.Headers["x-acs-version"] = version - request.pathPattern = uriPattern - request.locationServiceCode = serviceCode - request.locationEndpointType = endpointType - request.product = product - //request.version = version - request.actionName = action -} - -func (request *RoaRequest) initWithCommonRequest(commonRequest *CommonRequest) { - request.baseRequest = commonRequest.baseRequest - request.PathParams = commonRequest.PathParams - request.product = commonRequest.Product - //request.version = commonRequest.Version - request.Headers["x-acs-version"] = commonRequest.Version - request.actionName = commonRequest.ApiName - request.pathPattern = commonRequest.PathPattern - request.locationServiceCode = commonRequest.ServiceCode - request.locationEndpointType = "" -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/rpc_request.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/rpc_request.go deleted file mode 100644 index 01be6fd0..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/rpc_request.go +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 requests - -import ( - "fmt" - "io" - "strings" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" -) - -type RpcRequest struct { - *baseRequest -} - -func (request *RpcRequest) init() { - request.baseRequest = defaultBaseRequest() - request.Method = POST -} - -func (*RpcRequest) GetStyle() string { - return RPC -} - -func (request *RpcRequest) GetBodyReader() io.Reader { - if request.FormParams != nil && len(request.FormParams) > 0 { - formString := utils.GetUrlFormedMap(request.FormParams) - return strings.NewReader(formString) - } else { - return strings.NewReader("") - } -} - -func (request *RpcRequest) BuildQueries() string { - request.queries = "/?" + utils.GetUrlFormedMap(request.QueryParams) - return request.queries -} - -func (request *RpcRequest) BuildUrl() string { - url := fmt.Sprintf("%s://%s", strings.ToLower(request.Scheme), request.Domain) - if len(request.Port) > 0 { - url = fmt.Sprintf("%s:%s", url, request.Port) - } - return url + request.BuildQueries() -} - -func (request *RpcRequest) GetVersion() string { - return request.version -} - -func (request *RpcRequest) GetActionName() string { - return request.actionName -} - -func (request *RpcRequest) addPathParam(key, value string) { - panic("not support") -} - -func (request *RpcRequest) InitWithApiInfo(product, version, action, serviceCode, endpointType string) { - request.init() - request.product = product - request.version = version - request.actionName = action - request.locationServiceCode = serviceCode - request.locationEndpointType = endpointType -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/types.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/types.go deleted file mode 100644 index 28af63ea..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests/types.go +++ /dev/null @@ -1,53 +0,0 @@ -package requests - -import "strconv" - -type Integer string - -func NewInteger(integer int) Integer { - return Integer(strconv.Itoa(integer)) -} - -func (integer Integer) HasValue() bool { - return integer != "" -} - -func (integer Integer) GetValue() (int, error) { - return strconv.Atoi(string(integer)) -} - -func NewInteger64(integer int64) Integer { - return Integer(strconv.FormatInt(integer, 10)) -} - -func (integer Integer) GetValue64() (int64, error) { - return strconv.ParseInt(string(integer), 10, 0) -} - -type Boolean string - -func NewBoolean(bool bool) Boolean { - return Boolean(strconv.FormatBool(bool)) -} - -func (boolean Boolean) HasValue() bool { - return boolean != "" -} - -func (boolean Boolean) GetValue() (bool, error) { - return strconv.ParseBool(string(boolean)) -} - -type Float string - -func NewFloat(f float64) Float { - return Float(strconv.FormatFloat(f, 'f', 6, 64)) -} - -func (float Float) HasValue() bool { - return float != "" -} - -func (float Float) GetValue() (float64, error) { - return strconv.ParseFloat(string(float), 64) -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses/json_parser.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses/json_parser.go deleted file mode 100644 index 36604fe8..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses/json_parser.go +++ /dev/null @@ -1,328 +0,0 @@ -package responses - -import ( - "encoding/json" - "io" - "math" - "strconv" - "strings" - "unsafe" - - jsoniter "github.com/json-iterator/go" -) - -const maxUint = ^uint(0) -const maxInt = int(maxUint >> 1) -const minInt = -maxInt - 1 - -var jsonParser jsoniter.API - -func init() { - registerBetterFuzzyDecoder() - jsonParser = jsoniter.Config{ - EscapeHTML: true, - SortMapKeys: true, - ValidateJsonRawMessage: true, - CaseSensitive: true, - }.Froze() -} - -func registerBetterFuzzyDecoder() { - jsoniter.RegisterTypeDecoder("string", &nullableFuzzyStringDecoder{}) - jsoniter.RegisterTypeDecoder("bool", &fuzzyBoolDecoder{}) - jsoniter.RegisterTypeDecoder("float32", &nullableFuzzyFloat32Decoder{}) - jsoniter.RegisterTypeDecoder("float64", &nullableFuzzyFloat64Decoder{}) - jsoniter.RegisterTypeDecoder("int", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(maxInt) || val < float64(minInt) { - iter.ReportError("fuzzy decode int", "exceed range") - return - } - *((*int)(ptr)) = int(val) - } else { - *((*int)(ptr)) = iter.ReadInt() - } - }}) - jsoniter.RegisterTypeDecoder("uint", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(maxUint) || val < 0 { - iter.ReportError("fuzzy decode uint", "exceed range") - return - } - *((*uint)(ptr)) = uint(val) - } else { - *((*uint)(ptr)) = iter.ReadUint() - } - }}) - jsoniter.RegisterTypeDecoder("int8", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(math.MaxInt8) || val < float64(math.MinInt8) { - iter.ReportError("fuzzy decode int8", "exceed range") - return - } - *((*int8)(ptr)) = int8(val) - } else { - *((*int8)(ptr)) = iter.ReadInt8() - } - }}) - jsoniter.RegisterTypeDecoder("uint8", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(math.MaxUint8) || val < 0 { - iter.ReportError("fuzzy decode uint8", "exceed range") - return - } - *((*uint8)(ptr)) = uint8(val) - } else { - *((*uint8)(ptr)) = iter.ReadUint8() - } - }}) - jsoniter.RegisterTypeDecoder("int16", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(math.MaxInt16) || val < float64(math.MinInt16) { - iter.ReportError("fuzzy decode int16", "exceed range") - return - } - *((*int16)(ptr)) = int16(val) - } else { - *((*int16)(ptr)) = iter.ReadInt16() - } - }}) - jsoniter.RegisterTypeDecoder("uint16", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(math.MaxUint16) || val < 0 { - iter.ReportError("fuzzy decode uint16", "exceed range") - return - } - *((*uint16)(ptr)) = uint16(val) - } else { - *((*uint16)(ptr)) = iter.ReadUint16() - } - }}) - jsoniter.RegisterTypeDecoder("int32", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(math.MaxInt32) || val < float64(math.MinInt32) { - iter.ReportError("fuzzy decode int32", "exceed range") - return - } - *((*int32)(ptr)) = int32(val) - } else { - *((*int32)(ptr)) = iter.ReadInt32() - } - }}) - jsoniter.RegisterTypeDecoder("uint32", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(math.MaxUint32) || val < 0 { - iter.ReportError("fuzzy decode uint32", "exceed range") - return - } - *((*uint32)(ptr)) = uint32(val) - } else { - *((*uint32)(ptr)) = iter.ReadUint32() - } - }}) - jsoniter.RegisterTypeDecoder("int64", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(math.MaxInt64) || val < float64(math.MinInt64) { - iter.ReportError("fuzzy decode int64", "exceed range") - return - } - *((*int64)(ptr)) = int64(val) - } else { - *((*int64)(ptr)) = iter.ReadInt64() - } - }}) - jsoniter.RegisterTypeDecoder("uint64", &nullableFuzzyIntegerDecoder{func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) { - if isFloat { - val := iter.ReadFloat64() - if val > float64(math.MaxUint64) || val < 0 { - iter.ReportError("fuzzy decode uint64", "exceed range") - return - } - *((*uint64)(ptr)) = uint64(val) - } else { - *((*uint64)(ptr)) = iter.ReadUint64() - } - }}) -} - -type nullableFuzzyStringDecoder struct { -} - -func (decoder *nullableFuzzyStringDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { - valueType := iter.WhatIsNext() - switch valueType { - case jsoniter.NumberValue: - var number json.Number - iter.ReadVal(&number) - *((*string)(ptr)) = string(number) - case jsoniter.StringValue: - *((*string)(ptr)) = iter.ReadString() - case jsoniter.BoolValue: - *((*string)(ptr)) = strconv.FormatBool(iter.ReadBool()) - case jsoniter.NilValue: - iter.ReadNil() - *((*string)(ptr)) = "" - default: - iter.ReportError("fuzzyStringDecoder", "not number or string or bool") - } -} - -type fuzzyBoolDecoder struct { -} - -func (decoder *fuzzyBoolDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { - valueType := iter.WhatIsNext() - switch valueType { - case jsoniter.BoolValue: - *((*bool)(ptr)) = iter.ReadBool() - case jsoniter.NumberValue: - var number json.Number - iter.ReadVal(&number) - num, err := number.Int64() - if err != nil { - iter.ReportError("fuzzyBoolDecoder", "get value from json.number failed") - } - if num == 0 { - *((*bool)(ptr)) = false - } else { - *((*bool)(ptr)) = true - } - case jsoniter.StringValue: - strValue := strings.ToLower(iter.ReadString()) - if strValue == "true" { - *((*bool)(ptr)) = true - } else if strValue == "false" || strValue == "" { - *((*bool)(ptr)) = false - } else { - iter.ReportError("fuzzyBoolDecoder", "unsupported bool value: "+strValue) - } - case jsoniter.NilValue: - iter.ReadNil() - *((*bool)(ptr)) = false - default: - iter.ReportError("fuzzyBoolDecoder", "not number or string or nil") - } -} - -type nullableFuzzyIntegerDecoder struct { - fun func(isFloat bool, ptr unsafe.Pointer, iter *jsoniter.Iterator) -} - -func (decoder *nullableFuzzyIntegerDecoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { - valueType := iter.WhatIsNext() - var str string - switch valueType { - case jsoniter.NumberValue: - var number json.Number - iter.ReadVal(&number) - str = string(number) - case jsoniter.StringValue: - str = iter.ReadString() - // support empty string - if str == "" { - str = "0" - } - case jsoniter.BoolValue: - if iter.ReadBool() { - str = "1" - } else { - str = "0" - } - case jsoniter.NilValue: - iter.ReadNil() - str = "0" - default: - iter.ReportError("fuzzyIntegerDecoder", "not number or string") - } - newIter := iter.Pool().BorrowIterator([]byte(str)) - defer iter.Pool().ReturnIterator(newIter) - isFloat := strings.IndexByte(str, '.') != -1 - decoder.fun(isFloat, ptr, newIter) - if newIter.Error != nil && newIter.Error != io.EOF { - iter.Error = newIter.Error - } -} - -type nullableFuzzyFloat32Decoder struct { -} - -func (decoder *nullableFuzzyFloat32Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { - valueType := iter.WhatIsNext() - var str string - switch valueType { - case jsoniter.NumberValue: - *((*float32)(ptr)) = iter.ReadFloat32() - case jsoniter.StringValue: - str = iter.ReadString() - // support empty string - if str == "" { - *((*float32)(ptr)) = 0 - return - } - newIter := iter.Pool().BorrowIterator([]byte(str)) - defer iter.Pool().ReturnIterator(newIter) - *((*float32)(ptr)) = newIter.ReadFloat32() - if newIter.Error != nil && newIter.Error != io.EOF { - iter.Error = newIter.Error - } - case jsoniter.BoolValue: - // support bool to float32 - if iter.ReadBool() { - *((*float32)(ptr)) = 1 - } else { - *((*float32)(ptr)) = 0 - } - case jsoniter.NilValue: - iter.ReadNil() - *((*float32)(ptr)) = 0 - default: - iter.ReportError("nullableFuzzyFloat32Decoder", "not number or string") - } -} - -type nullableFuzzyFloat64Decoder struct { -} - -func (decoder *nullableFuzzyFloat64Decoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) { - valueType := iter.WhatIsNext() - var str string - switch valueType { - case jsoniter.NumberValue: - *((*float64)(ptr)) = iter.ReadFloat64() - case jsoniter.StringValue: - str = iter.ReadString() - // support empty string - if str == "" { - *((*float64)(ptr)) = 0 - return - } - newIter := iter.Pool().BorrowIterator([]byte(str)) - defer iter.Pool().ReturnIterator(newIter) - *((*float64)(ptr)) = newIter.ReadFloat64() - if newIter.Error != nil && newIter.Error != io.EOF { - iter.Error = newIter.Error - } - case jsoniter.BoolValue: - // support bool to float64 - if iter.ReadBool() { - *((*float64)(ptr)) = 1 - } else { - *((*float64)(ptr)) = 0 - } - case jsoniter.NilValue: - // support empty string - iter.ReadNil() - *((*float64)(ptr)) = 0 - default: - iter.ReportError("nullableFuzzyFloat64Decoder", "not number or string") - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses/response.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses/response.go deleted file mode 100644 index 2b9eff1a..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses/response.go +++ /dev/null @@ -1,152 +0,0 @@ -/* - * 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 responses - -import ( - "bytes" - "encoding/xml" - "fmt" - "io/ioutil" - "net/http" - "strings" - - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils" -) - -type AcsResponse interface { - IsSuccess() bool - GetHttpStatus() int - GetHttpHeaders() map[string][]string - GetHttpContentString() string - GetHttpContentBytes() []byte - GetOriginHttpResponse() *http.Response - parseFromHttpResponse(httpResponse *http.Response) error -} - -var debug utils.Debug - -func init() { - debug = utils.Init("sdk") -} - -// Unmarshal object from http response body to target Response -func Unmarshal(response AcsResponse, httpResponse *http.Response, format string) (err error) { - err = response.parseFromHttpResponse(httpResponse) - if err != nil { - return - } - if !response.IsSuccess() { - err = errors.NewServerError(response.GetHttpStatus(), response.GetHttpContentString(), "") - return - } - - if _, isCommonResponse := response.(*CommonResponse); isCommonResponse { - // common response need not unmarshal - return - } - - if len(response.GetHttpContentBytes()) == 0 { - return - } - - if strings.ToUpper(format) == "JSON" { - err = jsonParser.Unmarshal(response.GetHttpContentBytes(), response) - if err != nil { - err = errors.NewClientError(errors.JsonUnmarshalErrorCode, errors.JsonUnmarshalErrorMessage, err) - } - } else if strings.ToUpper(format) == "XML" { - err = xml.Unmarshal(response.GetHttpContentBytes(), response) - } - return -} - -type BaseResponse struct { - httpStatus int - httpHeaders map[string][]string - httpContentString string - httpContentBytes []byte - originHttpResponse *http.Response -} - -func (baseResponse *BaseResponse) GetHttpStatus() int { - return baseResponse.httpStatus -} - -func (baseResponse *BaseResponse) GetHttpHeaders() map[string][]string { - return baseResponse.httpHeaders -} - -func (baseResponse *BaseResponse) GetHttpContentString() string { - return baseResponse.httpContentString -} - -func (baseResponse *BaseResponse) GetHttpContentBytes() []byte { - return baseResponse.httpContentBytes -} - -func (baseResponse *BaseResponse) GetOriginHttpResponse() *http.Response { - return baseResponse.originHttpResponse -} - -func (baseResponse *BaseResponse) IsSuccess() bool { - if baseResponse.GetHttpStatus() >= 200 && baseResponse.GetHttpStatus() < 300 { - return true - } - - return false -} - -func (baseResponse *BaseResponse) parseFromHttpResponse(httpResponse *http.Response) (err error) { - defer httpResponse.Body.Close() - body, err := ioutil.ReadAll(httpResponse.Body) - if err != nil { - return - } - debug("%s", string(body)) - baseResponse.httpStatus = httpResponse.StatusCode - baseResponse.httpHeaders = httpResponse.Header - baseResponse.httpContentBytes = body - baseResponse.httpContentString = string(body) - baseResponse.originHttpResponse = httpResponse - return -} - -func (baseResponse *BaseResponse) String() string { - resultBuilder := bytes.Buffer{} - // statusCode - // resultBuilder.WriteString("\n") - resultBuilder.WriteString(fmt.Sprintf("%s %s\n", baseResponse.originHttpResponse.Proto, baseResponse.originHttpResponse.Status)) - // httpHeaders - //resultBuilder.WriteString("Headers:\n") - for key, value := range baseResponse.httpHeaders { - resultBuilder.WriteString(key + ": " + strings.Join(value, ";") + "\n") - } - resultBuilder.WriteString("\n") - // content - //resultBuilder.WriteString("Content:\n") - resultBuilder.WriteString(baseResponse.httpContentString + "\n") - return resultBuilder.String() -} - -type CommonResponse struct { - *BaseResponse -} - -func NewCommonResponse() (response *CommonResponse) { - return &CommonResponse{ - BaseResponse: &BaseResponse{}, - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils/debug.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils/debug.go deleted file mode 100644 index 09440d27..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils/debug.go +++ /dev/null @@ -1,36 +0,0 @@ -package utils - -import ( - "fmt" - "os" - "strings" -) - -type Debug func(format string, v ...interface{}) - -var hookGetEnv = func() string { - return os.Getenv("DEBUG") -} - -var hookPrint = func(input string) { - fmt.Println(input) -} - -func Init(flag string) Debug { - enable := false - - env := hookGetEnv() - parts := strings.Split(env, ",") - for _, part := range parts { - if part == flag { - enable = true - break - } - } - - return func(format string, v ...interface{}) { - if enable { - hookPrint(fmt.Sprintf(format, v...)) - } - } -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils/utils.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils/utils.go deleted file mode 100644 index f8a3ad38..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/utils/utils.go +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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 utils - -import ( - "crypto/md5" - "crypto/rand" - "encoding/base64" - "encoding/hex" - "hash" - rand2 "math/rand" - "net/url" - "reflect" - "strconv" - "time" -) - -type UUID [16]byte - -const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" - -func GetUUID() (uuidHex string) { - uuid := NewUUID() - uuidHex = hex.EncodeToString(uuid[:]) - return -} - -func RandStringBytes(n int) string { - b := make([]byte, n) - for i := range b { - b[i] = letterBytes[rand2.Intn(len(letterBytes))] - } - return string(b) -} - -func GetMD5Base64(bytes []byte) (base64Value string) { - md5Ctx := md5.New() - md5Ctx.Write(bytes) - md5Value := md5Ctx.Sum(nil) - base64Value = base64.StdEncoding.EncodeToString(md5Value) - return -} - -func GetTimeInFormatISO8601() (timeStr string) { - gmt := time.FixedZone("GMT", 0) - - return time.Now().In(gmt).Format("2006-01-02T15:04:05Z") -} - -func GetTimeInFormatRFC2616() (timeStr string) { - gmt := time.FixedZone("GMT", 0) - - return time.Now().In(gmt).Format("Mon, 02 Jan 2006 15:04:05 GMT") -} - -func GetUrlFormedMap(source map[string]string) (urlEncoded string) { - urlEncoder := url.Values{} - for key, value := range source { - urlEncoder.Add(key, value) - } - urlEncoded = urlEncoder.Encode() - return -} - -func InitStructWithDefaultTag(bean interface{}) { - configType := reflect.TypeOf(bean) - for i := 0; i < configType.Elem().NumField(); i++ { - field := configType.Elem().Field(i) - defaultValue := field.Tag.Get("default") - if defaultValue == "" { - continue - } - setter := reflect.ValueOf(bean).Elem().Field(i) - switch field.Type.String() { - case "int": - intValue, _ := strconv.ParseInt(defaultValue, 10, 64) - setter.SetInt(intValue) - case "time.Duration": - intValue, _ := strconv.ParseInt(defaultValue, 10, 64) - setter.SetInt(intValue) - case "string": - setter.SetString(defaultValue) - case "bool": - boolValue, _ := strconv.ParseBool(defaultValue) - setter.SetBool(boolValue) - } - } -} - -func NewUUID() UUID { - ns := UUID{} - safeRandom(ns[:]) - u := newFromHash(md5.New(), ns, RandStringBytes(16)) - u[6] = (u[6] & 0x0f) | (byte(2) << 4) - u[8] = (u[8]&(0xff>>2) | (0x02 << 6)) - - return u -} - -func newFromHash(h hash.Hash, ns UUID, name string) UUID { - u := UUID{} - h.Write(ns[:]) - h.Write([]byte(name)) - copy(u[:], h.Sum(nil)) - - return u -} - -func safeRandom(dest []byte) { - if _, err := rand.Read(dest); err != nil { - panic(err) - } -} - -func (u UUID) String() string { - buf := make([]byte, 36) - - hex.Encode(buf[0:8], u[0:4]) - buf[8] = '-' - hex.Encode(buf[9:13], u[4:6]) - buf[13] = '-' - hex.Encode(buf[14:18], u[6:8]) - buf[18] = '-' - hex.Encode(buf[19:23], u[8:10]) - buf[23] = '-' - hex.Encode(buf[24:], u[10:]) - - return string(buf) -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/cancel_key_deletion.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/cancel_key_deletion.go deleted file mode 100644 index 08ab80b5..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/cancel_key_deletion.go +++ /dev/null @@ -1,103 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// CancelKeyDeletion invokes the kms.CancelKeyDeletion API synchronously -// api document: https://help.aliyun.com/api/kms/cancelkeydeletion.html -func (client *Client) CancelKeyDeletion(request *CancelKeyDeletionRequest) (response *CancelKeyDeletionResponse, err error) { - response = CreateCancelKeyDeletionResponse() - err = client.DoAction(request, response) - return -} - -// CancelKeyDeletionWithChan invokes the kms.CancelKeyDeletion API asynchronously -// api document: https://help.aliyun.com/api/kms/cancelkeydeletion.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) CancelKeyDeletionWithChan(request *CancelKeyDeletionRequest) (<-chan *CancelKeyDeletionResponse, <-chan error) { - responseChan := make(chan *CancelKeyDeletionResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.CancelKeyDeletion(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// CancelKeyDeletionWithCallback invokes the kms.CancelKeyDeletion API asynchronously -// api document: https://help.aliyun.com/api/kms/cancelkeydeletion.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) CancelKeyDeletionWithCallback(request *CancelKeyDeletionRequest, callback func(response *CancelKeyDeletionResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *CancelKeyDeletionResponse - var err error - defer close(result) - response, err = client.CancelKeyDeletion(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// CancelKeyDeletionRequest is the request struct for api CancelKeyDeletion -type CancelKeyDeletionRequest struct { - *requests.RpcRequest - KeyId string `position:"Query" name:"KeyId"` -} - -// CancelKeyDeletionResponse is the response struct for api CancelKeyDeletion -type CancelKeyDeletionResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateCancelKeyDeletionRequest creates a request to invoke CancelKeyDeletion API -func CreateCancelKeyDeletionRequest() (request *CancelKeyDeletionRequest) { - request = &CancelKeyDeletionRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "CancelKeyDeletion", "kms", "openAPI") - return -} - -// CreateCancelKeyDeletionResponse creates a response to parse from CancelKeyDeletion response -func CreateCancelKeyDeletionResponse() (response *CancelKeyDeletionResponse) { - response = &CancelKeyDeletionResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/client.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/client.go deleted file mode 100644 index 27631c12..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/client.go +++ /dev/null @@ -1,81 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth" -) - -// Client is the sdk client struct, each func corresponds to an OpenAPI -type Client struct { - sdk.Client -} - -// NewClient creates a sdk client with environment variables -func NewClient() (client *Client, err error) { - client = &Client{} - err = client.Init() - return -} - -// NewClientWithOptions creates a sdk client with regionId/sdkConfig/credential -// this is the common api to create a sdk client -func NewClientWithOptions(regionId string, config *sdk.Config, credential auth.Credential) (client *Client, err error) { - client = &Client{} - err = client.InitWithOptions(regionId, config, credential) - return -} - -// NewClientWithAccessKey is a shortcut to create sdk client with accesskey -// usage: https://help.aliyun.com/document_detail/66217.html -func NewClientWithAccessKey(regionId, accessKeyId, accessKeySecret string) (client *Client, err error) { - client = &Client{} - err = client.InitWithAccessKey(regionId, accessKeyId, accessKeySecret) - return -} - -// NewClientWithStsToken is a shortcut to create sdk client with sts token -// usage: https://help.aliyun.com/document_detail/66222.html -func NewClientWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken string) (client *Client, err error) { - client = &Client{} - err = client.InitWithStsToken(regionId, stsAccessKeyId, stsAccessKeySecret, stsToken) - return -} - -// NewClientWithRamRoleArn is a shortcut to create sdk client with ram roleArn -// usage: https://help.aliyun.com/document_detail/66222.html -func NewClientWithRamRoleArn(regionId string, accessKeyId, accessKeySecret, roleArn, roleSessionName string) (client *Client, err error) { - client = &Client{} - err = client.InitWithRamRoleArn(regionId, accessKeyId, accessKeySecret, roleArn, roleSessionName) - return -} - -// NewClientWithEcsRamRole is a shortcut to create sdk client with ecs ram role -// usage: https://help.aliyun.com/document_detail/66223.html -func NewClientWithEcsRamRole(regionId string, roleName string) (client *Client, err error) { - client = &Client{} - err = client.InitWithEcsRamRole(regionId, roleName) - return -} - -// NewClientWithRsaKeyPair is a shortcut to create sdk client with rsa key pair -// attention: rsa key pair auth is only Japan regions available -func NewClientWithRsaKeyPair(regionId string, publicKeyId, privateKey string, sessionExpiration int) (client *Client, err error) { - client = &Client{} - err = client.InitWithRsaKeyPair(regionId, publicKeyId, privateKey, sessionExpiration) - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/create_alias.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/create_alias.go deleted file mode 100644 index bc639317..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/create_alias.go +++ /dev/null @@ -1,104 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// CreateAlias invokes the kms.CreateAlias API synchronously -// api document: https://help.aliyun.com/api/kms/createalias.html -func (client *Client) CreateAlias(request *CreateAliasRequest) (response *CreateAliasResponse, err error) { - response = CreateCreateAliasResponse() - err = client.DoAction(request, response) - return -} - -// CreateAliasWithChan invokes the kms.CreateAlias API asynchronously -// api document: https://help.aliyun.com/api/kms/createalias.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) CreateAliasWithChan(request *CreateAliasRequest) (<-chan *CreateAliasResponse, <-chan error) { - responseChan := make(chan *CreateAliasResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.CreateAlias(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// CreateAliasWithCallback invokes the kms.CreateAlias API asynchronously -// api document: https://help.aliyun.com/api/kms/createalias.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) CreateAliasWithCallback(request *CreateAliasRequest, callback func(response *CreateAliasResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *CreateAliasResponse - var err error - defer close(result) - response, err = client.CreateAlias(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// CreateAliasRequest is the request struct for api CreateAlias -type CreateAliasRequest struct { - *requests.RpcRequest - AliasName string `position:"Query" name:"AliasName"` - KeyId string `position:"Query" name:"KeyId"` -} - -// CreateAliasResponse is the response struct for api CreateAlias -type CreateAliasResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateCreateAliasRequest creates a request to invoke CreateAlias API -func CreateCreateAliasRequest() (request *CreateAliasRequest) { - request = &CreateAliasRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "CreateAlias", "kms", "openAPI") - return -} - -// CreateCreateAliasResponse creates a response to parse from CreateAlias response -func CreateCreateAliasResponse() (response *CreateAliasResponse) { - response = &CreateAliasResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/create_key.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/create_key.go deleted file mode 100644 index cf513f2e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/create_key.go +++ /dev/null @@ -1,106 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// CreateKey invokes the kms.CreateKey API synchronously -// api document: https://help.aliyun.com/api/kms/createkey.html -func (client *Client) CreateKey(request *CreateKeyRequest) (response *CreateKeyResponse, err error) { - response = CreateCreateKeyResponse() - err = client.DoAction(request, response) - return -} - -// CreateKeyWithChan invokes the kms.CreateKey API asynchronously -// api document: https://help.aliyun.com/api/kms/createkey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) CreateKeyWithChan(request *CreateKeyRequest) (<-chan *CreateKeyResponse, <-chan error) { - responseChan := make(chan *CreateKeyResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.CreateKey(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// CreateKeyWithCallback invokes the kms.CreateKey API asynchronously -// api document: https://help.aliyun.com/api/kms/createkey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) CreateKeyWithCallback(request *CreateKeyRequest, callback func(response *CreateKeyResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *CreateKeyResponse - var err error - defer close(result) - response, err = client.CreateKey(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// CreateKeyRequest is the request struct for api CreateKey -type CreateKeyRequest struct { - *requests.RpcRequest - KeyUsage string `position:"Query" name:"KeyUsage"` - Origin string `position:"Query" name:"Origin"` - Description string `position:"Query" name:"Description"` -} - -// CreateKeyResponse is the response struct for api CreateKey -type CreateKeyResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` - KeyMetadata KeyMetadata `json:"KeyMetadata" xml:"KeyMetadata"` -} - -// CreateCreateKeyRequest creates a request to invoke CreateKey API -func CreateCreateKeyRequest() (request *CreateKeyRequest) { - request = &CreateKeyRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "CreateKey", "kms", "openAPI") - return -} - -// CreateCreateKeyResponse creates a response to parse from CreateKey response -func CreateCreateKeyResponse() (response *CreateKeyResponse) { - response = &CreateKeyResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/decrypt.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/decrypt.go deleted file mode 100644 index e0e4f51b..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/decrypt.go +++ /dev/null @@ -1,106 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// Decrypt invokes the kms.Decrypt API synchronously -// api document: https://help.aliyun.com/api/kms/decrypt.html -func (client *Client) Decrypt(request *DecryptRequest) (response *DecryptResponse, err error) { - response = CreateDecryptResponse() - err = client.DoAction(request, response) - return -} - -// DecryptWithChan invokes the kms.Decrypt API asynchronously -// api document: https://help.aliyun.com/api/kms/decrypt.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DecryptWithChan(request *DecryptRequest) (<-chan *DecryptResponse, <-chan error) { - responseChan := make(chan *DecryptResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.Decrypt(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// DecryptWithCallback invokes the kms.Decrypt API asynchronously -// api document: https://help.aliyun.com/api/kms/decrypt.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DecryptWithCallback(request *DecryptRequest, callback func(response *DecryptResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *DecryptResponse - var err error - defer close(result) - response, err = client.Decrypt(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// DecryptRequest is the request struct for api Decrypt -type DecryptRequest struct { - *requests.RpcRequest - EncryptionContext string `position:"Query" name:"EncryptionContext"` - CiphertextBlob string `position:"Query" name:"CiphertextBlob"` -} - -// DecryptResponse is the response struct for api Decrypt -type DecryptResponse struct { - *responses.BaseResponse - Plaintext string `json:"Plaintext" xml:"Plaintext"` - KeyId string `json:"KeyId" xml:"KeyId"` - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateDecryptRequest creates a request to invoke Decrypt API -func CreateDecryptRequest() (request *DecryptRequest) { - request = &DecryptRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "Decrypt", "kms", "openAPI") - return -} - -// CreateDecryptResponse creates a response to parse from Decrypt response -func CreateDecryptResponse() (response *DecryptResponse) { - response = &DecryptResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/delete_alias.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/delete_alias.go deleted file mode 100644 index 591f11cb..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/delete_alias.go +++ /dev/null @@ -1,103 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// DeleteAlias invokes the kms.DeleteAlias API synchronously -// api document: https://help.aliyun.com/api/kms/deletealias.html -func (client *Client) DeleteAlias(request *DeleteAliasRequest) (response *DeleteAliasResponse, err error) { - response = CreateDeleteAliasResponse() - err = client.DoAction(request, response) - return -} - -// DeleteAliasWithChan invokes the kms.DeleteAlias API asynchronously -// api document: https://help.aliyun.com/api/kms/deletealias.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DeleteAliasWithChan(request *DeleteAliasRequest) (<-chan *DeleteAliasResponse, <-chan error) { - responseChan := make(chan *DeleteAliasResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.DeleteAlias(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// DeleteAliasWithCallback invokes the kms.DeleteAlias API asynchronously -// api document: https://help.aliyun.com/api/kms/deletealias.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DeleteAliasWithCallback(request *DeleteAliasRequest, callback func(response *DeleteAliasResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *DeleteAliasResponse - var err error - defer close(result) - response, err = client.DeleteAlias(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// DeleteAliasRequest is the request struct for api DeleteAlias -type DeleteAliasRequest struct { - *requests.RpcRequest - AliasName string `position:"Query" name:"AliasName"` -} - -// DeleteAliasResponse is the response struct for api DeleteAlias -type DeleteAliasResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateDeleteAliasRequest creates a request to invoke DeleteAlias API -func CreateDeleteAliasRequest() (request *DeleteAliasRequest) { - request = &DeleteAliasRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "DeleteAlias", "kms", "openAPI") - return -} - -// CreateDeleteAliasResponse creates a response to parse from DeleteAlias response -func CreateDeleteAliasResponse() (response *DeleteAliasResponse) { - response = &DeleteAliasResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/delete_key_material.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/delete_key_material.go deleted file mode 100644 index 522e0136..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/delete_key_material.go +++ /dev/null @@ -1,103 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// DeleteKeyMaterial invokes the kms.DeleteKeyMaterial API synchronously -// api document: https://help.aliyun.com/api/kms/deletekeymaterial.html -func (client *Client) DeleteKeyMaterial(request *DeleteKeyMaterialRequest) (response *DeleteKeyMaterialResponse, err error) { - response = CreateDeleteKeyMaterialResponse() - err = client.DoAction(request, response) - return -} - -// DeleteKeyMaterialWithChan invokes the kms.DeleteKeyMaterial API asynchronously -// api document: https://help.aliyun.com/api/kms/deletekeymaterial.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DeleteKeyMaterialWithChan(request *DeleteKeyMaterialRequest) (<-chan *DeleteKeyMaterialResponse, <-chan error) { - responseChan := make(chan *DeleteKeyMaterialResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.DeleteKeyMaterial(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// DeleteKeyMaterialWithCallback invokes the kms.DeleteKeyMaterial API asynchronously -// api document: https://help.aliyun.com/api/kms/deletekeymaterial.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DeleteKeyMaterialWithCallback(request *DeleteKeyMaterialRequest, callback func(response *DeleteKeyMaterialResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *DeleteKeyMaterialResponse - var err error - defer close(result) - response, err = client.DeleteKeyMaterial(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// DeleteKeyMaterialRequest is the request struct for api DeleteKeyMaterial -type DeleteKeyMaterialRequest struct { - *requests.RpcRequest - KeyId string `position:"Query" name:"KeyId"` -} - -// DeleteKeyMaterialResponse is the response struct for api DeleteKeyMaterial -type DeleteKeyMaterialResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateDeleteKeyMaterialRequest creates a request to invoke DeleteKeyMaterial API -func CreateDeleteKeyMaterialRequest() (request *DeleteKeyMaterialRequest) { - request = &DeleteKeyMaterialRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "DeleteKeyMaterial", "kms", "openAPI") - return -} - -// CreateDeleteKeyMaterialResponse creates a response to parse from DeleteKeyMaterial response -func CreateDeleteKeyMaterialResponse() (response *DeleteKeyMaterialResponse) { - response = &DeleteKeyMaterialResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/describe_key.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/describe_key.go deleted file mode 100644 index bf3cc412..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/describe_key.go +++ /dev/null @@ -1,104 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// DescribeKey invokes the kms.DescribeKey API synchronously -// api document: https://help.aliyun.com/api/kms/describekey.html -func (client *Client) DescribeKey(request *DescribeKeyRequest) (response *DescribeKeyResponse, err error) { - response = CreateDescribeKeyResponse() - err = client.DoAction(request, response) - return -} - -// DescribeKeyWithChan invokes the kms.DescribeKey API asynchronously -// api document: https://help.aliyun.com/api/kms/describekey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DescribeKeyWithChan(request *DescribeKeyRequest) (<-chan *DescribeKeyResponse, <-chan error) { - responseChan := make(chan *DescribeKeyResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.DescribeKey(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// DescribeKeyWithCallback invokes the kms.DescribeKey API asynchronously -// api document: https://help.aliyun.com/api/kms/describekey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DescribeKeyWithCallback(request *DescribeKeyRequest, callback func(response *DescribeKeyResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *DescribeKeyResponse - var err error - defer close(result) - response, err = client.DescribeKey(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// DescribeKeyRequest is the request struct for api DescribeKey -type DescribeKeyRequest struct { - *requests.RpcRequest - KeyId string `position:"Query" name:"KeyId"` -} - -// DescribeKeyResponse is the response struct for api DescribeKey -type DescribeKeyResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` - KeyMetadata KeyMetadata `json:"KeyMetadata" xml:"KeyMetadata"` -} - -// CreateDescribeKeyRequest creates a request to invoke DescribeKey API -func CreateDescribeKeyRequest() (request *DescribeKeyRequest) { - request = &DescribeKeyRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "DescribeKey", "kms", "openAPI") - return -} - -// CreateDescribeKeyResponse creates a response to parse from DescribeKey response -func CreateDescribeKeyResponse() (response *DescribeKeyResponse) { - response = &DescribeKeyResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/describe_regions.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/describe_regions.go deleted file mode 100644 index 9f56726e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/describe_regions.go +++ /dev/null @@ -1,103 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// DescribeRegions invokes the kms.DescribeRegions API synchronously -// api document: https://help.aliyun.com/api/kms/describeregions.html -func (client *Client) DescribeRegions(request *DescribeRegionsRequest) (response *DescribeRegionsResponse, err error) { - response = CreateDescribeRegionsResponse() - err = client.DoAction(request, response) - return -} - -// DescribeRegionsWithChan invokes the kms.DescribeRegions API asynchronously -// api document: https://help.aliyun.com/api/kms/describeregions.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DescribeRegionsWithChan(request *DescribeRegionsRequest) (<-chan *DescribeRegionsResponse, <-chan error) { - responseChan := make(chan *DescribeRegionsResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.DescribeRegions(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// DescribeRegionsWithCallback invokes the kms.DescribeRegions API asynchronously -// api document: https://help.aliyun.com/api/kms/describeregions.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DescribeRegionsWithCallback(request *DescribeRegionsRequest, callback func(response *DescribeRegionsResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *DescribeRegionsResponse - var err error - defer close(result) - response, err = client.DescribeRegions(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// DescribeRegionsRequest is the request struct for api DescribeRegions -type DescribeRegionsRequest struct { - *requests.RpcRequest -} - -// DescribeRegionsResponse is the response struct for api DescribeRegions -type DescribeRegionsResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` - Regions Regions `json:"Regions" xml:"Regions"` -} - -// CreateDescribeRegionsRequest creates a request to invoke DescribeRegions API -func CreateDescribeRegionsRequest() (request *DescribeRegionsRequest) { - request = &DescribeRegionsRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "DescribeRegions", "kms", "openAPI") - return -} - -// CreateDescribeRegionsResponse creates a response to parse from DescribeRegions response -func CreateDescribeRegionsResponse() (response *DescribeRegionsResponse) { - response = &DescribeRegionsResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/disable_key.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/disable_key.go deleted file mode 100644 index 5734e9e7..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/disable_key.go +++ /dev/null @@ -1,103 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// DisableKey invokes the kms.DisableKey API synchronously -// api document: https://help.aliyun.com/api/kms/disablekey.html -func (client *Client) DisableKey(request *DisableKeyRequest) (response *DisableKeyResponse, err error) { - response = CreateDisableKeyResponse() - err = client.DoAction(request, response) - return -} - -// DisableKeyWithChan invokes the kms.DisableKey API asynchronously -// api document: https://help.aliyun.com/api/kms/disablekey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DisableKeyWithChan(request *DisableKeyRequest) (<-chan *DisableKeyResponse, <-chan error) { - responseChan := make(chan *DisableKeyResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.DisableKey(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// DisableKeyWithCallback invokes the kms.DisableKey API asynchronously -// api document: https://help.aliyun.com/api/kms/disablekey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) DisableKeyWithCallback(request *DisableKeyRequest, callback func(response *DisableKeyResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *DisableKeyResponse - var err error - defer close(result) - response, err = client.DisableKey(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// DisableKeyRequest is the request struct for api DisableKey -type DisableKeyRequest struct { - *requests.RpcRequest - KeyId string `position:"Query" name:"KeyId"` -} - -// DisableKeyResponse is the response struct for api DisableKey -type DisableKeyResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateDisableKeyRequest creates a request to invoke DisableKey API -func CreateDisableKeyRequest() (request *DisableKeyRequest) { - request = &DisableKeyRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "DisableKey", "kms", "openAPI") - return -} - -// CreateDisableKeyResponse creates a response to parse from DisableKey response -func CreateDisableKeyResponse() (response *DisableKeyResponse) { - response = &DisableKeyResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/enable_key.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/enable_key.go deleted file mode 100644 index 94c2c139..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/enable_key.go +++ /dev/null @@ -1,103 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// EnableKey invokes the kms.EnableKey API synchronously -// api document: https://help.aliyun.com/api/kms/enablekey.html -func (client *Client) EnableKey(request *EnableKeyRequest) (response *EnableKeyResponse, err error) { - response = CreateEnableKeyResponse() - err = client.DoAction(request, response) - return -} - -// EnableKeyWithChan invokes the kms.EnableKey API asynchronously -// api document: https://help.aliyun.com/api/kms/enablekey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) EnableKeyWithChan(request *EnableKeyRequest) (<-chan *EnableKeyResponse, <-chan error) { - responseChan := make(chan *EnableKeyResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.EnableKey(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// EnableKeyWithCallback invokes the kms.EnableKey API asynchronously -// api document: https://help.aliyun.com/api/kms/enablekey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) EnableKeyWithCallback(request *EnableKeyRequest, callback func(response *EnableKeyResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *EnableKeyResponse - var err error - defer close(result) - response, err = client.EnableKey(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// EnableKeyRequest is the request struct for api EnableKey -type EnableKeyRequest struct { - *requests.RpcRequest - KeyId string `position:"Query" name:"KeyId"` -} - -// EnableKeyResponse is the response struct for api EnableKey -type EnableKeyResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateEnableKeyRequest creates a request to invoke EnableKey API -func CreateEnableKeyRequest() (request *EnableKeyRequest) { - request = &EnableKeyRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "EnableKey", "kms", "openAPI") - return -} - -// CreateEnableKeyResponse creates a response to parse from EnableKey response -func CreateEnableKeyResponse() (response *EnableKeyResponse) { - response = &EnableKeyResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/encrypt.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/encrypt.go deleted file mode 100644 index 3ca5e0f5..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/encrypt.go +++ /dev/null @@ -1,107 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// Encrypt invokes the kms.Encrypt API synchronously -// api document: https://help.aliyun.com/api/kms/encrypt.html -func (client *Client) Encrypt(request *EncryptRequest) (response *EncryptResponse, err error) { - response = CreateEncryptResponse() - err = client.DoAction(request, response) - return -} - -// EncryptWithChan invokes the kms.Encrypt API asynchronously -// api document: https://help.aliyun.com/api/kms/encrypt.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) EncryptWithChan(request *EncryptRequest) (<-chan *EncryptResponse, <-chan error) { - responseChan := make(chan *EncryptResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.Encrypt(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// EncryptWithCallback invokes the kms.Encrypt API asynchronously -// api document: https://help.aliyun.com/api/kms/encrypt.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) EncryptWithCallback(request *EncryptRequest, callback func(response *EncryptResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *EncryptResponse - var err error - defer close(result) - response, err = client.Encrypt(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// EncryptRequest is the request struct for api Encrypt -type EncryptRequest struct { - *requests.RpcRequest - EncryptionContext string `position:"Query" name:"EncryptionContext"` - KeyId string `position:"Query" name:"KeyId"` - Plaintext string `position:"Query" name:"Plaintext"` -} - -// EncryptResponse is the response struct for api Encrypt -type EncryptResponse struct { - *responses.BaseResponse - CiphertextBlob string `json:"CiphertextBlob" xml:"CiphertextBlob"` - KeyId string `json:"KeyId" xml:"KeyId"` - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateEncryptRequest creates a request to invoke Encrypt API -func CreateEncryptRequest() (request *EncryptRequest) { - request = &EncryptRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "Encrypt", "kms", "openAPI") - return -} - -// CreateEncryptResponse creates a response to parse from Encrypt response -func CreateEncryptResponse() (response *EncryptResponse) { - response = &EncryptResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/generate_data_key.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/generate_data_key.go deleted file mode 100644 index 9c62b6d7..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/generate_data_key.go +++ /dev/null @@ -1,109 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// GenerateDataKey invokes the kms.GenerateDataKey API synchronously -// api document: https://help.aliyun.com/api/kms/generatedatakey.html -func (client *Client) GenerateDataKey(request *GenerateDataKeyRequest) (response *GenerateDataKeyResponse, err error) { - response = CreateGenerateDataKeyResponse() - err = client.DoAction(request, response) - return -} - -// GenerateDataKeyWithChan invokes the kms.GenerateDataKey API asynchronously -// api document: https://help.aliyun.com/api/kms/generatedatakey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) GenerateDataKeyWithChan(request *GenerateDataKeyRequest) (<-chan *GenerateDataKeyResponse, <-chan error) { - responseChan := make(chan *GenerateDataKeyResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.GenerateDataKey(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// GenerateDataKeyWithCallback invokes the kms.GenerateDataKey API asynchronously -// api document: https://help.aliyun.com/api/kms/generatedatakey.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) GenerateDataKeyWithCallback(request *GenerateDataKeyRequest, callback func(response *GenerateDataKeyResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *GenerateDataKeyResponse - var err error - defer close(result) - response, err = client.GenerateDataKey(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// GenerateDataKeyRequest is the request struct for api GenerateDataKey -type GenerateDataKeyRequest struct { - *requests.RpcRequest - EncryptionContext string `position:"Query" name:"EncryptionContext"` - KeyId string `position:"Query" name:"KeyId"` - KeySpec string `position:"Query" name:"KeySpec"` - NumberOfBytes requests.Integer `position:"Query" name:"NumberOfBytes"` -} - -// GenerateDataKeyResponse is the response struct for api GenerateDataKey -type GenerateDataKeyResponse struct { - *responses.BaseResponse - CiphertextBlob string `json:"CiphertextBlob" xml:"CiphertextBlob"` - KeyId string `json:"KeyId" xml:"KeyId"` - Plaintext string `json:"Plaintext" xml:"Plaintext"` - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateGenerateDataKeyRequest creates a request to invoke GenerateDataKey API -func CreateGenerateDataKeyRequest() (request *GenerateDataKeyRequest) { - request = &GenerateDataKeyRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "GenerateDataKey", "kms", "openAPI") - return -} - -// CreateGenerateDataKeyResponse creates a response to parse from GenerateDataKey response -func CreateGenerateDataKeyResponse() (response *GenerateDataKeyResponse) { - response = &GenerateDataKeyResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/get_parameters_for_import.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/get_parameters_for_import.go deleted file mode 100644 index ef748a5e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/get_parameters_for_import.go +++ /dev/null @@ -1,109 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// GetParametersForImport invokes the kms.GetParametersForImport API synchronously -// api document: https://help.aliyun.com/api/kms/getparametersforimport.html -func (client *Client) GetParametersForImport(request *GetParametersForImportRequest) (response *GetParametersForImportResponse, err error) { - response = CreateGetParametersForImportResponse() - err = client.DoAction(request, response) - return -} - -// GetParametersForImportWithChan invokes the kms.GetParametersForImport API asynchronously -// api document: https://help.aliyun.com/api/kms/getparametersforimport.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) GetParametersForImportWithChan(request *GetParametersForImportRequest) (<-chan *GetParametersForImportResponse, <-chan error) { - responseChan := make(chan *GetParametersForImportResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.GetParametersForImport(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// GetParametersForImportWithCallback invokes the kms.GetParametersForImport API asynchronously -// api document: https://help.aliyun.com/api/kms/getparametersforimport.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) GetParametersForImportWithCallback(request *GetParametersForImportRequest, callback func(response *GetParametersForImportResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *GetParametersForImportResponse - var err error - defer close(result) - response, err = client.GetParametersForImport(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// GetParametersForImportRequest is the request struct for api GetParametersForImport -type GetParametersForImportRequest struct { - *requests.RpcRequest - KeyId string `position:"Query" name:"KeyId"` - WrappingAlgorithm string `position:"Query" name:"WrappingAlgorithm"` - WrappingKeySpec string `position:"Query" name:"WrappingKeySpec"` -} - -// GetParametersForImportResponse is the response struct for api GetParametersForImport -type GetParametersForImportResponse struct { - *responses.BaseResponse - KeyId string `json:"KeyId" xml:"KeyId"` - RequestId string `json:"RequestId" xml:"RequestId"` - ImportToken string `json:"ImportToken" xml:"ImportToken"` - PublicKey string `json:"PublicKey" xml:"PublicKey"` - TokenExpireTime string `json:"TokenExpireTime" xml:"TokenExpireTime"` -} - -// CreateGetParametersForImportRequest creates a request to invoke GetParametersForImport API -func CreateGetParametersForImportRequest() (request *GetParametersForImportRequest) { - request = &GetParametersForImportRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "GetParametersForImport", "kms", "openAPI") - return -} - -// CreateGetParametersForImportResponse creates a response to parse from GetParametersForImport response -func CreateGetParametersForImportResponse() (response *GetParametersForImportResponse) { - response = &GetParametersForImportResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/import_key_material.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/import_key_material.go deleted file mode 100644 index e594eb93..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/import_key_material.go +++ /dev/null @@ -1,106 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// ImportKeyMaterial invokes the kms.ImportKeyMaterial API synchronously -// api document: https://help.aliyun.com/api/kms/importkeymaterial.html -func (client *Client) ImportKeyMaterial(request *ImportKeyMaterialRequest) (response *ImportKeyMaterialResponse, err error) { - response = CreateImportKeyMaterialResponse() - err = client.DoAction(request, response) - return -} - -// ImportKeyMaterialWithChan invokes the kms.ImportKeyMaterial API asynchronously -// api document: https://help.aliyun.com/api/kms/importkeymaterial.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ImportKeyMaterialWithChan(request *ImportKeyMaterialRequest) (<-chan *ImportKeyMaterialResponse, <-chan error) { - responseChan := make(chan *ImportKeyMaterialResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.ImportKeyMaterial(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// ImportKeyMaterialWithCallback invokes the kms.ImportKeyMaterial API asynchronously -// api document: https://help.aliyun.com/api/kms/importkeymaterial.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ImportKeyMaterialWithCallback(request *ImportKeyMaterialRequest, callback func(response *ImportKeyMaterialResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *ImportKeyMaterialResponse - var err error - defer close(result) - response, err = client.ImportKeyMaterial(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// ImportKeyMaterialRequest is the request struct for api ImportKeyMaterial -type ImportKeyMaterialRequest struct { - *requests.RpcRequest - ImportToken string `position:"Query" name:"ImportToken"` - EncryptedKeyMaterial string `position:"Query" name:"EncryptedKeyMaterial"` - KeyMaterialExpireUnix requests.Integer `position:"Query" name:"KeyMaterialExpireUnix"` - KeyId string `position:"Query" name:"KeyId"` -} - -// ImportKeyMaterialResponse is the response struct for api ImportKeyMaterial -type ImportKeyMaterialResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateImportKeyMaterialRequest creates a request to invoke ImportKeyMaterial API -func CreateImportKeyMaterialRequest() (request *ImportKeyMaterialRequest) { - request = &ImportKeyMaterialRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "ImportKeyMaterial", "kms", "openAPI") - return -} - -// CreateImportKeyMaterialResponse creates a response to parse from ImportKeyMaterial response -func CreateImportKeyMaterialResponse() (response *ImportKeyMaterialResponse) { - response = &ImportKeyMaterialResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_aliases.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_aliases.go deleted file mode 100644 index fa961a8e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_aliases.go +++ /dev/null @@ -1,108 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// ListAliases invokes the kms.ListAliases API synchronously -// api document: https://help.aliyun.com/api/kms/listaliases.html -func (client *Client) ListAliases(request *ListAliasesRequest) (response *ListAliasesResponse, err error) { - response = CreateListAliasesResponse() - err = client.DoAction(request, response) - return -} - -// ListAliasesWithChan invokes the kms.ListAliases API asynchronously -// api document: https://help.aliyun.com/api/kms/listaliases.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ListAliasesWithChan(request *ListAliasesRequest) (<-chan *ListAliasesResponse, <-chan error) { - responseChan := make(chan *ListAliasesResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.ListAliases(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// ListAliasesWithCallback invokes the kms.ListAliases API asynchronously -// api document: https://help.aliyun.com/api/kms/listaliases.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ListAliasesWithCallback(request *ListAliasesRequest, callback func(response *ListAliasesResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *ListAliasesResponse - var err error - defer close(result) - response, err = client.ListAliases(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// ListAliasesRequest is the request struct for api ListAliases -type ListAliasesRequest struct { - *requests.RpcRequest - PageSize requests.Integer `position:"Query" name:"PageSize"` - PageNumber requests.Integer `position:"Query" name:"PageNumber"` -} - -// ListAliasesResponse is the response struct for api ListAliases -type ListAliasesResponse struct { - *responses.BaseResponse - TotalCount int `json:"TotalCount" xml:"TotalCount"` - PageNumber int `json:"PageNumber" xml:"PageNumber"` - PageSize int `json:"PageSize" xml:"PageSize"` - RequestId string `json:"RequestId" xml:"RequestId"` - Aliases AliasesInListAliases `json:"Aliases" xml:"Aliases"` -} - -// CreateListAliasesRequest creates a request to invoke ListAliases API -func CreateListAliasesRequest() (request *ListAliasesRequest) { - request = &ListAliasesRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "ListAliases", "kms", "openAPI") - return -} - -// CreateListAliasesResponse creates a response to parse from ListAliases response -func CreateListAliasesResponse() (response *ListAliasesResponse) { - response = &ListAliasesResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_aliases_by_key_id.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_aliases_by_key_id.go deleted file mode 100644 index 227d2794..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_aliases_by_key_id.go +++ /dev/null @@ -1,109 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// ListAliasesByKeyId invokes the kms.ListAliasesByKeyId API synchronously -// api document: https://help.aliyun.com/api/kms/listaliasesbykeyid.html -func (client *Client) ListAliasesByKeyId(request *ListAliasesByKeyIdRequest) (response *ListAliasesByKeyIdResponse, err error) { - response = CreateListAliasesByKeyIdResponse() - err = client.DoAction(request, response) - return -} - -// ListAliasesByKeyIdWithChan invokes the kms.ListAliasesByKeyId API asynchronously -// api document: https://help.aliyun.com/api/kms/listaliasesbykeyid.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ListAliasesByKeyIdWithChan(request *ListAliasesByKeyIdRequest) (<-chan *ListAliasesByKeyIdResponse, <-chan error) { - responseChan := make(chan *ListAliasesByKeyIdResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.ListAliasesByKeyId(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// ListAliasesByKeyIdWithCallback invokes the kms.ListAliasesByKeyId API asynchronously -// api document: https://help.aliyun.com/api/kms/listaliasesbykeyid.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ListAliasesByKeyIdWithCallback(request *ListAliasesByKeyIdRequest, callback func(response *ListAliasesByKeyIdResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *ListAliasesByKeyIdResponse - var err error - defer close(result) - response, err = client.ListAliasesByKeyId(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// ListAliasesByKeyIdRequest is the request struct for api ListAliasesByKeyId -type ListAliasesByKeyIdRequest struct { - *requests.RpcRequest - PageSize requests.Integer `position:"Query" name:"PageSize"` - KeyId string `position:"Query" name:"KeyId"` - PageNumber requests.Integer `position:"Query" name:"PageNumber"` -} - -// ListAliasesByKeyIdResponse is the response struct for api ListAliasesByKeyId -type ListAliasesByKeyIdResponse struct { - *responses.BaseResponse - TotalCount int `json:"TotalCount" xml:"TotalCount"` - PageNumber int `json:"PageNumber" xml:"PageNumber"` - PageSize int `json:"PageSize" xml:"PageSize"` - RequestId string `json:"RequestId" xml:"RequestId"` - Aliases AliasesInListAliasesByKeyId `json:"Aliases" xml:"Aliases"` -} - -// CreateListAliasesByKeyIdRequest creates a request to invoke ListAliasesByKeyId API -func CreateListAliasesByKeyIdRequest() (request *ListAliasesByKeyIdRequest) { - request = &ListAliasesByKeyIdRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "ListAliasesByKeyId", "kms", "openAPI") - return -} - -// CreateListAliasesByKeyIdResponse creates a response to parse from ListAliasesByKeyId response -func CreateListAliasesByKeyIdResponse() (response *ListAliasesByKeyIdResponse) { - response = &ListAliasesByKeyIdResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_keys.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_keys.go deleted file mode 100644 index 3384d709..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_keys.go +++ /dev/null @@ -1,108 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// ListKeys invokes the kms.ListKeys API synchronously -// api document: https://help.aliyun.com/api/kms/listkeys.html -func (client *Client) ListKeys(request *ListKeysRequest) (response *ListKeysResponse, err error) { - response = CreateListKeysResponse() - err = client.DoAction(request, response) - return -} - -// ListKeysWithChan invokes the kms.ListKeys API asynchronously -// api document: https://help.aliyun.com/api/kms/listkeys.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ListKeysWithChan(request *ListKeysRequest) (<-chan *ListKeysResponse, <-chan error) { - responseChan := make(chan *ListKeysResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.ListKeys(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// ListKeysWithCallback invokes the kms.ListKeys API asynchronously -// api document: https://help.aliyun.com/api/kms/listkeys.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ListKeysWithCallback(request *ListKeysRequest, callback func(response *ListKeysResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *ListKeysResponse - var err error - defer close(result) - response, err = client.ListKeys(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// ListKeysRequest is the request struct for api ListKeys -type ListKeysRequest struct { - *requests.RpcRequest - PageSize requests.Integer `position:"Query" name:"PageSize"` - PageNumber requests.Integer `position:"Query" name:"PageNumber"` -} - -// ListKeysResponse is the response struct for api ListKeys -type ListKeysResponse struct { - *responses.BaseResponse - TotalCount int `json:"TotalCount" xml:"TotalCount"` - PageNumber int `json:"PageNumber" xml:"PageNumber"` - PageSize int `json:"PageSize" xml:"PageSize"` - RequestId string `json:"RequestId" xml:"RequestId"` - Keys Keys `json:"Keys" xml:"Keys"` -} - -// CreateListKeysRequest creates a request to invoke ListKeys API -func CreateListKeysRequest() (request *ListKeysRequest) { - request = &ListKeysRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "ListKeys", "kms", "openAPI") - return -} - -// CreateListKeysResponse creates a response to parse from ListKeys response -func CreateListKeysResponse() (response *ListKeysResponse) { - response = &ListKeysResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_resource_tags.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_resource_tags.go deleted file mode 100644 index 4f642754..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/list_resource_tags.go +++ /dev/null @@ -1,104 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// ListResourceTags invokes the kms.ListResourceTags API synchronously -// api document: https://help.aliyun.com/api/kms/listresourcetags.html -func (client *Client) ListResourceTags(request *ListResourceTagsRequest) (response *ListResourceTagsResponse, err error) { - response = CreateListResourceTagsResponse() - err = client.DoAction(request, response) - return -} - -// ListResourceTagsWithChan invokes the kms.ListResourceTags API asynchronously -// api document: https://help.aliyun.com/api/kms/listresourcetags.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ListResourceTagsWithChan(request *ListResourceTagsRequest) (<-chan *ListResourceTagsResponse, <-chan error) { - responseChan := make(chan *ListResourceTagsResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.ListResourceTags(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// ListResourceTagsWithCallback invokes the kms.ListResourceTags API asynchronously -// api document: https://help.aliyun.com/api/kms/listresourcetags.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ListResourceTagsWithCallback(request *ListResourceTagsRequest, callback func(response *ListResourceTagsResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *ListResourceTagsResponse - var err error - defer close(result) - response, err = client.ListResourceTags(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// ListResourceTagsRequest is the request struct for api ListResourceTags -type ListResourceTagsRequest struct { - *requests.RpcRequest - KeyId string `position:"Query" name:"KeyId"` -} - -// ListResourceTagsResponse is the response struct for api ListResourceTags -type ListResourceTagsResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` - Tags Tags `json:"Tags" xml:"Tags"` -} - -// CreateListResourceTagsRequest creates a request to invoke ListResourceTags API -func CreateListResourceTagsRequest() (request *ListResourceTagsRequest) { - request = &ListResourceTagsRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "ListResourceTags", "kms", "openAPI") - return -} - -// CreateListResourceTagsResponse creates a response to parse from ListResourceTags response -func CreateListResourceTagsResponse() (response *ListResourceTagsResponse) { - response = &ListResourceTagsResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/schedule_key_deletion.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/schedule_key_deletion.go deleted file mode 100644 index 23ce5eb4..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/schedule_key_deletion.go +++ /dev/null @@ -1,104 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// ScheduleKeyDeletion invokes the kms.ScheduleKeyDeletion API synchronously -// api document: https://help.aliyun.com/api/kms/schedulekeydeletion.html -func (client *Client) ScheduleKeyDeletion(request *ScheduleKeyDeletionRequest) (response *ScheduleKeyDeletionResponse, err error) { - response = CreateScheduleKeyDeletionResponse() - err = client.DoAction(request, response) - return -} - -// ScheduleKeyDeletionWithChan invokes the kms.ScheduleKeyDeletion API asynchronously -// api document: https://help.aliyun.com/api/kms/schedulekeydeletion.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ScheduleKeyDeletionWithChan(request *ScheduleKeyDeletionRequest) (<-chan *ScheduleKeyDeletionResponse, <-chan error) { - responseChan := make(chan *ScheduleKeyDeletionResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.ScheduleKeyDeletion(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// ScheduleKeyDeletionWithCallback invokes the kms.ScheduleKeyDeletion API asynchronously -// api document: https://help.aliyun.com/api/kms/schedulekeydeletion.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) ScheduleKeyDeletionWithCallback(request *ScheduleKeyDeletionRequest, callback func(response *ScheduleKeyDeletionResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *ScheduleKeyDeletionResponse - var err error - defer close(result) - response, err = client.ScheduleKeyDeletion(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// ScheduleKeyDeletionRequest is the request struct for api ScheduleKeyDeletion -type ScheduleKeyDeletionRequest struct { - *requests.RpcRequest - PendingWindowInDays requests.Integer `position:"Query" name:"PendingWindowInDays"` - KeyId string `position:"Query" name:"KeyId"` -} - -// ScheduleKeyDeletionResponse is the response struct for api ScheduleKeyDeletion -type ScheduleKeyDeletionResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateScheduleKeyDeletionRequest creates a request to invoke ScheduleKeyDeletion API -func CreateScheduleKeyDeletionRequest() (request *ScheduleKeyDeletionRequest) { - request = &ScheduleKeyDeletionRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "ScheduleKeyDeletion", "kms", "openAPI") - return -} - -// CreateScheduleKeyDeletionResponse creates a response to parse from ScheduleKeyDeletion response -func CreateScheduleKeyDeletionResponse() (response *ScheduleKeyDeletionResponse) { - response = &ScheduleKeyDeletionResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_alias.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_alias.go deleted file mode 100644 index 56b5984e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_alias.go +++ /dev/null @@ -1,23 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// Alias is a nested struct in kms response -type Alias struct { - AliasArn string `json:"AliasArn" xml:"AliasArn"` - AliasName string `json:"AliasName" xml:"AliasName"` - KeyId string `json:"KeyId" xml:"KeyId"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_aliases_in_list_aliases.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_aliases_in_list_aliases.go deleted file mode 100644 index a08047f1..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_aliases_in_list_aliases.go +++ /dev/null @@ -1,21 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// AliasesInListAliases is a nested struct in kms response -type AliasesInListAliases struct { - Alias []Alias `json:"Alias" xml:"Alias"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_aliases_in_list_aliases_by_key_id.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_aliases_in_list_aliases_by_key_id.go deleted file mode 100644 index 8f52f423..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_aliases_in_list_aliases_by_key_id.go +++ /dev/null @@ -1,21 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// AliasesInListAliasesByKeyId is a nested struct in kms response -type AliasesInListAliasesByKeyId struct { - Alias []Alias `json:"Alias" xml:"Alias"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_key.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_key.go deleted file mode 100644 index 8e6f508e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_key.go +++ /dev/null @@ -1,22 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// Key is a nested struct in kms response -type Key struct { - KeyId string `json:"KeyId" xml:"KeyId"` - KeyArn string `json:"KeyArn" xml:"KeyArn"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_key_metadata.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_key_metadata.go deleted file mode 100644 index 5432b8c1..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_key_metadata.go +++ /dev/null @@ -1,30 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// KeyMetadata is a nested struct in kms response -type KeyMetadata struct { - Arn string `json:"Arn" xml:"Arn"` - KeyState string `json:"KeyState" xml:"KeyState"` - CreationDate string `json:"CreationDate" xml:"CreationDate"` - KeyUsage string `json:"KeyUsage" xml:"KeyUsage"` - DeleteDate string `json:"DeleteDate" xml:"DeleteDate"` - Creator string `json:"Creator" xml:"Creator"` - Origin string `json:"Origin" xml:"Origin"` - Description string `json:"Description" xml:"Description"` - KeyId string `json:"KeyId" xml:"KeyId"` - MaterialExpireTime string `json:"MaterialExpireTime" xml:"MaterialExpireTime"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_keys.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_keys.go deleted file mode 100644 index 5e36d49f..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_keys.go +++ /dev/null @@ -1,21 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// Keys is a nested struct in kms response -type Keys struct { - Key []Key `json:"Key" xml:"Key"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_region.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_region.go deleted file mode 100644 index d54b0e59..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_region.go +++ /dev/null @@ -1,21 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// Region is a nested struct in kms response -type Region struct { - RegionId string `json:"RegionId" xml:"RegionId"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_regions.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_regions.go deleted file mode 100644 index 4c87936e..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_regions.go +++ /dev/null @@ -1,21 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// Regions is a nested struct in kms response -type Regions struct { - Region []Region `json:"Region" xml:"Region"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_tag.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_tag.go deleted file mode 100644 index b2806f8c..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_tag.go +++ /dev/null @@ -1,23 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// Tag is a nested struct in kms response -type Tag struct { - KeyId string `json:"KeyId" xml:"KeyId"` - TagKey string `json:"TagKey" xml:"TagKey"` - TagValue string `json:"TagValue" xml:"TagValue"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_tags.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_tags.go deleted file mode 100644 index c3c2234b..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/struct_tags.go +++ /dev/null @@ -1,21 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -// Tags is a nested struct in kms response -type Tags struct { - Tag []Tag `json:"Tag" xml:"Tag"` -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/tag_resource.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/tag_resource.go deleted file mode 100644 index b5c29953..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/tag_resource.go +++ /dev/null @@ -1,104 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// TagResource invokes the kms.TagResource API synchronously -// api document: https://help.aliyun.com/api/kms/tagresource.html -func (client *Client) TagResource(request *TagResourceRequest) (response *TagResourceResponse, err error) { - response = CreateTagResourceResponse() - err = client.DoAction(request, response) - return -} - -// TagResourceWithChan invokes the kms.TagResource API asynchronously -// api document: https://help.aliyun.com/api/kms/tagresource.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) TagResourceWithChan(request *TagResourceRequest) (<-chan *TagResourceResponse, <-chan error) { - responseChan := make(chan *TagResourceResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.TagResource(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// TagResourceWithCallback invokes the kms.TagResource API asynchronously -// api document: https://help.aliyun.com/api/kms/tagresource.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) TagResourceWithCallback(request *TagResourceRequest, callback func(response *TagResourceResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *TagResourceResponse - var err error - defer close(result) - response, err = client.TagResource(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// TagResourceRequest is the request struct for api TagResource -type TagResourceRequest struct { - *requests.RpcRequest - KeyId string `position:"Query" name:"KeyId"` - Tags string `position:"Query" name:"Tags"` -} - -// TagResourceResponse is the response struct for api TagResource -type TagResourceResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateTagResourceRequest creates a request to invoke TagResource API -func CreateTagResourceRequest() (request *TagResourceRequest) { - request = &TagResourceRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "TagResource", "kms", "openAPI") - return -} - -// CreateTagResourceResponse creates a response to parse from TagResource response -func CreateTagResourceResponse() (response *TagResourceResponse) { - response = &TagResourceResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/untag_resource.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/untag_resource.go deleted file mode 100644 index 8135ac80..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/untag_resource.go +++ /dev/null @@ -1,104 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// UntagResource invokes the kms.UntagResource API synchronously -// api document: https://help.aliyun.com/api/kms/untagresource.html -func (client *Client) UntagResource(request *UntagResourceRequest) (response *UntagResourceResponse, err error) { - response = CreateUntagResourceResponse() - err = client.DoAction(request, response) - return -} - -// UntagResourceWithChan invokes the kms.UntagResource API asynchronously -// api document: https://help.aliyun.com/api/kms/untagresource.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) UntagResourceWithChan(request *UntagResourceRequest) (<-chan *UntagResourceResponse, <-chan error) { - responseChan := make(chan *UntagResourceResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.UntagResource(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// UntagResourceWithCallback invokes the kms.UntagResource API asynchronously -// api document: https://help.aliyun.com/api/kms/untagresource.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) UntagResourceWithCallback(request *UntagResourceRequest, callback func(response *UntagResourceResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *UntagResourceResponse - var err error - defer close(result) - response, err = client.UntagResource(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// UntagResourceRequest is the request struct for api UntagResource -type UntagResourceRequest struct { - *requests.RpcRequest - TagKeys string `position:"Query" name:"TagKeys"` - KeyId string `position:"Query" name:"KeyId"` -} - -// UntagResourceResponse is the response struct for api UntagResource -type UntagResourceResponse struct { - *responses.BaseResponse - KeyId string `json:"KeyId" xml:"KeyId"` -} - -// CreateUntagResourceRequest creates a request to invoke UntagResource API -func CreateUntagResourceRequest() (request *UntagResourceRequest) { - request = &UntagResourceRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "UntagResource", "kms", "openAPI") - return -} - -// CreateUntagResourceResponse creates a response to parse from UntagResource response -func CreateUntagResourceResponse() (response *UntagResourceResponse) { - response = &UntagResourceResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/update_alias.go b/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/update_alias.go deleted file mode 100644 index 16b52402..00000000 --- a/vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/kms/update_alias.go +++ /dev/null @@ -1,104 +0,0 @@ -package kms - -//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. -// -// Code generated by Alibaba Cloud SDK Code Generator. -// Changes may cause incorrect behavior and will be lost if the code is regenerated. - -import ( - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests" - "github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses" -) - -// UpdateAlias invokes the kms.UpdateAlias API synchronously -// api document: https://help.aliyun.com/api/kms/updatealias.html -func (client *Client) UpdateAlias(request *UpdateAliasRequest) (response *UpdateAliasResponse, err error) { - response = CreateUpdateAliasResponse() - err = client.DoAction(request, response) - return -} - -// UpdateAliasWithChan invokes the kms.UpdateAlias API asynchronously -// api document: https://help.aliyun.com/api/kms/updatealias.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) UpdateAliasWithChan(request *UpdateAliasRequest) (<-chan *UpdateAliasResponse, <-chan error) { - responseChan := make(chan *UpdateAliasResponse, 1) - errChan := make(chan error, 1) - err := client.AddAsyncTask(func() { - defer close(responseChan) - defer close(errChan) - response, err := client.UpdateAlias(request) - if err != nil { - errChan <- err - } else { - responseChan <- response - } - }) - if err != nil { - errChan <- err - close(responseChan) - close(errChan) - } - return responseChan, errChan -} - -// UpdateAliasWithCallback invokes the kms.UpdateAlias API asynchronously -// api document: https://help.aliyun.com/api/kms/updatealias.html -// asynchronous document: https://help.aliyun.com/document_detail/66220.html -func (client *Client) UpdateAliasWithCallback(request *UpdateAliasRequest, callback func(response *UpdateAliasResponse, err error)) <-chan int { - result := make(chan int, 1) - err := client.AddAsyncTask(func() { - var response *UpdateAliasResponse - var err error - defer close(result) - response, err = client.UpdateAlias(request) - callback(response, err) - result <- 1 - }) - if err != nil { - defer close(result) - callback(nil, err) - result <- 0 - } - return result -} - -// UpdateAliasRequest is the request struct for api UpdateAlias -type UpdateAliasRequest struct { - *requests.RpcRequest - AliasName string `position:"Query" name:"AliasName"` - KeyId string `position:"Query" name:"KeyId"` -} - -// UpdateAliasResponse is the response struct for api UpdateAlias -type UpdateAliasResponse struct { - *responses.BaseResponse - RequestId string `json:"RequestId" xml:"RequestId"` -} - -// CreateUpdateAliasRequest creates a request to invoke UpdateAlias API -func CreateUpdateAliasRequest() (request *UpdateAliasRequest) { - request = &UpdateAliasRequest{ - RpcRequest: &requests.RpcRequest{}, - } - request.InitWithApiInfo("Kms", "2016-01-20", "UpdateAlias", "kms", "openAPI") - return -} - -// CreateUpdateAliasResponse creates a response to parse from UpdateAlias response -func CreateUpdateAliasResponse() (response *UpdateAliasResponse) { - response = &UpdateAliasResponse{ - BaseResponse: &responses.BaseResponse{}, - } - return -} diff --git a/vendor/github.com/buger/jsonparser/.gitignore b/vendor/github.com/buger/jsonparser/.gitignore deleted file mode 100644 index 9de1b0fa..00000000 --- a/vendor/github.com/buger/jsonparser/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ - -*.test - -*.out - -*.mprof - -vendor/github.com/buger/goterm/ -prof.cpu -prof.mem diff --git a/vendor/github.com/buger/jsonparser/.travis.yml b/vendor/github.com/buger/jsonparser/.travis.yml deleted file mode 100644 index 8e29f131..00000000 --- a/vendor/github.com/buger/jsonparser/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go -go: - - 1.7.x - - 1.8.x - - 1.9.x - - 1.10.x - - 1.11.x -script: go test -v ./. diff --git a/vendor/github.com/buger/jsonparser/Dockerfile b/vendor/github.com/buger/jsonparser/Dockerfile deleted file mode 100644 index 37fc9fd0..00000000 --- a/vendor/github.com/buger/jsonparser/Dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -FROM golang:1.6 - -RUN go get github.com/Jeffail/gabs -RUN go get github.com/bitly/go-simplejson -RUN go get github.com/pquerna/ffjson -RUN go get github.com/antonholmquist/jason -RUN go get github.com/mreiferson/go-ujson -RUN go get -tags=unsafe -u github.com/ugorji/go/codec -RUN go get github.com/mailru/easyjson - -WORKDIR /go/src/github.com/buger/jsonparser -ADD . /go/src/github.com/buger/jsonparser \ No newline at end of file diff --git a/vendor/github.com/buger/jsonparser/LICENSE b/vendor/github.com/buger/jsonparser/LICENSE deleted file mode 100644 index ac25aeb7..00000000 --- a/vendor/github.com/buger/jsonparser/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2016 Leonid Bugaev - -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/buger/jsonparser/Makefile b/vendor/github.com/buger/jsonparser/Makefile deleted file mode 100644 index e843368c..00000000 --- a/vendor/github.com/buger/jsonparser/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -SOURCE = parser.go -CONTAINER = jsonparser -SOURCE_PATH = /go/src/github.com/buger/jsonparser -BENCHMARK = JsonParser -BENCHTIME = 5s -TEST = . -DRUN = docker run -v `pwd`:$(SOURCE_PATH) -i -t $(CONTAINER) - -build: - docker build -t $(CONTAINER) . - -race: - $(DRUN) --env GORACE="halt_on_error=1" go test ./. $(ARGS) -v -race -timeout 15s - -bench: - $(DRUN) go test $(LDFLAGS) -test.benchmem -bench $(BENCHMARK) ./benchmark/ $(ARGS) -benchtime $(BENCHTIME) -v - -bench_local: - $(DRUN) go test $(LDFLAGS) -test.benchmem -bench . $(ARGS) -benchtime $(BENCHTIME) -v - -profile: - $(DRUN) go test $(LDFLAGS) -test.benchmem -bench $(BENCHMARK) ./benchmark/ $(ARGS) -memprofile mem.mprof -v - $(DRUN) go test $(LDFLAGS) -test.benchmem -bench $(BENCHMARK) ./benchmark/ $(ARGS) -cpuprofile cpu.out -v - $(DRUN) go test $(LDFLAGS) -test.benchmem -bench $(BENCHMARK) ./benchmark/ $(ARGS) -c - -test: - $(DRUN) go test $(LDFLAGS) ./ -run $(TEST) -timeout 10s $(ARGS) -v - -fmt: - $(DRUN) go fmt ./... - -vet: - $(DRUN) go vet ./. - -bash: - $(DRUN) /bin/bash \ No newline at end of file diff --git a/vendor/github.com/buger/jsonparser/README.md b/vendor/github.com/buger/jsonparser/README.md deleted file mode 100644 index a9ee6022..00000000 --- a/vendor/github.com/buger/jsonparser/README.md +++ /dev/null @@ -1,365 +0,0 @@ -[![Go Report Card](https://goreportcard.com/badge/github.com/buger/jsonparser)](https://goreportcard.com/report/github.com/buger/jsonparser) ![License](https://img.shields.io/dub/l/vibe-d.svg) -# Alternative JSON parser for Go (so far fastest) - -It does not require you to know the structure of the payload (eg. create structs), and allows accessing fields by providing the path to them. It is up to **10 times faster** than standard `encoding/json` package (depending on payload size and usage), **allocates no memory**. See benchmarks below. - -## Rationale -Originally I made this for a project that relies on a lot of 3rd party APIs that can be unpredictable and complex. -I love simplicity and prefer to avoid external dependecies. `encoding/json` requires you to know exactly your data structures, or if you prefer to use `map[string]interface{}` instead, it will be very slow and hard to manage. -I investigated what's on the market and found that most libraries are just wrappers around `encoding/json`, there is few options with own parsers (`ffjson`, `easyjson`), but they still requires you to create data structures. - - -Goal of this project is to push JSON parser to the performance limits and not sacrifice with compliance and developer user experience. - -## Example -For the given JSON our goal is to extract the user's full name, number of github followers and avatar. - -```go -import "github.com/buger/jsonparser" - -... - -data := []byte(`{ - "person": { - "name": { - "first": "Leonid", - "last": "Bugaev", - "fullName": "Leonid Bugaev" - }, - "github": { - "handle": "buger", - "followers": 109 - }, - "avatars": [ - { "url": "https://avatars1.githubusercontent.com/u/14009?v=3&s=460", "type": "thumbnail" } - ] - }, - "company": { - "name": "Acme" - } -}`) - -// You can specify key path by providing arguments to Get function -jsonparser.Get(data, "person", "name", "fullName") - -// There is `GetInt` and `GetBoolean` helpers if you exactly know key data type -jsonparser.GetInt(data, "person", "github", "followers") - -// When you try to get object, it will return you []byte slice pointer to data containing it -// In `company` it will be `{"name": "Acme"}` -jsonparser.Get(data, "company") - -// If the key doesn't exist it will throw an error -var size int64 -if value, err := jsonparser.GetInt(data, "company", "size"); err == nil { - size = value -} - -// You can use `ArrayEach` helper to iterate items [item1, item2 .... itemN] -jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) { - fmt.Println(jsonparser.Get(value, "url")) -}, "person", "avatars") - -// Or use can access fields by index! -jsonparser.GetInt("person", "avatars", "[0]", "url") - -// You can use `ObjectEach` helper to iterate objects { "key1":object1, "key2":object2, .... "keyN":objectN } -jsonparser.ObjectEach(data, func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error { - fmt.Printf("Key: '%s'\n Value: '%s'\n Type: %s\n", string(key), string(value), dataType) - return nil -}, "person", "name") - -// The most efficient way to extract multiple keys is `EachKey` - -paths := [][]string{ - []string{"person", "name", "fullName"}, - []string{"person", "avatars", "[0]", "url"}, - []string{"company", "url"}, -} -jsonparser.EachKey(data, func(idx int, value []byte, vt jsonparser.ValueType, err error){ - switch idx { - case 0: // []string{"person", "name", "fullName"} - ... - case 1: // []string{"person", "avatars", "[0]", "url"} - ... - case 2: // []string{"company", "url"}, - ... - } -}, paths...) - -// For more information see docs below -``` - -## Need to speedup your app? - -I'm available for consulting and can help you push your app performance to the limits. Ping me at: leonsbox@gmail.com. - -## Reference - -Library API is really simple. You just need the `Get` method to perform any operation. The rest is just helpers around it. - -You also can view API at [godoc.org](https://godoc.org/github.com/buger/jsonparser) - - -### **`Get`** -```go -func Get(data []byte, keys ...string) (value []byte, dataType jsonparser.ValueType, offset int, err error) -``` -Receives data structure, and key path to extract value from. - -Returns: -* `value` - Pointer to original data structure containing key value, or just empty slice if nothing found or error -* `dataType` - Can be: `NotExist`, `String`, `Number`, `Object`, `Array`, `Boolean` or `Null` -* `offset` - Offset from provided data structure where key value ends. Used mostly internally, for example for `ArrayEach` helper. -* `err` - If the key is not found or any other parsing issue, it should return error. If key not found it also sets `dataType` to `NotExist` - -Accepts multiple keys to specify path to JSON value (in case of quering nested structures). -If no keys are provided it will try to extract the closest JSON value (simple ones or object/array), useful for reading streams or arrays, see `ArrayEach` implementation. - -Note that keys can be an array indexes: `jsonparser.GetInt("person", "avatars", "[0]", "url")`, pretty cool, yeah? - -### **`GetString`** -```go -func GetString(data []byte, keys ...string) (val string, err error) -``` -Returns strings properly handing escaped and unicode characters. Note that this will cause additional memory allocations. - -### **`GetUnsafeString`** -If you need string in your app, and ready to sacrifice with support of escaped symbols in favor of speed. It returns string mapped to existing byte slice memory, without any allocations: -```go -s, _, := jsonparser.GetUnsafeString(data, "person", "name", "title") -switch s { - case 'CEO': - ... - case 'Engineer' - ... - ... -} -``` -Note that `unsafe` here means that your string will exist until GC will free underlying byte slice, for most of cases it means that you can use this string only in current context, and should not pass it anywhere externally: through channels or any other way. - - -### **`GetBoolean`**, **`GetInt`** and **`GetFloat`** -```go -func GetBoolean(data []byte, keys ...string) (val bool, err error) - -func GetFloat(data []byte, keys ...string) (val float64, err error) - -func GetInt(data []byte, keys ...string) (val int64, err error) -``` -If you know the key type, you can use the helpers above. -If key data type do not match, it will return error. - -### **`ArrayEach`** -```go -func ArrayEach(data []byte, cb func(value []byte, dataType jsonparser.ValueType, offset int, err error), keys ...string) -``` -Needed for iterating arrays, accepts a callback function with the same return arguments as `Get`. - -### **`ObjectEach`** -```go -func ObjectEach(data []byte, callback func(key []byte, value []byte, dataType ValueType, offset int) error, keys ...string) (err error) -``` -Needed for iterating object, accepts a callback function. Example: -```go -var handler func([]byte, []byte, jsonparser.ValueType, int) error -handler = func(key []byte, value []byte, dataType jsonparser.ValueType, offset int) error { - //do stuff here -} -jsonparser.ObjectEach(myJson, handler) -``` - - -### **`EachKey`** -```go -func EachKey(data []byte, cb func(idx int, value []byte, dataType jsonparser.ValueType, err error), paths ...[]string) -``` -When you need to read multiple keys, and you do not afraid of low-level API `EachKey` is your friend. It read payload only single time, and calls callback function once path is found. For example when you call multiple times `Get`, it has to process payload multiple times, each time you call it. Depending on payload `EachKey` can be multiple times faster than `Get`. Path can use nested keys as well! - -```go -paths := [][]string{ - []string{"uuid"}, - []string{"tz"}, - []string{"ua"}, - []string{"st"}, -} -var data SmallPayload - -jsonparser.EachKey(smallFixture, func(idx int, value []byte, vt jsonparser.ValueType, err error){ - switch idx { - case 0: - data.Uuid, _ = value - case 1: - v, _ := jsonparser.ParseInt(value) - data.Tz = int(v) - case 2: - data.Ua, _ = value - case 3: - v, _ := jsonparser.ParseInt(value) - data.St = int(v) - } -}, paths...) -``` - -### **`Set`** -```go -func Set(data []byte, setValue []byte, keys ...string) (value []byte, err error) -``` -Receives existing data structure, key path to set, and value to set at that key. *This functionality is experimental.* - -Returns: -* `value` - Pointer to original data structure with updated or added key value. -* `err` - If any parsing issue, it should return error. - -Accepts multiple keys to specify path to JSON value (in case of updating or creating nested structures). - -Note that keys can be an array indexes: `jsonparser.Set(data, []byte("http://github.com"), "person", "avatars", "[0]", "url")` - -### **`Delete`** -```go -func Delete(data []byte, keys ...string) value []byte -``` -Receives existing data structure, and key path to delete. *This functionality is experimental.* - -Returns: -* `value` - Pointer to original data structure with key path deleted if it can be found. If there is no key path, then the whole data structure is deleted. - -Accepts multiple keys to specify path to JSON value (in case of updating or creating nested structures). - -Note that keys can be an array indexes: `jsonparser.Delete(data, "person", "avatars", "[0]", "url")` - - -## What makes it so fast? -* It does not rely on `encoding/json`, `reflection` or `interface{}`, the only real package dependency is `bytes`. -* Operates with JSON payload on byte level, providing you pointers to the original data structure: no memory allocation. -* No automatic type conversions, by default everything is a []byte, but it provides you value type, so you can convert by yourself (there is few helpers included). -* Does not parse full record, only keys you specified - - -## Benchmarks - -There are 3 benchmark types, trying to simulate real-life usage for small, medium and large JSON payloads. -For each metric, the lower value is better. Time/op is in nanoseconds. Values better than standard encoding/json marked as bold text. -Benchmarks run on standard Linode 1024 box. - -Compared libraries: -* https://golang.org/pkg/encoding/json -* https://github.com/Jeffail/gabs -* https://github.com/a8m/djson -* https://github.com/bitly/go-simplejson -* https://github.com/antonholmquist/jason -* https://github.com/mreiferson/go-ujson -* https://github.com/ugorji/go/codec -* https://github.com/pquerna/ffjson -* https://github.com/mailru/easyjson -* https://github.com/buger/jsonparser - -#### TLDR -If you want to skip next sections we have 2 winner: `jsonparser` and `easyjson`. -`jsonparser` is up to 10 times faster than standard `encoding/json` package (depending on payload size and usage), and almost infinitely (literally) better in memory consumption because it operates with data on byte level, and provide direct slice pointers. -`easyjson` wins in CPU in medium tests and frankly i'm impressed with this package: it is remarkable results considering that it is almost drop-in replacement for `encoding/json` (require some code generation). - -It's hard to fully compare `jsonparser` and `easyjson` (or `ffson`), they a true parsers and fully process record, unlike `jsonparser` which parse only keys you specified. - -If you searching for replacement of `encoding/json` while keeping structs, `easyjson` is an amazing choice. If you want to process dynamic JSON, have memory constrains, or more control over your data you should try `jsonparser`. - -`jsonparser` performance heavily depends on usage, and it works best when you do not need to process full record, only some keys. The more calls you need to make, the slower it will be, in contrast `easyjson` (or `ffjson`, `encoding/json`) parser record only 1 time, and then you can make as many calls as you want. - -With great power comes great responsibility! :) - - -#### Small payload - -Each test processes 190 bytes of http log as a JSON record. -It should read multiple fields. -https://github.com/buger/jsonparser/blob/master/benchmark/benchmark_small_payload_test.go - -Library | time/op | bytes/op | allocs/op - ------ | ------- | -------- | ------- -encoding/json struct | 7879 | 880 | 18 -encoding/json interface{} | 8946 | 1521 | 38 -Jeffail/gabs | 10053 | 1649 | 46 -bitly/go-simplejson | 10128 | 2241 | 36 -antonholmquist/jason | 27152 | 7237 | 101 -github.com/ugorji/go/codec | 8806 | 2176 | 31 -mreiferson/go-ujson | **7008** | **1409** | 37 -a8m/djson | 3862 | 1249 | 30 -pquerna/ffjson | **3769** | **624** | **15** -mailru/easyjson | **2002** | **192** | **9** -buger/jsonparser | **1367** | **0** | **0** -buger/jsonparser (EachKey API) | **809** | **0** | **0** - -Winners are ffjson, easyjson and jsonparser, where jsonparser is up to 9.8x faster than encoding/json and 4.6x faster than ffjson, and slightly faster than easyjson. -If you look at memory allocation, jsonparser has no rivals, as it makes no data copy and operates with raw []byte structures and pointers to it. - -#### Medium payload - -Each test processes a 2.4kb JSON record (based on Clearbit API). -It should read multiple nested fields and 1 array. - -https://github.com/buger/jsonparser/blob/master/benchmark/benchmark_medium_payload_test.go - -| Library | time/op | bytes/op | allocs/op | -| ------- | ------- | -------- | --------- | -| encoding/json struct | 57749 | 1336 | 29 | -| encoding/json interface{} | 79297 | 10627 | 215 | -| Jeffail/gabs | 83807 | 11202 | 235 | -| bitly/go-simplejson | 88187 | 17187 | 220 | -| antonholmquist/jason | 94099 | 19013 | 247 | -| github.com/ugorji/go/codec | 114719 | 6712 | 152 | -| mreiferson/go-ujson | **56972** | 11547 | 270 | -| a8m/djson | 28525 | 10196 | 198 | -| pquerna/ffjson | **20298** | **856** | **20** | -| mailru/easyjson | **10512** | **336** | **12** | -| buger/jsonparser | **15955** | **0** | **0** | -| buger/jsonparser (EachKey API) | **8916** | **0** | **0** | - -The difference between ffjson and jsonparser in CPU usage is smaller, while the memory consumption difference is growing. On the other hand `easyjson` shows remarkable performance for medium payload. - -`gabs`, `go-simplejson` and `jason` are based on encoding/json and map[string]interface{} and actually only helpers for unstructured JSON, their performance correlate with `encoding/json interface{}`, and they will skip next round. -`go-ujson` while have its own parser, shows same performance as `encoding/json`, also skips next round. Same situation with `ugorji/go/codec`, but it showed unexpectedly bad performance for complex payloads. - - -#### Large payload - -Each test processes a 24kb JSON record (based on Discourse API) -It should read 2 arrays, and for each item in array get a few fields. -Basically it means processing a full JSON file. - -https://github.com/buger/jsonparser/blob/master/benchmark/benchmark_large_payload_test.go - -| Library | time/op | bytes/op | allocs/op | -| --- | --- | --- | --- | -| encoding/json struct | 748336 | 8272 | 307 | -| encoding/json interface{} | 1224271 | 215425 | 3395 | -| a8m/djson | 510082 | 213682 | 2845 | -| pquerna/ffjson | **312271** | **7792** | **298** | -| mailru/easyjson | **154186** | **6992** | **288** | -| buger/jsonparser | **85308** | **0** | **0** | - -`jsonparser` now is a winner, but do not forget that it is way more lightweight parser than `ffson` or `easyjson`, and they have to parser all the data, while `jsonparser` parse only what you need. All `ffjson`, `easysjon` and `jsonparser` have their own parsing code, and does not depend on `encoding/json` or `interface{}`, thats one of the reasons why they are so fast. `easyjson` also use a bit of `unsafe` package to reduce memory consuption (in theory it can lead to some unexpected GC issue, but i did not tested enough) - -Also last benchmark did not included `EachKey` test, because in this particular case we need to read lot of Array values, and using `ArrayEach` is more efficient. - -## Questions and support - -All bug-reports and suggestions should go though Github Issues. - -## Contributing - -1. Fork it -2. Create your feature branch (git checkout -b my-new-feature) -3. Commit your changes (git commit -am 'Added some feature') -4. Push to the branch (git push origin my-new-feature) -5. Create new Pull Request - -## Development - -All my development happens using Docker, and repo include some Make tasks to simplify development. - -* `make build` - builds docker image, usually can be called only once -* `make test` - run tests -* `make fmt` - run go fmt -* `make bench` - run benchmarks (if you need to run only single benchmark modify `BENCHMARK` variable in make file) -* `make profile` - runs benchmark and generate 3 files- `cpu.out`, `mem.mprof` and `benchmark.test` binary, which can be used for `go tool pprof` -* `make bash` - enter container (i use it for running `go tool pprof` above) diff --git a/vendor/github.com/buger/jsonparser/bytes.go b/vendor/github.com/buger/jsonparser/bytes.go deleted file mode 100644 index 0bb0ff39..00000000 --- a/vendor/github.com/buger/jsonparser/bytes.go +++ /dev/null @@ -1,47 +0,0 @@ -package jsonparser - -import ( - bio "bytes" -) - -// minInt64 '-9223372036854775808' is the smallest representable number in int64 -const minInt64 = `9223372036854775808` - -// About 2x faster then strconv.ParseInt because it only supports base 10, which is enough for JSON -func parseInt(bytes []byte) (v int64, ok bool, overflow bool) { - if len(bytes) == 0 { - return 0, false, false - } - - var neg bool = false - if bytes[0] == '-' { - neg = true - bytes = bytes[1:] - } - - var b int64 = 0 - for _, c := range bytes { - if c >= '0' && c <= '9' { - b = (10 * v) + int64(c-'0') - } else { - return 0, false, false - } - if overflow = (b < v); overflow { - break - } - v = b - } - - if overflow { - if neg && bio.Equal(bytes, []byte(minInt64)) { - return b, true, false - } - return 0, false, true - } - - if neg { - return -v, true, false - } else { - return v, true, false - } -} diff --git a/vendor/github.com/buger/jsonparser/bytes_safe.go b/vendor/github.com/buger/jsonparser/bytes_safe.go deleted file mode 100644 index ff16a4a1..00000000 --- a/vendor/github.com/buger/jsonparser/bytes_safe.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build appengine appenginevm - -package jsonparser - -import ( - "strconv" -) - -// See fastbytes_unsafe.go for explanation on why *[]byte is used (signatures must be consistent with those in that file) - -func equalStr(b *[]byte, s string) bool { - return string(*b) == s -} - -func parseFloat(b *[]byte) (float64, error) { - return strconv.ParseFloat(string(*b), 64) -} - -func bytesToString(b *[]byte) string { - return string(*b) -} - -func StringToBytes(s string) []byte { - return []byte(s) -} diff --git a/vendor/github.com/buger/jsonparser/bytes_unsafe.go b/vendor/github.com/buger/jsonparser/bytes_unsafe.go deleted file mode 100644 index d3f523dd..00000000 --- a/vendor/github.com/buger/jsonparser/bytes_unsafe.go +++ /dev/null @@ -1,42 +0,0 @@ -// +build !appengine,!appenginevm - -package jsonparser - -import ( - "reflect" - "strconv" - "unsafe" -) - -// -// The reason for using *[]byte rather than []byte in parameters is an optimization. As of Go 1.6, -// the compiler cannot perfectly inline the function when using a non-pointer slice. That is, -// the non-pointer []byte parameter version is slower than if its function body is manually -// inlined, whereas the pointer []byte version is equally fast to the manually inlined -// version. Instruction count in assembly taken from "go tool compile" confirms this difference. -// -// TODO: Remove hack after Go 1.7 release -// -func equalStr(b *[]byte, s string) bool { - return *(*string)(unsafe.Pointer(b)) == s -} - -func parseFloat(b *[]byte) (float64, error) { - return strconv.ParseFloat(*(*string)(unsafe.Pointer(b)), 64) -} - -// A hack until issue golang/go#2632 is fixed. -// See: https://github.com/golang/go/issues/2632 -func bytesToString(b *[]byte) string { - return *(*string)(unsafe.Pointer(b)) -} - -func StringToBytes(s string) []byte { - sh := (*reflect.StringHeader)(unsafe.Pointer(&s)) - bh := reflect.SliceHeader{ - Data: sh.Data, - Len: sh.Len, - Cap: sh.Len, - } - return *(*[]byte)(unsafe.Pointer(&bh)) -} diff --git a/vendor/github.com/buger/jsonparser/escape.go b/vendor/github.com/buger/jsonparser/escape.go deleted file mode 100644 index 49669b94..00000000 --- a/vendor/github.com/buger/jsonparser/escape.go +++ /dev/null @@ -1,173 +0,0 @@ -package jsonparser - -import ( - "bytes" - "unicode/utf8" -) - -// JSON Unicode stuff: see https://tools.ietf.org/html/rfc7159#section-7 - -const supplementalPlanesOffset = 0x10000 -const highSurrogateOffset = 0xD800 -const lowSurrogateOffset = 0xDC00 - -const basicMultilingualPlaneReservedOffset = 0xDFFF -const basicMultilingualPlaneOffset = 0xFFFF - -func combineUTF16Surrogates(high, low rune) rune { - return supplementalPlanesOffset + (high-highSurrogateOffset)<<10 + (low - lowSurrogateOffset) -} - -const badHex = -1 - -func h2I(c byte) int { - switch { - case c >= '0' && c <= '9': - return int(c - '0') - case c >= 'A' && c <= 'F': - return int(c - 'A' + 10) - case c >= 'a' && c <= 'f': - return int(c - 'a' + 10) - } - return badHex -} - -// decodeSingleUnicodeEscape decodes a single \uXXXX escape sequence. The prefix \u is assumed to be present and -// is not checked. -// In JSON, these escapes can either come alone or as part of "UTF16 surrogate pairs" that must be handled together. -// This function only handles one; decodeUnicodeEscape handles this more complex case. -func decodeSingleUnicodeEscape(in []byte) (rune, bool) { - // We need at least 6 characters total - if len(in) < 6 { - return utf8.RuneError, false - } - - // Convert hex to decimal - h1, h2, h3, h4 := h2I(in[2]), h2I(in[3]), h2I(in[4]), h2I(in[5]) - if h1 == badHex || h2 == badHex || h3 == badHex || h4 == badHex { - return utf8.RuneError, false - } - - // Compose the hex digits - return rune(h1<<12 + h2<<8 + h3<<4 + h4), true -} - -// isUTF16EncodedRune checks if a rune is in the range for non-BMP characters, -// which is used to describe UTF16 chars. -// Source: https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane -func isUTF16EncodedRune(r rune) bool { - return highSurrogateOffset <= r && r <= basicMultilingualPlaneReservedOffset -} - -func decodeUnicodeEscape(in []byte) (rune, int) { - if r, ok := decodeSingleUnicodeEscape(in); !ok { - // Invalid Unicode escape - return utf8.RuneError, -1 - } else if r <= basicMultilingualPlaneOffset && !isUTF16EncodedRune(r) { - // Valid Unicode escape in Basic Multilingual Plane - return r, 6 - } else if r2, ok := decodeSingleUnicodeEscape(in[6:]); !ok { // Note: previous decodeSingleUnicodeEscape success guarantees at least 6 bytes remain - // UTF16 "high surrogate" without manditory valid following Unicode escape for the "low surrogate" - return utf8.RuneError, -1 - } else if r2 < lowSurrogateOffset { - // Invalid UTF16 "low surrogate" - return utf8.RuneError, -1 - } else { - // Valid UTF16 surrogate pair - return combineUTF16Surrogates(r, r2), 12 - } -} - -// backslashCharEscapeTable: when '\X' is found for some byte X, it is to be replaced with backslashCharEscapeTable[X] -var backslashCharEscapeTable = [...]byte{ - '"': '"', - '\\': '\\', - '/': '/', - 'b': '\b', - 'f': '\f', - 'n': '\n', - 'r': '\r', - 't': '\t', -} - -// unescapeToUTF8 unescapes the single escape sequence starting at 'in' into 'out' and returns -// how many characters were consumed from 'in' and emitted into 'out'. -// If a valid escape sequence does not appear as a prefix of 'in', (-1, -1) to signal the error. -func unescapeToUTF8(in, out []byte) (inLen int, outLen int) { - if len(in) < 2 || in[0] != '\\' { - // Invalid escape due to insufficient characters for any escape or no initial backslash - return -1, -1 - } - - // https://tools.ietf.org/html/rfc7159#section-7 - switch e := in[1]; e { - case '"', '\\', '/', 'b', 'f', 'n', 'r', 't': - // Valid basic 2-character escapes (use lookup table) - out[0] = backslashCharEscapeTable[e] - return 2, 1 - case 'u': - // Unicode escape - if r, inLen := decodeUnicodeEscape(in); inLen == -1 { - // Invalid Unicode escape - return -1, -1 - } else { - // Valid Unicode escape; re-encode as UTF8 - outLen := utf8.EncodeRune(out, r) - return inLen, outLen - } - } - - return -1, -1 -} - -// unescape unescapes the string contained in 'in' and returns it as a slice. -// If 'in' contains no escaped characters: -// Returns 'in'. -// Else, if 'out' is of sufficient capacity (guaranteed if cap(out) >= len(in)): -// 'out' is used to build the unescaped string and is returned with no extra allocation -// Else: -// A new slice is allocated and returned. -func Unescape(in, out []byte) ([]byte, error) { - firstBackslash := bytes.IndexByte(in, '\\') - if firstBackslash == -1 { - return in, nil - } - - // Get a buffer of sufficient size (allocate if needed) - if cap(out) < len(in) { - out = make([]byte, len(in)) - } else { - out = out[0:len(in)] - } - - // Copy the first sequence of unescaped bytes to the output and obtain a buffer pointer (subslice) - copy(out, in[:firstBackslash]) - in = in[firstBackslash:] - buf := out[firstBackslash:] - - for len(in) > 0 { - // Unescape the next escaped character - inLen, bufLen := unescapeToUTF8(in, buf) - if inLen == -1 { - return nil, MalformedStringEscapeError - } - - in = in[inLen:] - buf = buf[bufLen:] - - // Copy everything up until the next backslash - nextBackslash := bytes.IndexByte(in, '\\') - if nextBackslash == -1 { - copy(buf, in) - buf = buf[len(in):] - break - } else { - copy(buf, in[:nextBackslash]) - buf = buf[nextBackslash:] - in = in[nextBackslash:] - } - } - - // Trim the out buffer to the amount that was actually emitted - return out[:len(out)-len(buf)], nil -} diff --git a/vendor/github.com/buger/jsonparser/parser.go b/vendor/github.com/buger/jsonparser/parser.go deleted file mode 100644 index 73bb601a..00000000 --- a/vendor/github.com/buger/jsonparser/parser.go +++ /dev/null @@ -1,1211 +0,0 @@ -package jsonparser - -import ( - "bytes" - "errors" - "fmt" - "math" - "strconv" -) - -// Errors -var ( - KeyPathNotFoundError = errors.New("Key path not found") - UnknownValueTypeError = errors.New("Unknown value type") - MalformedJsonError = errors.New("Malformed JSON error") - MalformedStringError = errors.New("Value is string, but can't find closing '\"' symbol") - MalformedArrayError = errors.New("Value is array, but can't find closing ']' symbol") - MalformedObjectError = errors.New("Value looks like object, but can't find closing '}' symbol") - MalformedValueError = errors.New("Value looks like Number/Boolean/None, but can't find its end: ',' or '}' symbol") - OverflowIntegerError = errors.New("Value is number, but overflowed while parsing") - MalformedStringEscapeError = errors.New("Encountered an invalid escape sequence in a string") -) - -// How much stack space to allocate for unescaping JSON strings; if a string longer -// than this needs to be escaped, it will result in a heap allocation -const unescapeStackBufSize = 64 - -func tokenEnd(data []byte) int { - for i, c := range data { - switch c { - case ' ', '\n', '\r', '\t', ',', '}', ']': - return i - } - } - - return len(data) -} - -func findTokenStart(data []byte, token byte) int { - for i := len(data) - 1; i >= 0; i-- { - switch data[i] { - case token: - return i - case '[', '{': - return 0 - } - } - - return 0 -} - -func findKeyStart(data []byte, key string) (int, error) { - i := 0 - ln := len(data) - if ln > 0 && (data[0] == '{' || data[0] == '[') { - i = 1 - } - var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings - - if ku, err := Unescape(StringToBytes(key), stackbuf[:]); err == nil { - key = bytesToString(&ku) - } - - for i < ln { - switch data[i] { - case '"': - i++ - keyBegin := i - - strEnd, keyEscaped := stringEnd(data[i:]) - if strEnd == -1 { - break - } - i += strEnd - keyEnd := i - 1 - - valueOffset := nextToken(data[i:]) - if valueOffset == -1 { - break - } - - i += valueOffset - - // if string is a key, and key level match - k := data[keyBegin:keyEnd] - // for unescape: if there are no escape sequences, this is cheap; if there are, it is a - // bit more expensive, but causes no allocations unless len(key) > unescapeStackBufSize - if keyEscaped { - if ku, err := Unescape(k, stackbuf[:]); err != nil { - break - } else { - k = ku - } - } - - if data[i] == ':' && len(key) == len(k) && bytesToString(&k) == key { - return keyBegin - 1, nil - } - - case '[': - i = blockEnd(data[i:], data[i], ']') + i - case '{': - i = blockEnd(data[i:], data[i], '}') + i - } - i++ - } - - return -1, KeyPathNotFoundError -} - -func tokenStart(data []byte) int { - for i := len(data) - 1; i >= 0; i-- { - switch data[i] { - case '\n', '\r', '\t', ',', '{', '[': - return i - } - } - - return 0 -} - -// Find position of next character which is not whitespace -func nextToken(data []byte) int { - for i, c := range data { - switch c { - case ' ', '\n', '\r', '\t': - continue - default: - return i - } - } - - return -1 -} - -// Find position of last character which is not whitespace -func lastToken(data []byte) int { - for i := len(data) - 1; i >= 0; i-- { - switch data[i] { - case ' ', '\n', '\r', '\t': - continue - default: - return i - } - } - - return -1 -} - -// Tries to find the end of string -// Support if string contains escaped quote symbols. -func stringEnd(data []byte) (int, bool) { - escaped := false - for i, c := range data { - if c == '"' { - if !escaped { - return i + 1, false - } else { - j := i - 1 - for { - if j < 0 || data[j] != '\\' { - return i + 1, true // even number of backslashes - } - j-- - if j < 0 || data[j] != '\\' { - break // odd number of backslashes - } - j-- - - } - } - } else if c == '\\' { - escaped = true - } - } - - return -1, escaped -} - -// Find end of the data structure, array or object. -// For array openSym and closeSym will be '[' and ']', for object '{' and '}' -func blockEnd(data []byte, openSym byte, closeSym byte) int { - level := 0 - i := 0 - ln := len(data) - - for i < ln { - switch data[i] { - case '"': // If inside string, skip it - se, _ := stringEnd(data[i+1:]) - if se == -1 { - return -1 - } - i += se - case openSym: // If open symbol, increase level - level++ - case closeSym: // If close symbol, increase level - level-- - - // If we have returned to the original level, we're done - if level == 0 { - return i + 1 - } - } - i++ - } - - return -1 -} - -func searchKeys(data []byte, keys ...string) int { - keyLevel := 0 - level := 0 - i := 0 - ln := len(data) - lk := len(keys) - lastMatched := true - - if lk == 0 { - return 0 - } - - var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings - - for i < ln { - switch data[i] { - case '"': - i++ - keyBegin := i - - strEnd, keyEscaped := stringEnd(data[i:]) - if strEnd == -1 { - return -1 - } - i += strEnd - keyEnd := i - 1 - - valueOffset := nextToken(data[i:]) - if valueOffset == -1 { - return -1 - } - - i += valueOffset - - // if string is a key - if data[i] == ':' { - if level < 1 { - return -1 - } - - key := data[keyBegin:keyEnd] - - // for unescape: if there are no escape sequences, this is cheap; if there are, it is a - // bit more expensive, but causes no allocations unless len(key) > unescapeStackBufSize - var keyUnesc []byte - if !keyEscaped { - keyUnesc = key - } else if ku, err := Unescape(key, stackbuf[:]); err != nil { - return -1 - } else { - keyUnesc = ku - } - - if equalStr(&keyUnesc, keys[level-1]) { - lastMatched = true - - // if key level match - if keyLevel == level-1 { - keyLevel++ - // If we found all keys in path - if keyLevel == lk { - return i + 1 - } - } - } else { - lastMatched = false - } - } else { - i-- - } - case '{': - - // in case parent key is matched then only we will increase the level otherwise can directly - // can move to the end of this block - if !lastMatched { - end := blockEnd(data[i:], '{', '}') - i += end - 1 - } else { - level++ - } - case '}': - level-- - if level == keyLevel { - keyLevel-- - } - case '[': - // If we want to get array element by index - if keyLevel == level && keys[level][0] == '[' { - aIdx, err := strconv.Atoi(keys[level][1 : len(keys[level])-1]) - if err != nil { - return -1 - } - var curIdx int - var valueFound []byte - var valueOffset int - var curI = i - ArrayEach(data[i:], func(value []byte, dataType ValueType, offset int, err error) { - if curIdx == aIdx { - valueFound = value - valueOffset = offset - if dataType == String { - valueOffset = valueOffset - 2 - valueFound = data[curI+valueOffset : curI+valueOffset+len(value)+2] - } - } - curIdx += 1 - }) - - if valueFound == nil { - return -1 - } else { - subIndex := searchKeys(valueFound, keys[level+1:]...) - if subIndex < 0 { - return -1 - } - return i + valueOffset + subIndex - } - } else { - // Do not search for keys inside arrays - if arraySkip := blockEnd(data[i:], '[', ']'); arraySkip == -1 { - return -1 - } else { - i += arraySkip - 1 - } - } - } - - i++ - } - - return -1 -} - -var bitwiseFlags []int64 - -func init() { - for i := 0; i < 63; i++ { - bitwiseFlags = append(bitwiseFlags, int64(math.Pow(2, float64(i)))) - } -} - -func sameTree(p1, p2 []string) bool { - minLen := len(p1) - if len(p2) < minLen { - minLen = len(p2) - } - - for pi_1, p_1 := range p1[:minLen] { - if p2[pi_1] != p_1 { - return false - } - } - - return true -} - -func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]string) int { - var pathFlags int64 - var level, pathsMatched, i int - ln := len(data) - - var maxPath int - for _, p := range paths { - if len(p) > maxPath { - maxPath = len(p) - } - } - - var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings - pathsBuf := make([]string, maxPath) - - for i < ln { - switch data[i] { - case '"': - i++ - keyBegin := i - - strEnd, keyEscaped := stringEnd(data[i:]) - if strEnd == -1 { - return -1 - } - i += strEnd - - keyEnd := i - 1 - - valueOffset := nextToken(data[i:]) - if valueOffset == -1 { - return -1 - } - - i += valueOffset - - // if string is a key, and key level match - if data[i] == ':' { - match := -1 - key := data[keyBegin:keyEnd] - - // for unescape: if there are no escape sequences, this is cheap; if there are, it is a - // bit more expensive, but causes no allocations unless len(key) > unescapeStackBufSize - var keyUnesc []byte - if !keyEscaped { - keyUnesc = key - } else if ku, err := Unescape(key, stackbuf[:]); err != nil { - return -1 - } else { - keyUnesc = ku - } - - if maxPath >= level { - if level < 1 { - cb(-1, nil, Unknown, MalformedJsonError) - return -1 - } - - pathsBuf[level-1] = bytesToString(&keyUnesc) - for pi, p := range paths { - if len(p) != level || pathFlags&bitwiseFlags[pi+1] != 0 || !equalStr(&keyUnesc, p[level-1]) || !sameTree(p, pathsBuf[:level]) { - continue - } - - match = pi - - i++ - pathsMatched++ - pathFlags |= bitwiseFlags[pi+1] - - v, dt, of, e := Get(data[i:]) - cb(pi, v, dt, e) - - if of != -1 { - i += of - } - - if pathsMatched == len(paths) { - break - } - } - if pathsMatched == len(paths) { - return i - } - } - - if match == -1 { - tokenOffset := nextToken(data[i+1:]) - i += tokenOffset - - if data[i] == '{' { - blockSkip := blockEnd(data[i:], '{', '}') - i += blockSkip + 1 - } - } - - if i < ln { - switch data[i] { - case '{', '}', '[', '"': - i-- - } - } - } else { - i-- - } - case '{': - level++ - case '}': - level-- - case '[': - var arrIdxFlags int64 - var pIdxFlags int64 - - if level < 0 { - cb(-1, nil, Unknown, MalformedJsonError) - return -1 - } - - for pi, p := range paths { - if len(p) < level+1 || pathFlags&bitwiseFlags[pi+1] != 0 || p[level][0] != '[' || !sameTree(p, pathsBuf[:level]) { - continue - } - - aIdx, _ := strconv.Atoi(p[level][1 : len(p[level])-1]) - arrIdxFlags |= bitwiseFlags[aIdx+1] - pIdxFlags |= bitwiseFlags[pi+1] - } - - if arrIdxFlags > 0 { - level++ - - var curIdx int - arrOff, _ := ArrayEach(data[i:], func(value []byte, dataType ValueType, offset int, err error) { - if arrIdxFlags&bitwiseFlags[curIdx+1] != 0 { - for pi, p := range paths { - if pIdxFlags&bitwiseFlags[pi+1] != 0 { - aIdx, _ := strconv.Atoi(p[level-1][1 : len(p[level-1])-1]) - - if curIdx == aIdx { - of := searchKeys(value, p[level:]...) - - pathsMatched++ - pathFlags |= bitwiseFlags[pi+1] - - if of != -1 { - v, dt, _, e := Get(value[of:]) - cb(pi, v, dt, e) - } - } - } - } - } - - curIdx += 1 - }) - - if pathsMatched == len(paths) { - return i - } - - i += arrOff - 1 - } else { - // Do not search for keys inside arrays - if arraySkip := blockEnd(data[i:], '[', ']'); arraySkip == -1 { - return -1 - } else { - i += arraySkip - 1 - } - } - case ']': - level-- - } - - i++ - } - - return -1 -} - -// Data types available in valid JSON data. -type ValueType int - -const ( - NotExist = ValueType(iota) - String - Number - Object - Array - Boolean - Null - Unknown -) - -func (vt ValueType) String() string { - switch vt { - case NotExist: - return "non-existent" - case String: - return "string" - case Number: - return "number" - case Object: - return "object" - case Array: - return "array" - case Boolean: - return "boolean" - case Null: - return "null" - default: - return "unknown" - } -} - -var ( - trueLiteral = []byte("true") - falseLiteral = []byte("false") - nullLiteral = []byte("null") -) - -func createInsertComponent(keys []string, setValue []byte, comma, object bool) []byte { - var buffer bytes.Buffer - isIndex := string(keys[0][0]) == "[" - if comma { - buffer.WriteString(",") - } - if isIndex { - buffer.WriteString("[") - } else { - if object { - buffer.WriteString("{") - } - buffer.WriteString("\"") - buffer.WriteString(keys[0]) - buffer.WriteString("\":") - } - - for i := 1; i < len(keys); i++ { - if string(keys[i][0]) == "[" { - buffer.WriteString("[") - } else { - buffer.WriteString("{\"") - buffer.WriteString(keys[i]) - buffer.WriteString("\":") - } - } - buffer.Write(setValue) - for i := len(keys) - 1; i > 0; i-- { - if string(keys[i][0]) == "[" { - buffer.WriteString("]") - } else { - buffer.WriteString("}") - } - } - if isIndex { - buffer.WriteString("]") - } - if object && !isIndex { - buffer.WriteString("}") - } - return buffer.Bytes() -} - -/* - -Del - Receives existing data structure, path to delete. - -Returns: -`data` - return modified data - -*/ -func Delete(data []byte, keys ...string) []byte { - lk := len(keys) - if lk == 0 { - return data[:0] - } - - array := false - if len(keys[lk-1]) > 0 && string(keys[lk-1][0]) == "[" { - array = true - } - - var startOffset, keyOffset int - endOffset := len(data) - var err error - if !array { - if len(keys) > 1 { - _, _, startOffset, endOffset, err = internalGet(data, keys[:lk-1]...) - if err == KeyPathNotFoundError { - // problem parsing the data - return data - } - } - - keyOffset, err = findKeyStart(data[startOffset:endOffset], keys[lk-1]) - if err == KeyPathNotFoundError { - // problem parsing the data - return data - } - keyOffset += startOffset - _, _, _, subEndOffset, _ := internalGet(data[startOffset:endOffset], keys[lk-1]) - endOffset = startOffset + subEndOffset - tokEnd := tokenEnd(data[endOffset:]) - tokStart := findTokenStart(data[:keyOffset], ","[0]) - - if data[endOffset+tokEnd] == ","[0] { - endOffset += tokEnd + 1 - } else if data[endOffset+tokEnd] == " "[0] && len(data) > endOffset+tokEnd+1 && data[endOffset+tokEnd+1] == ","[0] { - endOffset += tokEnd + 2 - } else if data[endOffset+tokEnd] == "}"[0] && data[tokStart] == ","[0] { - keyOffset = tokStart - } - } else { - _, _, keyOffset, endOffset, err = internalGet(data, keys...) - if err == KeyPathNotFoundError { - // problem parsing the data - return data - } - - tokEnd := tokenEnd(data[endOffset:]) - tokStart := findTokenStart(data[:keyOffset], ","[0]) - - if data[endOffset+tokEnd] == ","[0] { - endOffset += tokEnd + 1 - } else if data[endOffset+tokEnd] == "]"[0] && data[tokStart] == ","[0] { - keyOffset = tokStart - } - } - - // We need to remove remaining trailing comma if we delete las element in the object - prevTok := lastToken(data[:keyOffset]) - remainedValue := data[endOffset:] - - var newOffset int - if nextToken(remainedValue) > -1 && remainedValue[nextToken(remainedValue)] == '}' && data[prevTok] == ',' { - newOffset = prevTok - } else { - newOffset = prevTok + 1 - } - - data = append(data[:newOffset], data[endOffset:]...) - return data -} - -/* - -Set - Receives existing data structure, path to set, and data to set at that key. - -Returns: -`value` - modified byte array -`err` - On any parsing error - -*/ -func Set(data []byte, setValue []byte, keys ...string) (value []byte, err error) { - // ensure keys are set - if len(keys) == 0 { - return nil, KeyPathNotFoundError - } - - _, _, startOffset, endOffset, err := internalGet(data, keys...) - if err != nil { - if err != KeyPathNotFoundError { - // problem parsing the data - return nil, err - } - // full path doesnt exist - // does any subpath exist? - var depth int - for i := range keys { - _, _, start, end, sErr := internalGet(data, keys[:i+1]...) - if sErr != nil { - break - } else { - endOffset = end - startOffset = start - depth++ - } - } - comma := true - object := false - if endOffset == -1 { - firstToken := nextToken(data) - // We can't set a top-level key if data isn't an object - if len(data) == 0 || data[firstToken] != '{' { - return nil, KeyPathNotFoundError - } - // Don't need a comma if the input is an empty object - secondToken := firstToken + 1 + nextToken(data[firstToken+1:]) - if data[secondToken] == '}' { - comma = false - } - // Set the top level key at the end (accounting for any trailing whitespace) - // This assumes last token is valid like '}', could check and return error - endOffset = lastToken(data) - } - depthOffset := endOffset - if depth != 0 { - // if subpath is a non-empty object, add to it - if data[startOffset] == '{' && data[startOffset+1+nextToken(data[startOffset+1:])] != '}' { - depthOffset-- - startOffset = depthOffset - // otherwise, over-write it with a new object - } else { - comma = false - object = true - } - } else { - startOffset = depthOffset - } - value = append(data[:startOffset], append(createInsertComponent(keys[depth:], setValue, comma, object), data[depthOffset:]...)...) - } else { - // path currently exists - startComponent := data[:startOffset] - endComponent := data[endOffset:] - - value = make([]byte, len(startComponent)+len(endComponent)+len(setValue)) - newEndOffset := startOffset + len(setValue) - copy(value[0:startOffset], startComponent) - copy(value[startOffset:newEndOffset], setValue) - copy(value[newEndOffset:], endComponent) - } - return value, nil -} - -func getType(data []byte, offset int) ([]byte, ValueType, int, error) { - var dataType ValueType - endOffset := offset - - // if string value - if data[offset] == '"' { - dataType = String - if idx, _ := stringEnd(data[offset+1:]); idx != -1 { - endOffset += idx + 1 - } else { - return nil, dataType, offset, MalformedStringError - } - } else if data[offset] == '[' { // if array value - dataType = Array - // break label, for stopping nested loops - endOffset = blockEnd(data[offset:], '[', ']') - - if endOffset == -1 { - return nil, dataType, offset, MalformedArrayError - } - - endOffset += offset - } else if data[offset] == '{' { // if object value - dataType = Object - // break label, for stopping nested loops - endOffset = blockEnd(data[offset:], '{', '}') - - if endOffset == -1 { - return nil, dataType, offset, MalformedObjectError - } - - endOffset += offset - } else { - // Number, Boolean or None - end := tokenEnd(data[endOffset:]) - - if end == -1 { - return nil, dataType, offset, MalformedValueError - } - - value := data[offset : endOffset+end] - - switch data[offset] { - case 't', 'f': // true or false - if bytes.Equal(value, trueLiteral) || bytes.Equal(value, falseLiteral) { - dataType = Boolean - } else { - return nil, Unknown, offset, UnknownValueTypeError - } - case 'u', 'n': // undefined or null - if bytes.Equal(value, nullLiteral) { - dataType = Null - } else { - return nil, Unknown, offset, UnknownValueTypeError - } - case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-': - dataType = Number - default: - return nil, Unknown, offset, UnknownValueTypeError - } - - endOffset += end - } - return data[offset:endOffset], dataType, endOffset, nil -} - -/* -Get - Receives data structure, and key path to extract value from. - -Returns: -`value` - Pointer to original data structure containing key value, or just empty slice if nothing found or error -`dataType` - Can be: `NotExist`, `String`, `Number`, `Object`, `Array`, `Boolean` or `Null` -`offset` - Offset from provided data structure where key value ends. Used mostly internally, for example for `ArrayEach` helper. -`err` - If key not found or any other parsing issue it should return error. If key not found it also sets `dataType` to `NotExist` - -Accept multiple keys to specify path to JSON value (in case of quering nested structures). -If no keys provided it will try to extract closest JSON value (simple ones or object/array), useful for reading streams or arrays, see `ArrayEach` implementation. -*/ -func Get(data []byte, keys ...string) (value []byte, dataType ValueType, offset int, err error) { - a, b, _, d, e := internalGet(data, keys...) - return a, b, d, e -} - -func internalGet(data []byte, keys ...string) (value []byte, dataType ValueType, offset, endOffset int, err error) { - if len(keys) > 0 { - if offset = searchKeys(data, keys...); offset == -1 { - return nil, NotExist, -1, -1, KeyPathNotFoundError - } - } - - // Go to closest value - nO := nextToken(data[offset:]) - if nO == -1 { - return nil, NotExist, offset, -1, MalformedJsonError - } - - offset += nO - value, dataType, endOffset, err = getType(data, offset) - if err != nil { - return value, dataType, offset, endOffset, err - } - - // Strip quotes from string values - if dataType == String { - value = value[1 : len(value)-1] - } - - return value, dataType, offset, endOffset, nil -} - -// ArrayEach is used when iterating arrays, accepts a callback function with the same return arguments as `Get`. -func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int, err error), keys ...string) (offset int, err error) { - if len(data) == 0 { - return -1, MalformedObjectError - } - - offset = 1 - - if len(keys) > 0 { - if offset = searchKeys(data, keys...); offset == -1 { - return offset, KeyPathNotFoundError - } - - // Go to closest value - nO := nextToken(data[offset:]) - if nO == -1 { - return offset, MalformedJsonError - } - - offset += nO - - if data[offset] != '[' { - return offset, MalformedArrayError - } - - offset++ - } - - nO := nextToken(data[offset:]) - if nO == -1 { - return offset, MalformedJsonError - } - - offset += nO - - if data[offset] == ']' { - return offset, nil - } - - for true { - v, t, o, e := Get(data[offset:]) - - if e != nil { - return offset, e - } - - if o == 0 { - break - } - - if t != NotExist { - cb(v, t, offset+o-len(v), e) - } - - if e != nil { - break - } - - offset += o - - skipToToken := nextToken(data[offset:]) - if skipToToken == -1 { - return offset, MalformedArrayError - } - offset += skipToToken - - if data[offset] == ']' { - break - } - - if data[offset] != ',' { - return offset, MalformedArrayError - } - - offset++ - } - - return offset, nil -} - -// ObjectEach iterates over the key-value pairs of a JSON object, invoking a given callback for each such entry -func ObjectEach(data []byte, callback func(key []byte, value []byte, dataType ValueType, offset int) error, keys ...string) (err error) { - var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings - offset := 0 - - // Descend to the desired key, if requested - if len(keys) > 0 { - if off := searchKeys(data, keys...); off == -1 { - return KeyPathNotFoundError - } else { - offset = off - } - } - - // Validate and skip past opening brace - if off := nextToken(data[offset:]); off == -1 { - return MalformedObjectError - } else if offset += off; data[offset] != '{' { - return MalformedObjectError - } else { - offset++ - } - - // Skip to the first token inside the object, or stop if we find the ending brace - if off := nextToken(data[offset:]); off == -1 { - return MalformedJsonError - } else if offset += off; data[offset] == '}' { - return nil - } - - // Loop pre-condition: data[offset] points to what should be either the next entry's key, or the closing brace (if it's anything else, the JSON is malformed) - for offset < len(data) { - // Step 1: find the next key - var key []byte - - // Check what the the next token is: start of string, end of object, or something else (error) - switch data[offset] { - case '"': - offset++ // accept as string and skip opening quote - case '}': - return nil // we found the end of the object; stop and return success - default: - return MalformedObjectError - } - - // Find the end of the key string - var keyEscaped bool - if off, esc := stringEnd(data[offset:]); off == -1 { - return MalformedJsonError - } else { - key, keyEscaped = data[offset:offset+off-1], esc - offset += off - } - - // Unescape the string if needed - if keyEscaped { - if keyUnescaped, err := Unescape(key, stackbuf[:]); err != nil { - return MalformedStringEscapeError - } else { - key = keyUnescaped - } - } - - // Step 2: skip the colon - if off := nextToken(data[offset:]); off == -1 { - return MalformedJsonError - } else if offset += off; data[offset] != ':' { - return MalformedJsonError - } else { - offset++ - } - - // Step 3: find the associated value, then invoke the callback - if value, valueType, off, err := Get(data[offset:]); err != nil { - return err - } else if err := callback(key, value, valueType, offset+off); err != nil { // Invoke the callback here! - return err - } else { - offset += off - } - - // Step 4: skip over the next comma to the following token, or stop if we hit the ending brace - if off := nextToken(data[offset:]); off == -1 { - return MalformedArrayError - } else { - offset += off - switch data[offset] { - case '}': - return nil // Stop if we hit the close brace - case ',': - offset++ // Ignore the comma - default: - return MalformedObjectError - } - } - - // Skip to the next token after the comma - if off := nextToken(data[offset:]); off == -1 { - return MalformedArrayError - } else { - offset += off - } - } - - return MalformedObjectError // we shouldn't get here; it's expected that we will return via finding the ending brace -} - -// GetUnsafeString returns the value retrieved by `Get`, use creates string without memory allocation by mapping string to slice memory. It does not handle escape symbols. -func GetUnsafeString(data []byte, keys ...string) (val string, err error) { - v, _, _, e := Get(data, keys...) - - if e != nil { - return "", e - } - - return bytesToString(&v), nil -} - -// GetString returns the value retrieved by `Get`, cast to a string if possible, trying to properly handle escape and utf8 symbols -// If key data type do not match, it will return an error. -func GetString(data []byte, keys ...string) (val string, err error) { - v, t, _, e := Get(data, keys...) - - if e != nil { - return "", e - } - - if t != String { - return "", fmt.Errorf("Value is not a string: %s", string(v)) - } - - // If no escapes return raw conten - if bytes.IndexByte(v, '\\') == -1 { - return string(v), nil - } - - return ParseString(v) -} - -// GetFloat returns the value retrieved by `Get`, cast to a float64 if possible. -// The offset is the same as in `Get`. -// If key data type do not match, it will return an error. -func GetFloat(data []byte, keys ...string) (val float64, err error) { - v, t, _, e := Get(data, keys...) - - if e != nil { - return 0, e - } - - if t != Number { - return 0, fmt.Errorf("Value is not a number: %s", string(v)) - } - - return ParseFloat(v) -} - -// GetInt returns the value retrieved by `Get`, cast to a int64 if possible. -// If key data type do not match, it will return an error. -func GetInt(data []byte, keys ...string) (val int64, err error) { - v, t, _, e := Get(data, keys...) - - if e != nil { - return 0, e - } - - if t != Number { - return 0, fmt.Errorf("Value is not a number: %s", string(v)) - } - - return ParseInt(v) -} - -// GetBoolean returns the value retrieved by `Get`, cast to a bool if possible. -// The offset is the same as in `Get`. -// If key data type do not match, it will return error. -func GetBoolean(data []byte, keys ...string) (val bool, err error) { - v, t, _, e := Get(data, keys...) - - if e != nil { - return false, e - } - - if t != Boolean { - return false, fmt.Errorf("Value is not a boolean: %s", string(v)) - } - - return ParseBoolean(v) -} - -// ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness) -func ParseBoolean(b []byte) (bool, error) { - switch { - case bytes.Equal(b, trueLiteral): - return true, nil - case bytes.Equal(b, falseLiteral): - return false, nil - default: - return false, MalformedValueError - } -} - -// ParseString parses a String ValueType into a Go string (the main parsing work is unescaping the JSON string) -func ParseString(b []byte) (string, error) { - var stackbuf [unescapeStackBufSize]byte // stack-allocated array for allocation-free unescaping of small strings - if bU, err := Unescape(b, stackbuf[:]); err != nil { - return "", MalformedValueError - } else { - return string(bU), nil - } -} - -// ParseNumber parses a Number ValueType into a Go float64 -func ParseFloat(b []byte) (float64, error) { - if v, err := parseFloat(&b); err != nil { - return 0, MalformedValueError - } else { - return v, nil - } -} - -// ParseInt parses a Number ValueType into a Go int64 -func ParseInt(b []byte) (int64, error) { - if v, ok, overflow := parseInt(b); !ok { - if overflow { - return 0, OverflowIntegerError - } - return 0, MalformedValueError - } else { - return v, nil - } -} diff --git a/vendor/github.com/davecgh/go-spew/LICENSE b/vendor/github.com/davecgh/go-spew/LICENSE deleted file mode 100644 index bc52e96f..00000000 --- a/vendor/github.com/davecgh/go-spew/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -ISC License - -Copyright (c) 2012-2016 Dave Collins - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/vendor/github.com/davecgh/go-spew/spew/bypass.go b/vendor/github.com/davecgh/go-spew/spew/bypass.go deleted file mode 100644 index 79299478..00000000 --- a/vendor/github.com/davecgh/go-spew/spew/bypass.go +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (c) 2015-2016 Dave Collins -// -// Permission to use, copy, modify, and distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -// NOTE: Due to the following build constraints, this file will only be compiled -// when the code is not running on Google App Engine, compiled by GopherJS, and -// "-tags safe" is not added to the go build command line. The "disableunsafe" -// tag is deprecated and thus should not be used. -// Go versions prior to 1.4 are disabled because they use a different layout -// for interfaces which make the implementation of unsafeReflectValue more complex. -// +build !js,!appengine,!safe,!disableunsafe,go1.4 - -package spew - -import ( - "reflect" - "unsafe" -) - -const ( - // UnsafeDisabled is a build-time constant which specifies whether or - // not access to the unsafe package is available. - UnsafeDisabled = false - - // ptrSize is the size of a pointer on the current arch. - ptrSize = unsafe.Sizeof((*byte)(nil)) -) - -type flag uintptr - -var ( - // flagRO indicates whether the value field of a reflect.Value - // is read-only. - flagRO flag - - // flagAddr indicates whether the address of the reflect.Value's - // value may be taken. - flagAddr flag -) - -// flagKindMask holds the bits that make up the kind -// part of the flags field. In all the supported versions, -// it is in the lower 5 bits. -const flagKindMask = flag(0x1f) - -// Different versions of Go have used different -// bit layouts for the flags type. This table -// records the known combinations. -var okFlags = []struct { - ro, addr flag -}{{ - // From Go 1.4 to 1.5 - ro: 1 << 5, - addr: 1 << 7, -}, { - // Up to Go tip. - ro: 1<<5 | 1<<6, - addr: 1 << 8, -}} - -var flagValOffset = func() uintptr { - field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") - if !ok { - panic("reflect.Value has no flag field") - } - return field.Offset -}() - -// flagField returns a pointer to the flag field of a reflect.Value. -func flagField(v *reflect.Value) *flag { - return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset)) -} - -// unsafeReflectValue converts the passed reflect.Value into a one that bypasses -// the typical safety restrictions preventing access to unaddressable and -// unexported data. It works by digging the raw pointer to the underlying -// value out of the protected value and generating a new unprotected (unsafe) -// reflect.Value to it. -// -// This allows us to check for implementations of the Stringer and error -// interfaces to be used for pretty printing ordinarily unaddressable and -// inaccessible values such as unexported struct fields. -func unsafeReflectValue(v reflect.Value) reflect.Value { - if !v.IsValid() || (v.CanInterface() && v.CanAddr()) { - return v - } - flagFieldPtr := flagField(&v) - *flagFieldPtr &^= flagRO - *flagFieldPtr |= flagAddr - return v -} - -// Sanity checks against future reflect package changes -// to the type or semantics of the Value.flag field. -func init() { - field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") - if !ok { - panic("reflect.Value has no flag field") - } - if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() { - panic("reflect.Value flag field has changed kind") - } - type t0 int - var t struct { - A t0 - // t0 will have flagEmbedRO set. - t0 - // a will have flagStickyRO set - a t0 - } - vA := reflect.ValueOf(t).FieldByName("A") - va := reflect.ValueOf(t).FieldByName("a") - vt0 := reflect.ValueOf(t).FieldByName("t0") - - // Infer flagRO from the difference between the flags - // for the (otherwise identical) fields in t. - flagPublic := *flagField(&vA) - flagWithRO := *flagField(&va) | *flagField(&vt0) - flagRO = flagPublic ^ flagWithRO - - // Infer flagAddr from the difference between a value - // taken from a pointer and not. - vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A") - flagNoPtr := *flagField(&vA) - flagPtr := *flagField(&vPtrA) - flagAddr = flagNoPtr ^ flagPtr - - // Check that the inferred flags tally with one of the known versions. - for _, f := range okFlags { - if flagRO == f.ro && flagAddr == f.addr { - return - } - } - panic("reflect.Value read-only flag has changed semantics") -} diff --git a/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go b/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go deleted file mode 100644 index 205c28d6..00000000 --- a/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2015-2016 Dave Collins -// -// Permission to use, copy, modify, and distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -// NOTE: Due to the following build constraints, this file will only be compiled -// when the code is running on Google App Engine, compiled by GopherJS, or -// "-tags safe" is added to the go build command line. The "disableunsafe" -// tag is deprecated and thus should not be used. -// +build js appengine safe disableunsafe !go1.4 - -package spew - -import "reflect" - -const ( - // UnsafeDisabled is a build-time constant which specifies whether or - // not access to the unsafe package is available. - UnsafeDisabled = true -) - -// unsafeReflectValue typically converts the passed reflect.Value into a one -// that bypasses the typical safety restrictions preventing access to -// unaddressable and unexported data. However, doing this relies on access to -// the unsafe package. This is a stub version which simply returns the passed -// reflect.Value when the unsafe package is not available. -func unsafeReflectValue(v reflect.Value) reflect.Value { - return v -} diff --git a/vendor/github.com/davecgh/go-spew/spew/common.go b/vendor/github.com/davecgh/go-spew/spew/common.go deleted file mode 100644 index 1be8ce94..00000000 --- a/vendor/github.com/davecgh/go-spew/spew/common.go +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "bytes" - "fmt" - "io" - "reflect" - "sort" - "strconv" -) - -// Some constants in the form of bytes to avoid string overhead. This mirrors -// the technique used in the fmt package. -var ( - panicBytes = []byte("(PANIC=") - plusBytes = []byte("+") - iBytes = []byte("i") - trueBytes = []byte("true") - falseBytes = []byte("false") - interfaceBytes = []byte("(interface {})") - commaNewlineBytes = []byte(",\n") - newlineBytes = []byte("\n") - openBraceBytes = []byte("{") - openBraceNewlineBytes = []byte("{\n") - closeBraceBytes = []byte("}") - asteriskBytes = []byte("*") - colonBytes = []byte(":") - colonSpaceBytes = []byte(": ") - openParenBytes = []byte("(") - closeParenBytes = []byte(")") - spaceBytes = []byte(" ") - pointerChainBytes = []byte("->") - nilAngleBytes = []byte("") - maxNewlineBytes = []byte("\n") - maxShortBytes = []byte("") - circularBytes = []byte("") - circularShortBytes = []byte("") - invalidAngleBytes = []byte("") - openBracketBytes = []byte("[") - closeBracketBytes = []byte("]") - percentBytes = []byte("%") - precisionBytes = []byte(".") - openAngleBytes = []byte("<") - closeAngleBytes = []byte(">") - openMapBytes = []byte("map[") - closeMapBytes = []byte("]") - lenEqualsBytes = []byte("len=") - capEqualsBytes = []byte("cap=") -) - -// hexDigits is used to map a decimal value to a hex digit. -var hexDigits = "0123456789abcdef" - -// catchPanic handles any panics that might occur during the handleMethods -// calls. -func catchPanic(w io.Writer, v reflect.Value) { - if err := recover(); err != nil { - w.Write(panicBytes) - fmt.Fprintf(w, "%v", err) - w.Write(closeParenBytes) - } -} - -// handleMethods attempts to call the Error and String methods on the underlying -// type the passed reflect.Value represents and outputes the result to Writer w. -// -// It handles panics in any called methods by catching and displaying the error -// as the formatted value. -func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) { - // We need an interface to check if the type implements the error or - // Stringer interface. However, the reflect package won't give us an - // interface on certain things like unexported struct fields in order - // to enforce visibility rules. We use unsafe, when it's available, - // to bypass these restrictions since this package does not mutate the - // values. - if !v.CanInterface() { - if UnsafeDisabled { - return false - } - - v = unsafeReflectValue(v) - } - - // Choose whether or not to do error and Stringer interface lookups against - // the base type or a pointer to the base type depending on settings. - // Technically calling one of these methods with a pointer receiver can - // mutate the value, however, types which choose to satisify an error or - // Stringer interface with a pointer receiver should not be mutating their - // state inside these interface methods. - if !cs.DisablePointerMethods && !UnsafeDisabled && !v.CanAddr() { - v = unsafeReflectValue(v) - } - if v.CanAddr() { - v = v.Addr() - } - - // Is it an error or Stringer? - switch iface := v.Interface().(type) { - case error: - defer catchPanic(w, v) - if cs.ContinueOnMethod { - w.Write(openParenBytes) - w.Write([]byte(iface.Error())) - w.Write(closeParenBytes) - w.Write(spaceBytes) - return false - } - - w.Write([]byte(iface.Error())) - return true - - case fmt.Stringer: - defer catchPanic(w, v) - if cs.ContinueOnMethod { - w.Write(openParenBytes) - w.Write([]byte(iface.String())) - w.Write(closeParenBytes) - w.Write(spaceBytes) - return false - } - w.Write([]byte(iface.String())) - return true - } - return false -} - -// printBool outputs a boolean value as true or false to Writer w. -func printBool(w io.Writer, val bool) { - if val { - w.Write(trueBytes) - } else { - w.Write(falseBytes) - } -} - -// printInt outputs a signed integer value to Writer w. -func printInt(w io.Writer, val int64, base int) { - w.Write([]byte(strconv.FormatInt(val, base))) -} - -// printUint outputs an unsigned integer value to Writer w. -func printUint(w io.Writer, val uint64, base int) { - w.Write([]byte(strconv.FormatUint(val, base))) -} - -// printFloat outputs a floating point value using the specified precision, -// which is expected to be 32 or 64bit, to Writer w. -func printFloat(w io.Writer, val float64, precision int) { - w.Write([]byte(strconv.FormatFloat(val, 'g', -1, precision))) -} - -// printComplex outputs a complex value using the specified float precision -// for the real and imaginary parts to Writer w. -func printComplex(w io.Writer, c complex128, floatPrecision int) { - r := real(c) - w.Write(openParenBytes) - w.Write([]byte(strconv.FormatFloat(r, 'g', -1, floatPrecision))) - i := imag(c) - if i >= 0 { - w.Write(plusBytes) - } - w.Write([]byte(strconv.FormatFloat(i, 'g', -1, floatPrecision))) - w.Write(iBytes) - w.Write(closeParenBytes) -} - -// printHexPtr outputs a uintptr formatted as hexadecimal with a leading '0x' -// prefix to Writer w. -func printHexPtr(w io.Writer, p uintptr) { - // Null pointer. - num := uint64(p) - if num == 0 { - w.Write(nilAngleBytes) - return - } - - // Max uint64 is 16 bytes in hex + 2 bytes for '0x' prefix - buf := make([]byte, 18) - - // It's simpler to construct the hex string right to left. - base := uint64(16) - i := len(buf) - 1 - for num >= base { - buf[i] = hexDigits[num%base] - num /= base - i-- - } - buf[i] = hexDigits[num] - - // Add '0x' prefix. - i-- - buf[i] = 'x' - i-- - buf[i] = '0' - - // Strip unused leading bytes. - buf = buf[i:] - w.Write(buf) -} - -// valuesSorter implements sort.Interface to allow a slice of reflect.Value -// elements to be sorted. -type valuesSorter struct { - values []reflect.Value - strings []string // either nil or same len and values - cs *ConfigState -} - -// newValuesSorter initializes a valuesSorter instance, which holds a set of -// surrogate keys on which the data should be sorted. It uses flags in -// ConfigState to decide if and how to populate those surrogate keys. -func newValuesSorter(values []reflect.Value, cs *ConfigState) sort.Interface { - vs := &valuesSorter{values: values, cs: cs} - if canSortSimply(vs.values[0].Kind()) { - return vs - } - if !cs.DisableMethods { - vs.strings = make([]string, len(values)) - for i := range vs.values { - b := bytes.Buffer{} - if !handleMethods(cs, &b, vs.values[i]) { - vs.strings = nil - break - } - vs.strings[i] = b.String() - } - } - if vs.strings == nil && cs.SpewKeys { - vs.strings = make([]string, len(values)) - for i := range vs.values { - vs.strings[i] = Sprintf("%#v", vs.values[i].Interface()) - } - } - return vs -} - -// canSortSimply tests whether a reflect.Kind is a primitive that can be sorted -// directly, or whether it should be considered for sorting by surrogate keys -// (if the ConfigState allows it). -func canSortSimply(kind reflect.Kind) bool { - // This switch parallels valueSortLess, except for the default case. - switch kind { - case reflect.Bool: - return true - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - return true - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: - return true - case reflect.Float32, reflect.Float64: - return true - case reflect.String: - return true - case reflect.Uintptr: - return true - case reflect.Array: - return true - } - return false -} - -// Len returns the number of values in the slice. It is part of the -// sort.Interface implementation. -func (s *valuesSorter) Len() int { - return len(s.values) -} - -// Swap swaps the values at the passed indices. It is part of the -// sort.Interface implementation. -func (s *valuesSorter) Swap(i, j int) { - s.values[i], s.values[j] = s.values[j], s.values[i] - if s.strings != nil { - s.strings[i], s.strings[j] = s.strings[j], s.strings[i] - } -} - -// valueSortLess returns whether the first value should sort before the second -// value. It is used by valueSorter.Less as part of the sort.Interface -// implementation. -func valueSortLess(a, b reflect.Value) bool { - switch a.Kind() { - case reflect.Bool: - return !a.Bool() && b.Bool() - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - return a.Int() < b.Int() - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: - return a.Uint() < b.Uint() - case reflect.Float32, reflect.Float64: - return a.Float() < b.Float() - case reflect.String: - return a.String() < b.String() - case reflect.Uintptr: - return a.Uint() < b.Uint() - case reflect.Array: - // Compare the contents of both arrays. - l := a.Len() - for i := 0; i < l; i++ { - av := a.Index(i) - bv := b.Index(i) - if av.Interface() == bv.Interface() { - continue - } - return valueSortLess(av, bv) - } - } - return a.String() < b.String() -} - -// Less returns whether the value at index i should sort before the -// value at index j. It is part of the sort.Interface implementation. -func (s *valuesSorter) Less(i, j int) bool { - if s.strings == nil { - return valueSortLess(s.values[i], s.values[j]) - } - return s.strings[i] < s.strings[j] -} - -// sortValues is a sort function that handles both native types and any type that -// can be converted to error or Stringer. Other inputs are sorted according to -// their Value.String() value to ensure display stability. -func sortValues(values []reflect.Value, cs *ConfigState) { - if len(values) == 0 { - return - } - sort.Sort(newValuesSorter(values, cs)) -} diff --git a/vendor/github.com/davecgh/go-spew/spew/config.go b/vendor/github.com/davecgh/go-spew/spew/config.go deleted file mode 100644 index 2e3d22f3..00000000 --- a/vendor/github.com/davecgh/go-spew/spew/config.go +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "bytes" - "fmt" - "io" - "os" -) - -// ConfigState houses the configuration options used by spew to format and -// display values. There is a global instance, Config, that is used to control -// all top-level Formatter and Dump functionality. Each ConfigState instance -// provides methods equivalent to the top-level functions. -// -// The zero value for ConfigState provides no indentation. You would typically -// want to set it to a space or a tab. -// -// Alternatively, you can use NewDefaultConfig to get a ConfigState instance -// with default settings. See the documentation of NewDefaultConfig for default -// values. -type ConfigState struct { - // Indent specifies the string to use for each indentation level. The - // global config instance that all top-level functions use set this to a - // single space by default. If you would like more indentation, you might - // set this to a tab with "\t" or perhaps two spaces with " ". - Indent string - - // MaxDepth controls the maximum number of levels to descend into nested - // data structures. The default, 0, means there is no limit. - // - // NOTE: Circular data structures are properly detected, so it is not - // necessary to set this value unless you specifically want to limit deeply - // nested data structures. - MaxDepth int - - // DisableMethods specifies whether or not error and Stringer interfaces are - // invoked for types that implement them. - DisableMethods bool - - // DisablePointerMethods specifies whether or not to check for and invoke - // error and Stringer interfaces on types which only accept a pointer - // receiver when the current type is not a pointer. - // - // NOTE: This might be an unsafe action since calling one of these methods - // with a pointer receiver could technically mutate the value, however, - // in practice, types which choose to satisify an error or Stringer - // interface with a pointer receiver should not be mutating their state - // inside these interface methods. As a result, this option relies on - // access to the unsafe package, so it will not have any effect when - // running in environments without access to the unsafe package such as - // Google App Engine or with the "safe" build tag specified. - DisablePointerMethods bool - - // DisablePointerAddresses specifies whether to disable the printing of - // pointer addresses. This is useful when diffing data structures in tests. - DisablePointerAddresses bool - - // DisableCapacities specifies whether to disable the printing of capacities - // for arrays, slices, maps and channels. This is useful when diffing - // data structures in tests. - DisableCapacities bool - - // ContinueOnMethod specifies whether or not recursion should continue once - // a custom error or Stringer interface is invoked. The default, false, - // means it will print the results of invoking the custom error or Stringer - // interface and return immediately instead of continuing to recurse into - // the internals of the data type. - // - // NOTE: This flag does not have any effect if method invocation is disabled - // via the DisableMethods or DisablePointerMethods options. - ContinueOnMethod bool - - // SortKeys specifies map keys should be sorted before being printed. Use - // this to have a more deterministic, diffable output. Note that only - // native types (bool, int, uint, floats, uintptr and string) and types - // that support the error or Stringer interfaces (if methods are - // enabled) are supported, with other types sorted according to the - // reflect.Value.String() output which guarantees display stability. - SortKeys bool - - // SpewKeys specifies that, as a last resort attempt, map keys should - // be spewed to strings and sorted by those strings. This is only - // considered if SortKeys is true. - SpewKeys bool -} - -// Config is the active configuration of the top-level functions. -// The configuration can be changed by modifying the contents of spew.Config. -var Config = ConfigState{Indent: " "} - -// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the formatted string as a value that satisfies error. See NewFormatter -// for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Errorf(format, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Errorf(format string, a ...interface{}) (err error) { - return fmt.Errorf(format, c.convertArgs(a)...) -} - -// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprint(w, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Fprint(w io.Writer, a ...interface{}) (n int, err error) { - return fmt.Fprint(w, c.convertArgs(a)...) -} - -// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprintf(w, format, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { - return fmt.Fprintf(w, format, c.convertArgs(a)...) -} - -// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it -// passed with a Formatter interface returned by c.NewFormatter. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprintln(w, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Fprintln(w io.Writer, a ...interface{}) (n int, err error) { - return fmt.Fprintln(w, c.convertArgs(a)...) -} - -// Print is a wrapper for fmt.Print that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Print(c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Print(a ...interface{}) (n int, err error) { - return fmt.Print(c.convertArgs(a)...) -} - -// Printf is a wrapper for fmt.Printf that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Printf(format, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Printf(format string, a ...interface{}) (n int, err error) { - return fmt.Printf(format, c.convertArgs(a)...) -} - -// Println is a wrapper for fmt.Println that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Println(c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Println(a ...interface{}) (n int, err error) { - return fmt.Println(c.convertArgs(a)...) -} - -// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprint(c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Sprint(a ...interface{}) string { - return fmt.Sprint(c.convertArgs(a)...) -} - -// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprintf(format, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Sprintf(format string, a ...interface{}) string { - return fmt.Sprintf(format, c.convertArgs(a)...) -} - -// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it -// were passed with a Formatter interface returned by c.NewFormatter. It -// returns the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprintln(c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Sprintln(a ...interface{}) string { - return fmt.Sprintln(c.convertArgs(a)...) -} - -/* -NewFormatter returns a custom formatter that satisfies the fmt.Formatter -interface. As a result, it integrates cleanly with standard fmt package -printing functions. The formatter is useful for inline printing of smaller data -types similar to the standard %v format specifier. - -The custom formatter only responds to the %v (most compact), %+v (adds pointer -addresses), %#v (adds types), and %#+v (adds types and pointer addresses) verb -combinations. Any other verbs such as %x and %q will be sent to the the -standard fmt package for formatting. In addition, the custom formatter ignores -the width and precision arguments (however they will still work on the format -specifiers not handled by the custom formatter). - -Typically this function shouldn't be called directly. It is much easier to make -use of the custom formatter by calling one of the convenience functions such as -c.Printf, c.Println, or c.Printf. -*/ -func (c *ConfigState) NewFormatter(v interface{}) fmt.Formatter { - return newFormatter(c, v) -} - -// Fdump formats and displays the passed arguments to io.Writer w. It formats -// exactly the same as Dump. -func (c *ConfigState) Fdump(w io.Writer, a ...interface{}) { - fdump(c, w, a...) -} - -/* -Dump displays the passed parameters to standard out with newlines, customizable -indentation, and additional debug information such as complete types and all -pointer addresses used to indirect to the final value. It provides the -following features over the built-in printing facilities provided by the fmt -package: - - * Pointers are dereferenced and followed - * Circular data structures are detected and handled properly - * Custom Stringer/error interfaces are optionally invoked, including - on unexported types - * Custom types which only implement the Stringer/error interfaces via - a pointer receiver are optionally invoked when passing non-pointer - variables - * Byte arrays and slices are dumped like the hexdump -C command which - includes offsets, byte values in hex, and ASCII output - -The configuration options are controlled by modifying the public members -of c. See ConfigState for options documentation. - -See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to -get the formatted result as a string. -*/ -func (c *ConfigState) Dump(a ...interface{}) { - fdump(c, os.Stdout, a...) -} - -// Sdump returns a string with the passed arguments formatted exactly the same -// as Dump. -func (c *ConfigState) Sdump(a ...interface{}) string { - var buf bytes.Buffer - fdump(c, &buf, a...) - return buf.String() -} - -// convertArgs accepts a slice of arguments and returns a slice of the same -// length with each argument converted to a spew Formatter interface using -// the ConfigState associated with s. -func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{}) { - formatters = make([]interface{}, len(args)) - for index, arg := range args { - formatters[index] = newFormatter(c, arg) - } - return formatters -} - -// NewDefaultConfig returns a ConfigState with the following default settings. -// -// Indent: " " -// MaxDepth: 0 -// DisableMethods: false -// DisablePointerMethods: false -// ContinueOnMethod: false -// SortKeys: false -func NewDefaultConfig() *ConfigState { - return &ConfigState{Indent: " "} -} diff --git a/vendor/github.com/davecgh/go-spew/spew/doc.go b/vendor/github.com/davecgh/go-spew/spew/doc.go deleted file mode 100644 index aacaac6f..00000000 --- a/vendor/github.com/davecgh/go-spew/spew/doc.go +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* -Package spew implements a deep pretty printer for Go data structures to aid in -debugging. - -A quick overview of the additional features spew provides over the built-in -printing facilities for Go data types are as follows: - - * Pointers are dereferenced and followed - * Circular data structures are detected and handled properly - * Custom Stringer/error interfaces are optionally invoked, including - on unexported types - * Custom types which only implement the Stringer/error interfaces via - a pointer receiver are optionally invoked when passing non-pointer - variables - * Byte arrays and slices are dumped like the hexdump -C command which - includes offsets, byte values in hex, and ASCII output (only when using - Dump style) - -There are two different approaches spew allows for dumping Go data structures: - - * Dump style which prints with newlines, customizable indentation, - and additional debug information such as types and all pointer addresses - used to indirect to the final value - * A custom Formatter interface that integrates cleanly with the standard fmt - package and replaces %v, %+v, %#v, and %#+v to provide inline printing - similar to the default %v while providing the additional functionality - outlined above and passing unsupported format verbs such as %x and %q - along to fmt - -Quick Start - -This section demonstrates how to quickly get started with spew. See the -sections below for further details on formatting and configuration options. - -To dump a variable with full newlines, indentation, type, and pointer -information use Dump, Fdump, or Sdump: - spew.Dump(myVar1, myVar2, ...) - spew.Fdump(someWriter, myVar1, myVar2, ...) - str := spew.Sdump(myVar1, myVar2, ...) - -Alternatively, if you would prefer to use format strings with a compacted inline -printing style, use the convenience wrappers Printf, Fprintf, etc with -%v (most compact), %+v (adds pointer addresses), %#v (adds types), or -%#+v (adds types and pointer addresses): - spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) - spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) - spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) - spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) - -Configuration Options - -Configuration of spew is handled by fields in the ConfigState type. For -convenience, all of the top-level functions use a global state available -via the spew.Config global. - -It is also possible to create a ConfigState instance that provides methods -equivalent to the top-level functions. This allows concurrent configuration -options. See the ConfigState documentation for more details. - -The following configuration options are available: - * Indent - String to use for each indentation level for Dump functions. - It is a single space by default. A popular alternative is "\t". - - * MaxDepth - Maximum number of levels to descend into nested data structures. - There is no limit by default. - - * DisableMethods - Disables invocation of error and Stringer interface methods. - Method invocation is enabled by default. - - * DisablePointerMethods - Disables invocation of error and Stringer interface methods on types - which only accept pointer receivers from non-pointer variables. - Pointer method invocation is enabled by default. - - * DisablePointerAddresses - DisablePointerAddresses specifies whether to disable the printing of - pointer addresses. This is useful when diffing data structures in tests. - - * DisableCapacities - DisableCapacities specifies whether to disable the printing of - capacities for arrays, slices, maps and channels. This is useful when - diffing data structures in tests. - - * ContinueOnMethod - Enables recursion into types after invoking error and Stringer interface - methods. Recursion after method invocation is disabled by default. - - * SortKeys - Specifies map keys should be sorted before being printed. Use - this to have a more deterministic, diffable output. Note that - only native types (bool, int, uint, floats, uintptr and string) - and types which implement error or Stringer interfaces are - supported with other types sorted according to the - reflect.Value.String() output which guarantees display - stability. Natural map order is used by default. - - * SpewKeys - Specifies that, as a last resort attempt, map keys should be - spewed to strings and sorted by those strings. This is only - considered if SortKeys is true. - -Dump Usage - -Simply call spew.Dump with a list of variables you want to dump: - - spew.Dump(myVar1, myVar2, ...) - -You may also call spew.Fdump if you would prefer to output to an arbitrary -io.Writer. For example, to dump to standard error: - - spew.Fdump(os.Stderr, myVar1, myVar2, ...) - -A third option is to call spew.Sdump to get the formatted output as a string: - - str := spew.Sdump(myVar1, myVar2, ...) - -Sample Dump Output - -See the Dump example for details on the setup of the types and variables being -shown here. - - (main.Foo) { - unexportedField: (*main.Bar)(0xf84002e210)({ - flag: (main.Flag) flagTwo, - data: (uintptr) - }), - ExportedField: (map[interface {}]interface {}) (len=1) { - (string) (len=3) "one": (bool) true - } - } - -Byte (and uint8) arrays and slices are displayed uniquely like the hexdump -C -command as shown. - ([]uint8) (len=32 cap=32) { - 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... | - 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0| - 00000020 31 32 |12| - } - -Custom Formatter - -Spew provides a custom formatter that implements the fmt.Formatter interface -so that it integrates cleanly with standard fmt package printing functions. The -formatter is useful for inline printing of smaller data types similar to the -standard %v format specifier. - -The custom formatter only responds to the %v (most compact), %+v (adds pointer -addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb -combinations. Any other verbs such as %x and %q will be sent to the the -standard fmt package for formatting. In addition, the custom formatter ignores -the width and precision arguments (however they will still work on the format -specifiers not handled by the custom formatter). - -Custom Formatter Usage - -The simplest way to make use of the spew custom formatter is to call one of the -convenience functions such as spew.Printf, spew.Println, or spew.Printf. The -functions have syntax you are most likely already familiar with: - - spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) - spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) - spew.Println(myVar, myVar2) - spew.Fprintf(os.Stderr, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) - spew.Fprintf(os.Stderr, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) - -See the Index for the full list convenience functions. - -Sample Formatter Output - -Double pointer to a uint8: - %v: <**>5 - %+v: <**>(0xf8400420d0->0xf8400420c8)5 - %#v: (**uint8)5 - %#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5 - -Pointer to circular struct with a uint8 field and a pointer to itself: - %v: <*>{1 <*>} - %+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)} - %#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)} - %#+v: (*main.circular)(0xf84003e260){ui8:(uint8)1 c:(*main.circular)(0xf84003e260)} - -See the Printf example for details on the setup of variables being shown -here. - -Errors - -Since it is possible for custom Stringer/error interfaces to panic, spew -detects them and handles them internally by printing the panic information -inline with the output. Since spew is intended to provide deep pretty printing -capabilities on structures, it intentionally does not return any errors. -*/ -package spew diff --git a/vendor/github.com/davecgh/go-spew/spew/dump.go b/vendor/github.com/davecgh/go-spew/spew/dump.go deleted file mode 100644 index f78d89fc..00000000 --- a/vendor/github.com/davecgh/go-spew/spew/dump.go +++ /dev/null @@ -1,509 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "bytes" - "encoding/hex" - "fmt" - "io" - "os" - "reflect" - "regexp" - "strconv" - "strings" -) - -var ( - // uint8Type is a reflect.Type representing a uint8. It is used to - // convert cgo types to uint8 slices for hexdumping. - uint8Type = reflect.TypeOf(uint8(0)) - - // cCharRE is a regular expression that matches a cgo char. - // It is used to detect character arrays to hexdump them. - cCharRE = regexp.MustCompile(`^.*\._Ctype_char$`) - - // cUnsignedCharRE is a regular expression that matches a cgo unsigned - // char. It is used to detect unsigned character arrays to hexdump - // them. - cUnsignedCharRE = regexp.MustCompile(`^.*\._Ctype_unsignedchar$`) - - // cUint8tCharRE is a regular expression that matches a cgo uint8_t. - // It is used to detect uint8_t arrays to hexdump them. - cUint8tCharRE = regexp.MustCompile(`^.*\._Ctype_uint8_t$`) -) - -// dumpState contains information about the state of a dump operation. -type dumpState struct { - w io.Writer - depth int - pointers map[uintptr]int - ignoreNextType bool - ignoreNextIndent bool - cs *ConfigState -} - -// indent performs indentation according to the depth level and cs.Indent -// option. -func (d *dumpState) indent() { - if d.ignoreNextIndent { - d.ignoreNextIndent = false - return - } - d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth)) -} - -// unpackValue returns values inside of non-nil interfaces when possible. -// This is useful for data types like structs, arrays, slices, and maps which -// can contain varying types packed inside an interface. -func (d *dumpState) unpackValue(v reflect.Value) reflect.Value { - if v.Kind() == reflect.Interface && !v.IsNil() { - v = v.Elem() - } - return v -} - -// dumpPtr handles formatting of pointers by indirecting them as necessary. -func (d *dumpState) dumpPtr(v reflect.Value) { - // Remove pointers at or below the current depth from map used to detect - // circular refs. - for k, depth := range d.pointers { - if depth >= d.depth { - delete(d.pointers, k) - } - } - - // Keep list of all dereferenced pointers to show later. - pointerChain := make([]uintptr, 0) - - // Figure out how many levels of indirection there are by dereferencing - // pointers and unpacking interfaces down the chain while detecting circular - // references. - nilFound := false - cycleFound := false - indirects := 0 - ve := v - for ve.Kind() == reflect.Ptr { - if ve.IsNil() { - nilFound = true - break - } - indirects++ - addr := ve.Pointer() - pointerChain = append(pointerChain, addr) - if pd, ok := d.pointers[addr]; ok && pd < d.depth { - cycleFound = true - indirects-- - break - } - d.pointers[addr] = d.depth - - ve = ve.Elem() - if ve.Kind() == reflect.Interface { - if ve.IsNil() { - nilFound = true - break - } - ve = ve.Elem() - } - } - - // Display type information. - d.w.Write(openParenBytes) - d.w.Write(bytes.Repeat(asteriskBytes, indirects)) - d.w.Write([]byte(ve.Type().String())) - d.w.Write(closeParenBytes) - - // Display pointer information. - if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 { - d.w.Write(openParenBytes) - for i, addr := range pointerChain { - if i > 0 { - d.w.Write(pointerChainBytes) - } - printHexPtr(d.w, addr) - } - d.w.Write(closeParenBytes) - } - - // Display dereferenced value. - d.w.Write(openParenBytes) - switch { - case nilFound: - d.w.Write(nilAngleBytes) - - case cycleFound: - d.w.Write(circularBytes) - - default: - d.ignoreNextType = true - d.dump(ve) - } - d.w.Write(closeParenBytes) -} - -// dumpSlice handles formatting of arrays and slices. Byte (uint8 under -// reflection) arrays and slices are dumped in hexdump -C fashion. -func (d *dumpState) dumpSlice(v reflect.Value) { - // Determine whether this type should be hex dumped or not. Also, - // for types which should be hexdumped, try to use the underlying data - // first, then fall back to trying to convert them to a uint8 slice. - var buf []uint8 - doConvert := false - doHexDump := false - numEntries := v.Len() - if numEntries > 0 { - vt := v.Index(0).Type() - vts := vt.String() - switch { - // C types that need to be converted. - case cCharRE.MatchString(vts): - fallthrough - case cUnsignedCharRE.MatchString(vts): - fallthrough - case cUint8tCharRE.MatchString(vts): - doConvert = true - - // Try to use existing uint8 slices and fall back to converting - // and copying if that fails. - case vt.Kind() == reflect.Uint8: - // We need an addressable interface to convert the type - // to a byte slice. However, the reflect package won't - // give us an interface on certain things like - // unexported struct fields in order to enforce - // visibility rules. We use unsafe, when available, to - // bypass these restrictions since this package does not - // mutate the values. - vs := v - if !vs.CanInterface() || !vs.CanAddr() { - vs = unsafeReflectValue(vs) - } - if !UnsafeDisabled { - vs = vs.Slice(0, numEntries) - - // Use the existing uint8 slice if it can be - // type asserted. - iface := vs.Interface() - if slice, ok := iface.([]uint8); ok { - buf = slice - doHexDump = true - break - } - } - - // The underlying data needs to be converted if it can't - // be type asserted to a uint8 slice. - doConvert = true - } - - // Copy and convert the underlying type if needed. - if doConvert && vt.ConvertibleTo(uint8Type) { - // Convert and copy each element into a uint8 byte - // slice. - buf = make([]uint8, numEntries) - for i := 0; i < numEntries; i++ { - vv := v.Index(i) - buf[i] = uint8(vv.Convert(uint8Type).Uint()) - } - doHexDump = true - } - } - - // Hexdump the entire slice as needed. - if doHexDump { - indent := strings.Repeat(d.cs.Indent, d.depth) - str := indent + hex.Dump(buf) - str = strings.Replace(str, "\n", "\n"+indent, -1) - str = strings.TrimRight(str, d.cs.Indent) - d.w.Write([]byte(str)) - return - } - - // Recursively call dump for each item. - for i := 0; i < numEntries; i++ { - d.dump(d.unpackValue(v.Index(i))) - if i < (numEntries - 1) { - d.w.Write(commaNewlineBytes) - } else { - d.w.Write(newlineBytes) - } - } -} - -// dump is the main workhorse for dumping a value. It uses the passed reflect -// value to figure out what kind of object we are dealing with and formats it -// appropriately. It is a recursive function, however circular data structures -// are detected and handled properly. -func (d *dumpState) dump(v reflect.Value) { - // Handle invalid reflect values immediately. - kind := v.Kind() - if kind == reflect.Invalid { - d.w.Write(invalidAngleBytes) - return - } - - // Handle pointers specially. - if kind == reflect.Ptr { - d.indent() - d.dumpPtr(v) - return - } - - // Print type information unless already handled elsewhere. - if !d.ignoreNextType { - d.indent() - d.w.Write(openParenBytes) - d.w.Write([]byte(v.Type().String())) - d.w.Write(closeParenBytes) - d.w.Write(spaceBytes) - } - d.ignoreNextType = false - - // Display length and capacity if the built-in len and cap functions - // work with the value's kind and the len/cap itself is non-zero. - valueLen, valueCap := 0, 0 - switch v.Kind() { - case reflect.Array, reflect.Slice, reflect.Chan: - valueLen, valueCap = v.Len(), v.Cap() - case reflect.Map, reflect.String: - valueLen = v.Len() - } - if valueLen != 0 || !d.cs.DisableCapacities && valueCap != 0 { - d.w.Write(openParenBytes) - if valueLen != 0 { - d.w.Write(lenEqualsBytes) - printInt(d.w, int64(valueLen), 10) - } - if !d.cs.DisableCapacities && valueCap != 0 { - if valueLen != 0 { - d.w.Write(spaceBytes) - } - d.w.Write(capEqualsBytes) - printInt(d.w, int64(valueCap), 10) - } - d.w.Write(closeParenBytes) - d.w.Write(spaceBytes) - } - - // Call Stringer/error interfaces if they exist and the handle methods flag - // is enabled - if !d.cs.DisableMethods { - if (kind != reflect.Invalid) && (kind != reflect.Interface) { - if handled := handleMethods(d.cs, d.w, v); handled { - return - } - } - } - - switch kind { - case reflect.Invalid: - // Do nothing. We should never get here since invalid has already - // been handled above. - - case reflect.Bool: - printBool(d.w, v.Bool()) - - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - printInt(d.w, v.Int(), 10) - - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: - printUint(d.w, v.Uint(), 10) - - case reflect.Float32: - printFloat(d.w, v.Float(), 32) - - case reflect.Float64: - printFloat(d.w, v.Float(), 64) - - case reflect.Complex64: - printComplex(d.w, v.Complex(), 32) - - case reflect.Complex128: - printComplex(d.w, v.Complex(), 64) - - case reflect.Slice: - if v.IsNil() { - d.w.Write(nilAngleBytes) - break - } - fallthrough - - case reflect.Array: - d.w.Write(openBraceNewlineBytes) - d.depth++ - if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { - d.indent() - d.w.Write(maxNewlineBytes) - } else { - d.dumpSlice(v) - } - d.depth-- - d.indent() - d.w.Write(closeBraceBytes) - - case reflect.String: - d.w.Write([]byte(strconv.Quote(v.String()))) - - case reflect.Interface: - // The only time we should get here is for nil interfaces due to - // unpackValue calls. - if v.IsNil() { - d.w.Write(nilAngleBytes) - } - - case reflect.Ptr: - // Do nothing. We should never get here since pointers have already - // been handled above. - - case reflect.Map: - // nil maps should be indicated as different than empty maps - if v.IsNil() { - d.w.Write(nilAngleBytes) - break - } - - d.w.Write(openBraceNewlineBytes) - d.depth++ - if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { - d.indent() - d.w.Write(maxNewlineBytes) - } else { - numEntries := v.Len() - keys := v.MapKeys() - if d.cs.SortKeys { - sortValues(keys, d.cs) - } - for i, key := range keys { - d.dump(d.unpackValue(key)) - d.w.Write(colonSpaceBytes) - d.ignoreNextIndent = true - d.dump(d.unpackValue(v.MapIndex(key))) - if i < (numEntries - 1) { - d.w.Write(commaNewlineBytes) - } else { - d.w.Write(newlineBytes) - } - } - } - d.depth-- - d.indent() - d.w.Write(closeBraceBytes) - - case reflect.Struct: - d.w.Write(openBraceNewlineBytes) - d.depth++ - if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { - d.indent() - d.w.Write(maxNewlineBytes) - } else { - vt := v.Type() - numFields := v.NumField() - for i := 0; i < numFields; i++ { - d.indent() - vtf := vt.Field(i) - d.w.Write([]byte(vtf.Name)) - d.w.Write(colonSpaceBytes) - d.ignoreNextIndent = true - d.dump(d.unpackValue(v.Field(i))) - if i < (numFields - 1) { - d.w.Write(commaNewlineBytes) - } else { - d.w.Write(newlineBytes) - } - } - } - d.depth-- - d.indent() - d.w.Write(closeBraceBytes) - - case reflect.Uintptr: - printHexPtr(d.w, uintptr(v.Uint())) - - case reflect.UnsafePointer, reflect.Chan, reflect.Func: - printHexPtr(d.w, v.Pointer()) - - // There were not any other types at the time this code was written, but - // fall back to letting the default fmt package handle it in case any new - // types are added. - default: - if v.CanInterface() { - fmt.Fprintf(d.w, "%v", v.Interface()) - } else { - fmt.Fprintf(d.w, "%v", v.String()) - } - } -} - -// fdump is a helper function to consolidate the logic from the various public -// methods which take varying writers and config states. -func fdump(cs *ConfigState, w io.Writer, a ...interface{}) { - for _, arg := range a { - if arg == nil { - w.Write(interfaceBytes) - w.Write(spaceBytes) - w.Write(nilAngleBytes) - w.Write(newlineBytes) - continue - } - - d := dumpState{w: w, cs: cs} - d.pointers = make(map[uintptr]int) - d.dump(reflect.ValueOf(arg)) - d.w.Write(newlineBytes) - } -} - -// Fdump formats and displays the passed arguments to io.Writer w. It formats -// exactly the same as Dump. -func Fdump(w io.Writer, a ...interface{}) { - fdump(&Config, w, a...) -} - -// Sdump returns a string with the passed arguments formatted exactly the same -// as Dump. -func Sdump(a ...interface{}) string { - var buf bytes.Buffer - fdump(&Config, &buf, a...) - return buf.String() -} - -/* -Dump displays the passed parameters to standard out with newlines, customizable -indentation, and additional debug information such as complete types and all -pointer addresses used to indirect to the final value. It provides the -following features over the built-in printing facilities provided by the fmt -package: - - * Pointers are dereferenced and followed - * Circular data structures are detected and handled properly - * Custom Stringer/error interfaces are optionally invoked, including - on unexported types - * Custom types which only implement the Stringer/error interfaces via - a pointer receiver are optionally invoked when passing non-pointer - variables - * Byte arrays and slices are dumped like the hexdump -C command which - includes offsets, byte values in hex, and ASCII output - -The configuration options are controlled by an exported package global, -spew.Config. See ConfigState for options documentation. - -See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to -get the formatted result as a string. -*/ -func Dump(a ...interface{}) { - fdump(&Config, os.Stdout, a...) -} diff --git a/vendor/github.com/davecgh/go-spew/spew/format.go b/vendor/github.com/davecgh/go-spew/spew/format.go deleted file mode 100644 index b04edb7d..00000000 --- a/vendor/github.com/davecgh/go-spew/spew/format.go +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "bytes" - "fmt" - "reflect" - "strconv" - "strings" -) - -// supportedFlags is a list of all the character flags supported by fmt package. -const supportedFlags = "0-+# " - -// formatState implements the fmt.Formatter interface and contains information -// about the state of a formatting operation. The NewFormatter function can -// be used to get a new Formatter which can be used directly as arguments -// in standard fmt package printing calls. -type formatState struct { - value interface{} - fs fmt.State - depth int - pointers map[uintptr]int - ignoreNextType bool - cs *ConfigState -} - -// buildDefaultFormat recreates the original format string without precision -// and width information to pass in to fmt.Sprintf in the case of an -// unrecognized type. Unless new types are added to the language, this -// function won't ever be called. -func (f *formatState) buildDefaultFormat() (format string) { - buf := bytes.NewBuffer(percentBytes) - - for _, flag := range supportedFlags { - if f.fs.Flag(int(flag)) { - buf.WriteRune(flag) - } - } - - buf.WriteRune('v') - - format = buf.String() - return format -} - -// constructOrigFormat recreates the original format string including precision -// and width information to pass along to the standard fmt package. This allows -// automatic deferral of all format strings this package doesn't support. -func (f *formatState) constructOrigFormat(verb rune) (format string) { - buf := bytes.NewBuffer(percentBytes) - - for _, flag := range supportedFlags { - if f.fs.Flag(int(flag)) { - buf.WriteRune(flag) - } - } - - if width, ok := f.fs.Width(); ok { - buf.WriteString(strconv.Itoa(width)) - } - - if precision, ok := f.fs.Precision(); ok { - buf.Write(precisionBytes) - buf.WriteString(strconv.Itoa(precision)) - } - - buf.WriteRune(verb) - - format = buf.String() - return format -} - -// unpackValue returns values inside of non-nil interfaces when possible and -// ensures that types for values which have been unpacked from an interface -// are displayed when the show types flag is also set. -// This is useful for data types like structs, arrays, slices, and maps which -// can contain varying types packed inside an interface. -func (f *formatState) unpackValue(v reflect.Value) reflect.Value { - if v.Kind() == reflect.Interface { - f.ignoreNextType = false - if !v.IsNil() { - v = v.Elem() - } - } - return v -} - -// formatPtr handles formatting of pointers by indirecting them as necessary. -func (f *formatState) formatPtr(v reflect.Value) { - // Display nil if top level pointer is nil. - showTypes := f.fs.Flag('#') - if v.IsNil() && (!showTypes || f.ignoreNextType) { - f.fs.Write(nilAngleBytes) - return - } - - // Remove pointers at or below the current depth from map used to detect - // circular refs. - for k, depth := range f.pointers { - if depth >= f.depth { - delete(f.pointers, k) - } - } - - // Keep list of all dereferenced pointers to possibly show later. - pointerChain := make([]uintptr, 0) - - // Figure out how many levels of indirection there are by derferencing - // pointers and unpacking interfaces down the chain while detecting circular - // references. - nilFound := false - cycleFound := false - indirects := 0 - ve := v - for ve.Kind() == reflect.Ptr { - if ve.IsNil() { - nilFound = true - break - } - indirects++ - addr := ve.Pointer() - pointerChain = append(pointerChain, addr) - if pd, ok := f.pointers[addr]; ok && pd < f.depth { - cycleFound = true - indirects-- - break - } - f.pointers[addr] = f.depth - - ve = ve.Elem() - if ve.Kind() == reflect.Interface { - if ve.IsNil() { - nilFound = true - break - } - ve = ve.Elem() - } - } - - // Display type or indirection level depending on flags. - if showTypes && !f.ignoreNextType { - f.fs.Write(openParenBytes) - f.fs.Write(bytes.Repeat(asteriskBytes, indirects)) - f.fs.Write([]byte(ve.Type().String())) - f.fs.Write(closeParenBytes) - } else { - if nilFound || cycleFound { - indirects += strings.Count(ve.Type().String(), "*") - } - f.fs.Write(openAngleBytes) - f.fs.Write([]byte(strings.Repeat("*", indirects))) - f.fs.Write(closeAngleBytes) - } - - // Display pointer information depending on flags. - if f.fs.Flag('+') && (len(pointerChain) > 0) { - f.fs.Write(openParenBytes) - for i, addr := range pointerChain { - if i > 0 { - f.fs.Write(pointerChainBytes) - } - printHexPtr(f.fs, addr) - } - f.fs.Write(closeParenBytes) - } - - // Display dereferenced value. - switch { - case nilFound: - f.fs.Write(nilAngleBytes) - - case cycleFound: - f.fs.Write(circularShortBytes) - - default: - f.ignoreNextType = true - f.format(ve) - } -} - -// format is the main workhorse for providing the Formatter interface. It -// uses the passed reflect value to figure out what kind of object we are -// dealing with and formats it appropriately. It is a recursive function, -// however circular data structures are detected and handled properly. -func (f *formatState) format(v reflect.Value) { - // Handle invalid reflect values immediately. - kind := v.Kind() - if kind == reflect.Invalid { - f.fs.Write(invalidAngleBytes) - return - } - - // Handle pointers specially. - if kind == reflect.Ptr { - f.formatPtr(v) - return - } - - // Print type information unless already handled elsewhere. - if !f.ignoreNextType && f.fs.Flag('#') { - f.fs.Write(openParenBytes) - f.fs.Write([]byte(v.Type().String())) - f.fs.Write(closeParenBytes) - } - f.ignoreNextType = false - - // Call Stringer/error interfaces if they exist and the handle methods - // flag is enabled. - if !f.cs.DisableMethods { - if (kind != reflect.Invalid) && (kind != reflect.Interface) { - if handled := handleMethods(f.cs, f.fs, v); handled { - return - } - } - } - - switch kind { - case reflect.Invalid: - // Do nothing. We should never get here since invalid has already - // been handled above. - - case reflect.Bool: - printBool(f.fs, v.Bool()) - - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - printInt(f.fs, v.Int(), 10) - - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: - printUint(f.fs, v.Uint(), 10) - - case reflect.Float32: - printFloat(f.fs, v.Float(), 32) - - case reflect.Float64: - printFloat(f.fs, v.Float(), 64) - - case reflect.Complex64: - printComplex(f.fs, v.Complex(), 32) - - case reflect.Complex128: - printComplex(f.fs, v.Complex(), 64) - - case reflect.Slice: - if v.IsNil() { - f.fs.Write(nilAngleBytes) - break - } - fallthrough - - case reflect.Array: - f.fs.Write(openBracketBytes) - f.depth++ - if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { - f.fs.Write(maxShortBytes) - } else { - numEntries := v.Len() - for i := 0; i < numEntries; i++ { - if i > 0 { - f.fs.Write(spaceBytes) - } - f.ignoreNextType = true - f.format(f.unpackValue(v.Index(i))) - } - } - f.depth-- - f.fs.Write(closeBracketBytes) - - case reflect.String: - f.fs.Write([]byte(v.String())) - - case reflect.Interface: - // The only time we should get here is for nil interfaces due to - // unpackValue calls. - if v.IsNil() { - f.fs.Write(nilAngleBytes) - } - - case reflect.Ptr: - // Do nothing. We should never get here since pointers have already - // been handled above. - - case reflect.Map: - // nil maps should be indicated as different than empty maps - if v.IsNil() { - f.fs.Write(nilAngleBytes) - break - } - - f.fs.Write(openMapBytes) - f.depth++ - if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { - f.fs.Write(maxShortBytes) - } else { - keys := v.MapKeys() - if f.cs.SortKeys { - sortValues(keys, f.cs) - } - for i, key := range keys { - if i > 0 { - f.fs.Write(spaceBytes) - } - f.ignoreNextType = true - f.format(f.unpackValue(key)) - f.fs.Write(colonBytes) - f.ignoreNextType = true - f.format(f.unpackValue(v.MapIndex(key))) - } - } - f.depth-- - f.fs.Write(closeMapBytes) - - case reflect.Struct: - numFields := v.NumField() - f.fs.Write(openBraceBytes) - f.depth++ - if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { - f.fs.Write(maxShortBytes) - } else { - vt := v.Type() - for i := 0; i < numFields; i++ { - if i > 0 { - f.fs.Write(spaceBytes) - } - vtf := vt.Field(i) - if f.fs.Flag('+') || f.fs.Flag('#') { - f.fs.Write([]byte(vtf.Name)) - f.fs.Write(colonBytes) - } - f.format(f.unpackValue(v.Field(i))) - } - } - f.depth-- - f.fs.Write(closeBraceBytes) - - case reflect.Uintptr: - printHexPtr(f.fs, uintptr(v.Uint())) - - case reflect.UnsafePointer, reflect.Chan, reflect.Func: - printHexPtr(f.fs, v.Pointer()) - - // There were not any other types at the time this code was written, but - // fall back to letting the default fmt package handle it if any get added. - default: - format := f.buildDefaultFormat() - if v.CanInterface() { - fmt.Fprintf(f.fs, format, v.Interface()) - } else { - fmt.Fprintf(f.fs, format, v.String()) - } - } -} - -// Format satisfies the fmt.Formatter interface. See NewFormatter for usage -// details. -func (f *formatState) Format(fs fmt.State, verb rune) { - f.fs = fs - - // Use standard formatting for verbs that are not v. - if verb != 'v' { - format := f.constructOrigFormat(verb) - fmt.Fprintf(fs, format, f.value) - return - } - - if f.value == nil { - if fs.Flag('#') { - fs.Write(interfaceBytes) - } - fs.Write(nilAngleBytes) - return - } - - f.format(reflect.ValueOf(f.value)) -} - -// newFormatter is a helper function to consolidate the logic from the various -// public methods which take varying config states. -func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter { - fs := &formatState{value: v, cs: cs} - fs.pointers = make(map[uintptr]int) - return fs -} - -/* -NewFormatter returns a custom formatter that satisfies the fmt.Formatter -interface. As a result, it integrates cleanly with standard fmt package -printing functions. The formatter is useful for inline printing of smaller data -types similar to the standard %v format specifier. - -The custom formatter only responds to the %v (most compact), %+v (adds pointer -addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb -combinations. Any other verbs such as %x and %q will be sent to the the -standard fmt package for formatting. In addition, the custom formatter ignores -the width and precision arguments (however they will still work on the format -specifiers not handled by the custom formatter). - -Typically this function shouldn't be called directly. It is much easier to make -use of the custom formatter by calling one of the convenience functions such as -Printf, Println, or Fprintf. -*/ -func NewFormatter(v interface{}) fmt.Formatter { - return newFormatter(&Config, v) -} diff --git a/vendor/github.com/davecgh/go-spew/spew/spew.go b/vendor/github.com/davecgh/go-spew/spew/spew.go deleted file mode 100644 index 32c0e338..00000000 --- a/vendor/github.com/davecgh/go-spew/spew/spew.go +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "fmt" - "io" -) - -// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the formatted string as a value that satisfies error. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Errorf(format, spew.NewFormatter(a), spew.NewFormatter(b)) -func Errorf(format string, a ...interface{}) (err error) { - return fmt.Errorf(format, convertArgs(a)...) -} - -// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprint(w, spew.NewFormatter(a), spew.NewFormatter(b)) -func Fprint(w io.Writer, a ...interface{}) (n int, err error) { - return fmt.Fprint(w, convertArgs(a)...) -} - -// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprintf(w, format, spew.NewFormatter(a), spew.NewFormatter(b)) -func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { - return fmt.Fprintf(w, format, convertArgs(a)...) -} - -// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it -// passed with a default Formatter interface returned by NewFormatter. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprintln(w, spew.NewFormatter(a), spew.NewFormatter(b)) -func Fprintln(w io.Writer, a ...interface{}) (n int, err error) { - return fmt.Fprintln(w, convertArgs(a)...) -} - -// Print is a wrapper for fmt.Print that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Print(spew.NewFormatter(a), spew.NewFormatter(b)) -func Print(a ...interface{}) (n int, err error) { - return fmt.Print(convertArgs(a)...) -} - -// Printf is a wrapper for fmt.Printf that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Printf(format, spew.NewFormatter(a), spew.NewFormatter(b)) -func Printf(format string, a ...interface{}) (n int, err error) { - return fmt.Printf(format, convertArgs(a)...) -} - -// Println is a wrapper for fmt.Println that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Println(spew.NewFormatter(a), spew.NewFormatter(b)) -func Println(a ...interface{}) (n int, err error) { - return fmt.Println(convertArgs(a)...) -} - -// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprint(spew.NewFormatter(a), spew.NewFormatter(b)) -func Sprint(a ...interface{}) string { - return fmt.Sprint(convertArgs(a)...) -} - -// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprintf(format, spew.NewFormatter(a), spew.NewFormatter(b)) -func Sprintf(format string, a ...interface{}) string { - return fmt.Sprintf(format, convertArgs(a)...) -} - -// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it -// were passed with a default Formatter interface returned by NewFormatter. It -// returns the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprintln(spew.NewFormatter(a), spew.NewFormatter(b)) -func Sprintln(a ...interface{}) string { - return fmt.Sprintln(convertArgs(a)...) -} - -// convertArgs accepts a slice of arguments and returns a slice of the same -// length with each argument converted to a default spew Formatter interface. -func convertArgs(args []interface{}) (formatters []interface{}) { - formatters = make([]interface{}, len(args)) - for index, arg := range args { - formatters[index] = NewFormatter(arg) - } - return formatters -} diff --git a/vendor/github.com/go-errors/errors/.travis.yml b/vendor/github.com/go-errors/errors/.travis.yml deleted file mode 100644 index 9d00fdd5..00000000 --- a/vendor/github.com/go-errors/errors/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: go - -go: - - "1.8.x" - - "1.10.x" diff --git a/vendor/github.com/go-errors/errors/LICENSE.MIT b/vendor/github.com/go-errors/errors/LICENSE.MIT deleted file mode 100644 index c9a5b2ee..00000000 --- a/vendor/github.com/go-errors/errors/LICENSE.MIT +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (c) 2015 Conrad Irwin - -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-errors/errors/README.md b/vendor/github.com/go-errors/errors/README.md deleted file mode 100644 index 5d4f1873..00000000 --- a/vendor/github.com/go-errors/errors/README.md +++ /dev/null @@ -1,66 +0,0 @@ -go-errors/errors -================ - -[![Build Status](https://travis-ci.org/go-errors/errors.svg?branch=master)](https://travis-ci.org/go-errors/errors) - -Package errors adds stacktrace support to errors in go. - -This is particularly useful when you want to understand the state of execution -when an error was returned unexpectedly. - -It provides the type \*Error which implements the standard golang error -interface, so you can use this library interchangably with code that is -expecting a normal error return. - -Usage ------ - -Full documentation is available on -[godoc](https://godoc.org/github.com/go-errors/errors), but here's a simple -example: - -```go -package crashy - -import "github.com/go-errors/errors" - -var Crashed = errors.Errorf("oh dear") - -func Crash() error { - return errors.New(Crashed) -} -``` - -This can be called as follows: - -```go -package main - -import ( - "crashy" - "fmt" - "github.com/go-errors/errors" -) - -func main() { - err := crashy.Crash() - if err != nil { - if errors.Is(err, crashy.Crashed) { - fmt.Println(err.(*errors.Error).ErrorStack()) - } else { - panic(err) - } - } -} -``` - -Meta-fu -------- - -This package was original written to allow reporting to -[Bugsnag](https://bugsnag.com/) from -[bugsnag-go](https://github.com/bugsnag/bugsnag-go), but after I found similar -packages by Facebook and Dropbox, it was moved to one canonical location so -everyone can benefit. - -This package is licensed under the MIT license, see LICENSE.MIT for details. diff --git a/vendor/github.com/go-errors/errors/cover.out b/vendor/github.com/go-errors/errors/cover.out deleted file mode 100644 index ab18b051..00000000 --- a/vendor/github.com/go-errors/errors/cover.out +++ /dev/null @@ -1,89 +0,0 @@ -mode: set -github.com/go-errors/errors/stackframe.go:27.51,30.25 2 1 -github.com/go-errors/errors/stackframe.go:33.2,38.8 3 1 -github.com/go-errors/errors/stackframe.go:30.25,32.3 1 0 -github.com/go-errors/errors/stackframe.go:43.47,44.31 1 1 -github.com/go-errors/errors/stackframe.go:47.2,47.48 1 1 -github.com/go-errors/errors/stackframe.go:44.31,46.3 1 1 -github.com/go-errors/errors/stackframe.go:52.42,56.16 3 1 -github.com/go-errors/errors/stackframe.go:60.2,60.60 1 1 -github.com/go-errors/errors/stackframe.go:56.16,58.3 1 0 -github.com/go-errors/errors/stackframe.go:64.55,67.16 2 1 -github.com/go-errors/errors/stackframe.go:71.2,72.61 2 1 -github.com/go-errors/errors/stackframe.go:76.2,76.66 1 1 -github.com/go-errors/errors/stackframe.go:67.16,69.3 1 0 -github.com/go-errors/errors/stackframe.go:72.61,74.3 1 0 -github.com/go-errors/errors/stackframe.go:79.56,91.63 3 1 -github.com/go-errors/errors/stackframe.go:95.2,95.53 1 1 -github.com/go-errors/errors/stackframe.go:100.2,101.18 2 1 -github.com/go-errors/errors/stackframe.go:91.63,94.3 2 1 -github.com/go-errors/errors/stackframe.go:95.53,98.3 2 1 -github.com/go-errors/errors/error.go:70.32,73.23 2 1 -github.com/go-errors/errors/error.go:80.2,85.3 3 1 -github.com/go-errors/errors/error.go:74.2,75.10 1 1 -github.com/go-errors/errors/error.go:76.2,77.28 1 1 -github.com/go-errors/errors/error.go:92.43,95.23 2 1 -github.com/go-errors/errors/error.go:104.2,109.3 3 1 -github.com/go-errors/errors/error.go:96.2,97.11 1 1 -github.com/go-errors/errors/error.go:98.2,99.10 1 1 -github.com/go-errors/errors/error.go:100.2,101.28 1 1 -github.com/go-errors/errors/error.go:115.39,117.19 1 1 -github.com/go-errors/errors/error.go:121.2,121.29 1 1 -github.com/go-errors/errors/error.go:125.2,125.43 1 1 -github.com/go-errors/errors/error.go:129.2,129.14 1 1 -github.com/go-errors/errors/error.go:117.19,119.3 1 1 -github.com/go-errors/errors/error.go:121.29,123.3 1 1 -github.com/go-errors/errors/error.go:125.43,127.3 1 1 -github.com/go-errors/errors/error.go:135.53,137.2 1 1 -github.com/go-errors/errors/error.go:140.34,142.2 1 1 -github.com/go-errors/errors/error.go:146.34,149.42 2 1 -github.com/go-errors/errors/error.go:153.2,153.20 1 1 -github.com/go-errors/errors/error.go:149.42,151.3 1 1 -github.com/go-errors/errors/error.go:158.39,160.2 1 1 -github.com/go-errors/errors/error.go:164.46,165.23 1 1 -github.com/go-errors/errors/error.go:173.2,173.19 1 1 -github.com/go-errors/errors/error.go:165.23,168.32 2 1 -github.com/go-errors/errors/error.go:168.32,170.4 1 1 -github.com/go-errors/errors/error.go:177.37,178.42 1 1 -github.com/go-errors/errors/error.go:181.2,181.41 1 1 -github.com/go-errors/errors/error.go:178.42,180.3 1 1 -github.com/go-errors/errors/parse_panic.go:10.39,12.2 1 1 -github.com/go-errors/errors/parse_panic.go:16.46,24.34 5 1 -github.com/go-errors/errors/parse_panic.go:70.2,70.43 1 1 -github.com/go-errors/errors/parse_panic.go:73.2,73.55 1 0 -github.com/go-errors/errors/parse_panic.go:24.34,27.23 2 1 -github.com/go-errors/errors/parse_panic.go:27.23,28.42 1 1 -github.com/go-errors/errors/parse_panic.go:28.42,31.5 2 1 -github.com/go-errors/errors/parse_panic.go:31.6,33.5 1 0 -github.com/go-errors/errors/parse_panic.go:35.5,35.29 1 1 -github.com/go-errors/errors/parse_panic.go:35.29,36.86 1 1 -github.com/go-errors/errors/parse_panic.go:36.86,38.5 1 1 -github.com/go-errors/errors/parse_panic.go:40.5,40.32 1 1 -github.com/go-errors/errors/parse_panic.go:40.32,41.18 1 1 -github.com/go-errors/errors/parse_panic.go:45.4,46.46 2 1 -github.com/go-errors/errors/parse_panic.go:51.4,53.23 2 1 -github.com/go-errors/errors/parse_panic.go:57.4,58.18 2 1 -github.com/go-errors/errors/parse_panic.go:62.4,63.17 2 1 -github.com/go-errors/errors/parse_panic.go:41.18,43.10 2 1 -github.com/go-errors/errors/parse_panic.go:46.46,49.5 2 1 -github.com/go-errors/errors/parse_panic.go:53.23,55.5 1 0 -github.com/go-errors/errors/parse_panic.go:58.18,60.5 1 0 -github.com/go-errors/errors/parse_panic.go:63.17,65.10 2 1 -github.com/go-errors/errors/parse_panic.go:70.43,72.3 1 1 -github.com/go-errors/errors/parse_panic.go:80.85,82.29 2 1 -github.com/go-errors/errors/parse_panic.go:85.2,85.15 1 1 -github.com/go-errors/errors/parse_panic.go:88.2,90.63 2 1 -github.com/go-errors/errors/parse_panic.go:94.2,94.53 1 1 -github.com/go-errors/errors/parse_panic.go:99.2,101.36 2 1 -github.com/go-errors/errors/parse_panic.go:105.2,106.15 2 1 -github.com/go-errors/errors/parse_panic.go:109.2,112.49 3 1 -github.com/go-errors/errors/parse_panic.go:116.2,117.16 2 1 -github.com/go-errors/errors/parse_panic.go:121.2,126.8 1 1 -github.com/go-errors/errors/parse_panic.go:82.29,84.3 1 0 -github.com/go-errors/errors/parse_panic.go:85.15,87.3 1 1 -github.com/go-errors/errors/parse_panic.go:90.63,93.3 2 1 -github.com/go-errors/errors/parse_panic.go:94.53,97.3 2 1 -github.com/go-errors/errors/parse_panic.go:101.36,103.3 1 0 -github.com/go-errors/errors/parse_panic.go:106.15,108.3 1 0 -github.com/go-errors/errors/parse_panic.go:112.49,114.3 1 1 -github.com/go-errors/errors/parse_panic.go:117.16,119.3 1 0 diff --git a/vendor/github.com/go-errors/errors/error.go b/vendor/github.com/go-errors/errors/error.go deleted file mode 100644 index 60062a43..00000000 --- a/vendor/github.com/go-errors/errors/error.go +++ /dev/null @@ -1,217 +0,0 @@ -// Package errors provides errors that have stack-traces. -// -// This is particularly useful when you want to understand the -// state of execution when an error was returned unexpectedly. -// -// It provides the type *Error which implements the standard -// golang error interface, so you can use this library interchangably -// with code that is expecting a normal error return. -// -// For example: -// -// package crashy -// -// import "github.com/go-errors/errors" -// -// var Crashed = errors.Errorf("oh dear") -// -// func Crash() error { -// return errors.New(Crashed) -// } -// -// This can be called as follows: -// -// package main -// -// import ( -// "crashy" -// "fmt" -// "github.com/go-errors/errors" -// ) -// -// func main() { -// err := crashy.Crash() -// if err != nil { -// if errors.Is(err, crashy.Crashed) { -// fmt.Println(err.(*errors.Error).ErrorStack()) -// } else { -// panic(err) -// } -// } -// } -// -// This package was original written to allow reporting to Bugsnag, -// but after I found similar packages by Facebook and Dropbox, it -// was moved to one canonical location so everyone can benefit. -package errors - -import ( - "bytes" - "fmt" - "reflect" - "runtime" -) - -// The maximum number of stackframes on any error. -var MaxStackDepth = 50 - -// Error is an error with an attached stacktrace. It can be used -// wherever the builtin error interface is expected. -type Error struct { - Err error - stack []uintptr - frames []StackFrame - prefix string -} - -// New makes an Error from the given value. If that value is already an -// error then it will be used directly, if not, it will be passed to -// fmt.Errorf("%v"). The stacktrace will point to the line of code that -// called New. -func New(e interface{}) *Error { - var err error - - switch e := e.(type) { - case error: - err = e - default: - err = fmt.Errorf("%v", e) - } - - stack := make([]uintptr, MaxStackDepth) - length := runtime.Callers(2, stack[:]) - return &Error{ - Err: err, - stack: stack[:length], - } -} - -// Wrap makes an Error from the given value. If that value is already an -// error then it will be used directly, if not, it will be passed to -// fmt.Errorf("%v"). The skip parameter indicates how far up the stack -// to start the stacktrace. 0 is from the current call, 1 from its caller, etc. -func Wrap(e interface{}, skip int) *Error { - var err error - - switch e := e.(type) { - case *Error: - return e - case error: - err = e - default: - err = fmt.Errorf("%v", e) - } - - stack := make([]uintptr, MaxStackDepth) - length := runtime.Callers(2+skip, stack[:]) - return &Error{ - Err: err, - stack: stack[:length], - } -} - -// WrapPrefix makes an Error from the given value. If that value is already an -// error then it will be used directly, if not, it will be passed to -// fmt.Errorf("%v"). The prefix parameter is used to add a prefix to the -// error message when calling Error(). The skip parameter indicates how far -// up the stack to start the stacktrace. 0 is from the current call, -// 1 from its caller, etc. -func WrapPrefix(e interface{}, prefix string, skip int) *Error { - - err := Wrap(e, 1+skip) - - if err.prefix != "" { - prefix = fmt.Sprintf("%s: %s", prefix, err.prefix) - } - - return &Error{ - Err: err.Err, - stack: err.stack, - prefix: prefix, - } - -} - -// Is detects whether the error is equal to a given error. Errors -// are considered equal by this function if they are the same object, -// or if they both contain the same error inside an errors.Error. -func Is(e error, original error) bool { - - if e == original { - return true - } - - if e, ok := e.(*Error); ok { - return Is(e.Err, original) - } - - if original, ok := original.(*Error); ok { - return Is(e, original.Err) - } - - return false -} - -// Errorf creates a new error with the given message. You can use it -// as a drop-in replacement for fmt.Errorf() to provide descriptive -// errors in return values. -func Errorf(format string, a ...interface{}) *Error { - return Wrap(fmt.Errorf(format, a...), 1) -} - -// Error returns the underlying error's message. -func (err *Error) Error() string { - - msg := err.Err.Error() - if err.prefix != "" { - msg = fmt.Sprintf("%s: %s", err.prefix, msg) - } - - return msg -} - -// Stack returns the callstack formatted the same way that go does -// in runtime/debug.Stack() -func (err *Error) Stack() []byte { - buf := bytes.Buffer{} - - for _, frame := range err.StackFrames() { - buf.WriteString(frame.String()) - } - - return buf.Bytes() -} - -// Callers satisfies the bugsnag ErrorWithCallerS() interface -// so that the stack can be read out. -func (err *Error) Callers() []uintptr { - return err.stack -} - -// ErrorStack returns a string that contains both the -// error message and the callstack. -func (err *Error) ErrorStack() string { - return err.TypeName() + " " + err.Error() + "\n" + string(err.Stack()) -} - -// StackFrames returns an array of frames containing information about the -// stack. -func (err *Error) StackFrames() []StackFrame { - if err.frames == nil { - err.frames = make([]StackFrame, len(err.stack)) - - for i, pc := range err.stack { - err.frames[i] = NewStackFrame(pc) - } - } - - return err.frames -} - -// TypeName returns the type this error. e.g. *errors.stringError. -func (err *Error) TypeName() string { - if _, ok := err.Err.(uncaughtPanic); ok { - return "panic" - } - return reflect.TypeOf(err.Err).String() -} diff --git a/vendor/github.com/go-errors/errors/parse_panic.go b/vendor/github.com/go-errors/errors/parse_panic.go deleted file mode 100644 index cc37052d..00000000 --- a/vendor/github.com/go-errors/errors/parse_panic.go +++ /dev/null @@ -1,127 +0,0 @@ -package errors - -import ( - "strconv" - "strings" -) - -type uncaughtPanic struct{ message string } - -func (p uncaughtPanic) Error() string { - return p.message -} - -// ParsePanic allows you to get an error object from the output of a go program -// that panicked. This is particularly useful with https://github.com/mitchellh/panicwrap. -func ParsePanic(text string) (*Error, error) { - lines := strings.Split(text, "\n") - - state := "start" - - var message string - var stack []StackFrame - - for i := 0; i < len(lines); i++ { - line := lines[i] - - if state == "start" { - if strings.HasPrefix(line, "panic: ") { - message = strings.TrimPrefix(line, "panic: ") - state = "seek" - } else { - return nil, Errorf("bugsnag.panicParser: Invalid line (no prefix): %s", line) - } - - } else if state == "seek" { - if strings.HasPrefix(line, "goroutine ") && strings.HasSuffix(line, "[running]:") { - state = "parsing" - } - - } else if state == "parsing" { - if line == "" { - state = "done" - break - } - createdBy := false - if strings.HasPrefix(line, "created by ") { - line = strings.TrimPrefix(line, "created by ") - createdBy = true - } - - i++ - - if i >= len(lines) { - return nil, Errorf("bugsnag.panicParser: Invalid line (unpaired): %s", line) - } - - frame, err := parsePanicFrame(line, lines[i], createdBy) - if err != nil { - return nil, err - } - - stack = append(stack, *frame) - if createdBy { - state = "done" - break - } - } - } - - if state == "done" || state == "parsing" { - return &Error{Err: uncaughtPanic{message}, frames: stack}, nil - } - return nil, Errorf("could not parse panic: %v", text) -} - -// The lines we're passing look like this: -// -// main.(*foo).destruct(0xc208067e98) -// /0/go/src/github.com/bugsnag/bugsnag-go/pan/main.go:22 +0x151 -func parsePanicFrame(name string, line string, createdBy bool) (*StackFrame, error) { - idx := strings.LastIndex(name, "(") - if idx == -1 && !createdBy { - return nil, Errorf("bugsnag.panicParser: Invalid line (no call): %s", name) - } - if idx != -1 { - name = name[:idx] - } - pkg := "" - - if lastslash := strings.LastIndex(name, "/"); lastslash >= 0 { - pkg += name[:lastslash] + "/" - name = name[lastslash+1:] - } - if period := strings.Index(name, "."); period >= 0 { - pkg += name[:period] - name = name[period+1:] - } - - name = strings.Replace(name, "·", ".", -1) - - if !strings.HasPrefix(line, "\t") { - return nil, Errorf("bugsnag.panicParser: Invalid line (no tab): %s", line) - } - - idx = strings.LastIndex(line, ":") - if idx == -1 { - return nil, Errorf("bugsnag.panicParser: Invalid line (no line number): %s", line) - } - file := line[1:idx] - - number := line[idx+1:] - if idx = strings.Index(number, " +"); idx > -1 { - number = number[:idx] - } - - lno, err := strconv.ParseInt(number, 10, 32) - if err != nil { - return nil, Errorf("bugsnag.panicParser: Invalid line (bad line number): %s", line) - } - - return &StackFrame{ - File: file, - LineNumber: int(lno), - Package: pkg, - Name: name, - }, nil -} diff --git a/vendor/github.com/go-errors/errors/stackframe.go b/vendor/github.com/go-errors/errors/stackframe.go deleted file mode 100644 index 750ab9a5..00000000 --- a/vendor/github.com/go-errors/errors/stackframe.go +++ /dev/null @@ -1,102 +0,0 @@ -package errors - -import ( - "bytes" - "fmt" - "io/ioutil" - "runtime" - "strings" -) - -// A StackFrame contains all necessary information about to generate a line -// in a callstack. -type StackFrame struct { - // The path to the file containing this ProgramCounter - File string - // The LineNumber in that file - LineNumber int - // The Name of the function that contains this ProgramCounter - Name string - // The Package that contains this function - Package string - // The underlying ProgramCounter - ProgramCounter uintptr -} - -// NewStackFrame popoulates a stack frame object from the program counter. -func NewStackFrame(pc uintptr) (frame StackFrame) { - - frame = StackFrame{ProgramCounter: pc} - if frame.Func() == nil { - return - } - frame.Package, frame.Name = packageAndName(frame.Func()) - - // pc -1 because the program counters we use are usually return addresses, - // and we want to show the line that corresponds to the function call - frame.File, frame.LineNumber = frame.Func().FileLine(pc - 1) - return - -} - -// Func returns the function that contained this frame. -func (frame *StackFrame) Func() *runtime.Func { - if frame.ProgramCounter == 0 { - return nil - } - return runtime.FuncForPC(frame.ProgramCounter) -} - -// String returns the stackframe formatted in the same way as go does -// in runtime/debug.Stack() -func (frame *StackFrame) String() string { - str := fmt.Sprintf("%s:%d (0x%x)\n", frame.File, frame.LineNumber, frame.ProgramCounter) - - source, err := frame.SourceLine() - if err != nil { - return str - } - - return str + fmt.Sprintf("\t%s: %s\n", frame.Name, source) -} - -// SourceLine gets the line of code (from File and Line) of the original source if possible. -func (frame *StackFrame) SourceLine() (string, error) { - data, err := ioutil.ReadFile(frame.File) - - if err != nil { - return "", New(err) - } - - lines := bytes.Split(data, []byte{'\n'}) - if frame.LineNumber <= 0 || frame.LineNumber >= len(lines) { - return "???", nil - } - // -1 because line-numbers are 1 based, but our array is 0 based - return string(bytes.Trim(lines[frame.LineNumber-1], " \t")), nil -} - -func packageAndName(fn *runtime.Func) (string, string) { - name := fn.Name() - pkg := "" - - // 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 - // Since the package path might contains dots (e.g. code.google.com/...), - // we first remove the path prefix if there is one. - if lastslash := strings.LastIndex(name, "/"); lastslash >= 0 { - pkg += name[:lastslash] + "/" - name = name[lastslash+1:] - } - if period := strings.Index(name, "."); period >= 0 { - pkg += name[:period] - name = name[period+1:] - } - - name = strings.Replace(name, "·", ".", -1) - return pkg, name -} diff --git a/vendor/github.com/golang/mock/AUTHORS b/vendor/github.com/golang/mock/AUTHORS deleted file mode 100644 index 660b8ccc..00000000 --- a/vendor/github.com/golang/mock/AUTHORS +++ /dev/null @@ -1,12 +0,0 @@ -# This is the official list of GoMock authors for copyright purposes. -# This file is distinct from the CONTRIBUTORS files. -# See the latter for an explanation. - -# Names should be added to this file as -# Name or Organization -# The email address is not required for organizations. - -# Please keep the list sorted. - -Alex Reece -Google Inc. diff --git a/vendor/github.com/golang/mock/CONTRIBUTORS b/vendor/github.com/golang/mock/CONTRIBUTORS deleted file mode 100644 index def849ca..00000000 --- a/vendor/github.com/golang/mock/CONTRIBUTORS +++ /dev/null @@ -1,37 +0,0 @@ -# This is the official list of people who can contribute (and typically -# have contributed) code to the gomock repository. -# The AUTHORS file lists the copyright holders; this file -# lists people. For example, Google employees are listed here -# but not in AUTHORS, because Google holds the copyright. -# -# The submission process automatically checks to make sure -# that people submitting code are listed in this file (by email address). -# -# Names should be added to this file only after verifying that -# the individual or the individual's organization has agreed to -# the appropriate Contributor License Agreement, found here: -# -# http://code.google.com/legal/individual-cla-v1.0.html -# http://code.google.com/legal/corporate-cla-v1.0.html -# -# The agreement for individuals can be filled out on the web. -# -# When adding J Random Contributor's name to this file, -# either J's name or J's organization's name should be -# added to the AUTHORS file, depending on whether the -# individual or corporate CLA was used. - -# Names should be added to this file like so: -# Name -# -# An entry with two email addresses specifies that the -# first address should be used in the submit logs and -# that the second address should be recognized as the -# same person when interacting with Rietveld. - -# Please keep the list sorted. - -Aaron Jacobs -Alex Reece -David Symonds -Ryan Barrett diff --git a/vendor/github.com/golang/mock/LICENSE b/vendor/github.com/golang/mock/LICENSE deleted file mode 100644 index d6456956..00000000 --- a/vendor/github.com/golang/mock/LICENSE +++ /dev/null @@ -1,202 +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. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/vendor/github.com/golang/mock/gomock/call.go b/vendor/github.com/golang/mock/gomock/call.go deleted file mode 100644 index 3d54d9f5..00000000 --- a/vendor/github.com/golang/mock/gomock/call.go +++ /dev/null @@ -1,420 +0,0 @@ -// Copyright 2010 Google Inc. -// -// 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 gomock - -import ( - "fmt" - "reflect" - "strconv" - "strings" -) - -// Call represents an expected call to a mock. -type Call struct { - t TestHelper // for triggering test failures on invalid call setup - - receiver interface{} // the receiver of the method call - method string // the name of the method - methodType reflect.Type // the type of the method - args []Matcher // the args - origin string // file and line number of call setup - - preReqs []*Call // prerequisite calls - - // Expectations - minCalls, maxCalls int - - numCalls int // actual number made - - // actions are called when this Call is called. Each action gets the args and - // can set the return values by returning a non-nil slice. Actions run in the - // order they are created. - actions []func([]interface{}) []interface{} -} - -// newCall creates a *Call. It requires the method type in order to support -// unexported methods. -func newCall(t TestHelper, receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call { - t.Helper() - - // TODO: check arity, types. - margs := make([]Matcher, len(args)) - for i, arg := range args { - if m, ok := arg.(Matcher); ok { - margs[i] = m - } else if arg == nil { - // Handle nil specially so that passing a nil interface value - // will match the typed nils of concrete args. - margs[i] = Nil() - } else { - margs[i] = Eq(arg) - } - } - - origin := callerInfo(3) - actions := []func([]interface{}) []interface{}{func([]interface{}) []interface{} { - // Synthesize the zero value for each of the return args' types. - rets := make([]interface{}, methodType.NumOut()) - for i := 0; i < methodType.NumOut(); i++ { - rets[i] = reflect.Zero(methodType.Out(i)).Interface() - } - return rets - }} - return &Call{t: t, receiver: receiver, method: method, methodType: methodType, - args: margs, origin: origin, minCalls: 1, maxCalls: 1, actions: actions} -} - -// AnyTimes allows the expectation to be called 0 or more times -func (c *Call) AnyTimes() *Call { - c.minCalls, c.maxCalls = 0, 1e8 // close enough to infinity - return c -} - -// MinTimes requires the call to occur at least n times. If AnyTimes or MaxTimes have not been called, MinTimes also -// sets the maximum number of calls to infinity. -func (c *Call) MinTimes(n int) *Call { - c.minCalls = n - if c.maxCalls == 1 { - c.maxCalls = 1e8 - } - return c -} - -// MaxTimes limits the number of calls to n times. If AnyTimes or MinTimes have not been called, MaxTimes also -// sets the minimum number of calls to 0. -func (c *Call) MaxTimes(n int) *Call { - c.maxCalls = n - if c.minCalls == 1 { - c.minCalls = 0 - } - return c -} - -// DoAndReturn declares the action to run when the call is matched. -// The return values from this function are returned by the mocked function. -// It takes an interface{} argument to support n-arity functions. -func (c *Call) DoAndReturn(f interface{}) *Call { - // TODO: Check arity and types here, rather than dying badly elsewhere. - v := reflect.ValueOf(f) - - c.addAction(func(args []interface{}) []interface{} { - vargs := make([]reflect.Value, len(args)) - ft := v.Type() - for i := 0; i < len(args); i++ { - if args[i] != nil { - vargs[i] = reflect.ValueOf(args[i]) - } else { - // Use the zero value for the arg. - vargs[i] = reflect.Zero(ft.In(i)) - } - } - vrets := v.Call(vargs) - rets := make([]interface{}, len(vrets)) - for i, ret := range vrets { - rets[i] = ret.Interface() - } - return rets - }) - return c -} - -// Do declares the action to run when the call is matched. The function's -// return values are ignored to retain backward compatibility. To use the -// return values call DoAndReturn. -// It takes an interface{} argument to support n-arity functions. -func (c *Call) Do(f interface{}) *Call { - // TODO: Check arity and types here, rather than dying badly elsewhere. - v := reflect.ValueOf(f) - - c.addAction(func(args []interface{}) []interface{} { - vargs := make([]reflect.Value, len(args)) - ft := v.Type() - for i := 0; i < len(args); i++ { - if args[i] != nil { - vargs[i] = reflect.ValueOf(args[i]) - } else { - // Use the zero value for the arg. - vargs[i] = reflect.Zero(ft.In(i)) - } - } - v.Call(vargs) - return nil - }) - return c -} - -// Return declares the values to be returned by the mocked function call. -func (c *Call) Return(rets ...interface{}) *Call { - c.t.Helper() - - mt := c.methodType - if len(rets) != mt.NumOut() { - c.t.Fatalf("wrong number of arguments to Return for %T.%v: got %d, want %d [%s]", - c.receiver, c.method, len(rets), mt.NumOut(), c.origin) - } - for i, ret := range rets { - if got, want := reflect.TypeOf(ret), mt.Out(i); got == want { - // Identical types; nothing to do. - } else if got == nil { - // Nil needs special handling. - switch want.Kind() { - case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: - // ok - default: - c.t.Fatalf("argument %d to Return for %T.%v is nil, but %v is not nillable [%s]", - i, c.receiver, c.method, want, c.origin) - } - } else if got.AssignableTo(want) { - // Assignable type relation. Make the assignment now so that the generated code - // can return the values with a type assertion. - v := reflect.New(want).Elem() - v.Set(reflect.ValueOf(ret)) - rets[i] = v.Interface() - } else { - c.t.Fatalf("wrong type of argument %d to Return for %T.%v: %v is not assignable to %v [%s]", - i, c.receiver, c.method, got, want, c.origin) - } - } - - c.addAction(func([]interface{}) []interface{} { - return rets - }) - - return c -} - -// Times declares the exact number of times a function call is expected to be executed. -func (c *Call) Times(n int) *Call { - c.minCalls, c.maxCalls = n, n - return c -} - -// SetArg declares an action that will set the nth argument's value, -// indirected through a pointer. Or, in the case of a slice, SetArg -// will copy value's elements into the nth argument. -func (c *Call) SetArg(n int, value interface{}) *Call { - c.t.Helper() - - mt := c.methodType - // TODO: This will break on variadic methods. - // We will need to check those at invocation time. - if n < 0 || n >= mt.NumIn() { - c.t.Fatalf("SetArg(%d, ...) called for a method with %d args [%s]", - n, mt.NumIn(), c.origin) - } - // Permit setting argument through an interface. - // In the interface case, we don't (nay, can't) check the type here. - at := mt.In(n) - switch at.Kind() { - case reflect.Ptr: - dt := at.Elem() - if vt := reflect.TypeOf(value); !vt.AssignableTo(dt) { - c.t.Fatalf("SetArg(%d, ...) argument is a %v, not assignable to %v [%s]", - n, vt, dt, c.origin) - } - case reflect.Interface: - // nothing to do - case reflect.Slice: - // nothing to do - default: - c.t.Fatalf("SetArg(%d, ...) referring to argument of non-pointer non-interface non-slice type %v [%s]", - n, at, c.origin) - } - - c.addAction(func(args []interface{}) []interface{} { - v := reflect.ValueOf(value) - switch reflect.TypeOf(args[n]).Kind() { - case reflect.Slice: - setSlice(args[n], v) - default: - reflect.ValueOf(args[n]).Elem().Set(v) - } - return nil - }) - return c -} - -// isPreReq returns true if other is a direct or indirect prerequisite to c. -func (c *Call) isPreReq(other *Call) bool { - for _, preReq := range c.preReqs { - if other == preReq || preReq.isPreReq(other) { - return true - } - } - return false -} - -// After declares that the call may only match after preReq has been exhausted. -func (c *Call) After(preReq *Call) *Call { - c.t.Helper() - - if c == preReq { - c.t.Fatalf("A call isn't allowed to be its own prerequisite") - } - if preReq.isPreReq(c) { - c.t.Fatalf("Loop in call order: %v is a prerequisite to %v (possibly indirectly).", c, preReq) - } - - c.preReqs = append(c.preReqs, preReq) - return c -} - -// Returns true if the minimum number of calls have been made. -func (c *Call) satisfied() bool { - return c.numCalls >= c.minCalls -} - -// Returns true iff the maximum number of calls have been made. -func (c *Call) exhausted() bool { - return c.numCalls >= c.maxCalls -} - -func (c *Call) String() string { - args := make([]string, len(c.args)) - for i, arg := range c.args { - args[i] = arg.String() - } - arguments := strings.Join(args, ", ") - return fmt.Sprintf("%T.%v(%s) %s", c.receiver, c.method, arguments, c.origin) -} - -// Tests if the given call matches the expected call. -// If yes, returns nil. If no, returns error with message explaining why it does not match. -func (c *Call) matches(args []interface{}) error { - if !c.methodType.IsVariadic() { - if len(args) != len(c.args) { - return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d", - c.origin, len(args), len(c.args)) - } - - for i, m := range c.args { - if !m.Matches(args[i]) { - return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v", - c.origin, strconv.Itoa(i), args[i], m) - } - } - } else { - if len(c.args) < c.methodType.NumIn()-1 { - return fmt.Errorf("Expected call at %s has the wrong number of matchers. Got: %d, want: %d", - c.origin, len(c.args), c.methodType.NumIn()-1) - } - if len(c.args) != c.methodType.NumIn() && len(args) != len(c.args) { - return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: %d", - c.origin, len(args), len(c.args)) - } - if len(args) < len(c.args)-1 { - return fmt.Errorf("Expected call at %s has the wrong number of arguments. Got: %d, want: greater than or equal to %d", - c.origin, len(args), len(c.args)-1) - } - - for i, m := range c.args { - if i < c.methodType.NumIn()-1 { - // Non-variadic args - if !m.Matches(args[i]) { - return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v", - c.origin, strconv.Itoa(i), args[i], m) - } - continue - } - // The last arg has a possibility of a variadic argument, so let it branch - - // sample: Foo(a int, b int, c ...int) - if i < len(c.args) && i < len(args) { - if m.Matches(args[i]) { - // Got Foo(a, b, c) want Foo(matcherA, matcherB, gomock.Any()) - // Got Foo(a, b, c) want Foo(matcherA, matcherB, someSliceMatcher) - // Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC) - // Got Foo(a, b) want Foo(matcherA, matcherB) - // Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD) - continue - } - } - - // The number of actual args don't match the number of matchers, - // or the last matcher is a slice and the last arg is not. - // If this function still matches it is because the last matcher - // matches all the remaining arguments or the lack of any. - // Convert the remaining arguments, if any, into a slice of the - // expected type. - vargsType := c.methodType.In(c.methodType.NumIn() - 1) - vargs := reflect.MakeSlice(vargsType, 0, len(args)-i) - for _, arg := range args[i:] { - vargs = reflect.Append(vargs, reflect.ValueOf(arg)) - } - if m.Matches(vargs.Interface()) { - // Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, gomock.Any()) - // Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, someSliceMatcher) - // Got Foo(a, b) want Foo(matcherA, matcherB, gomock.Any()) - // Got Foo(a, b) want Foo(matcherA, matcherB, someEmptySliceMatcher) - break - } - // Wrong number of matchers or not match. Fail. - // Got Foo(a, b) want Foo(matcherA, matcherB, matcherC, matcherD) - // Got Foo(a, b, c) want Foo(matcherA, matcherB, matcherC, matcherD) - // Got Foo(a, b, c, d) want Foo(matcherA, matcherB, matcherC, matcherD, matcherE) - // Got Foo(a, b, c, d, e) want Foo(matcherA, matcherB, matcherC, matcherD) - // Got Foo(a, b, c) want Foo(matcherA, matcherB) - return fmt.Errorf("Expected call at %s doesn't match the argument at index %s.\nGot: %v\nWant: %v", - c.origin, strconv.Itoa(i), args[i:], c.args[i]) - - } - } - - // Check that all prerequisite calls have been satisfied. - for _, preReqCall := range c.preReqs { - if !preReqCall.satisfied() { - return fmt.Errorf("Expected call at %s doesn't have a prerequisite call satisfied:\n%v\nshould be called before:\n%v", - c.origin, preReqCall, c) - } - } - - // Check that the call is not exhausted. - if c.exhausted() { - return fmt.Errorf("Expected call at %s has already been called the max number of times.", c.origin) - } - - return nil -} - -// dropPrereqs tells the expected Call to not re-check prerequisite calls any -// longer, and to return its current set. -func (c *Call) dropPrereqs() (preReqs []*Call) { - preReqs = c.preReqs - c.preReqs = nil - return -} - -func (c *Call) call(args []interface{}) []func([]interface{}) []interface{} { - c.numCalls++ - return c.actions -} - -// InOrder declares that the given calls should occur in order. -func InOrder(calls ...*Call) { - for i := 1; i < len(calls); i++ { - calls[i].After(calls[i-1]) - } -} - -func setSlice(arg interface{}, v reflect.Value) { - va := reflect.ValueOf(arg) - for i := 0; i < v.Len(); i++ { - va.Index(i).Set(v.Index(i)) - } -} - -func (c *Call) addAction(action func([]interface{}) []interface{}) { - c.actions = append(c.actions, action) -} diff --git a/vendor/github.com/golang/mock/gomock/callset.go b/vendor/github.com/golang/mock/gomock/callset.go deleted file mode 100644 index c44a8a58..00000000 --- a/vendor/github.com/golang/mock/gomock/callset.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2011 Google Inc. -// -// 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 gomock - -import ( - "bytes" - "fmt" -) - -// callSet represents a set of expected calls, indexed by receiver and method -// name. -type callSet struct { - // Calls that are still expected. - expected map[callSetKey][]*Call - // Calls that have been exhausted. - exhausted map[callSetKey][]*Call -} - -// callSetKey is the key in the maps in callSet -type callSetKey struct { - receiver interface{} - fname string -} - -func newCallSet() *callSet { - return &callSet{make(map[callSetKey][]*Call), make(map[callSetKey][]*Call)} -} - -// Add adds a new expected call. -func (cs callSet) Add(call *Call) { - key := callSetKey{call.receiver, call.method} - m := cs.expected - if call.exhausted() { - m = cs.exhausted - } - m[key] = append(m[key], call) -} - -// Remove removes an expected call. -func (cs callSet) Remove(call *Call) { - key := callSetKey{call.receiver, call.method} - calls := cs.expected[key] - for i, c := range calls { - if c == call { - // maintain order for remaining calls - cs.expected[key] = append(calls[:i], calls[i+1:]...) - cs.exhausted[key] = append(cs.exhausted[key], call) - break - } - } -} - -// FindMatch searches for a matching call. Returns error with explanation message if no call matched. -func (cs callSet) FindMatch(receiver interface{}, method string, args []interface{}) (*Call, error) { - key := callSetKey{receiver, method} - - // Search through the expected calls. - expected := cs.expected[key] - var callsErrors bytes.Buffer - for _, call := range expected { - err := call.matches(args) - if err != nil { - fmt.Fprintf(&callsErrors, "\n%v", err) - } else { - return call, nil - } - } - - // If we haven't found a match then search through the exhausted calls so we - // get useful error messages. - exhausted := cs.exhausted[key] - for _, call := range exhausted { - if err := call.matches(args); err != nil { - fmt.Fprintf(&callsErrors, "\n%v", err) - } - } - - if len(expected)+len(exhausted) == 0 { - fmt.Fprintf(&callsErrors, "there are no expected calls of the method %q for that receiver", method) - } - - return nil, fmt.Errorf(callsErrors.String()) -} - -// Failures returns the calls that are not satisfied. -func (cs callSet) Failures() []*Call { - failures := make([]*Call, 0, len(cs.expected)) - for _, calls := range cs.expected { - for _, call := range calls { - if !call.satisfied() { - failures = append(failures, call) - } - } - } - return failures -} diff --git a/vendor/github.com/golang/mock/gomock/controller.go b/vendor/github.com/golang/mock/gomock/controller.go deleted file mode 100644 index 0651c91e..00000000 --- a/vendor/github.com/golang/mock/gomock/controller.go +++ /dev/null @@ -1,264 +0,0 @@ -// Copyright 2010 Google Inc. -// -// 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 gomock is a mock framework for Go. -// -// Standard usage: -// (1) Define an interface that you wish to mock. -// type MyInterface interface { -// SomeMethod(x int64, y string) -// } -// (2) Use mockgen to generate a mock from the interface. -// (3) Use the mock in a test: -// func TestMyThing(t *testing.T) { -// mockCtrl := gomock.NewController(t) -// defer mockCtrl.Finish() -// -// mockObj := something.NewMockMyInterface(mockCtrl) -// mockObj.EXPECT().SomeMethod(4, "blah") -// // pass mockObj to a real object and play with it. -// } -// -// By default, expected calls are not enforced to run in any particular order. -// Call order dependency can be enforced by use of InOrder and/or Call.After. -// Call.After can create more varied call order dependencies, but InOrder is -// often more convenient. -// -// The following examples create equivalent call order dependencies. -// -// Example of using Call.After to chain expected call order: -// -// firstCall := mockObj.EXPECT().SomeMethod(1, "first") -// secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall) -// mockObj.EXPECT().SomeMethod(3, "third").After(secondCall) -// -// Example of using InOrder to declare expected call order: -// -// gomock.InOrder( -// mockObj.EXPECT().SomeMethod(1, "first"), -// mockObj.EXPECT().SomeMethod(2, "second"), -// mockObj.EXPECT().SomeMethod(3, "third"), -// ) -// -// TODO: -// - Handle different argument/return types (e.g. ..., chan, map, interface). -package gomock - -import ( - "context" - "fmt" - "reflect" - "runtime" - "sync" -) - -// A TestReporter is something that can be used to report test failures. It -// is satisfied by the standard library's *testing.T. -type TestReporter interface { - Errorf(format string, args ...interface{}) - Fatalf(format string, args ...interface{}) -} - -// TestHelper is a TestReporter that has the Helper method. It is satisfied -// by the standard library's *testing.T. -type TestHelper interface { - TestReporter - Helper() -} - -// A Controller represents the top-level control of a mock ecosystem. It -// defines the scope and lifetime of mock objects, as well as their -// expectations. It is safe to call Controller's methods from multiple -// goroutines. Each test should create a new Controller and invoke Finish via -// defer. -// -// func TestFoo(t *testing.T) { -// ctrl := gomock.NewController(st) -// defer ctrl.Finish() -// // .. -// } -// -// func TestBar(t *testing.T) { -// t.Run("Sub-Test-1", st) { -// ctrl := gomock.NewController(st) -// defer ctrl.Finish() -// // .. -// }) -// t.Run("Sub-Test-2", st) { -// ctrl := gomock.NewController(st) -// defer ctrl.Finish() -// // .. -// }) -// }) -type Controller struct { - // T should only be called within a generated mock. It is not intended to - // be used in user code and may be changed in future versions. T is the - // TestReporter passed in when creating the Controller via NewController. - // If the TestReporter does not implement a TestHelper it will be wrapped - // with a nopTestHelper. - T TestHelper - mu sync.Mutex - expectedCalls *callSet - finished bool -} - -// NewController returns a new Controller. It is the preferred way to create a -// Controller. -func NewController(t TestReporter) *Controller { - h, ok := t.(TestHelper) - if !ok { - h = nopTestHelper{t} - } - - return &Controller{ - T: h, - expectedCalls: newCallSet(), - } -} - -type cancelReporter struct { - TestHelper - cancel func() -} - -func (r *cancelReporter) Errorf(format string, args ...interface{}) { - r.TestHelper.Errorf(format, args...) -} -func (r *cancelReporter) Fatalf(format string, args ...interface{}) { - defer r.cancel() - r.TestHelper.Fatalf(format, args...) -} - -// WithContext returns a new Controller and a Context, which is cancelled on any -// fatal failure. -func WithContext(ctx context.Context, t TestReporter) (*Controller, context.Context) { - h, ok := t.(TestHelper) - if !ok { - h = nopTestHelper{t} - } - - ctx, cancel := context.WithCancel(ctx) - return NewController(&cancelReporter{h, cancel}), ctx -} - -type nopTestHelper struct { - TestReporter -} - -func (h nopTestHelper) Helper() {} - -// RecordCall is called by a mock. It should not be called by user code. -func (ctrl *Controller) RecordCall(receiver interface{}, method string, args ...interface{}) *Call { - ctrl.T.Helper() - - recv := reflect.ValueOf(receiver) - for i := 0; i < recv.Type().NumMethod(); i++ { - if recv.Type().Method(i).Name == method { - return ctrl.RecordCallWithMethodType(receiver, method, recv.Method(i).Type(), args...) - } - } - ctrl.T.Fatalf("gomock: failed finding method %s on %T", method, receiver) - panic("unreachable") -} - -// RecordCallWithMethodType is called by a mock. It should not be called by user code. -func (ctrl *Controller) RecordCallWithMethodType(receiver interface{}, method string, methodType reflect.Type, args ...interface{}) *Call { - ctrl.T.Helper() - - call := newCall(ctrl.T, receiver, method, methodType, args...) - - ctrl.mu.Lock() - defer ctrl.mu.Unlock() - ctrl.expectedCalls.Add(call) - - return call -} - -// Call is called by a mock. It should not be called by user code. -func (ctrl *Controller) Call(receiver interface{}, method string, args ...interface{}) []interface{} { - ctrl.T.Helper() - - // Nest this code so we can use defer to make sure the lock is released. - actions := func() []func([]interface{}) []interface{} { - ctrl.T.Helper() - ctrl.mu.Lock() - defer ctrl.mu.Unlock() - - expected, err := ctrl.expectedCalls.FindMatch(receiver, method, args) - if err != nil { - origin := callerInfo(2) - ctrl.T.Fatalf("Unexpected call to %T.%v(%v) at %s because: %s", receiver, method, args, origin, err) - } - - // Two things happen here: - // * the matching call no longer needs to check prerequite calls, - // * and the prerequite calls are no longer expected, so remove them. - preReqCalls := expected.dropPrereqs() - for _, preReqCall := range preReqCalls { - ctrl.expectedCalls.Remove(preReqCall) - } - - actions := expected.call(args) - if expected.exhausted() { - ctrl.expectedCalls.Remove(expected) - } - return actions - }() - - var rets []interface{} - for _, action := range actions { - if r := action(args); r != nil { - rets = r - } - } - - return rets -} - -// Finish checks to see if all the methods that were expected to be called -// were called. It should be invoked for each Controller. It is not idempotent -// and therefore can only be invoked once. -func (ctrl *Controller) Finish() { - ctrl.T.Helper() - - ctrl.mu.Lock() - defer ctrl.mu.Unlock() - - if ctrl.finished { - ctrl.T.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.") - } - ctrl.finished = true - - // If we're currently panicking, probably because this is a deferred call, - // pass through the panic. - if err := recover(); err != nil { - panic(err) - } - - // Check that all remaining expected calls are satisfied. - failures := ctrl.expectedCalls.Failures() - for _, call := range failures { - ctrl.T.Errorf("missing call(s) to %v", call) - } - if len(failures) != 0 { - ctrl.T.Fatalf("aborting test due to missing call(s)") - } -} - -func callerInfo(skip int) string { - if _, file, line, ok := runtime.Caller(skip + 1); ok { - return fmt.Sprintf("%s:%d", file, line) - } - return "unknown file" -} diff --git a/vendor/github.com/golang/mock/gomock/matchers.go b/vendor/github.com/golang/mock/gomock/matchers.go deleted file mode 100644 index fbff0606..00000000 --- a/vendor/github.com/golang/mock/gomock/matchers.go +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2010 Google Inc. -// -// 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 gomock - -import ( - "fmt" - "reflect" -) - -// A Matcher is a representation of a class of values. -// It is used to represent the valid or expected arguments to a mocked method. -type Matcher interface { - // Matches returns whether x is a match. - Matches(x interface{}) bool - - // String describes what the matcher matches. - String() string -} - -type anyMatcher struct{} - -func (anyMatcher) Matches(x interface{}) bool { - return true -} - -func (anyMatcher) String() string { - return "is anything" -} - -type eqMatcher struct { - x interface{} -} - -func (e eqMatcher) Matches(x interface{}) bool { - return reflect.DeepEqual(e.x, x) -} - -func (e eqMatcher) String() string { - return fmt.Sprintf("is equal to %v", e.x) -} - -type nilMatcher struct{} - -func (nilMatcher) Matches(x interface{}) bool { - if x == nil { - return true - } - - v := reflect.ValueOf(x) - switch v.Kind() { - case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, - reflect.Ptr, reflect.Slice: - return v.IsNil() - } - - return false -} - -func (nilMatcher) String() string { - return "is nil" -} - -type notMatcher struct { - m Matcher -} - -func (n notMatcher) Matches(x interface{}) bool { - return !n.m.Matches(x) -} - -func (n notMatcher) String() string { - // TODO: Improve this if we add a NotString method to the Matcher interface. - return "not(" + n.m.String() + ")" -} - -type assignableToTypeOfMatcher struct { - targetType reflect.Type -} - -func (m assignableToTypeOfMatcher) Matches(x interface{}) bool { - return reflect.TypeOf(x).AssignableTo(m.targetType) -} - -func (m assignableToTypeOfMatcher) String() string { - return "is assignable to " + m.targetType.Name() -} - -// Constructors -// Any returns a matcher that always matches. -func Any() Matcher { return anyMatcher{} } - -// Eq returns a matcher that matches on equality. -// -// Example usage: -// Eq(5).Matches(5) // returns true -// Eq(5).Matches(4) // returns false -func Eq(x interface{}) Matcher { return eqMatcher{x} } - -// Nil returns a matcher that matches if the received value is nil. -// -// Example usage: -// var x *bytes.Buffer -// Nil().Matches(x) // returns true -// x = &bytes.Buffer{} -// Nil().Matches(x) // returns false -func Nil() Matcher { return nilMatcher{} } - -// Not reverses the results of its given child matcher. -// -// Example usage: -// Not(Eq(5)).Matches(4) // returns true -// Not(Eq(5)).Matches(5) // returns false -func Not(x interface{}) Matcher { - if m, ok := x.(Matcher); ok { - return notMatcher{m} - } - return notMatcher{Eq(x)} -} - -// AssignableToTypeOf is a Matcher that matches if the parameter to the mock -// function is assignable to the type of the parameter to this function. -// -// Example usage: -// var s fmt.Stringer = &bytes.Buffer{} -// AssignableToTypeOf(s).Matches(time.Second) // returns true -// AssignableToTypeOf(s).Matches(99) // returns false -func AssignableToTypeOf(x interface{}) Matcher { - return assignableToTypeOfMatcher{reflect.TypeOf(x)} -} diff --git a/vendor/github.com/jmespath/go-jmespath/.gitignore b/vendor/github.com/jmespath/go-jmespath/.gitignore deleted file mode 100644 index 5091fb07..00000000 --- a/vendor/github.com/jmespath/go-jmespath/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/jpgo -jmespath-fuzz.zip -cpu.out -go-jmespath.test diff --git a/vendor/github.com/jmespath/go-jmespath/.travis.yml b/vendor/github.com/jmespath/go-jmespath/.travis.yml deleted file mode 100644 index 1f980775..00000000 --- a/vendor/github.com/jmespath/go-jmespath/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: go - -sudo: false - -go: - - 1.4 - -install: go get -v -t ./... -script: make test diff --git a/vendor/github.com/jmespath/go-jmespath/LICENSE b/vendor/github.com/jmespath/go-jmespath/LICENSE deleted file mode 100644 index b03310a9..00000000 --- a/vendor/github.com/jmespath/go-jmespath/LICENSE +++ /dev/null @@ -1,13 +0,0 @@ -Copyright 2015 James Saryerwinnie - -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. diff --git a/vendor/github.com/jmespath/go-jmespath/Makefile b/vendor/github.com/jmespath/go-jmespath/Makefile deleted file mode 100644 index a828d284..00000000 --- a/vendor/github.com/jmespath/go-jmespath/Makefile +++ /dev/null @@ -1,44 +0,0 @@ - -CMD = jpgo - -help: - @echo "Please use \`make ' where is one of" - @echo " test to run all the tests" - @echo " build to build the library and jp executable" - @echo " generate to run codegen" - - -generate: - go generate ./... - -build: - rm -f $(CMD) - go build ./... - rm -f cmd/$(CMD)/$(CMD) && cd cmd/$(CMD)/ && go build ./... - mv cmd/$(CMD)/$(CMD) . - -test: - go test -v ./... - -check: - go vet ./... - @echo "golint ./..." - @lint=`golint ./...`; \ - lint=`echo "$$lint" | grep -v "astnodetype_string.go" | grep -v "toktype_string.go"`; \ - echo "$$lint"; \ - if [ "$$lint" != "" ]; then exit 1; fi - -htmlc: - go test -coverprofile="/tmp/jpcov" && go tool cover -html="/tmp/jpcov" && unlink /tmp/jpcov - -buildfuzz: - go-fuzz-build github.com/jmespath/go-jmespath/fuzz - -fuzz: buildfuzz - go-fuzz -bin=./jmespath-fuzz.zip -workdir=fuzz/testdata - -bench: - go test -bench . -cpuprofile cpu.out - -pprof-cpu: - go tool pprof ./go-jmespath.test ./cpu.out diff --git a/vendor/github.com/jmespath/go-jmespath/README.md b/vendor/github.com/jmespath/go-jmespath/README.md deleted file mode 100644 index 187ef676..00000000 --- a/vendor/github.com/jmespath/go-jmespath/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# go-jmespath - A JMESPath implementation in Go - -[![Build Status](https://img.shields.io/travis/jmespath/go-jmespath.svg)](https://travis-ci.org/jmespath/go-jmespath) - - - -See http://jmespath.org for more info. diff --git a/vendor/github.com/jmespath/go-jmespath/api.go b/vendor/github.com/jmespath/go-jmespath/api.go deleted file mode 100644 index 8e26ffee..00000000 --- a/vendor/github.com/jmespath/go-jmespath/api.go +++ /dev/null @@ -1,49 +0,0 @@ -package jmespath - -import "strconv" - -// JMESPath is the epresentation of a compiled JMES path query. A JMESPath is -// safe for concurrent use by multiple goroutines. -type JMESPath struct { - ast ASTNode - intr *treeInterpreter -} - -// Compile parses a JMESPath expression and returns, if successful, a JMESPath -// object that can be used to match against data. -func Compile(expression string) (*JMESPath, error) { - parser := NewParser() - ast, err := parser.Parse(expression) - if err != nil { - return nil, err - } - jmespath := &JMESPath{ast: ast, intr: newInterpreter()} - return jmespath, nil -} - -// MustCompile is like Compile but panics if the expression cannot be parsed. -// It simplifies safe initialization of global variables holding compiled -// JMESPaths. -func MustCompile(expression string) *JMESPath { - jmespath, err := Compile(expression) - if err != nil { - panic(`jmespath: Compile(` + strconv.Quote(expression) + `): ` + err.Error()) - } - return jmespath -} - -// Search evaluates a JMESPath expression against input data and returns the result. -func (jp *JMESPath) Search(data interface{}) (interface{}, error) { - return jp.intr.Execute(jp.ast, data) -} - -// Search evaluates a JMESPath expression against input data and returns the result. -func Search(expression string, data interface{}) (interface{}, error) { - intr := newInterpreter() - parser := NewParser() - ast, err := parser.Parse(expression) - if err != nil { - return nil, err - } - return intr.Execute(ast, data) -} diff --git a/vendor/github.com/jmespath/go-jmespath/astnodetype_string.go b/vendor/github.com/jmespath/go-jmespath/astnodetype_string.go deleted file mode 100644 index 1cd2d239..00000000 --- a/vendor/github.com/jmespath/go-jmespath/astnodetype_string.go +++ /dev/null @@ -1,16 +0,0 @@ -// generated by stringer -type astNodeType; DO NOT EDIT - -package jmespath - -import "fmt" - -const _astNodeType_name = "ASTEmptyASTComparatorASTCurrentNodeASTExpRefASTFunctionExpressionASTFieldASTFilterProjectionASTFlattenASTIdentityASTIndexASTIndexExpressionASTKeyValPairASTLiteralASTMultiSelectHashASTMultiSelectListASTOrExpressionASTAndExpressionASTNotExpressionASTPipeASTProjectionASTSubexpressionASTSliceASTValueProjection" - -var _astNodeType_index = [...]uint16{0, 8, 21, 35, 44, 65, 73, 92, 102, 113, 121, 139, 152, 162, 180, 198, 213, 229, 245, 252, 265, 281, 289, 307} - -func (i astNodeType) String() string { - if i < 0 || i >= astNodeType(len(_astNodeType_index)-1) { - return fmt.Sprintf("astNodeType(%d)", i) - } - return _astNodeType_name[_astNodeType_index[i]:_astNodeType_index[i+1]] -} diff --git a/vendor/github.com/jmespath/go-jmespath/functions.go b/vendor/github.com/jmespath/go-jmespath/functions.go deleted file mode 100644 index 9b7cd89b..00000000 --- a/vendor/github.com/jmespath/go-jmespath/functions.go +++ /dev/null @@ -1,842 +0,0 @@ -package jmespath - -import ( - "encoding/json" - "errors" - "fmt" - "math" - "reflect" - "sort" - "strconv" - "strings" - "unicode/utf8" -) - -type jpFunction func(arguments []interface{}) (interface{}, error) - -type jpType string - -const ( - jpUnknown jpType = "unknown" - jpNumber jpType = "number" - jpString jpType = "string" - jpArray jpType = "array" - jpObject jpType = "object" - jpArrayNumber jpType = "array[number]" - jpArrayString jpType = "array[string]" - jpExpref jpType = "expref" - jpAny jpType = "any" -) - -type functionEntry struct { - name string - arguments []argSpec - handler jpFunction - hasExpRef bool -} - -type argSpec struct { - types []jpType - variadic bool -} - -type byExprString struct { - intr *treeInterpreter - node ASTNode - items []interface{} - hasError bool -} - -func (a *byExprString) Len() int { - return len(a.items) -} -func (a *byExprString) Swap(i, j int) { - a.items[i], a.items[j] = a.items[j], a.items[i] -} -func (a *byExprString) Less(i, j int) bool { - first, err := a.intr.Execute(a.node, a.items[i]) - if err != nil { - a.hasError = true - // Return a dummy value. - return true - } - ith, ok := first.(string) - if !ok { - a.hasError = true - return true - } - second, err := a.intr.Execute(a.node, a.items[j]) - if err != nil { - a.hasError = true - // Return a dummy value. - return true - } - jth, ok := second.(string) - if !ok { - a.hasError = true - return true - } - return ith < jth -} - -type byExprFloat struct { - intr *treeInterpreter - node ASTNode - items []interface{} - hasError bool -} - -func (a *byExprFloat) Len() int { - return len(a.items) -} -func (a *byExprFloat) Swap(i, j int) { - a.items[i], a.items[j] = a.items[j], a.items[i] -} -func (a *byExprFloat) Less(i, j int) bool { - first, err := a.intr.Execute(a.node, a.items[i]) - if err != nil { - a.hasError = true - // Return a dummy value. - return true - } - ith, ok := first.(float64) - if !ok { - a.hasError = true - return true - } - second, err := a.intr.Execute(a.node, a.items[j]) - if err != nil { - a.hasError = true - // Return a dummy value. - return true - } - jth, ok := second.(float64) - if !ok { - a.hasError = true - return true - } - return ith < jth -} - -type functionCaller struct { - functionTable map[string]functionEntry -} - -func newFunctionCaller() *functionCaller { - caller := &functionCaller{} - caller.functionTable = map[string]functionEntry{ - "length": { - name: "length", - arguments: []argSpec{ - {types: []jpType{jpString, jpArray, jpObject}}, - }, - handler: jpfLength, - }, - "starts_with": { - name: "starts_with", - arguments: []argSpec{ - {types: []jpType{jpString}}, - {types: []jpType{jpString}}, - }, - handler: jpfStartsWith, - }, - "abs": { - name: "abs", - arguments: []argSpec{ - {types: []jpType{jpNumber}}, - }, - handler: jpfAbs, - }, - "avg": { - name: "avg", - arguments: []argSpec{ - {types: []jpType{jpArrayNumber}}, - }, - handler: jpfAvg, - }, - "ceil": { - name: "ceil", - arguments: []argSpec{ - {types: []jpType{jpNumber}}, - }, - handler: jpfCeil, - }, - "contains": { - name: "contains", - arguments: []argSpec{ - {types: []jpType{jpArray, jpString}}, - {types: []jpType{jpAny}}, - }, - handler: jpfContains, - }, - "ends_with": { - name: "ends_with", - arguments: []argSpec{ - {types: []jpType{jpString}}, - {types: []jpType{jpString}}, - }, - handler: jpfEndsWith, - }, - "floor": { - name: "floor", - arguments: []argSpec{ - {types: []jpType{jpNumber}}, - }, - handler: jpfFloor, - }, - "map": { - name: "amp", - arguments: []argSpec{ - {types: []jpType{jpExpref}}, - {types: []jpType{jpArray}}, - }, - handler: jpfMap, - hasExpRef: true, - }, - "max": { - name: "max", - arguments: []argSpec{ - {types: []jpType{jpArrayNumber, jpArrayString}}, - }, - handler: jpfMax, - }, - "merge": { - name: "merge", - arguments: []argSpec{ - {types: []jpType{jpObject}, variadic: true}, - }, - handler: jpfMerge, - }, - "max_by": { - name: "max_by", - arguments: []argSpec{ - {types: []jpType{jpArray}}, - {types: []jpType{jpExpref}}, - }, - handler: jpfMaxBy, - hasExpRef: true, - }, - "sum": { - name: "sum", - arguments: []argSpec{ - {types: []jpType{jpArrayNumber}}, - }, - handler: jpfSum, - }, - "min": { - name: "min", - arguments: []argSpec{ - {types: []jpType{jpArrayNumber, jpArrayString}}, - }, - handler: jpfMin, - }, - "min_by": { - name: "min_by", - arguments: []argSpec{ - {types: []jpType{jpArray}}, - {types: []jpType{jpExpref}}, - }, - handler: jpfMinBy, - hasExpRef: true, - }, - "type": { - name: "type", - arguments: []argSpec{ - {types: []jpType{jpAny}}, - }, - handler: jpfType, - }, - "keys": { - name: "keys", - arguments: []argSpec{ - {types: []jpType{jpObject}}, - }, - handler: jpfKeys, - }, - "values": { - name: "values", - arguments: []argSpec{ - {types: []jpType{jpObject}}, - }, - handler: jpfValues, - }, - "sort": { - name: "sort", - arguments: []argSpec{ - {types: []jpType{jpArrayString, jpArrayNumber}}, - }, - handler: jpfSort, - }, - "sort_by": { - name: "sort_by", - arguments: []argSpec{ - {types: []jpType{jpArray}}, - {types: []jpType{jpExpref}}, - }, - handler: jpfSortBy, - hasExpRef: true, - }, - "join": { - name: "join", - arguments: []argSpec{ - {types: []jpType{jpString}}, - {types: []jpType{jpArrayString}}, - }, - handler: jpfJoin, - }, - "reverse": { - name: "reverse", - arguments: []argSpec{ - {types: []jpType{jpArray, jpString}}, - }, - handler: jpfReverse, - }, - "to_array": { - name: "to_array", - arguments: []argSpec{ - {types: []jpType{jpAny}}, - }, - handler: jpfToArray, - }, - "to_string": { - name: "to_string", - arguments: []argSpec{ - {types: []jpType{jpAny}}, - }, - handler: jpfToString, - }, - "to_number": { - name: "to_number", - arguments: []argSpec{ - {types: []jpType{jpAny}}, - }, - handler: jpfToNumber, - }, - "not_null": { - name: "not_null", - arguments: []argSpec{ - {types: []jpType{jpAny}, variadic: true}, - }, - handler: jpfNotNull, - }, - } - return caller -} - -func (e *functionEntry) resolveArgs(arguments []interface{}) ([]interface{}, error) { - if len(e.arguments) == 0 { - return arguments, nil - } - if !e.arguments[len(e.arguments)-1].variadic { - if len(e.arguments) != len(arguments) { - return nil, errors.New("incorrect number of args") - } - for i, spec := range e.arguments { - userArg := arguments[i] - err := spec.typeCheck(userArg) - if err != nil { - return nil, err - } - } - return arguments, nil - } - if len(arguments) < len(e.arguments) { - return nil, errors.New("Invalid arity.") - } - return arguments, nil -} - -func (a *argSpec) typeCheck(arg interface{}) error { - for _, t := range a.types { - switch t { - case jpNumber: - if _, ok := arg.(float64); ok { - return nil - } - case jpString: - if _, ok := arg.(string); ok { - return nil - } - case jpArray: - if isSliceType(arg) { - return nil - } - case jpObject: - if _, ok := arg.(map[string]interface{}); ok { - return nil - } - case jpArrayNumber: - if _, ok := toArrayNum(arg); ok { - return nil - } - case jpArrayString: - if _, ok := toArrayStr(arg); ok { - return nil - } - case jpAny: - return nil - case jpExpref: - if _, ok := arg.(expRef); ok { - return nil - } - } - } - return fmt.Errorf("Invalid type for: %v, expected: %#v", arg, a.types) -} - -func (f *functionCaller) CallFunction(name string, arguments []interface{}, intr *treeInterpreter) (interface{}, error) { - entry, ok := f.functionTable[name] - if !ok { - return nil, errors.New("unknown function: " + name) - } - resolvedArgs, err := entry.resolveArgs(arguments) - if err != nil { - return nil, err - } - if entry.hasExpRef { - var extra []interface{} - extra = append(extra, intr) - resolvedArgs = append(extra, resolvedArgs...) - } - return entry.handler(resolvedArgs) -} - -func jpfAbs(arguments []interface{}) (interface{}, error) { - num := arguments[0].(float64) - return math.Abs(num), nil -} - -func jpfLength(arguments []interface{}) (interface{}, error) { - arg := arguments[0] - if c, ok := arg.(string); ok { - return float64(utf8.RuneCountInString(c)), nil - } else if isSliceType(arg) { - v := reflect.ValueOf(arg) - return float64(v.Len()), nil - } else if c, ok := arg.(map[string]interface{}); ok { - return float64(len(c)), nil - } - return nil, errors.New("could not compute length()") -} - -func jpfStartsWith(arguments []interface{}) (interface{}, error) { - search := arguments[0].(string) - prefix := arguments[1].(string) - return strings.HasPrefix(search, prefix), nil -} - -func jpfAvg(arguments []interface{}) (interface{}, error) { - // We've already type checked the value so we can safely use - // type assertions. - args := arguments[0].([]interface{}) - length := float64(len(args)) - numerator := 0.0 - for _, n := range args { - numerator += n.(float64) - } - return numerator / length, nil -} -func jpfCeil(arguments []interface{}) (interface{}, error) { - val := arguments[0].(float64) - return math.Ceil(val), nil -} -func jpfContains(arguments []interface{}) (interface{}, error) { - search := arguments[0] - el := arguments[1] - if searchStr, ok := search.(string); ok { - if elStr, ok := el.(string); ok { - return strings.Index(searchStr, elStr) != -1, nil - } - return false, nil - } - // Otherwise this is a generic contains for []interface{} - general := search.([]interface{}) - for _, item := range general { - if item == el { - return true, nil - } - } - return false, nil -} -func jpfEndsWith(arguments []interface{}) (interface{}, error) { - search := arguments[0].(string) - suffix := arguments[1].(string) - return strings.HasSuffix(search, suffix), nil -} -func jpfFloor(arguments []interface{}) (interface{}, error) { - val := arguments[0].(float64) - return math.Floor(val), nil -} -func jpfMap(arguments []interface{}) (interface{}, error) { - intr := arguments[0].(*treeInterpreter) - exp := arguments[1].(expRef) - node := exp.ref - arr := arguments[2].([]interface{}) - mapped := make([]interface{}, 0, len(arr)) - for _, value := range arr { - current, err := intr.Execute(node, value) - if err != nil { - return nil, err - } - mapped = append(mapped, current) - } - return mapped, nil -} -func jpfMax(arguments []interface{}) (interface{}, error) { - if items, ok := toArrayNum(arguments[0]); ok { - if len(items) == 0 { - return nil, nil - } - if len(items) == 1 { - return items[0], nil - } - best := items[0] - for _, item := range items[1:] { - if item > best { - best = item - } - } - return best, nil - } - // Otherwise we're dealing with a max() of strings. - items, _ := toArrayStr(arguments[0]) - if len(items) == 0 { - return nil, nil - } - if len(items) == 1 { - return items[0], nil - } - best := items[0] - for _, item := range items[1:] { - if item > best { - best = item - } - } - return best, nil -} -func jpfMerge(arguments []interface{}) (interface{}, error) { - final := make(map[string]interface{}) - for _, m := range arguments { - mapped := m.(map[string]interface{}) - for key, value := range mapped { - final[key] = value - } - } - return final, nil -} -func jpfMaxBy(arguments []interface{}) (interface{}, error) { - intr := arguments[0].(*treeInterpreter) - arr := arguments[1].([]interface{}) - exp := arguments[2].(expRef) - node := exp.ref - if len(arr) == 0 { - return nil, nil - } else if len(arr) == 1 { - return arr[0], nil - } - start, err := intr.Execute(node, arr[0]) - if err != nil { - return nil, err - } - switch t := start.(type) { - case float64: - bestVal := t - bestItem := arr[0] - for _, item := range arr[1:] { - result, err := intr.Execute(node, item) - if err != nil { - return nil, err - } - current, ok := result.(float64) - if !ok { - return nil, errors.New("invalid type, must be number") - } - if current > bestVal { - bestVal = current - bestItem = item - } - } - return bestItem, nil - case string: - bestVal := t - bestItem := arr[0] - for _, item := range arr[1:] { - result, err := intr.Execute(node, item) - if err != nil { - return nil, err - } - current, ok := result.(string) - if !ok { - return nil, errors.New("invalid type, must be string") - } - if current > bestVal { - bestVal = current - bestItem = item - } - } - return bestItem, nil - default: - return nil, errors.New("invalid type, must be number of string") - } -} -func jpfSum(arguments []interface{}) (interface{}, error) { - items, _ := toArrayNum(arguments[0]) - sum := 0.0 - for _, item := range items { - sum += item - } - return sum, nil -} - -func jpfMin(arguments []interface{}) (interface{}, error) { - if items, ok := toArrayNum(arguments[0]); ok { - if len(items) == 0 { - return nil, nil - } - if len(items) == 1 { - return items[0], nil - } - best := items[0] - for _, item := range items[1:] { - if item < best { - best = item - } - } - return best, nil - } - items, _ := toArrayStr(arguments[0]) - if len(items) == 0 { - return nil, nil - } - if len(items) == 1 { - return items[0], nil - } - best := items[0] - for _, item := range items[1:] { - if item < best { - best = item - } - } - return best, nil -} - -func jpfMinBy(arguments []interface{}) (interface{}, error) { - intr := arguments[0].(*treeInterpreter) - arr := arguments[1].([]interface{}) - exp := arguments[2].(expRef) - node := exp.ref - if len(arr) == 0 { - return nil, nil - } else if len(arr) == 1 { - return arr[0], nil - } - start, err := intr.Execute(node, arr[0]) - if err != nil { - return nil, err - } - if t, ok := start.(float64); ok { - bestVal := t - bestItem := arr[0] - for _, item := range arr[1:] { - result, err := intr.Execute(node, item) - if err != nil { - return nil, err - } - current, ok := result.(float64) - if !ok { - return nil, errors.New("invalid type, must be number") - } - if current < bestVal { - bestVal = current - bestItem = item - } - } - return bestItem, nil - } else if t, ok := start.(string); ok { - bestVal := t - bestItem := arr[0] - for _, item := range arr[1:] { - result, err := intr.Execute(node, item) - if err != nil { - return nil, err - } - current, ok := result.(string) - if !ok { - return nil, errors.New("invalid type, must be string") - } - if current < bestVal { - bestVal = current - bestItem = item - } - } - return bestItem, nil - } else { - return nil, errors.New("invalid type, must be number of string") - } -} -func jpfType(arguments []interface{}) (interface{}, error) { - arg := arguments[0] - if _, ok := arg.(float64); ok { - return "number", nil - } - if _, ok := arg.(string); ok { - return "string", nil - } - if _, ok := arg.([]interface{}); ok { - return "array", nil - } - if _, ok := arg.(map[string]interface{}); ok { - return "object", nil - } - if arg == nil { - return "null", nil - } - if arg == true || arg == false { - return "boolean", nil - } - return nil, errors.New("unknown type") -} -func jpfKeys(arguments []interface{}) (interface{}, error) { - arg := arguments[0].(map[string]interface{}) - collected := make([]interface{}, 0, len(arg)) - for key := range arg { - collected = append(collected, key) - } - return collected, nil -} -func jpfValues(arguments []interface{}) (interface{}, error) { - arg := arguments[0].(map[string]interface{}) - collected := make([]interface{}, 0, len(arg)) - for _, value := range arg { - collected = append(collected, value) - } - return collected, nil -} -func jpfSort(arguments []interface{}) (interface{}, error) { - if items, ok := toArrayNum(arguments[0]); ok { - d := sort.Float64Slice(items) - sort.Stable(d) - final := make([]interface{}, len(d)) - for i, val := range d { - final[i] = val - } - return final, nil - } - // Otherwise we're dealing with sort()'ing strings. - items, _ := toArrayStr(arguments[0]) - d := sort.StringSlice(items) - sort.Stable(d) - final := make([]interface{}, len(d)) - for i, val := range d { - final[i] = val - } - return final, nil -} -func jpfSortBy(arguments []interface{}) (interface{}, error) { - intr := arguments[0].(*treeInterpreter) - arr := arguments[1].([]interface{}) - exp := arguments[2].(expRef) - node := exp.ref - if len(arr) == 0 { - return arr, nil - } else if len(arr) == 1 { - return arr, nil - } - start, err := intr.Execute(node, arr[0]) - if err != nil { - return nil, err - } - if _, ok := start.(float64); ok { - sortable := &byExprFloat{intr, node, arr, false} - sort.Stable(sortable) - if sortable.hasError { - return nil, errors.New("error in sort_by comparison") - } - return arr, nil - } else if _, ok := start.(string); ok { - sortable := &byExprString{intr, node, arr, false} - sort.Stable(sortable) - if sortable.hasError { - return nil, errors.New("error in sort_by comparison") - } - return arr, nil - } else { - return nil, errors.New("invalid type, must be number of string") - } -} -func jpfJoin(arguments []interface{}) (interface{}, error) { - sep := arguments[0].(string) - // We can't just do arguments[1].([]string), we have to - // manually convert each item to a string. - arrayStr := []string{} - for _, item := range arguments[1].([]interface{}) { - arrayStr = append(arrayStr, item.(string)) - } - return strings.Join(arrayStr, sep), nil -} -func jpfReverse(arguments []interface{}) (interface{}, error) { - if s, ok := arguments[0].(string); ok { - r := []rune(s) - for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 { - r[i], r[j] = r[j], r[i] - } - return string(r), nil - } - items := arguments[0].([]interface{}) - length := len(items) - reversed := make([]interface{}, length) - for i, item := range items { - reversed[length-(i+1)] = item - } - return reversed, nil -} -func jpfToArray(arguments []interface{}) (interface{}, error) { - if _, ok := arguments[0].([]interface{}); ok { - return arguments[0], nil - } - return arguments[:1:1], nil -} -func jpfToString(arguments []interface{}) (interface{}, error) { - if v, ok := arguments[0].(string); ok { - return v, nil - } - result, err := json.Marshal(arguments[0]) - if err != nil { - return nil, err - } - return string(result), nil -} -func jpfToNumber(arguments []interface{}) (interface{}, error) { - arg := arguments[0] - if v, ok := arg.(float64); ok { - return v, nil - } - if v, ok := arg.(string); ok { - conv, err := strconv.ParseFloat(v, 64) - if err != nil { - return nil, nil - } - return conv, nil - } - if _, ok := arg.([]interface{}); ok { - return nil, nil - } - if _, ok := arg.(map[string]interface{}); ok { - return nil, nil - } - if arg == nil { - return nil, nil - } - if arg == true || arg == false { - return nil, nil - } - return nil, errors.New("unknown type") -} -func jpfNotNull(arguments []interface{}) (interface{}, error) { - for _, arg := range arguments { - if arg != nil { - return arg, nil - } - } - return nil, nil -} diff --git a/vendor/github.com/jmespath/go-jmespath/interpreter.go b/vendor/github.com/jmespath/go-jmespath/interpreter.go deleted file mode 100644 index 13c74604..00000000 --- a/vendor/github.com/jmespath/go-jmespath/interpreter.go +++ /dev/null @@ -1,418 +0,0 @@ -package jmespath - -import ( - "errors" - "reflect" - "unicode" - "unicode/utf8" -) - -/* This is a tree based interpreter. It walks the AST and directly - interprets the AST to search through a JSON document. -*/ - -type treeInterpreter struct { - fCall *functionCaller -} - -func newInterpreter() *treeInterpreter { - interpreter := treeInterpreter{} - interpreter.fCall = newFunctionCaller() - return &interpreter -} - -type expRef struct { - ref ASTNode -} - -// Execute takes an ASTNode and input data and interprets the AST directly. -// It will produce the result of applying the JMESPath expression associated -// with the ASTNode to the input data "value". -func (intr *treeInterpreter) Execute(node ASTNode, value interface{}) (interface{}, error) { - switch node.nodeType { - case ASTComparator: - left, err := intr.Execute(node.children[0], value) - if err != nil { - return nil, err - } - right, err := intr.Execute(node.children[1], value) - if err != nil { - return nil, err - } - switch node.value { - case tEQ: - return objsEqual(left, right), nil - case tNE: - return !objsEqual(left, right), nil - } - leftNum, ok := left.(float64) - if !ok { - return nil, nil - } - rightNum, ok := right.(float64) - if !ok { - return nil, nil - } - switch node.value { - case tGT: - return leftNum > rightNum, nil - case tGTE: - return leftNum >= rightNum, nil - case tLT: - return leftNum < rightNum, nil - case tLTE: - return leftNum <= rightNum, nil - } - case ASTExpRef: - return expRef{ref: node.children[0]}, nil - case ASTFunctionExpression: - resolvedArgs := []interface{}{} - for _, arg := range node.children { - current, err := intr.Execute(arg, value) - if err != nil { - return nil, err - } - resolvedArgs = append(resolvedArgs, current) - } - return intr.fCall.CallFunction(node.value.(string), resolvedArgs, intr) - case ASTField: - if m, ok := value.(map[string]interface{}); ok { - key := node.value.(string) - return m[key], nil - } - return intr.fieldFromStruct(node.value.(string), value) - case ASTFilterProjection: - left, err := intr.Execute(node.children[0], value) - if err != nil { - return nil, nil - } - sliceType, ok := left.([]interface{}) - if !ok { - if isSliceType(left) { - return intr.filterProjectionWithReflection(node, left) - } - return nil, nil - } - compareNode := node.children[2] - collected := []interface{}{} - for _, element := range sliceType { - result, err := intr.Execute(compareNode, element) - if err != nil { - return nil, err - } - if !isFalse(result) { - current, err := intr.Execute(node.children[1], element) - if err != nil { - return nil, err - } - if current != nil { - collected = append(collected, current) - } - } - } - return collected, nil - case ASTFlatten: - left, err := intr.Execute(node.children[0], value) - if err != nil { - return nil, nil - } - sliceType, ok := left.([]interface{}) - if !ok { - // If we can't type convert to []interface{}, there's - // a chance this could still work via reflection if we're - // dealing with user provided types. - if isSliceType(left) { - return intr.flattenWithReflection(left) - } - return nil, nil - } - flattened := []interface{}{} - for _, element := range sliceType { - if elementSlice, ok := element.([]interface{}); ok { - flattened = append(flattened, elementSlice...) - } else if isSliceType(element) { - reflectFlat := []interface{}{} - v := reflect.ValueOf(element) - for i := 0; i < v.Len(); i++ { - reflectFlat = append(reflectFlat, v.Index(i).Interface()) - } - flattened = append(flattened, reflectFlat...) - } else { - flattened = append(flattened, element) - } - } - return flattened, nil - case ASTIdentity, ASTCurrentNode: - return value, nil - case ASTIndex: - if sliceType, ok := value.([]interface{}); ok { - index := node.value.(int) - if index < 0 { - index += len(sliceType) - } - if index < len(sliceType) && index >= 0 { - return sliceType[index], nil - } - return nil, nil - } - // Otherwise try via reflection. - rv := reflect.ValueOf(value) - if rv.Kind() == reflect.Slice { - index := node.value.(int) - if index < 0 { - index += rv.Len() - } - if index < rv.Len() && index >= 0 { - v := rv.Index(index) - return v.Interface(), nil - } - } - return nil, nil - case ASTKeyValPair: - return intr.Execute(node.children[0], value) - case ASTLiteral: - return node.value, nil - case ASTMultiSelectHash: - if value == nil { - return nil, nil - } - collected := make(map[string]interface{}) - for _, child := range node.children { - current, err := intr.Execute(child, value) - if err != nil { - return nil, err - } - key := child.value.(string) - collected[key] = current - } - return collected, nil - case ASTMultiSelectList: - if value == nil { - return nil, nil - } - collected := []interface{}{} - for _, child := range node.children { - current, err := intr.Execute(child, value) - if err != nil { - return nil, err - } - collected = append(collected, current) - } - return collected, nil - case ASTOrExpression: - matched, err := intr.Execute(node.children[0], value) - if err != nil { - return nil, err - } - if isFalse(matched) { - matched, err = intr.Execute(node.children[1], value) - if err != nil { - return nil, err - } - } - return matched, nil - case ASTAndExpression: - matched, err := intr.Execute(node.children[0], value) - if err != nil { - return nil, err - } - if isFalse(matched) { - return matched, nil - } - return intr.Execute(node.children[1], value) - case ASTNotExpression: - matched, err := intr.Execute(node.children[0], value) - if err != nil { - return nil, err - } - if isFalse(matched) { - return true, nil - } - return false, nil - case ASTPipe: - result := value - var err error - for _, child := range node.children { - result, err = intr.Execute(child, result) - if err != nil { - return nil, err - } - } - return result, nil - case ASTProjection: - left, err := intr.Execute(node.children[0], value) - if err != nil { - return nil, err - } - sliceType, ok := left.([]interface{}) - if !ok { - if isSliceType(left) { - return intr.projectWithReflection(node, left) - } - return nil, nil - } - collected := []interface{}{} - var current interface{} - for _, element := range sliceType { - current, err = intr.Execute(node.children[1], element) - if err != nil { - return nil, err - } - if current != nil { - collected = append(collected, current) - } - } - return collected, nil - case ASTSubexpression, ASTIndexExpression: - left, err := intr.Execute(node.children[0], value) - if err != nil { - return nil, err - } - return intr.Execute(node.children[1], left) - case ASTSlice: - sliceType, ok := value.([]interface{}) - if !ok { - if isSliceType(value) { - return intr.sliceWithReflection(node, value) - } - return nil, nil - } - parts := node.value.([]*int) - sliceParams := make([]sliceParam, 3) - for i, part := range parts { - if part != nil { - sliceParams[i].Specified = true - sliceParams[i].N = *part - } - } - return slice(sliceType, sliceParams) - case ASTValueProjection: - left, err := intr.Execute(node.children[0], value) - if err != nil { - return nil, nil - } - mapType, ok := left.(map[string]interface{}) - if !ok { - return nil, nil - } - values := make([]interface{}, len(mapType)) - for _, value := range mapType { - values = append(values, value) - } - collected := []interface{}{} - for _, element := range values { - current, err := intr.Execute(node.children[1], element) - if err != nil { - return nil, err - } - if current != nil { - collected = append(collected, current) - } - } - return collected, nil - } - return nil, errors.New("Unknown AST node: " + node.nodeType.String()) -} - -func (intr *treeInterpreter) fieldFromStruct(key string, value interface{}) (interface{}, error) { - rv := reflect.ValueOf(value) - first, n := utf8.DecodeRuneInString(key) - fieldName := string(unicode.ToUpper(first)) + key[n:] - if rv.Kind() == reflect.Struct { - v := rv.FieldByName(fieldName) - if !v.IsValid() { - return nil, nil - } - return v.Interface(), nil - } else if rv.Kind() == reflect.Ptr { - // Handle multiple levels of indirection? - if rv.IsNil() { - return nil, nil - } - rv = rv.Elem() - v := rv.FieldByName(fieldName) - if !v.IsValid() { - return nil, nil - } - return v.Interface(), nil - } - return nil, nil -} - -func (intr *treeInterpreter) flattenWithReflection(value interface{}) (interface{}, error) { - v := reflect.ValueOf(value) - flattened := []interface{}{} - for i := 0; i < v.Len(); i++ { - element := v.Index(i).Interface() - if reflect.TypeOf(element).Kind() == reflect.Slice { - // Then insert the contents of the element - // slice into the flattened slice, - // i.e flattened = append(flattened, mySlice...) - elementV := reflect.ValueOf(element) - for j := 0; j < elementV.Len(); j++ { - flattened = append( - flattened, elementV.Index(j).Interface()) - } - } else { - flattened = append(flattened, element) - } - } - return flattened, nil -} - -func (intr *treeInterpreter) sliceWithReflection(node ASTNode, value interface{}) (interface{}, error) { - v := reflect.ValueOf(value) - parts := node.value.([]*int) - sliceParams := make([]sliceParam, 3) - for i, part := range parts { - if part != nil { - sliceParams[i].Specified = true - sliceParams[i].N = *part - } - } - final := []interface{}{} - for i := 0; i < v.Len(); i++ { - element := v.Index(i).Interface() - final = append(final, element) - } - return slice(final, sliceParams) -} - -func (intr *treeInterpreter) filterProjectionWithReflection(node ASTNode, value interface{}) (interface{}, error) { - compareNode := node.children[2] - collected := []interface{}{} - v := reflect.ValueOf(value) - for i := 0; i < v.Len(); i++ { - element := v.Index(i).Interface() - result, err := intr.Execute(compareNode, element) - if err != nil { - return nil, err - } - if !isFalse(result) { - current, err := intr.Execute(node.children[1], element) - if err != nil { - return nil, err - } - if current != nil { - collected = append(collected, current) - } - } - } - return collected, nil -} - -func (intr *treeInterpreter) projectWithReflection(node ASTNode, value interface{}) (interface{}, error) { - collected := []interface{}{} - v := reflect.ValueOf(value) - for i := 0; i < v.Len(); i++ { - element := v.Index(i).Interface() - result, err := intr.Execute(node.children[1], element) - if err != nil { - return nil, err - } - if result != nil { - collected = append(collected, result) - } - } - return collected, nil -} diff --git a/vendor/github.com/jmespath/go-jmespath/lexer.go b/vendor/github.com/jmespath/go-jmespath/lexer.go deleted file mode 100644 index 817900c8..00000000 --- a/vendor/github.com/jmespath/go-jmespath/lexer.go +++ /dev/null @@ -1,420 +0,0 @@ -package jmespath - -import ( - "bytes" - "encoding/json" - "fmt" - "strconv" - "strings" - "unicode/utf8" -) - -type token struct { - tokenType tokType - value string - position int - length int -} - -type tokType int - -const eof = -1 - -// Lexer contains information about the expression being tokenized. -type Lexer struct { - expression string // The expression provided by the user. - currentPos int // The current position in the string. - lastWidth int // The width of the current rune. This - buf bytes.Buffer // Internal buffer used for building up values. -} - -// SyntaxError is the main error used whenever a lexing or parsing error occurs. -type SyntaxError struct { - msg string // Error message displayed to user - Expression string // Expression that generated a SyntaxError - Offset int // The location in the string where the error occurred -} - -func (e SyntaxError) Error() string { - // In the future, it would be good to underline the specific - // location where the error occurred. - return "SyntaxError: " + e.msg -} - -// HighlightLocation will show where the syntax error occurred. -// It will place a "^" character on a line below the expression -// at the point where the syntax error occurred. -func (e SyntaxError) HighlightLocation() string { - return e.Expression + "\n" + strings.Repeat(" ", e.Offset) + "^" -} - -//go:generate stringer -type=tokType -const ( - tUnknown tokType = iota - tStar - tDot - tFilter - tFlatten - tLparen - tRparen - tLbracket - tRbracket - tLbrace - tRbrace - tOr - tPipe - tNumber - tUnquotedIdentifier - tQuotedIdentifier - tComma - tColon - tLT - tLTE - tGT - tGTE - tEQ - tNE - tJSONLiteral - tStringLiteral - tCurrent - tExpref - tAnd - tNot - tEOF -) - -var basicTokens = map[rune]tokType{ - '.': tDot, - '*': tStar, - ',': tComma, - ':': tColon, - '{': tLbrace, - '}': tRbrace, - ']': tRbracket, // tLbracket not included because it could be "[]" - '(': tLparen, - ')': tRparen, - '@': tCurrent, -} - -// Bit mask for [a-zA-Z_] shifted down 64 bits to fit in a single uint64. -// When using this bitmask just be sure to shift the rune down 64 bits -// before checking against identifierStartBits. -const identifierStartBits uint64 = 576460745995190270 - -// Bit mask for [a-zA-Z0-9], 128 bits -> 2 uint64s. -var identifierTrailingBits = [2]uint64{287948901175001088, 576460745995190270} - -var whiteSpace = map[rune]bool{ - ' ': true, '\t': true, '\n': true, '\r': true, -} - -func (t token) String() string { - return fmt.Sprintf("Token{%+v, %s, %d, %d}", - t.tokenType, t.value, t.position, t.length) -} - -// NewLexer creates a new JMESPath lexer. -func NewLexer() *Lexer { - lexer := Lexer{} - return &lexer -} - -func (lexer *Lexer) next() rune { - if lexer.currentPos >= len(lexer.expression) { - lexer.lastWidth = 0 - return eof - } - r, w := utf8.DecodeRuneInString(lexer.expression[lexer.currentPos:]) - lexer.lastWidth = w - lexer.currentPos += w - return r -} - -func (lexer *Lexer) back() { - lexer.currentPos -= lexer.lastWidth -} - -func (lexer *Lexer) peek() rune { - t := lexer.next() - lexer.back() - return t -} - -// tokenize takes an expression and returns corresponding tokens. -func (lexer *Lexer) tokenize(expression string) ([]token, error) { - var tokens []token - lexer.expression = expression - lexer.currentPos = 0 - lexer.lastWidth = 0 -loop: - for { - r := lexer.next() - if identifierStartBits&(1<<(uint64(r)-64)) > 0 { - t := lexer.consumeUnquotedIdentifier() - tokens = append(tokens, t) - } else if val, ok := basicTokens[r]; ok { - // Basic single char token. - t := token{ - tokenType: val, - value: string(r), - position: lexer.currentPos - lexer.lastWidth, - length: 1, - } - tokens = append(tokens, t) - } else if r == '-' || (r >= '0' && r <= '9') { - t := lexer.consumeNumber() - tokens = append(tokens, t) - } else if r == '[' { - t := lexer.consumeLBracket() - tokens = append(tokens, t) - } else if r == '"' { - t, err := lexer.consumeQuotedIdentifier() - if err != nil { - return tokens, err - } - tokens = append(tokens, t) - } else if r == '\'' { - t, err := lexer.consumeRawStringLiteral() - if err != nil { - return tokens, err - } - tokens = append(tokens, t) - } else if r == '`' { - t, err := lexer.consumeLiteral() - if err != nil { - return tokens, err - } - tokens = append(tokens, t) - } else if r == '|' { - t := lexer.matchOrElse(r, '|', tOr, tPipe) - tokens = append(tokens, t) - } else if r == '<' { - t := lexer.matchOrElse(r, '=', tLTE, tLT) - tokens = append(tokens, t) - } else if r == '>' { - t := lexer.matchOrElse(r, '=', tGTE, tGT) - tokens = append(tokens, t) - } else if r == '!' { - t := lexer.matchOrElse(r, '=', tNE, tNot) - tokens = append(tokens, t) - } else if r == '=' { - t := lexer.matchOrElse(r, '=', tEQ, tUnknown) - tokens = append(tokens, t) - } else if r == '&' { - t := lexer.matchOrElse(r, '&', tAnd, tExpref) - tokens = append(tokens, t) - } else if r == eof { - break loop - } else if _, ok := whiteSpace[r]; ok { - // Ignore whitespace - } else { - return tokens, lexer.syntaxError(fmt.Sprintf("Unknown char: %s", strconv.QuoteRuneToASCII(r))) - } - } - tokens = append(tokens, token{tEOF, "", len(lexer.expression), 0}) - return tokens, nil -} - -// Consume characters until the ending rune "r" is reached. -// If the end of the expression is reached before seeing the -// terminating rune "r", then an error is returned. -// If no error occurs then the matching substring is returned. -// The returned string will not include the ending rune. -func (lexer *Lexer) consumeUntil(end rune) (string, error) { - start := lexer.currentPos - current := lexer.next() - for current != end && current != eof { - if current == '\\' && lexer.peek() != eof { - lexer.next() - } - current = lexer.next() - } - if lexer.lastWidth == 0 { - // Then we hit an EOF so we never reached the closing - // delimiter. - return "", SyntaxError{ - msg: "Unclosed delimiter: " + string(end), - Expression: lexer.expression, - Offset: len(lexer.expression), - } - } - return lexer.expression[start : lexer.currentPos-lexer.lastWidth], nil -} - -func (lexer *Lexer) consumeLiteral() (token, error) { - start := lexer.currentPos - value, err := lexer.consumeUntil('`') - if err != nil { - return token{}, err - } - value = strings.Replace(value, "\\`", "`", -1) - return token{ - tokenType: tJSONLiteral, - value: value, - position: start, - length: len(value), - }, nil -} - -func (lexer *Lexer) consumeRawStringLiteral() (token, error) { - start := lexer.currentPos - currentIndex := start - current := lexer.next() - for current != '\'' && lexer.peek() != eof { - if current == '\\' && lexer.peek() == '\'' { - chunk := lexer.expression[currentIndex : lexer.currentPos-1] - lexer.buf.WriteString(chunk) - lexer.buf.WriteString("'") - lexer.next() - currentIndex = lexer.currentPos - } - current = lexer.next() - } - if lexer.lastWidth == 0 { - // Then we hit an EOF so we never reached the closing - // delimiter. - return token{}, SyntaxError{ - msg: "Unclosed delimiter: '", - Expression: lexer.expression, - Offset: len(lexer.expression), - } - } - if currentIndex < lexer.currentPos { - lexer.buf.WriteString(lexer.expression[currentIndex : lexer.currentPos-1]) - } - value := lexer.buf.String() - // Reset the buffer so it can reused again. - lexer.buf.Reset() - return token{ - tokenType: tStringLiteral, - value: value, - position: start, - length: len(value), - }, nil -} - -func (lexer *Lexer) syntaxError(msg string) SyntaxError { - return SyntaxError{ - msg: msg, - Expression: lexer.expression, - Offset: lexer.currentPos - 1, - } -} - -// Checks for a two char token, otherwise matches a single character -// token. This is used whenever a two char token overlaps a single -// char token, e.g. "||" -> tPipe, "|" -> tOr. -func (lexer *Lexer) matchOrElse(first rune, second rune, matchedType tokType, singleCharType tokType) token { - start := lexer.currentPos - lexer.lastWidth - nextRune := lexer.next() - var t token - if nextRune == second { - t = token{ - tokenType: matchedType, - value: string(first) + string(second), - position: start, - length: 2, - } - } else { - lexer.back() - t = token{ - tokenType: singleCharType, - value: string(first), - position: start, - length: 1, - } - } - return t -} - -func (lexer *Lexer) consumeLBracket() token { - // There's three options here: - // 1. A filter expression "[?" - // 2. A flatten operator "[]" - // 3. A bare rbracket "[" - start := lexer.currentPos - lexer.lastWidth - nextRune := lexer.next() - var t token - if nextRune == '?' { - t = token{ - tokenType: tFilter, - value: "[?", - position: start, - length: 2, - } - } else if nextRune == ']' { - t = token{ - tokenType: tFlatten, - value: "[]", - position: start, - length: 2, - } - } else { - t = token{ - tokenType: tLbracket, - value: "[", - position: start, - length: 1, - } - lexer.back() - } - return t -} - -func (lexer *Lexer) consumeQuotedIdentifier() (token, error) { - start := lexer.currentPos - value, err := lexer.consumeUntil('"') - if err != nil { - return token{}, err - } - var decoded string - asJSON := []byte("\"" + value + "\"") - if err := json.Unmarshal([]byte(asJSON), &decoded); err != nil { - return token{}, err - } - return token{ - tokenType: tQuotedIdentifier, - value: decoded, - position: start - 1, - length: len(decoded), - }, nil -} - -func (lexer *Lexer) consumeUnquotedIdentifier() token { - // Consume runes until we reach the end of an unquoted - // identifier. - start := lexer.currentPos - lexer.lastWidth - for { - r := lexer.next() - if r < 0 || r > 128 || identifierTrailingBits[uint64(r)/64]&(1<<(uint64(r)%64)) == 0 { - lexer.back() - break - } - } - value := lexer.expression[start:lexer.currentPos] - return token{ - tokenType: tUnquotedIdentifier, - value: value, - position: start, - length: lexer.currentPos - start, - } -} - -func (lexer *Lexer) consumeNumber() token { - // Consume runes until we reach something that's not a number. - start := lexer.currentPos - lexer.lastWidth - for { - r := lexer.next() - if r < '0' || r > '9' { - lexer.back() - break - } - } - value := lexer.expression[start:lexer.currentPos] - return token{ - tokenType: tNumber, - value: value, - position: start, - length: lexer.currentPos - start, - } -} diff --git a/vendor/github.com/jmespath/go-jmespath/parser.go b/vendor/github.com/jmespath/go-jmespath/parser.go deleted file mode 100644 index 1240a175..00000000 --- a/vendor/github.com/jmespath/go-jmespath/parser.go +++ /dev/null @@ -1,603 +0,0 @@ -package jmespath - -import ( - "encoding/json" - "fmt" - "strconv" - "strings" -) - -type astNodeType int - -//go:generate stringer -type astNodeType -const ( - ASTEmpty astNodeType = iota - ASTComparator - ASTCurrentNode - ASTExpRef - ASTFunctionExpression - ASTField - ASTFilterProjection - ASTFlatten - ASTIdentity - ASTIndex - ASTIndexExpression - ASTKeyValPair - ASTLiteral - ASTMultiSelectHash - ASTMultiSelectList - ASTOrExpression - ASTAndExpression - ASTNotExpression - ASTPipe - ASTProjection - ASTSubexpression - ASTSlice - ASTValueProjection -) - -// ASTNode represents the abstract syntax tree of a JMESPath expression. -type ASTNode struct { - nodeType astNodeType - value interface{} - children []ASTNode -} - -func (node ASTNode) String() string { - return node.PrettyPrint(0) -} - -// PrettyPrint will pretty print the parsed AST. -// The AST is an implementation detail and this pretty print -// function is provided as a convenience method to help with -// debugging. You should not rely on its output as the internal -// structure of the AST may change at any time. -func (node ASTNode) PrettyPrint(indent int) string { - spaces := strings.Repeat(" ", indent) - output := fmt.Sprintf("%s%s {\n", spaces, node.nodeType) - nextIndent := indent + 2 - if node.value != nil { - if converted, ok := node.value.(fmt.Stringer); ok { - // Account for things like comparator nodes - // that are enums with a String() method. - output += fmt.Sprintf("%svalue: %s\n", strings.Repeat(" ", nextIndent), converted.String()) - } else { - output += fmt.Sprintf("%svalue: %#v\n", strings.Repeat(" ", nextIndent), node.value) - } - } - lastIndex := len(node.children) - if lastIndex > 0 { - output += fmt.Sprintf("%schildren: {\n", strings.Repeat(" ", nextIndent)) - childIndent := nextIndent + 2 - for _, elem := range node.children { - output += elem.PrettyPrint(childIndent) - } - } - output += fmt.Sprintf("%s}\n", spaces) - return output -} - -var bindingPowers = map[tokType]int{ - tEOF: 0, - tUnquotedIdentifier: 0, - tQuotedIdentifier: 0, - tRbracket: 0, - tRparen: 0, - tComma: 0, - tRbrace: 0, - tNumber: 0, - tCurrent: 0, - tExpref: 0, - tColon: 0, - tPipe: 1, - tOr: 2, - tAnd: 3, - tEQ: 5, - tLT: 5, - tLTE: 5, - tGT: 5, - tGTE: 5, - tNE: 5, - tFlatten: 9, - tStar: 20, - tFilter: 21, - tDot: 40, - tNot: 45, - tLbrace: 50, - tLbracket: 55, - tLparen: 60, -} - -// Parser holds state about the current expression being parsed. -type Parser struct { - expression string - tokens []token - index int -} - -// NewParser creates a new JMESPath parser. -func NewParser() *Parser { - p := Parser{} - return &p -} - -// Parse will compile a JMESPath expression. -func (p *Parser) Parse(expression string) (ASTNode, error) { - lexer := NewLexer() - p.expression = expression - p.index = 0 - tokens, err := lexer.tokenize(expression) - if err != nil { - return ASTNode{}, err - } - p.tokens = tokens - parsed, err := p.parseExpression(0) - if err != nil { - return ASTNode{}, err - } - if p.current() != tEOF { - return ASTNode{}, p.syntaxError(fmt.Sprintf( - "Unexpected token at the end of the expresssion: %s", p.current())) - } - return parsed, nil -} - -func (p *Parser) parseExpression(bindingPower int) (ASTNode, error) { - var err error - leftToken := p.lookaheadToken(0) - p.advance() - leftNode, err := p.nud(leftToken) - if err != nil { - return ASTNode{}, err - } - currentToken := p.current() - for bindingPower < bindingPowers[currentToken] { - p.advance() - leftNode, err = p.led(currentToken, leftNode) - if err != nil { - return ASTNode{}, err - } - currentToken = p.current() - } - return leftNode, nil -} - -func (p *Parser) parseIndexExpression() (ASTNode, error) { - if p.lookahead(0) == tColon || p.lookahead(1) == tColon { - return p.parseSliceExpression() - } - indexStr := p.lookaheadToken(0).value - parsedInt, err := strconv.Atoi(indexStr) - if err != nil { - return ASTNode{}, err - } - indexNode := ASTNode{nodeType: ASTIndex, value: parsedInt} - p.advance() - if err := p.match(tRbracket); err != nil { - return ASTNode{}, err - } - return indexNode, nil -} - -func (p *Parser) parseSliceExpression() (ASTNode, error) { - parts := []*int{nil, nil, nil} - index := 0 - current := p.current() - for current != tRbracket && index < 3 { - if current == tColon { - index++ - p.advance() - } else if current == tNumber { - parsedInt, err := strconv.Atoi(p.lookaheadToken(0).value) - if err != nil { - return ASTNode{}, err - } - parts[index] = &parsedInt - p.advance() - } else { - return ASTNode{}, p.syntaxError( - "Expected tColon or tNumber" + ", received: " + p.current().String()) - } - current = p.current() - } - if err := p.match(tRbracket); err != nil { - return ASTNode{}, err - } - return ASTNode{ - nodeType: ASTSlice, - value: parts, - }, nil -} - -func (p *Parser) match(tokenType tokType) error { - if p.current() == tokenType { - p.advance() - return nil - } - return p.syntaxError("Expected " + tokenType.String() + ", received: " + p.current().String()) -} - -func (p *Parser) led(tokenType tokType, node ASTNode) (ASTNode, error) { - switch tokenType { - case tDot: - if p.current() != tStar { - right, err := p.parseDotRHS(bindingPowers[tDot]) - return ASTNode{ - nodeType: ASTSubexpression, - children: []ASTNode{node, right}, - }, err - } - p.advance() - right, err := p.parseProjectionRHS(bindingPowers[tDot]) - return ASTNode{ - nodeType: ASTValueProjection, - children: []ASTNode{node, right}, - }, err - case tPipe: - right, err := p.parseExpression(bindingPowers[tPipe]) - return ASTNode{nodeType: ASTPipe, children: []ASTNode{node, right}}, err - case tOr: - right, err := p.parseExpression(bindingPowers[tOr]) - return ASTNode{nodeType: ASTOrExpression, children: []ASTNode{node, right}}, err - case tAnd: - right, err := p.parseExpression(bindingPowers[tAnd]) - return ASTNode{nodeType: ASTAndExpression, children: []ASTNode{node, right}}, err - case tLparen: - name := node.value - var args []ASTNode - for p.current() != tRparen { - expression, err := p.parseExpression(0) - if err != nil { - return ASTNode{}, err - } - if p.current() == tComma { - if err := p.match(tComma); err != nil { - return ASTNode{}, err - } - } - args = append(args, expression) - } - if err := p.match(tRparen); err != nil { - return ASTNode{}, err - } - return ASTNode{ - nodeType: ASTFunctionExpression, - value: name, - children: args, - }, nil - case tFilter: - return p.parseFilter(node) - case tFlatten: - left := ASTNode{nodeType: ASTFlatten, children: []ASTNode{node}} - right, err := p.parseProjectionRHS(bindingPowers[tFlatten]) - return ASTNode{ - nodeType: ASTProjection, - children: []ASTNode{left, right}, - }, err - case tEQ, tNE, tGT, tGTE, tLT, tLTE: - right, err := p.parseExpression(bindingPowers[tokenType]) - if err != nil { - return ASTNode{}, err - } - return ASTNode{ - nodeType: ASTComparator, - value: tokenType, - children: []ASTNode{node, right}, - }, nil - case tLbracket: - tokenType := p.current() - var right ASTNode - var err error - if tokenType == tNumber || tokenType == tColon { - right, err = p.parseIndexExpression() - if err != nil { - return ASTNode{}, err - } - return p.projectIfSlice(node, right) - } - // Otherwise this is a projection. - if err := p.match(tStar); err != nil { - return ASTNode{}, err - } - if err := p.match(tRbracket); err != nil { - return ASTNode{}, err - } - right, err = p.parseProjectionRHS(bindingPowers[tStar]) - if err != nil { - return ASTNode{}, err - } - return ASTNode{ - nodeType: ASTProjection, - children: []ASTNode{node, right}, - }, nil - } - return ASTNode{}, p.syntaxError("Unexpected token: " + tokenType.String()) -} - -func (p *Parser) nud(token token) (ASTNode, error) { - switch token.tokenType { - case tJSONLiteral: - var parsed interface{} - err := json.Unmarshal([]byte(token.value), &parsed) - if err != nil { - return ASTNode{}, err - } - return ASTNode{nodeType: ASTLiteral, value: parsed}, nil - case tStringLiteral: - return ASTNode{nodeType: ASTLiteral, value: token.value}, nil - case tUnquotedIdentifier: - return ASTNode{ - nodeType: ASTField, - value: token.value, - }, nil - case tQuotedIdentifier: - node := ASTNode{nodeType: ASTField, value: token.value} - if p.current() == tLparen { - return ASTNode{}, p.syntaxErrorToken("Can't have quoted identifier as function name.", token) - } - return node, nil - case tStar: - left := ASTNode{nodeType: ASTIdentity} - var right ASTNode - var err error - if p.current() == tRbracket { - right = ASTNode{nodeType: ASTIdentity} - } else { - right, err = p.parseProjectionRHS(bindingPowers[tStar]) - } - return ASTNode{nodeType: ASTValueProjection, children: []ASTNode{left, right}}, err - case tFilter: - return p.parseFilter(ASTNode{nodeType: ASTIdentity}) - case tLbrace: - return p.parseMultiSelectHash() - case tFlatten: - left := ASTNode{ - nodeType: ASTFlatten, - children: []ASTNode{{nodeType: ASTIdentity}}, - } - right, err := p.parseProjectionRHS(bindingPowers[tFlatten]) - if err != nil { - return ASTNode{}, err - } - return ASTNode{nodeType: ASTProjection, children: []ASTNode{left, right}}, nil - case tLbracket: - tokenType := p.current() - //var right ASTNode - if tokenType == tNumber || tokenType == tColon { - right, err := p.parseIndexExpression() - if err != nil { - return ASTNode{}, nil - } - return p.projectIfSlice(ASTNode{nodeType: ASTIdentity}, right) - } else if tokenType == tStar && p.lookahead(1) == tRbracket { - p.advance() - p.advance() - right, err := p.parseProjectionRHS(bindingPowers[tStar]) - if err != nil { - return ASTNode{}, err - } - return ASTNode{ - nodeType: ASTProjection, - children: []ASTNode{{nodeType: ASTIdentity}, right}, - }, nil - } else { - return p.parseMultiSelectList() - } - case tCurrent: - return ASTNode{nodeType: ASTCurrentNode}, nil - case tExpref: - expression, err := p.parseExpression(bindingPowers[tExpref]) - if err != nil { - return ASTNode{}, err - } - return ASTNode{nodeType: ASTExpRef, children: []ASTNode{expression}}, nil - case tNot: - expression, err := p.parseExpression(bindingPowers[tNot]) - if err != nil { - return ASTNode{}, err - } - return ASTNode{nodeType: ASTNotExpression, children: []ASTNode{expression}}, nil - case tLparen: - expression, err := p.parseExpression(0) - if err != nil { - return ASTNode{}, err - } - if err := p.match(tRparen); err != nil { - return ASTNode{}, err - } - return expression, nil - case tEOF: - return ASTNode{}, p.syntaxErrorToken("Incomplete expression", token) - } - - return ASTNode{}, p.syntaxErrorToken("Invalid token: "+token.tokenType.String(), token) -} - -func (p *Parser) parseMultiSelectList() (ASTNode, error) { - var expressions []ASTNode - for { - expression, err := p.parseExpression(0) - if err != nil { - return ASTNode{}, err - } - expressions = append(expressions, expression) - if p.current() == tRbracket { - break - } - err = p.match(tComma) - if err != nil { - return ASTNode{}, err - } - } - err := p.match(tRbracket) - if err != nil { - return ASTNode{}, err - } - return ASTNode{ - nodeType: ASTMultiSelectList, - children: expressions, - }, nil -} - -func (p *Parser) parseMultiSelectHash() (ASTNode, error) { - var children []ASTNode - for { - keyToken := p.lookaheadToken(0) - if err := p.match(tUnquotedIdentifier); err != nil { - if err := p.match(tQuotedIdentifier); err != nil { - return ASTNode{}, p.syntaxError("Expected tQuotedIdentifier or tUnquotedIdentifier") - } - } - keyName := keyToken.value - err := p.match(tColon) - if err != nil { - return ASTNode{}, err - } - value, err := p.parseExpression(0) - if err != nil { - return ASTNode{}, err - } - node := ASTNode{ - nodeType: ASTKeyValPair, - value: keyName, - children: []ASTNode{value}, - } - children = append(children, node) - if p.current() == tComma { - err := p.match(tComma) - if err != nil { - return ASTNode{}, nil - } - } else if p.current() == tRbrace { - err := p.match(tRbrace) - if err != nil { - return ASTNode{}, nil - } - break - } - } - return ASTNode{ - nodeType: ASTMultiSelectHash, - children: children, - }, nil -} - -func (p *Parser) projectIfSlice(left ASTNode, right ASTNode) (ASTNode, error) { - indexExpr := ASTNode{ - nodeType: ASTIndexExpression, - children: []ASTNode{left, right}, - } - if right.nodeType == ASTSlice { - right, err := p.parseProjectionRHS(bindingPowers[tStar]) - return ASTNode{ - nodeType: ASTProjection, - children: []ASTNode{indexExpr, right}, - }, err - } - return indexExpr, nil -} -func (p *Parser) parseFilter(node ASTNode) (ASTNode, error) { - var right, condition ASTNode - var err error - condition, err = p.parseExpression(0) - if err != nil { - return ASTNode{}, err - } - if err := p.match(tRbracket); err != nil { - return ASTNode{}, err - } - if p.current() == tFlatten { - right = ASTNode{nodeType: ASTIdentity} - } else { - right, err = p.parseProjectionRHS(bindingPowers[tFilter]) - if err != nil { - return ASTNode{}, err - } - } - - return ASTNode{ - nodeType: ASTFilterProjection, - children: []ASTNode{node, right, condition}, - }, nil -} - -func (p *Parser) parseDotRHS(bindingPower int) (ASTNode, error) { - lookahead := p.current() - if tokensOneOf([]tokType{tQuotedIdentifier, tUnquotedIdentifier, tStar}, lookahead) { - return p.parseExpression(bindingPower) - } else if lookahead == tLbracket { - if err := p.match(tLbracket); err != nil { - return ASTNode{}, err - } - return p.parseMultiSelectList() - } else if lookahead == tLbrace { - if err := p.match(tLbrace); err != nil { - return ASTNode{}, err - } - return p.parseMultiSelectHash() - } - return ASTNode{}, p.syntaxError("Expected identifier, lbracket, or lbrace") -} - -func (p *Parser) parseProjectionRHS(bindingPower int) (ASTNode, error) { - current := p.current() - if bindingPowers[current] < 10 { - return ASTNode{nodeType: ASTIdentity}, nil - } else if current == tLbracket { - return p.parseExpression(bindingPower) - } else if current == tFilter { - return p.parseExpression(bindingPower) - } else if current == tDot { - err := p.match(tDot) - if err != nil { - return ASTNode{}, err - } - return p.parseDotRHS(bindingPower) - } else { - return ASTNode{}, p.syntaxError("Error") - } -} - -func (p *Parser) lookahead(number int) tokType { - return p.lookaheadToken(number).tokenType -} - -func (p *Parser) current() tokType { - return p.lookahead(0) -} - -func (p *Parser) lookaheadToken(number int) token { - return p.tokens[p.index+number] -} - -func (p *Parser) advance() { - p.index++ -} - -func tokensOneOf(elements []tokType, token tokType) bool { - for _, elem := range elements { - if elem == token { - return true - } - } - return false -} - -func (p *Parser) syntaxError(msg string) SyntaxError { - return SyntaxError{ - msg: msg, - Expression: p.expression, - Offset: p.lookaheadToken(0).position, - } -} - -// Create a SyntaxError based on the provided token. -// This differs from syntaxError() which creates a SyntaxError -// based on the current lookahead token. -func (p *Parser) syntaxErrorToken(msg string, t token) SyntaxError { - return SyntaxError{ - msg: msg, - Expression: p.expression, - Offset: t.position, - } -} diff --git a/vendor/github.com/jmespath/go-jmespath/toktype_string.go b/vendor/github.com/jmespath/go-jmespath/toktype_string.go deleted file mode 100644 index dae79cbd..00000000 --- a/vendor/github.com/jmespath/go-jmespath/toktype_string.go +++ /dev/null @@ -1,16 +0,0 @@ -// generated by stringer -type=tokType; DO NOT EDIT - -package jmespath - -import "fmt" - -const _tokType_name = "tUnknowntStartDottFiltertFlattentLparentRparentLbrackettRbrackettLbracetRbracetOrtPipetNumbertUnquotedIdentifiertQuotedIdentifiertCommatColontLTtLTEtGTtGTEtEQtNEtJSONLiteraltStringLiteraltCurrenttExpreftAndtNottEOF" - -var _tokType_index = [...]uint8{0, 8, 13, 17, 24, 32, 39, 46, 55, 64, 71, 78, 81, 86, 93, 112, 129, 135, 141, 144, 148, 151, 155, 158, 161, 173, 187, 195, 202, 206, 210, 214} - -func (i tokType) String() string { - if i < 0 || i >= tokType(len(_tokType_index)-1) { - return fmt.Sprintf("tokType(%d)", i) - } - return _tokType_name[_tokType_index[i]:_tokType_index[i+1]] -} diff --git a/vendor/github.com/jmespath/go-jmespath/util.go b/vendor/github.com/jmespath/go-jmespath/util.go deleted file mode 100644 index ddc1b7d7..00000000 --- a/vendor/github.com/jmespath/go-jmespath/util.go +++ /dev/null @@ -1,185 +0,0 @@ -package jmespath - -import ( - "errors" - "reflect" -) - -// IsFalse determines if an object is false based on the JMESPath spec. -// JMESPath defines false values to be any of: -// - An empty string array, or hash. -// - The boolean value false. -// - nil -func isFalse(value interface{}) bool { - switch v := value.(type) { - case bool: - return !v - case []interface{}: - return len(v) == 0 - case map[string]interface{}: - return len(v) == 0 - case string: - return len(v) == 0 - case nil: - return true - } - // Try the reflection cases before returning false. - rv := reflect.ValueOf(value) - switch rv.Kind() { - case reflect.Struct: - // A struct type will never be false, even if - // all of its values are the zero type. - return false - case reflect.Slice, reflect.Map: - return rv.Len() == 0 - case reflect.Ptr: - if rv.IsNil() { - return true - } - // If it's a pointer type, we'll try to deref the pointer - // and evaluate the pointer value for isFalse. - element := rv.Elem() - return isFalse(element.Interface()) - } - return false -} - -// ObjsEqual is a generic object equality check. -// It will take two arbitrary objects and recursively determine -// if they are equal. -func objsEqual(left interface{}, right interface{}) bool { - return reflect.DeepEqual(left, right) -} - -// SliceParam refers to a single part of a slice. -// A slice consists of a start, a stop, and a step, similar to -// python slices. -type sliceParam struct { - N int - Specified bool -} - -// Slice supports [start:stop:step] style slicing that's supported in JMESPath. -func slice(slice []interface{}, parts []sliceParam) ([]interface{}, error) { - computed, err := computeSliceParams(len(slice), parts) - if err != nil { - return nil, err - } - start, stop, step := computed[0], computed[1], computed[2] - result := []interface{}{} - if step > 0 { - for i := start; i < stop; i += step { - result = append(result, slice[i]) - } - } else { - for i := start; i > stop; i += step { - result = append(result, slice[i]) - } - } - return result, nil -} - -func computeSliceParams(length int, parts []sliceParam) ([]int, error) { - var start, stop, step int - if !parts[2].Specified { - step = 1 - } else if parts[2].N == 0 { - return nil, errors.New("Invalid slice, step cannot be 0") - } else { - step = parts[2].N - } - var stepValueNegative bool - if step < 0 { - stepValueNegative = true - } else { - stepValueNegative = false - } - - if !parts[0].Specified { - if stepValueNegative { - start = length - 1 - } else { - start = 0 - } - } else { - start = capSlice(length, parts[0].N, step) - } - - if !parts[1].Specified { - if stepValueNegative { - stop = -1 - } else { - stop = length - } - } else { - stop = capSlice(length, parts[1].N, step) - } - return []int{start, stop, step}, nil -} - -func capSlice(length int, actual int, step int) int { - if actual < 0 { - actual += length - if actual < 0 { - if step < 0 { - actual = -1 - } else { - actual = 0 - } - } - } else if actual >= length { - if step < 0 { - actual = length - 1 - } else { - actual = length - } - } - return actual -} - -// ToArrayNum converts an empty interface type to a slice of float64. -// If any element in the array cannot be converted, then nil is returned -// along with a second value of false. -func toArrayNum(data interface{}) ([]float64, bool) { - // Is there a better way to do this with reflect? - if d, ok := data.([]interface{}); ok { - result := make([]float64, len(d)) - for i, el := range d { - item, ok := el.(float64) - if !ok { - return nil, false - } - result[i] = item - } - return result, true - } - return nil, false -} - -// ToArrayStr converts an empty interface type to a slice of strings. -// If any element in the array cannot be converted, then nil is returned -// along with a second value of false. If the input data could be entirely -// converted, then the converted data, along with a second value of true, -// will be returned. -func toArrayStr(data interface{}) ([]string, bool) { - // Is there a better way to do this with reflect? - if d, ok := data.([]interface{}); ok { - result := make([]string, len(d)) - for i, el := range d { - item, ok := el.(string) - if !ok { - return nil, false - } - result[i] = item - } - return result, true - } - return nil, false -} - -func isSliceType(v interface{}) bool { - if v == nil { - return false - } - return reflect.TypeOf(v).Kind() == reflect.Slice -} 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 955dc0be..00000000 --- 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 15556530..00000000 --- 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 449e67cd..00000000 --- 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 c8a9fbb3..00000000 --- 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 313a0f88..00000000 --- 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 2cf4f5ab..00000000 --- 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 50d56ffb..00000000 --- a/vendor/github.com/json-iterator/go/README.md +++ /dev/null @@ -1,87 +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) - -# 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 e674d0f3..00000000 --- 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 f6b8aeab..00000000 --- a/vendor/github.com/json-iterator/go/any.go +++ /dev/null @@ -1,325 +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) - if any == nil { - stream.WriteNil() - return - } - 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 0449e9aa..00000000 --- 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 9452324a..00000000 --- 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 35fdb094..00000000 --- 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 1b56f399..00000000 --- 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 c440d72b..00000000 --- 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 1d859eac..00000000 --- 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 d04cb54c..00000000 --- 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 9d1e901a..00000000 --- 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 c44ef5c9..00000000 --- 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 a4b93c78..00000000 --- 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 656bbd33..00000000 --- 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 7df2fce3..00000000 --- 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 100755 index b45ef688..00000000 --- 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 8c58fcba..00000000 --- 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 3095662b..00000000 --- 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 95ae54fb..00000000 --- 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 6188cb45..00000000 --- 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 b9754638..00000000 --- a/vendor/github.com/json-iterator/go/iter_float.go +++ /dev/null @@ -1,339 +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) { - 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, 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) { - 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, 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 21423203..00000000 --- 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 1c575767..00000000 --- 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 f58beb91..00000000 --- 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 8fcdc3b6..00000000 --- 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 6cf66d04..00000000 --- a/vendor/github.com/json-iterator/go/iter_skip_strict.go +++ /dev/null @@ -1,99 +0,0 @@ -//+build !jsoniter_sloppy - -package jsoniter - -import ( - "fmt" - "io" -) - -func (iter *Iterator) skipNumber() { - if !iter.trySkipNumber() { - iter.unreadByte() - if iter.Error != nil && iter.Error != io.EOF { - return - } - iter.ReadFloat64() - if iter.Error != nil && iter.Error != io.EOF { - iter.Error = nil - iter.ReadBigFloat() - } - } -} - -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 adc487ea..00000000 --- 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 c2934f91..00000000 --- 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 e2389b56..00000000 --- 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 4459e203..00000000 --- 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 13a0b7b0..00000000 --- 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 8b6bc8b4..00000000 --- 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 05e8fbf1..00000000 --- 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 && !field.Anonymous() { - 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 98d45c1e..00000000 --- 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 f2619936..00000000 --- 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 547b4421..00000000 --- a/vendor/github.com/json-iterator/go/reflect_map.go +++ /dev/null @@ -1,338 +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(unmarshalerType) { - return &referenceDecoder{ - &unmarshalerDecoder{ - valType: ptrType, - }, - } - } - if typ.Implements(unmarshalerType) { - return &unmarshalerDecoder{ - valType: typ, - } - } - if ptrType.Implements(textUnmarshalerType) { - return &referenceDecoder{ - &textUnmarshalerDecoder{ - valType: ptrType, - }, - } - } - if typ.Implements(textUnmarshalerType) { - 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 fea50719..00000000 --- a/vendor/github.com/json-iterator/go/reflect_marshaler.go +++ /dev/null @@ -1,217 +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 - } - bytes, err := json.Marshal(obj) - 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 9042eb0c..00000000 --- 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 43ec71d6..00000000 --- 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 9441d79d..00000000 --- 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 355d2d11..00000000 --- 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 d0759cf6..00000000 --- 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 17662fde..00000000 --- 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 f318d2c5..00000000 --- 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 d1059ee4..00000000 --- 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 54c2ba0b..00000000 --- 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