fix: slice/map make init cap (#2300)

feat/remove-config-debugf
jesse.tang 2 years ago committed by GitHub
parent cb6176dbbb
commit 73a8323ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      cmd/protoc-gen-go-http/http.go
  2. 4
      config/value.go
  3. 2
      contrib/registry/consul/client.go
  4. 2
      contrib/registry/discovery/discovery.go
  5. 2
      transport/grpc/balancer.go

@ -213,9 +213,9 @@ func buildPathVars(path string) (res map[string]*string) {
if strings.HasSuffix(path, "/") {
fmt.Fprintf(os.Stderr, "\u001B[31mWARN\u001B[m: Path %s should not end with \"/\" \n", path)
}
res = make(map[string]*string)
pattern := regexp.MustCompile(`(?i){([a-z\.0-9_\s]*)=?([^{}]*)}`)
matches := pattern.FindAllStringSubmatch(path, -1)
res = make(map[string]*string, len(matches))
for _, m := range matches {
name := strings.TrimSpace(m[1])
if len(name) > 1 && len(m[2]) > 0 {

@ -93,9 +93,9 @@ func (v *atomicValue) Slice() ([]Value, error) {
func (v *atomicValue) Map() (map[string]Value, error) {
if vals, ok := v.Load().(map[string]interface{}); ok {
m := make(map[string]Value)
m := make(map[string]Value, len(vals))
for key, val := range vals {
a := &atomicValue{}
a := new(atomicValue)
a.Store(val)
m[key] = a
}

@ -95,7 +95,7 @@ func (c *Client) Service(ctx context.Context, service string, index uint64, pass
// Register register service instance to consul
func (c *Client) Register(_ context.Context, svc *registry.ServiceInstance, enableHealthCheck bool) error {
addresses := make(map[string]api.ServiceAddress)
addresses := make(map[string]api.ServiceAddress, len(svc.Endpoints))
checkAddresses := make([]string, 0, len(svc.Endpoints))
for _, endpoint := range svc.Endpoints {
raw, err := url.Parse(endpoint)

@ -439,7 +439,7 @@ func (r *Resolve) fetch(ctx context.Context) (ins *disInstancesInfo, ok bool) {
ins = new(disInstancesInfo)
ins.LastTs = appIns.LastTs
ins.Scheduler = appIns.Scheduler
ins.Instances = make(map[string][]*discoveryInstance)
ins.Instances = make(map[string][]*discoveryInstance, len(appIns.Instances))
for zone, in := range appIns.Instances {
ins.Instances[zone] = in
}

@ -40,7 +40,7 @@ func (b *balancerBuilder) Build(info base.PickerBuildInfo) balancer.Picker {
// Block the RPC until a new picker is available via UpdateState().
return base.NewErrPicker(balancer.ErrNoSubConnAvailable)
}
nodes := make([]selector.Node, 0)
nodes := make([]selector.Node, 0, len(info.ReadySCs))
for conn, info := range info.ReadySCs {
ins, _ := info.Address.Attributes.Value("rawServiceInstance").(*registry.ServiceInstance)
nodes = append(nodes, &grpcNode{

Loading…
Cancel
Save