Skip to content

Commit

Permalink
home: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Aug 30, 2023
1 parent ef40d07 commit a50ff16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
16 changes: 6 additions & 10 deletions internal/home/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -1566,11 +1566,7 @@ func moveField[T any](fromObj, newConf yobj, key, newKey string) (err error) {
return err
}

if newVal == nil {
newConf[newKey] = nil
} else {
newConf[newKey] = *newVal
}
newConf[newKey] = newVal

return nil
}
Expand All @@ -1583,22 +1579,22 @@ func moveFieldValue[T any](fromObj, newConf yobj, key string) (err error) {

// fieldValue returns the value of type T for key in confObj object. Returns
// nil for fields with nil values.
func fieldValue[T any](confObj yobj, key string) (ok bool, field *T, err error) {
func fieldValue[T any](confObj yobj, key string) (ok bool, field T, err error) {
fieldVal, ok := confObj[key]
if !ok {
return false, new(T), nil
return false, field, nil
}

if fieldVal == nil {
return true, nil, nil
return true, field, nil
}

f, ok := fieldVal.(T)
if !ok {
return false, nil, fmt.Errorf("unexpected type of %s: %T", key, fieldVal)
return false, field, fmt.Errorf("unexpected type of %s: %T", key, fieldVal)
}

return true, &f, nil
return true, f, nil
}

// coalesceError returns the first non-nil error. It is named after function
Expand Down
4 changes: 2 additions & 2 deletions internal/home/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ func TestUpgradeSchema25to26(t *testing.T) {
"blocking_ipv4": "1.2.3.4",
"blocking_ipv6": "1:2:3::4",
"blocked_response_ttl": 10,
"protection_disabled_until": nil,
"protection_disabled_until": "2023-08-30T11:19:53.056354+03:00",
"parental_block_host": "p.dns.adguard.com",
"safebrowsing_block_host": "s.dns.adguard.com",
},
Expand Down Expand Up @@ -1548,7 +1548,7 @@ func TestUpgradeSchema25to26(t *testing.T) {
"blocking_ipv4": "1.2.3.4",
"blocking_ipv6": "1:2:3::4",
"blocked_response_ttl": 10,
"protection_disabled_until": nil,
"protection_disabled_until": "2023-08-30T11:19:53.056354+03:00",
"parental_block_host": "p.dns.adguard.com",
"safebrowsing_block_host": "s.dns.adguard.com",
},
Expand Down

0 comments on commit a50ff16

Please sign in to comment.