AdGuardHome/internal/configmigrate/v7.go
Ainar Garipov ee619b2dbd 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
2024-04-04 15:52:39 +03:00

57 lines
1.3 KiB
Go

package configmigrate
import "github.com/AdguardTeam/golibs/errors"
// migrateTo7 performs the following changes:
//
// # BEFORE:
// 'schema_version': 6
// 'dhcp':
// 'enabled': false
// 'interface_name': vboxnet0
// 'gateway_ip': '192.168.56.1'
// 'subnet_mask': '255.255.255.0'
// 'range_start': '192.168.56.10'
// 'range_end': '192.168.56.240'
// 'lease_duration': 86400
// 'icmp_timeout_msec': 1000
// # …
//
// # AFTER:
// 'schema_version': 7
// 'dhcp':
// 'enabled': false
// 'interface_name': vboxnet0
// 'dhcpv4':
// 'gateway_ip': '192.168.56.1'
// 'subnet_mask': '255.255.255.0'
// 'range_start': '192.168.56.10'
// 'range_end': '192.168.56.240'
// 'lease_duration': 86400
// 'icmp_timeout_msec': 1000
// # …
func migrateTo7(diskConf yobj) (err error) {
diskConf["schema_version"] = 7
dhcp, ok, _ := fieldVal[yobj](diskConf, "dhcp")
if !ok {
return nil
}
dhcpv4 := yobj{}
err = errors.Join(
moveSameVal[string](dhcp, dhcpv4, "gateway_ip"),
moveSameVal[string](dhcp, dhcpv4, "subnet_mask"),
moveSameVal[string](dhcp, dhcpv4, "range_start"),
moveSameVal[string](dhcp, dhcpv4, "range_end"),
moveSameVal[int](dhcp, dhcpv4, "lease_duration"),
moveSameVal[int](dhcp, dhcpv4, "icmp_timeout_msec"),
)
if err != nil {
return err
}
dhcp["dhcpv4"] = dhcpv4
return nil
}