From fbe0ca9ede483494219b4365e142eabd41250713 Mon Sep 17 00:00:00 2001 From: Carl Baldwin Date: Fri, 16 Aug 2019 09:17:43 -0600 Subject: Document config API and provide examples --- pkg/config/config_test.go | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 pkg/config/config_test.go (limited to 'pkg/config/config_test.go') 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 + } + } +} -- cgit v1.2.3