Use newConfig more consistently when apply initial configuration

This block of code has for loops that shadow the variable `c` declared
above it. This commit makes the scoping a little clearer by using
newConfig where possible to avoid the ambiguity.
This commit is contained in:
Carl Baldwin
2019-08-28 09:06:20 +09:00
committed by FUJITA Tomonori
parent bf2df3ec6f
commit 72094dfcee
+8 -8
View File
@@ -238,25 +238,25 @@ func main() {
if c == nil {
c = newConfig
if err := bgpServer.StartBgp(context.Background(), &api.StartBgpRequest{
Global: config.NewGlobalFromConfigStruct(&c.Global),
Global: config.NewGlobalFromConfigStruct(&newConfig.Global),
}); err != nil {
log.Fatalf("failed to set global config: %s", err)
}
if newConfig.Zebra.Config.Enabled {
tps := c.Zebra.Config.RedistributeRouteTypeList
tps := newConfig.Zebra.Config.RedistributeRouteTypeList
l := make([]string, 0, len(tps))
for _, t := range tps {
l = append(l, string(t))
}
if err := bgpServer.EnableZebra(context.Background(), &api.EnableZebraRequest{
Url: c.Zebra.Config.Url,
Url: newConfig.Zebra.Config.Url,
RouteTypes: l,
Version: uint32(c.Zebra.Config.Version),
NexthopTriggerEnable: c.Zebra.Config.NexthopTriggerEnable,
NexthopTriggerDelay: uint32(c.Zebra.Config.NexthopTriggerDelay),
MplsLabelRangeSize: uint32(c.Zebra.Config.MplsLabelRangeSize),
SoftwareName: c.Zebra.Config.SoftwareName,
Version: uint32(newConfig.Zebra.Config.Version),
NexthopTriggerEnable: newConfig.Zebra.Config.NexthopTriggerEnable,
NexthopTriggerDelay: uint32(newConfig.Zebra.Config.NexthopTriggerDelay),
MplsLabelRangeSize: uint32(newConfig.Zebra.Config.MplsLabelRangeSize),
SoftwareName: newConfig.Zebra.Config.SoftwareName,
}); err != nil {
log.Fatalf("failed to set zebra config: %s", err)
}