github.com/osrg/gobgp/v3@v3.30.0/pkg/config/config_test.go (about) 1 package config 2 3 import ( 4 "context" 5 "os" 6 "os/signal" 7 "syscall" 8 9 "github.com/osrg/gobgp/v3/pkg/server" 10 ) 11 12 // ExampleUpdateConfig shows how InitialConfig can be used without UpdateConfig 13 func ExampleInitialConfig() { 14 bgpServer := server.NewBgpServer() 15 go bgpServer.Serve() 16 17 initialConfig, err := ReadConfigFile("gobgp.conf", "toml") 18 if err != nil { 19 // Handle error 20 return 21 } 22 23 isGracefulRestart := true 24 _, err = InitialConfig(context.Background(), bgpServer, initialConfig, isGracefulRestart) 25 26 if err != nil { 27 // Handle error 28 return 29 } 30 } 31 32 // ExampleUpdateConfig shows how UpdateConfig is used in conjunction with 33 // InitialConfig. 34 func ExampleUpdateConfig() { 35 bgpServer := server.NewBgpServer() 36 go bgpServer.Serve() 37 38 initialConfig, err := ReadConfigFile("gobgp.conf", "toml") 39 if err != nil { 40 // Handle error 41 return 42 } 43 44 isGracefulRestart := true 45 currentConfig, err := InitialConfig(context.Background(), bgpServer, initialConfig, isGracefulRestart) 46 47 if err != nil { 48 // Handle error 49 return 50 } 51 52 sigCh := make(chan os.Signal, 1) 53 signal.Notify(sigCh, syscall.SIGHUP) 54 55 for range sigCh { 56 newConfig, err := ReadConfigFile("gobgp.conf", "toml") 57 if err != nil { 58 // Handle error 59 continue 60 } 61 62 currentConfig, err = UpdateConfig(context.Background(), bgpServer, currentConfig, newConfig) 63 if err != nil { 64 // Handle error 65 continue 66 } 67 } 68 }