Cherry Servers golang API client library for Cherry Servers RESTful API.
You can view the client API docs here: https://pkg.go.dev/github.com/cherryservers/cherrygo/v3
You can view Cherry Servers API docs here: https://api.cherryservers.com/doc
Download the library to your GOPATH:
go get github.com/cherryservers/cherrygo/v3
Then import the library in your Go code:
import "github.com/cherryservers/cherrygo/v3
To authenticate to the Cherry Servers API, you must have an API token. You can create API tokens in the Cherry Servers client portal. Tokens must be exported in the CHERRY_AUTH_TOKEN
environment variable or passed to the client directly.
Use an exported CHERRY_AUTH_TOKEN environment variable:
export CHERRY_AUTH_TOKEN="4bdc0acb8f7af4bdc0acb8f7afe78522e6dae9b7e03b0e78522e6dae9b7e03b0"
func main() {
c, err := cherrygo.NewClient()
}
Pass a token directly to the client:
func main() {
c, err := cherrygo.NewClient(cherrygo.WithAuthToken("your-api-token"))
}
You will need a team ID for subsequent function calls, for example, to get projects for a specified team, you will need to provide a team ID.
teams, _, err := c.Teams.List(nil)
if err != nil {
log.Fatal("Error", err)
}
for _, t := range teams {
log.Println(t.ID, t.Name, t.Credit.Promo.Remaining, t.Credit.Promo.Usage, t.Credit.Resources.Pricing.Price)
}
After you have your team ID, you can list your projects. You will need your project ID to list your servers or order new ones.
projects, _, err := c.Projects.List(teamID, nil)
if err != nil {
log.Fatal("Error", err)
}
for _, p := range projects {
log.Println(p.ID, p.Name, p.Href)
}
View available server plans.
plans, _, err := c.Plans.List(teamID, nil)
if err != nil {
log.Fatalf("Plans error: %v", err)
}
for _, p := range plans {
log.Println(p.Name, p.Slug)
}
View OS images available for a specific plan.
images, _, err := c.Images.List(planSlug, nil)
if err != nil {
log.Fatal("Error", err)
}
for _, i := range images {
log.Println(i.Name, i.Slug)
}
addServerRequest := cherrygo.CreateServer{
ProjectID: projectID,
Image: imageSlug,
Region: regionSlug,
Plan: planSlug,
}
server, _, err := c.Servers.Create(&addServerRequest)
if err != nil {
log.Fatal("Error while creating new server: ", err)
}
log.Println(server.ID, server.Name, server.Hostname)
If you want to debug this library, set the CHERRY_DEBUG environment variable to true, which enable full API request and response logging.
export CHERRY_DEBUG="true"
Unset the variable to stop debugging.
unset CHERRY_DEBUG
See the LICENSE file for license rights and limitations.