mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: remove unnecessary redeclarations in for loops (part 2) (#18593)
This commit is contained in:
@@ -565,7 +565,6 @@ func (a *agent) reportMetadata(ctx context.Context, aAPI proto.DRPCAgentClient26
|
||||
// channel to synchronize the results and avoid both messy
|
||||
// mutex logic and overloading the API.
|
||||
for _, md := range manifest.Metadata {
|
||||
md := md
|
||||
// We send the result to the channel in the goroutine to avoid
|
||||
// sending the same result multiple times. So, we don't care about
|
||||
// the return values.
|
||||
|
||||
@@ -149,7 +149,6 @@ func (r *Runner) Init(scripts []codersdk.WorkspaceAgentScript, scriptCompleted S
|
||||
if script.Cron == "" {
|
||||
continue
|
||||
}
|
||||
script := script
|
||||
_, err := r.cron.AddFunc(script.Cron, func() {
|
||||
err := r.trackRun(r.cronCtx, script, ExecuteCronScripts)
|
||||
if err != nil {
|
||||
@@ -224,7 +223,6 @@ func (r *Runner) Execute(ctx context.Context, option ExecuteOption) error {
|
||||
continue
|
||||
}
|
||||
|
||||
script := script
|
||||
eg.Go(func() error {
|
||||
err := r.trackRun(ctx, script, option)
|
||||
if err != nil {
|
||||
|
||||
@@ -435,7 +435,6 @@ func applyOrgResourceActions(role *codersdk.Role, resource string, actions []str
|
||||
// Construct new site perms with only new perms for the resource
|
||||
keep := make([]codersdk.Permission, 0)
|
||||
for _, perm := range role.OrganizationPermissions {
|
||||
perm := perm
|
||||
if string(perm.ResourceType) != resource {
|
||||
keep = append(keep, perm)
|
||||
}
|
||||
|
||||
@@ -116,7 +116,6 @@ func (r *RootCmd) setOrganizationSettings(orgContext *OrganizationContext, setti
|
||||
}
|
||||
|
||||
for _, set := range settings {
|
||||
set := set
|
||||
patch := set.Patch
|
||||
cmd.Children = append(cmd.Children, &serpent.Command{
|
||||
Use: set.Name,
|
||||
@@ -192,7 +191,6 @@ func (r *RootCmd) printOrganizationSetting(orgContext *OrganizationContext, sett
|
||||
}
|
||||
|
||||
for _, set := range settings {
|
||||
set := set
|
||||
fetch := set.Fetch
|
||||
cmd.Children = append(cmd.Children, &serpent.Command{
|
||||
Use: set.Name,
|
||||
|
||||
@@ -1184,7 +1184,6 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
|
||||
var wg sync.WaitGroup
|
||||
for i, provisionerDaemon := range provisionerDaemons {
|
||||
id := i + 1
|
||||
provisionerDaemon := provisionerDaemon
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
@@ -1662,7 +1661,6 @@ func configureServerTLS(ctx context.Context, logger slog.Logger, tlsMinVersion,
|
||||
|
||||
// Expensively check which certificate matches the client hello.
|
||||
for _, cert := range certs {
|
||||
cert := cert
|
||||
if err := hi.SupportsCertificate(&cert); err == nil {
|
||||
return &cert, nil
|
||||
}
|
||||
|
||||
@@ -73,7 +73,6 @@ func (m *MemoryPubsub) Publish(event string, message []byte) error {
|
||||
var wg sync.WaitGroup
|
||||
for _, listener := range listeners {
|
||||
wg.Add(1)
|
||||
listener := listener
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
listener.send(context.Background(), message)
|
||||
|
||||
@@ -505,8 +505,6 @@ func ConvertConfig(instrument *promoauth.Factory, entries []codersdk.ExternalAut
|
||||
ids := map[string]struct{}{}
|
||||
configs := []*Config{}
|
||||
for _, entry := range entries {
|
||||
entry := entry
|
||||
|
||||
// Applies defaults to the config entry.
|
||||
// This allows users to very simply state that they type is "GitHub",
|
||||
// apply their client secret and ID, and have the UI appear nicely.
|
||||
|
||||
@@ -99,7 +99,6 @@ func (s AGPLIDPSync) SyncGroups(ctx context.Context, db database.Store, user dat
|
||||
// membership via the groups the user is in.
|
||||
userOrgs := make(map[uuid.UUID][]database.GetGroupsRow)
|
||||
for _, g := range userGroups {
|
||||
g := g
|
||||
userOrgs[g.Group.OrganizationID] = append(userOrgs[g.Group.OrganizationID], g)
|
||||
}
|
||||
|
||||
@@ -337,8 +336,6 @@ func (s GroupSyncSettings) ParseClaims(orgID uuid.UUID, mergedClaims jwt.MapClai
|
||||
|
||||
groups := make([]ExpectedGroup, 0)
|
||||
for _, group := range parsedGroups {
|
||||
group := group
|
||||
|
||||
// Legacy group mappings happen before the regex filter.
|
||||
mappedGroupName, ok := s.LegacyNameMapping[group]
|
||||
if ok {
|
||||
@@ -355,7 +352,6 @@ func (s GroupSyncSettings) ParseClaims(orgID uuid.UUID, mergedClaims jwt.MapClai
|
||||
mappedGroupIDs, ok := s.Mapping[group]
|
||||
if ok {
|
||||
for _, gid := range mappedGroupIDs {
|
||||
gid := gid
|
||||
groups = append(groups, ExpectedGroup{OrganizationID: orgID, GroupID: &gid})
|
||||
}
|
||||
continue
|
||||
|
||||
@@ -760,7 +760,6 @@ func rbacTraceAttributes(actor Subject, action policy.Action, objectType string,
|
||||
uniqueRoleNames := actor.SafeRoleNames()
|
||||
roleStrings := make([]string, 0, len(uniqueRoleNames))
|
||||
for _, roleName := range uniqueRoleNames {
|
||||
roleName := roleName
|
||||
roleStrings = append(roleStrings, roleName.String())
|
||||
}
|
||||
return trace.WithAttributes(
|
||||
|
||||
@@ -845,7 +845,6 @@ func Permissions(perms map[string][]policy.Action) []Permission {
|
||||
list := make([]Permission, 0, len(perms))
|
||||
for k, actions := range perms {
|
||||
for _, act := range actions {
|
||||
act := act
|
||||
list = append(list, Permission{
|
||||
Negate: false,
|
||||
ResourceType: k,
|
||||
|
||||
@@ -103,7 +103,6 @@ func (n *Webpusher) Dispatch(ctx context.Context, userID uuid.UUID, msg codersdk
|
||||
var mu sync.Mutex
|
||||
var eg errgroup.Group
|
||||
for _, subscription := range subscriptions {
|
||||
subscription := subscription
|
||||
eg.Go(func() error {
|
||||
// TODO: Implement some retry logic here. For now, this is just a
|
||||
// best-effort attempt.
|
||||
|
||||
@@ -240,7 +240,6 @@ func (p *ProxyHealth) runOnce(ctx context.Context, now time.Time) (map[uuid.UUID
|
||||
}
|
||||
// Each proxy needs to have a status set. Make a local copy for the
|
||||
// call to be run async.
|
||||
proxy := proxy
|
||||
status := ProxyStatus{
|
||||
Proxy: proxy,
|
||||
CheckedAt: now,
|
||||
|
||||
@@ -408,9 +408,6 @@ func (m *Manager) AllPrimary() []database.Replica {
|
||||
continue
|
||||
}
|
||||
|
||||
// When we assign the non-pointer to a
|
||||
// variable it loses the reference.
|
||||
replica := replica
|
||||
replicas = append(replicas, replica)
|
||||
}
|
||||
return replicas
|
||||
|
||||
@@ -849,8 +849,6 @@ func verifyBinSha1IsCurrent(dest string, siteFS fs.FS, shaFiles map[string]strin
|
||||
|
||||
// Verify the hash of each on-disk binary.
|
||||
for file, hash1 := range shaFiles {
|
||||
file := file
|
||||
hash1 := hash1
|
||||
eg.Go(func() error {
|
||||
hash2, err := sha1HashFile(filepath.Join(dest, file))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user