Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: remove unnecessary redeclarations in for loops (part 2)#18593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
aslilac wants to merge4 commits intomain
base:main
Choose a base branch
Loading
fromlilac/go-122-range-fix-all
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletionagent/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand Down
2 changes: 0 additions & 2 deletionsagent/agentscripts/agentscripts.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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 {
Expand DownExpand Up@@ -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 {
Expand Down
1 change: 0 additions & 1 deletioncli/organizationroles.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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:=rangerole.OrganizationPermissions {
perm:=perm
ifstring(perm.ResourceType)!=resource {
keep=append(keep,perm)
}
Expand Down
2 changes: 0 additions & 2 deletionscli/organizationsettings.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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,
Expand DownExpand Up@@ -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,
Expand Down
2 changes: 0 additions & 2 deletionscli/server.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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()
Expand DownExpand Up@@ -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
}
Expand Down
1 change: 0 additions & 1 deletioncoderd/database/pubsub/pubsub_memory.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand Down
2 changes: 0 additions & 2 deletionscoderd/externalauth/externalauth.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand Down
4 changes: 0 additions & 4 deletionscoderd/idpsync/group.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
}

Expand DownExpand Up@@ -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 {
Expand All@@ -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
Expand Down
1 change: 0 additions & 1 deletioncoderd/rbac/authz.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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(
Expand Down
1 change: 0 additions & 1 deletioncoderd/rbac/roles.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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,
Expand Down
1 change: 0 additions & 1 deletioncoderd/webpush/webpush.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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.
Expand Down
1 change: 0 additions & 1 deletionenterprise/coderd/proxyhealth/proxyhealth.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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,
Expand Down
3 changes: 0 additions & 3 deletionsenterprise/replicasync/replicasync.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Comment on lines -411 to -413
Copy link
MemberAuthor

@aslilacaslilacJun 25, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@johnstcn you called out this one as potentially being a concern, but I think there are already two "copies" happening here that make this safe

  • it gets copied from the slice to thereplica variable by the loop
  • it gets copied from thereplica variable to the argument value as part of theappend call on the next line

ie. go does nothave "references", it has pointers and values. you're either copying a pointer or you're copying the whole value.

here's a go playground that hopefully instills confidencehttps://go.dev/play/p/MfFltxQepYE

johnstcn reacted with thumbs up emoji
replicas = append(replicas, replica)
}
return replicas
Expand Down
2 changes: 0 additions & 2 deletionssite/site.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -849,8 +849,6 @@ func verifyBinSha1IsCurrent(dest string, siteFS fs.FS, shaFiles map[string]strin

// Verify the hash of each on-disk binary.
forfile,hash1:=rangeshaFiles {
file:=file
hash1:=hash1
eg.Go(func()error {
hash2,err:=sha1HashFile(filepath.Join(dest,file))
iferr!=nil {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp