mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-14 02:33:03 +02:00
fix: slice/map make init cap (#2300)
This commit is contained in:
parent
cb6176dbbb
commit
73a8323ee7
@ -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…
Reference in New Issue
Block a user