Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go example needs some cleanup. #35

Open
linuxus opened this issue Oct 15, 2017 · 0 comments
Open

Go example needs some cleanup. #35

linuxus opened this issue Oct 15, 2017 · 0 comments

Comments

@linuxus
Copy link

linuxus commented Oct 15, 2017

The Go example for list all enterprises contains couple mistakes. It should have the following changes:

  • To avoid SSL error (invalide certificate) we should includ *Session.SetInsecureSkipVerify(true)

  • Also, err.Description is not a valid method in the bambou package.

  • Sample code should be rather more like this:


import (
	"fmt"
	"os"
	"strconv"

	"github.com/nuagenetworks/vspk-go/vspk"
)

var vsdURL = "https://localhost:8443"
var vsdUser = "csproot"
var vsdPass = "csproot"
var vsdEnterprise = "csp"

func main() {
	mysession, root := vspk.NewSession(vsdUser, vsdPass, vsdEnterprise, vsdURL)
        // Skip x509 Error
	mysession.SetInsecureSkipVerify(true)
	if err := mysession.Start(); err != nil {
		fmt.Println("Unable to connect to Nuage VSD: " + err.Message) //err.Description is not a valid method in bambou package.
		os.Exit(1)
	}

	enterprises, err := root.Enterprises(nil)
	if err != nil {
		fmt.Println("Unable to fetch enterprises: " + err.Message) //err.Description is not a valid method in bambou package.
		os.Exit(1)
	}
	fmt.Println("Number of enterprises retrieved: " + strconv.Itoa(len(enterprises)))

	for _, enterprise := range enterprises {
		fmt.Println(enterprise.Name)
	}
}

Thanks for sharing the examples!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant