With Golang gaining so much traction, we started to implement support for the language in November ‘18. Since then, we’ve implemented a lot of functionality – adding support for endpoints, implementing testing and adding high-end documentation – Along with this (and much more) we’re proud to release v2.0.0 of our gsclient-go.
This post is going to take you briefly into our Golang library, explain some concepts and help you get started.
The latest release brings some important updates:
- Enabling sync mode
- Default resource configurations
- Auto retry upon receiving 5xx and 424 error codes
- Fully controlled library through context
Then install our gsclient-go with `go get “github.com/gridscale/gsclient-go”`
@nvthongswansea has done a huge amount of work recently, making the v2.0.0 release possible. He’s also gone ahead and made it even easier to get started, and has given us some examples to get started. We will take a look at the server.go examples.
We’ll set our credentials as environment variables
`export GRIDSCALE_TOKEN=”API_TOKEN” GRIDSCALE_UUID=”USER_UUID”`
Replace API_TOKEN & USER_UUID with your API credentials
Spinning up a simple setup
Navigate to the gsclient-go directory
Running `go run server.go` will now go through these steps, prompting you to press enter before executing each step:
- Create a new server with `CreateServer()`.
- Get the created server with `GetServer()`.
- Start the created server with `StartServer()` as a test.
- Switch it off again with `ShutdownServer()` – this is an ACPI shutdown. The alternative, but less safe is `StopServer()`.
- Update the details and resources of the server with `UpdateServer()`.
- Print the event log of the created server with `GetServerEventList()`.
- Create a storage with `CreateStorage()`.
- Create a network with `CreateNetwork()`.
- Create an IP address with `CreateIP()`.
- Create an ISO Image with `CreateISOImage()` – This downloads an image from tinycorelinux.net
- We then link all the created resources with `LinkStorage()`, `LinkNetwork()`, `LinkIP()` and `LinkIsoImage()` respectively.
You’ll then be prompted to unlink and delete all of the created resources. Either confirm with `enter`, or exit with `ctrl+c` to keep the resources and take some further steps yourself.
You can check out the other files in the example directory, they’re pretty verbose so customizing them to your needs should be a walk in the park.
Have fun managing infrastructure with golang, this library is also the basis for our Terraform integration.
Marc Harriss | Product Owner
As gridscales Product Owner, Marc works closely on product processes and maximising the value of the product from working with the Development teams. He works with the philosophy of "develop products as a customer" in mind, has a passion for software and how things work. With a professional background in I.T. and Logistics management in the startup scene, Marc is used to working with fast paced, interdisciplinary teams, to move things forward.