https://github.com/hetznercloud/hcloud-go
A Go library for the Hetzner Cloud API
https://github.com/hetznercloud/hcloud-go
api go golang hcloud hetzner hetzner-cloud
Last synced: 3 months ago
JSON representation
A Go library for the Hetzner Cloud API
- Host: GitHub
- URL: https://github.com/hetznercloud/hcloud-go
- Owner: hetznercloud
- License: mit
- Created: 2017-11-29T17:09:45.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2025-05-07T02:21:38.000Z (about 1 year ago)
- Last Synced: 2025-05-07T03:27:37.840Z (about 1 year ago)
- Topics: api, go, golang, hcloud, hetzner, hetzner-cloud
- Language: Go
- Homepage: https://pkg.go.dev/github.com/hetznercloud/hcloud-go/v2/hcloud
- Size: 4.78 MB
- Stars: 423
- Watchers: 11
- Forks: 46
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-hcloud - hcloud-go
README
# hcloud: A Go library for the Hetzner Cloud API
[](https://github.com/hetznercloud/hcloud-go/actions/workflows/ci.yml)
[](https://codecov.io/github/hetznercloud/hcloud-go/tree/main)
[](https://pkg.go.dev/github.com/hetznercloud/hcloud-go/v2/hcloud)
Package hcloud is a library for the Hetzner Cloud API.
The library’s documentation is available at [pkg.go.dev](https://pkg.go.dev/github.com/hetznercloud/hcloud-go/v2/hcloud),
the public API documentation is available at [docs.hetzner.cloud](https://docs.hetzner.cloud/).
> [!IMPORTANT]
> Make sure to follow our API changelog available at
> [docs.hetzner.cloud/changelog](https://docs.hetzner.cloud/changelog) (or the RSS feed
> available at
> [docs.hetzner.cloud/changelog/feed.rss](https://docs.hetzner.cloud/changelog/feed.rss))
> to be notified about additions, deprecations and removals.
## Installation
```sh
go get github.com/hetznercloud/hcloud-go/v2/hcloud
```
## Example
```go
package main
import (
"context"
"fmt"
"log"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/exp/actionutil"
)
func main() {
ctx := context.Background()
client := hcloud.NewClient(
hcloud.WithToken("token"),
hcloud.WithApplication("my-tool", "v1.0.0"),
)
result, _, err := client.Server.Create(ctx, hcloud.ServerCreateOpts{
Name: "Foo",
Image: &hcloud.Image{Name: "ubuntu-24.0"},
ServerType: &hcloud.ServerType{Name: "cpx22"},
Location: &hcloud.Location{Name: "hel1"},
})
if err != nil {
log.Fatalf("error creating server: %s\n", err)
}
// Always await any returned actions, to make sure the async process is completed before you use the result:
err = client.Action.WaitFor(ctx, actionutil.AppendNext(result.Action, result.NextActions)...)
if err != nil {
log.Fatalf("error creating server: %s\n", err)
}
server, _, err := client.Server.GetByID(ctx, result.Server.ID)
if err != nil {
log.Fatalf("error retrieving server: %s\n", err)
}
if server != nil {
fmt.Printf("server is called %q\n", server.Name) // prints 'server is called "Foo"'
} else {
fmt.Println("server not found")
}
}
```
## Experimental features
Experimental features are published as part of our regular releases (e.g. a product
public beta). During an experimental phase, breaking changes on those features may occur
within minor releases.
The stability of experimental features is not related to the stability of its upstream API.
Experimental features have different levels of maturity (e.g. experimental, alpha, beta)
based on the maturity of the upstream API.
While experimental features will be announced in the release notes, you can also find
whether a struct or function is experimental in its Go code comment:
```go
// Experimental: $PRODUCT is $MATURITY, breaking changes may occur within minor releases.
// See https://docs.hetzner.cloud/changelog#$SLUG for more details.
```
## Upgrading
### Support
- `v2` is actively maintained by Hetzner Cloud
- `v1` is unsupported since February 2025.
### From v1 to v2
Version 2.0.0 was published because we changed the datatype of all `ID` fields from `int` to `int64`.
To migrate to the new version, replace all your imports to reference the new module path:
```diff
import (
- "github.com/hetznercloud/hcloud-go/hcloud"
+ "github.com/hetznercloud/hcloud-go/v2/hcloud"
)
```
When you compile your code, it will show any invalid usages of `int` in your code that you need to fix. We commonly found these changes while updating our integrations:
- `strconv.Atoi(idString)` (parsing integers) needs to be replaced by `strconv.ParseInt(idString, 10, 64)`
- `strconv.Itoa(id)` (formatting integers) needs to be replaced by `strconv.FormatInt(id, 10)`
## Go Version Support
The library supports the latest two Go minor versions, e.g. at the time Go 1.19 is released, it supports Go 1.18 and 1.19.
This matches the official [Go Release Policy](https://go.dev/doc/devel/release#policy).
When the minimum required Go version is changed, it is announced in the release notes for that version.
## Development
### Experimental Features
When adding an experimental feature:
1. Add the marker comment above the declaration:
```go
// Experimental: $PRODUCT is $MATURITY, breaking changes may occur within minor releases.
```
2. Include a link to the changelog entry:
```go
// See https://docs.hetzner.cloud/changelog#slug for more details.
```
3. Add an announcement to the release notes.
Example:
```go
// String returns a pointer to the passed string s.
//
// Experimental: Product is beta, breaking changes may occur within minor releases.
// See https://docs.hetzner.cloud/changelog#slug for more details.
func String(s string) *string { return Ptr(s) }
```
## License
MIT license