Skip to content

Instantly share code, notes, and snippets.

@fredhsu
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredhsu/e6a32deee56c56ef3784 to your computer and use it in GitHub Desktop.
Save fredhsu/e6a32deee56c56ef3784 to your computer and use it in GitHub Desktop.
Some examples of using Go with concurrency for eAPI
package main
import (
"fmt"
"github.com/fredhsu/go-eapi"
//"time"
)
func main() {
cmds2 := []string{"enable", "show running-config"}
url1 := "https://admin:admin@bleaf1/command-api/"
msg1 := eapi.Call(url1, cmds2, "text")
fmt.Println(msg1)
}
package main
import (
"fmt"
"github.com/fredhsu/go-eapi"
//"time"
)
func versionFetcher(url string, cmds []string, format string, c chan eapi.JsonRpcResponse) {
response := eapi.Call(url, cmds, format)
c <- response
}
func main() {
cmds2 := []string{"enable", "show running-config"}
url1 := "https://admin:admin@bleaf1/command-api/"
url2 := "https://admin:admin@bleaf2/command-api/"
url3 := "https://admin:admin@bleaf3/command-api/"
url4 := "https://admin:admin@bleaf5/command-api/"
msg1 := eapi.Call(url1, cmds2, "text")
msg2 := eapi.Call(url2, cmds2, "text")
msg3 := eapi.Call(url3, cmds2, "text")
msg4 := eapi.Call(url4, cmds2, "text")
fmt.Println(msg1)
fmt.Println(msg2)
fmt.Println(msg3)
fmt.Println(msg4)
}
package main
import (
"fmt"
"github.com/fredhsu/go-eapi"
)
func configFetcher(url string, cmds []string, format string, c chan eapi.JsonRpcResponse) {
response := eapi.Call(url, cmds, format)
c <- response
}
func main() {
cmds2 := []string{"enable", "show running-config"}
url1 := "https://admin:admin@bleaf1/command-api/"
url2 := "https://admin:admin@bleaf2/command-api/"
url3 := "https://admin:admin@bleaf3/command-api/"
url4 := "https://admin:admin@bleaf5/command-api/"
c1 := make(chan eapi.JsonRpcResponse)
c2 := make(chan eapi.JsonRpcResponse)
c3 := make(chan eapi.JsonRpcResponse)
c4 := make(chan eapi.JsonRpcResponse)
go configFetcher(url1, cmds2, "text", c1)
go configFetcher(url2, cmds2, "text", c2)
go configFetcher(url3, cmds2, "text", c3)
go configFetcher(url4, cmds2, "text", c4)
msg1 := <- c1
msg2 := <- c2
msg3 := <- c3
msg4 := <- c4
fmt.Println(msg1)
fmt.Println(msg2)
fmt.Println(msg3)
fmt.Println(msg4)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment