diff --git a/config/base_config.go b/config/base_config.go index d06a0efbd42e585a036f344a99d4878073a0ae70..6678e7c6813230d9ce2563621ae684dbd155eedf 100644 --- a/config/base_config.go +++ b/config/base_config.go @@ -47,7 +47,7 @@ type BaseConfig struct { } func (c *BaseConfig) startConfigCenter(ctx context.Context) error { - url, err := common.NewURL(ctx, c.ConfigCenterConfig.Address, common.WithProtocol(c.ConfigCenterConfig.Protocol),common.WithParams(c.ConfigCenterConfig.GetUrlMap())) + url, err := common.NewURL(ctx, c.ConfigCenterConfig.Address, common.WithProtocol(c.ConfigCenterConfig.Protocol), common.WithParams(c.ConfigCenterConfig.GetUrlMap())) if err != nil { return err } diff --git a/config_center/apollo/factory.go b/config_center/apollo/factory.go index 98acfe7177bf0633f901906af52636bf80fe84f3..a1c1409aa59f089150ff3ec8e4a898a1cd58a89a 100644 --- a/config_center/apollo/factory.go +++ b/config_center/apollo/factory.go @@ -50,4 +50,3 @@ func (f *apolloDynamicConfigurationFactory) GetDynamicConfiguration(url *common. return dynamicConfiguration, err } - diff --git a/config_center/apollo/impl.go b/config_center/apollo/impl.go index 2a6cefc96d9152faff468b6c33ef047e12cac33d..a8c2dc9d57e58a6c0c295a1d0e6eb4e7251d86ca 100644 --- a/config_center/apollo/impl.go +++ b/config_center/apollo/impl.go @@ -35,7 +35,7 @@ import ( const ( apolloProtocolPrefix = "http://" - apolloConfigFormat = "%s.%s" + apolloConfigFormat = "%s.%s" ) type apolloDynamicConfiguration struct { @@ -53,12 +53,12 @@ func newApolloDynamicConfiguration(url *common.URL) (*apolloDynamicConfiguration configAddr := c.getAddressWithProtocolPrefix(url) configCluster := url.GetParam(constant.CONFIG_CLUSTER_KEY, "") - appId := url.GetParam(constant.CONFIG_GROUP_KEY, config_center.DEFAULT_GROUP) + appId := url.GetParam(constant.CONFIG_GROUP_KEY, config_center.DEFAULT_GROUP) namespaces := url.GetParam(constant.CONFIG_NAMESPACE_KEY, getProperties(config_center.DEFAULT_GROUP)) readyConfig := &agollo.AppConfig{ AppId: appId, Cluster: configCluster, - NamespaceName: namespaces, + NamespaceName: namespaces, Ip: configAddr, } @@ -130,11 +130,11 @@ func (c *apolloDynamicConfiguration) RemoveListener(key string, listener config_ } } -func getProperties(namespace string) string{ - return getNamespaceName(namespace,agollo.Properties) +func getProperties(namespace string) string { + return getNamespaceName(namespace, agollo.Properties) } -func getNamespaceName(namespace string,configFileFormat agollo.ConfigFileFormat ) string{ +func getNamespaceName(namespace string, configFileFormat agollo.ConfigFileFormat) string { return fmt.Sprintf(apolloConfigFormat, namespace, configFileFormat) } @@ -145,10 +145,10 @@ func (c *apolloDynamicConfiguration) GetConfig(key string, opts ...config_center } namespace := c.url.GetParam(constant.CONFIG_NAMESPACE_KEY, getProperties(config_center.DEFAULT_GROUP)) config := agollo.GetConfig(namespace) - if config==nil{ - return "",errors.New(fmt.Sprintf("nothiing in namespace:%s ",namespace)) + if config == nil { + return "", errors.New(fmt.Sprintf("nothiing in namespace:%s ", namespace)) } - return config.GetContent(agollo.Properties),nil + return config.GetContent(agollo.Properties), nil } func (c *apolloDynamicConfiguration) getAddressWithProtocolPrefix(url *common.URL) string { diff --git a/config_center/apollo/impl_test.go b/config_center/apollo/impl_test.go index 9c1c52b492efa042112c27d655f91ddc1e58ea58..41846ae14a178e3008b0c9b6d602943451711341 100644 --- a/config_center/apollo/impl_test.go +++ b/config_center/apollo/impl_test.go @@ -31,21 +31,21 @@ import ( ) const ( - mockAppId="testApplication_yang" - mockCluster="dev" - mockNamespace="mockDubbog.properties" - mockConfigRes=`{"appId":"testApplication_yang","cluster":"default","namespaceName":"mockDubbog.properties","configurations":{"registries.hangzhouzk.username":"","application.owner":"ZX","registries.shanghaizk.username":"","protocols.dubbo.ip":"127.0.0.1","protocol_conf.dubbo.getty_session_param.tcp_write_timeout":"5s","services.UserProvider.cluster":"failover","application.module":"dubbogo user-info server","services.UserProvider.interface":"com.ikurento.user.UserProvider","protocol_conf.dubbo.getty_session_param.compress_encoding":"false","registries.shanghaizk.address":"127.0.0.1:2182","protocol_conf.dubbo.session_timeout":"20s","registries.shanghaizk.timeout":"3s","protocol_conf.dubbo.getty_session_param.keep_alive_period":"120s","services.UserProvider.warmup":"100","application.version":"0.0.1","registries.hangzhouzk.protocol":"zookeeper","registries.hangzhouzk.password":"","protocols.dubbo.name":"dubbo","protocol_conf.dubbo.getty_session_param.wait_timeout":"1s","protocols.dubbo.port":"20000","application_config.owner":"demo","application_config.name":"demo","application_config.version":"0.0.1","application_config.environment":"dev","protocol_conf.dubbo.getty_session_param.session_name":"server","application.name":"BDTService","registries.hangzhouzk.timeout":"3s","protocol_conf.dubbo.getty_session_param.tcp_read_timeout":"1s","services.UserProvider.loadbalance":"random","protocol_conf.dubbo.session_number":"700","protocol_conf.dubbo.getty_session_param.max_msg_len":"1024","services.UserProvider.registry":"hangzhouzk","application_config.module":"demo","services.UserProvider.methods[0].name":"GetUser","protocol_conf.dubbo.getty_session_param.tcp_no_delay":"true","services.UserProvider.methods[0].retries":"1","protocol_conf.dubbo.getty_session_param.tcp_w_buf_size":"65536","protocol_conf.dubbo.getty_session_param.tcp_r_buf_size":"262144","registries.shanghaizk.password":"","application_config.organization":"demo","registries.shanghaizk.protocol":"zookeeper","protocol_conf.dubbo.getty_session_param.tcp_keep_alive":"true","registries.hangzhouzk.address":"127.0.0.1:2181","application.environment":"dev","services.UserProvider.protocol":"dubbo","application.organization":"ikurento.com","protocol_conf.dubbo.getty_session_param.pkg_wq_size":"512","services.UserProvider.methods[0].loadbalance":"random"},"releaseKey":"20191104105242-0f13805d89f834a4"}` - mockNotifyRes=`[{"namespaceName":"mockDubbog","notificationId":53050,"messages":{"details":{"testApplication_yang+default+mockDubbog":53050}}}]` - mockServiceConfigRes=`[{"appName":"APOLLO-CONFIGSERVICE","instanceId":"instance-300408ep:apollo-configservice:8080","homepageUrl":"http://localhost:8080"}]` + mockAppId = "testApplication_yang" + mockCluster = "dev" + mockNamespace = "mockDubbog.properties" + mockConfigRes = `{"appId":"testApplication_yang","cluster":"default","namespaceName":"mockDubbog.properties","configurations":{"registries.hangzhouzk.username":"","application.owner":"ZX","registries.shanghaizk.username":"","protocols.dubbo.ip":"127.0.0.1","protocol_conf.dubbo.getty_session_param.tcp_write_timeout":"5s","services.UserProvider.cluster":"failover","application.module":"dubbogo user-info server","services.UserProvider.interface":"com.ikurento.user.UserProvider","protocol_conf.dubbo.getty_session_param.compress_encoding":"false","registries.shanghaizk.address":"127.0.0.1:2182","protocol_conf.dubbo.session_timeout":"20s","registries.shanghaizk.timeout":"3s","protocol_conf.dubbo.getty_session_param.keep_alive_period":"120s","services.UserProvider.warmup":"100","application.version":"0.0.1","registries.hangzhouzk.protocol":"zookeeper","registries.hangzhouzk.password":"","protocols.dubbo.name":"dubbo","protocol_conf.dubbo.getty_session_param.wait_timeout":"1s","protocols.dubbo.port":"20000","application_config.owner":"demo","application_config.name":"demo","application_config.version":"0.0.1","application_config.environment":"dev","protocol_conf.dubbo.getty_session_param.session_name":"server","application.name":"BDTService","registries.hangzhouzk.timeout":"3s","protocol_conf.dubbo.getty_session_param.tcp_read_timeout":"1s","services.UserProvider.loadbalance":"random","protocol_conf.dubbo.session_number":"700","protocol_conf.dubbo.getty_session_param.max_msg_len":"1024","services.UserProvider.registry":"hangzhouzk","application_config.module":"demo","services.UserProvider.methods[0].name":"GetUser","protocol_conf.dubbo.getty_session_param.tcp_no_delay":"true","services.UserProvider.methods[0].retries":"1","protocol_conf.dubbo.getty_session_param.tcp_w_buf_size":"65536","protocol_conf.dubbo.getty_session_param.tcp_r_buf_size":"262144","registries.shanghaizk.password":"","application_config.organization":"demo","registries.shanghaizk.protocol":"zookeeper","protocol_conf.dubbo.getty_session_param.tcp_keep_alive":"true","registries.hangzhouzk.address":"127.0.0.1:2181","application.environment":"dev","services.UserProvider.protocol":"dubbo","application.organization":"ikurento.com","protocol_conf.dubbo.getty_session_param.pkg_wq_size":"512","services.UserProvider.methods[0].loadbalance":"random"},"releaseKey":"20191104105242-0f13805d89f834a4"}` + mockNotifyRes = `[{"namespaceName":"mockDubbog","notificationId":53050,"messages":{"details":{"testApplication_yang+default+mockDubbog":53050}}}]` + mockServiceConfigRes = `[{"appName":"APOLLO-CONFIGSERVICE","instanceId":"instance-300408ep:apollo-configservice:8080","homepageUrl":"http://localhost:8080"}]` - apolloUrl ="apollo://%s" + apolloUrl = "apollo://%s" ) func initApollo() *httptest.Server { handlerMap := make(map[string]func(http.ResponseWriter, *http.Request), 1) - handlerMap[mockNamespace]=configResponse + handlerMap[mockNamespace] = configResponse - return runMockConfigServer(handlerMap,notifyResponse) + return runMockConfigServer(handlerMap, notifyResponse) } func configResponse(rw http.ResponseWriter, req *http.Request) { @@ -54,32 +54,31 @@ func configResponse(rw http.ResponseWriter, req *http.Request) { } func notifyResponse(rw http.ResponseWriter, req *http.Request) { - result := fmt.Sprintf(mockNotifyRes ) + result := fmt.Sprintf(mockNotifyRes) fmt.Fprintf(rw, "%s", result) } func serviceConfigResponse(rw http.ResponseWriter, req *http.Request) { - result := fmt.Sprintf(mockServiceConfigRes ) + result := fmt.Sprintf(mockServiceConfigRes) fmt.Fprintf(rw, "%s", result) } - //run mock config server func runMockConfigServer(handlerMap map[string]func(http.ResponseWriter, *http.Request), - notifyHandler func(http.ResponseWriter, *http.Request)) *httptest.Server{ + notifyHandler func(http.ResponseWriter, *http.Request)) *httptest.Server { uriHandlerMap := make(map[string]func(http.ResponseWriter, *http.Request), 0) for namespace, handler := range handlerMap { uri := fmt.Sprintf("/configs/%s/%s/%s", mockAppId, mockCluster, namespace) - uriHandlerMap[uri]=handler + uriHandlerMap[uri] = handler } - uriHandlerMap["/notifications/v2"]=notifyHandler - uriHandlerMap["/services/config"]=serviceConfigResponse + uriHandlerMap["/notifications/v2"] = notifyHandler + uriHandlerMap["/services/config"] = serviceConfigResponse ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { uri := r.RequestURI for path, handler := range uriHandlerMap { - if strings.HasPrefix(uri,path){ - handler(w,r) + if strings.HasPrefix(uri, path) { + handler(w, r) break } } @@ -88,19 +87,17 @@ func runMockConfigServer(handlerMap map[string]func(http.ResponseWriter, *http.R return ts } - - func Test_GetConfig(t *testing.T) { c := &config.BaseConfig{ConfigCenterConfig: &config.ConfigCenterConfig{ - Protocol: "apollo", - Address: "106.12.25.204:8080", - Group: "testApplication_yang", - Cluster: "dev", - ConfigFile: "mockDubbog.properties", - }} + Protocol: "apollo", + Address: "106.12.25.204:8080", + Group: "testApplication_yang", + Cluster: "dev", + ConfigFile: "mockDubbog.properties", + }} apollo := initApollo() apolloUrl := strings.ReplaceAll(apollo.URL, "http", "apollo") - url, err:= common.NewURL(context.TODO(), apolloUrl,common.WithParams(c.ConfigCenterConfig.GetUrlMap())) + url, err := common.NewURL(context.TODO(), apolloUrl, common.WithParams(c.ConfigCenterConfig.GetUrlMap())) assert.NoError(t, err) configuration, err := newApolloDynamicConfiguration(&url) assert.NoError(t, err) diff --git a/config_center/apollo/listener.go b/config_center/apollo/listener.go index 1d443165c96bcbf5076963a6f6909ab362d94f93..d9a0fddcb19c7169a338756ad0c9ffdc3bdb46fb 100644 --- a/config_center/apollo/listener.go +++ b/config_center/apollo/listener.go @@ -40,5 +40,3 @@ func (al *apolloListener) AddListener(l config_center.ConfigurationListener) { func (al *apolloListener) RemoveListener(l config_center.ConfigurationListener) { delete(al.listeners, l) } - - diff --git a/go.sum b/go.sum index 423381fa9980ed16011cc4de1a948d2e716648d9..33c0fb51a9523868d7ec8b170f9aab9d923eca8c 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,6 @@ github.com/NYTimes/gziphandler v1.0.1 h1:iLrQrdwjDd52kHDA5op2UBJFjmOb9g+7scBan4R github.com/NYTimes/gziphandler v1.0.1/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= -github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/SAP/go-hdb v0.12.0 h1:5hBQZ2jjyZ268qjDmoDZJuCyLzR6oRLI60eYzmTW9m4= github.com/SAP/go-hdb v0.12.0/go.mod h1:etBT+FAi1t5k3K3tf5vQTnosgYmhDkRi8jEnQqCnxF0= github.com/SermoDigital/jose v0.0.0-20180104203859-803625baeddc h1:LkkwnbY+S8WmwkWq1SVyRWMH9nYWO1P5XN3OD1tts/w= @@ -69,8 +67,6 @@ github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23 h1:D21IyuvjDCshj1 github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY= github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible h1:C29Ae4G5GtYyYMm1aztcyj/J5ckgJm2zwdDajFbx1NY= github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3 h1:TJH+oke8D16535+jHExHj4nQvzlZrj7ug5D7I/orNUA= @@ -78,8 +74,6 @@ github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/containerd/continuity v0.0.0-20181203112020-004b46473808 h1:4BX8f882bXEDKfWIf0wa8HRvpnBoPszJJXL+TVbBw4M= github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= -github.com/coocood/freecache v1.1.0 h1:ENiHOsWdj1BrrlPwblhbn4GdAsMymK3pZORJ+bJGAjA= -github.com/coocood/freecache v1.1.0/go.mod h1:ePwxCDzOYvARfHdr1pByNct1at3CoKnsipOHwKlNbzI= github.com/coredns/coredns v1.1.2 h1:bAFHrSsBeTeRG5W3Nf2su3lUGw7Npw2UKeCJm/3A638= github.com/coredns/coredns v1.1.2/go.mod h1:zASH/MVDgR6XZTbxvOnsZfffS+31vg6Ackf/wo1+AM0= github.com/coreos/bbolt v1.3.3 h1:n6AiVyVRKQFNb6mJlwESEvvLoDyiTzXX7ORAUlkeBdY= @@ -445,8 +439,6 @@ github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d h1:bVQRCxQv github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d/go.mod h1:Cw4GTlQccdRGSEf6KiMju767x0NEHE0YIVPJSaXjlsw= github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=