diff options
author | Carl Baldwin <carl@ecbaldwin.net> | 2019-08-16 09:17:43 -0600 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-08-28 09:06:20 +0900 |
commit | fbe0ca9ede483494219b4365e142eabd41250713 (patch) | |
tree | 23bc8892a6fcaf5fb852a32fd210cc8a9e80b836 /pkg/config/config_test.go | |
parent | 8d9d5c91e99ef4a8582ff2d9bc16443dff9de78d (diff) |
Document config API and provide examples
Diffstat (limited to 'pkg/config/config_test.go')
-rw-r--r-- | pkg/config/config_test.go | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go new file mode 100644 index 00000000..67ffa5e7 --- /dev/null +++ b/pkg/config/config_test.go @@ -0,0 +1,68 @@ +package config + +import ( + "context" + "os" + "os/signal" + "syscall" + + "github.com/osrg/gobgp/pkg/server" +) + +// ExampleUpdateConfig shows how InitialConfig can be used without UpdateConfig +func ExampleInitialConfig() { + bgpServer := server.NewBgpServer() + go bgpServer.Serve() + + initialConfig, err := ReadConfigFile("gobgp.conf", "toml") + if err != nil { + // Handle error + return + } + + isGracefulRestart := true + _, err = InitialConfig(context.Background(), bgpServer, initialConfig, isGracefulRestart) + + if err != nil { + // Handle error + return + } +} + +// ExampleUpdateConfig shows how UpdateConfig is used in conjuction with +// InitialConfig. +func ExampleUpdateConfig() { + bgpServer := server.NewBgpServer() + go bgpServer.Serve() + + initialConfig, err := ReadConfigFile("gobgp.conf", "toml") + if err != nil { + // Handle error + return + } + + isGracefulRestart := true + currentConfig, err := InitialConfig(context.Background(), bgpServer, initialConfig, isGracefulRestart) + + if err != nil { + // Handle error + return + } + + sigCh := make(chan os.Signal, 1) + signal.Notify(sigCh, syscall.SIGHUP) + + for range sigCh { + newConfig, err := ReadConfigFile("gobgp.conf", "toml") + if err != nil { + // Handle error + continue + } + + currentConfig, err = UpdateConfig(context.Background(), bgpServer, currentConfig, newConfig) + if err != nil { + // Handle error + continue + } + } +} |