config.go: iterate slices via indices to get pointers instead of copies
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Iterating over a slice returns a copy of the respective member instead of a reference to the original slice member. Thus, any modification are discarded and the pointers saved inside cfg.users and cfg.rrconfigs are incorrect, too.
This commit is contained in:
parent
e15da33296
commit
76286b6388
1 changed files with 7 additions and 4 deletions
11
config.go
11
config.go
|
|
@ -61,7 +61,8 @@ func prepareConfig(cfg *Config) (*Config, error) {
|
|||
|
||||
// populate user map
|
||||
cfg.users = map[string]*User{}
|
||||
for _, user := range cfg.Users {
|
||||
for u := range cfg.Users {
|
||||
user := &cfg.Users[u]
|
||||
if _, ok := cfg.users[user.Username]; ok {
|
||||
return nil, fmt.Errorf("Duplicate username detected: %s", user.Username)
|
||||
}
|
||||
|
|
@ -80,12 +81,14 @@ func prepareConfig(cfg *Config) (*Config, error) {
|
|||
user.records[record] = true
|
||||
globRecords[record] = true
|
||||
}
|
||||
cfg.users[user.Username] = &user
|
||||
cfg.users[user.Username] = user
|
||||
}
|
||||
|
||||
// populate record map
|
||||
cfg.rrconfigs = map[string]*RRConfig{}
|
||||
for _, record := range cfg.RRConfigs {
|
||||
for r := range cfg.RRConfigs {
|
||||
record := &cfg.RRConfigs[r]
|
||||
|
||||
// check for duplicate record before verifying association to users
|
||||
if _, ok := cfg.rrconfigs[record.Recordname]; ok {
|
||||
return nil, fmt.Errorf("Duplicate record detected: %s", record.Recordname)
|
||||
|
|
@ -97,7 +100,7 @@ func prepareConfig(cfg *Config) (*Config, error) {
|
|||
// need to remove record from globRecords for detecting orphaned records
|
||||
delete(globRecords, record.Recordname)
|
||||
|
||||
cfg.rrconfigs[record.Recordname] = &record
|
||||
cfg.rrconfigs[record.Recordname] = record
|
||||
}
|
||||
|
||||
// check whether all records have been processed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue