From 2e2658ab6f3efb52a06f5008a2f8a3b2d11c3013 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Thu, 3 Nov 2016 04:18:26 -0400 Subject: [PATCH] examples: make the libmgmt example more fun You can try it out yourself by running `go build` and then calling it. Use a bare integer argument to create that number of noop resources. There are clearly some performance optimizations that we could do for extremely large graphs. --- examples/lib/libmgmt2.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/lib/libmgmt2.go b/examples/lib/libmgmt2.go index 6a993dba..9f27cf76 100644 --- a/examples/lib/libmgmt2.go +++ b/examples/lib/libmgmt2.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/signal" + "strconv" "sync" "syscall" "time" @@ -120,7 +121,7 @@ func (obj *MyGAPI) Close() error { } // Run runs an embedded mgmt server. -func Run() error { +func Run(count uint) error { obj := &mgmt.Main{} obj.Program = "libmgmt" // TODO: set on compilation @@ -132,7 +133,7 @@ func Run() error { obj.GAPI = &MyGAPI{ // graph API Name: "libmgmt", // TODO: set on compilation - Count: 60, // number of vertices to add + Count: count, // number of vertices to add Interval: 15, // arbitrarily change graph every 15 seconds } @@ -172,7 +173,13 @@ func Run() error { func main() { log.Printf("Hello!") - if err := Run(); err != nil { + var count uint = 1 // default + if len(os.Args) == 2 { + if i, err := strconv.Atoi(os.Args[1]); err == nil && i > 0 { + count = uint(i) + } + } + if err := Run(count); err != nil { fmt.Println(err) os.Exit(1) return