Skip to content

Commit

Permalink
fix:nil map problem caused by temporary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
XZ0730 committed Nov 25, 2023
1 parent 080fd6b commit 13368e2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions .agollo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"limit":{"echo":"{\n \"connection_limit\": 11,\n \"qps_limit\": 200\n}"},"retry":{"echo":"{\n \"connection_limit\": 101,\n \"qps_limit\": 200\n}","echo.temp":"{\n\t\"*\": {\n\t\t\"enable\": true,\n\t\t\"type\": 0,\n\t\t\"failure_policy\": {\n\t\t\t\"stop_policy\": {\n\t\t\t\t\"max_retry_times\": 3,\n\t\t\t\t\"max_duration_ms\": 2000,\n\t\t\t\t\"cb_policy\": {\n\t\t\t\t\t\"error_rate\": 0.5\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"backoff_policy\": {\n\t\t\t\t\"backoff_type\": \"fixed\",\n\t\t\t\t\"cfg_items\": {\n\t\t\t\t\t\"fix_ms\": 50\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t},\n\t\"Echo\": {\n\t\t\"enable\": true,\n\t\t\"type\": 1,\n\t\t\"backup_policy\": {\n\t\t\t\"retry_delay_ms\": 200,\n\t\t\t\"stop_policy\": {\n\t\t\t\t\"max_retry_times\": 2,\n\t\t\t\t\"max_duration_ms\": 1000,\n\t\t\t\t\"cb_policy\": {\n\t\t\t\t\t\"error_rate\": 0.3\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}"}}
6 changes: 3 additions & 3 deletions apollo/apollo.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func getConfigParamKey(in *ConfigParam) configParamKey {
return configParamKey{
Key: in.Key,
NameSpace: in.nameSpace,
Cluster: in.Cluster,
}
}

Expand Down Expand Up @@ -145,7 +146,7 @@ func NewClient(opts Options, optsfunc ...OptionFunc) (Client, error) {
clusterTemplate: clusterTemplate,
serverKeyTemplate: serverKeyTemplate,
clientKeyTemplate: clientKeyTemplate,
handlers: map[configParamKey]map[int64]callbackHandler{},
handlers: make(map[configParamKey]map[int64]callbackHandler),
}

return cli, nil
Expand Down Expand Up @@ -229,7 +230,6 @@ func (c *client) onChange(namespace, cluster, key, data string) {
handlers = append(handlers, handler)
}
c.handlerMutex.RUnlock()

for _, handler := range handlers {
handler(namespace, cluster, key, data)
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func (c *client) listenConfig(param ConfigParam, stop chan bool, callback func(n
c.handlerMutex.Lock()
handlers, ok := c.handlers[configKey]
if !ok {
handlers := map[int64]callbackHandler{}
handlers = make(map[int64]callbackHandler)
c.handlers[configKey] = handlers
}
handlers[uniqueID] = callback
Expand Down
2 changes: 1 addition & 1 deletion client/circurit_breaker.go → client/circuit_breaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func initCircuitBreaker(param apollo.ConfigParam, dest, src string,
configs := map[string]circuitbreak.CBConfig{}
err := parser.Decode(param.Type, data, &configs)
if err != nil {
klog.Warnf("[apollo] %s client apollo rpc timeout: unmarshal data %s failed: %s, skip...", dest, data, err)
klog.Warnf("[apollo] %s client apollo circuit breakr: unmarshal data %s failed: %s, skip...", dest, data, err)
return
}

Expand Down
4 changes: 2 additions & 2 deletions example/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func main() {
}
cl := &configLog{}

serviceName := "ServiceName"
clientName := "ClientName"
serviceName := "ServiceName" // your server-side service name
clientName := "ClientName" // your client-side service name
client, err := echo.NewClient(
serviceName,
client.WithHostPorts("localhost:8899"),
Expand Down

0 comments on commit 13368e2

Please sign in to comment.