mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 00:50:20 +08:00
chore: initialize some slice type variables (#4249)
This commit is contained in:
parent
9f8455ddb3
commit
c02fb3acab
@ -105,7 +105,7 @@ func newRedisBitSet(store *redis.Redis, key string, bits uint) *redisBitSet {
|
||||
}
|
||||
|
||||
func (r *redisBitSet) buildOffsetArgs(offsets []uint) ([]string, error) {
|
||||
var args []string
|
||||
args := make([]string, 0, len(offsets))
|
||||
|
||||
for _, offset := range offsets {
|
||||
if offset >= r.bits {
|
||||
|
@ -269,7 +269,7 @@ func (ew *errorWindow) add(reason string) {
|
||||
}
|
||||
|
||||
func (ew *errorWindow) String() string {
|
||||
var reasons []string
|
||||
reasons := make([]string, 0, ew.count)
|
||||
|
||||
ew.lock.Lock()
|
||||
// reverse order
|
||||
|
@ -143,7 +143,7 @@ func fillPath(u *nurl.URL, val map[string]any) error {
|
||||
delete(val, key)
|
||||
}
|
||||
|
||||
var unused []string
|
||||
unused := make([]string, 0, len(val))
|
||||
for key := range val {
|
||||
unused = append(unused, key)
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ func (s *Server) PrintRoutes() {
|
||||
|
||||
// Routes returns the HTTP routers that registered in the server.
|
||||
func (s *Server) Routes() []Route {
|
||||
var routes []Route
|
||||
routes := make([]Route, 0, len(s.ngin.routes))
|
||||
|
||||
for _, r := range s.ngin.routes {
|
||||
routes = append(routes, r.routes...)
|
||||
@ -249,7 +249,7 @@ func WithNotAllowedHandler(handler http.Handler) RunOption {
|
||||
// WithPrefix adds group as a prefix to the route paths.
|
||||
func WithPrefix(group string) RouteOption {
|
||||
return func(r *featuredRoutes) {
|
||||
var routes []Route
|
||||
routes := make([]Route, 0, len(r.routes))
|
||||
for _, rt := range r.routes {
|
||||
p := path.Join(group, rt.Path)
|
||||
routes = append(routes, Route{
|
||||
|
@ -182,7 +182,7 @@ func (p *p2cPicker) choose(c1, c2 *subConn) *subConn {
|
||||
}
|
||||
|
||||
func (p *p2cPicker) logStats() {
|
||||
var stats []string
|
||||
stats := make([]string, 0, len(p.conns))
|
||||
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
@ -22,8 +22,9 @@ func (b *discovBuilder) Build(target resolver.Target, cc resolver.ClientConn, _
|
||||
}
|
||||
|
||||
update := func() {
|
||||
var addrs []resolver.Address
|
||||
for _, val := range subset(sub.Values(), subsetSize) {
|
||||
vals := subset(sub.Values(), subsetSize)
|
||||
addrs := make([]resolver.Address, 0, len(vals))
|
||||
for _, val := range vals {
|
||||
addrs = append(addrs, resolver.Address{
|
||||
Addr: val,
|
||||
})
|
||||
|
@ -69,8 +69,9 @@ func (b *kubeBuilder) Build(target resolver.Target, cc resolver.ClientConn,
|
||||
}
|
||||
|
||||
handler := kube.NewEventHandler(func(endpoints []string) {
|
||||
var addrs []resolver.Address
|
||||
for _, val := range subset(endpoints, subsetSize) {
|
||||
endpoints = subset(endpoints, subsetSize)
|
||||
addrs := make([]resolver.Address, 0, len(endpoints))
|
||||
for _, val := range endpoints {
|
||||
addrs = append(addrs, resolver.Address{
|
||||
Addr: fmt.Sprintf("%s:%d", val, svc.Port),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user