Pull request 2195: upd-go-code
Squashed commit of the following: commit a1bd3c249be043108c84a902d2e88bf80946d444 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Apr 4 14:59:37 2024 +0300 all: upd more commit 9e55bbb02c2af2064aa2a2ca7b49fd28b544a02c Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Apr 4 14:12:45 2024 +0300 all: upd go code
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package configmigrate
|
||||
|
||||
import "github.com/AdguardTeam/golibs/errors"
|
||||
|
||||
// migrateTo15 performs the following changes:
|
||||
//
|
||||
// # BEFORE:
|
||||
@@ -43,7 +45,7 @@ func migrateTo15(diskConf yobj) (err error) {
|
||||
}
|
||||
diskConf["querylog"] = qlog
|
||||
|
||||
return coalesceError(
|
||||
return errors.Join(
|
||||
moveVal[bool](dns, qlog, "querylog_enabled", "enabled"),
|
||||
moveVal[bool](dns, qlog, "querylog_file_enabled", "file_enabled"),
|
||||
moveVal[any](dns, qlog, "querylog_interval", "interval"),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package configmigrate
|
||||
|
||||
import "github.com/AdguardTeam/golibs/errors"
|
||||
|
||||
// migrateTo24 performs the following changes:
|
||||
//
|
||||
// # BEFORE:
|
||||
@@ -28,7 +30,7 @@ func migrateTo24(diskConf yobj) (err error) {
|
||||
diskConf["schema_version"] = 24
|
||||
|
||||
logObj := yobj{}
|
||||
err = coalesceError(
|
||||
err = errors.Join(
|
||||
moveVal[string](diskConf, logObj, "log_file", "file"),
|
||||
moveVal[int](diskConf, logObj, "log_max_backups", "max_backups"),
|
||||
moveVal[int](diskConf, logObj, "log_max_size", "max_size"),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package configmigrate
|
||||
|
||||
import "github.com/AdguardTeam/golibs/errors"
|
||||
|
||||
// migrateTo26 performs the following changes:
|
||||
//
|
||||
// # BEFORE:
|
||||
@@ -78,7 +80,7 @@ func migrateTo26(diskConf yobj) (err error) {
|
||||
}
|
||||
|
||||
filteringObj := yobj{}
|
||||
err = coalesceError(
|
||||
err = errors.Join(
|
||||
moveSameVal[bool](dns, filteringObj, "filtering_enabled"),
|
||||
moveSameVal[int](dns, filteringObj, "filters_update_interval"),
|
||||
moveSameVal[bool](dns, filteringObj, "parental_enabled"),
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package configmigrate
|
||||
|
||||
import "github.com/AdguardTeam/golibs/errors"
|
||||
|
||||
// migrateTo7 performs the following changes:
|
||||
//
|
||||
// # BEFORE:
|
||||
@@ -37,7 +39,7 @@ func migrateTo7(diskConf yobj) (err error) {
|
||||
}
|
||||
|
||||
dhcpv4 := yobj{}
|
||||
err = coalesceError(
|
||||
err = errors.Join(
|
||||
moveSameVal[string](dhcp, dhcpv4, "gateway_ip"),
|
||||
moveSameVal[string](dhcp, dhcpv4, "subnet_mask"),
|
||||
moveSameVal[string](dhcp, dhcpv4, "range_start"),
|
||||
|
||||
@@ -50,19 +50,3 @@ func moveVal[T any](src, dst yobj, srcKey, dstKey string) (err error) {
|
||||
func moveSameVal[T any](src, dst yobj, key string) (err error) {
|
||||
return moveVal[T](src, dst, key, key)
|
||||
}
|
||||
|
||||
// coalesceError returns the first non-nil error. It is named after function
|
||||
// COALESCE in SQL. If all errors are nil, it returns nil.
|
||||
//
|
||||
// TODO(e.burkov): Replace with [errors.Join].
|
||||
//
|
||||
// TODO(a.garipov): Think of ways to merge with [aghalg.Coalesce].
|
||||
func coalesceError(errors ...error) (res error) {
|
||||
for _, err := range errors {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user