Package domains-go provides Go SDK to work with the Selectel Domains API.
The Go library documentation is available at go.dev.
You can use this library to work with the following objects of the Selectel Domains API:
You can install needed domains-go
packages via go get
command:
go get github.com/selectel/domains-go/pkg/v1/domain github.com/selectel/domains-go/pkg/v1/record
To work with the Selectel Domains API you first need to:
- Create a Selectel account: registration page.
- Create an API token: https://my.selectel.ru/profile/apikeys
package main
import (
"context"
"fmt"
"log"
v1 "github.com/selectel/domains-go/pkg/v1"
"github.com/selectel/domains-go/pkg/v1/domain"
"github.com/selectel/domains-go/pkg/v1/record"
)
func main() {
// Token to work with Selectel Cloud project
token := "gAAAAABeVNzu-..."
// Domains API V1 endpoint to work with
endpoint := "https://api.selectel.ru/domains/v1"
// Initialize the Domains API V1 client
client := v1.NewDomainsClientV1(token, endpoint)
createDomainOpts := &domain.CreateOpts{
Name: "testdomain.xyz",
}
// Create domain
selectelDomain, _, err := domain.Create(context.Background(), client, createDomainOpts)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created domain: %+v\n", selectelDomain)
// List domains
selectelDomains, _, err := domain.List(context.Background(), client)
if err != nil {
log.Fatal(err)
}
for _, d := range selectelDomains {
fmt.Printf("%+v\n", d)
}
createRecordOpts := &record.CreateOpts{
Name: "share.testdomain.xyz",
Type: record.TypeCNAME,
TTL: 60,
Content: "origin.example.com",
}
// Create domain record
domainRecord, _, err := record.Create(context.Background(), client, selectelDomain.ID, createRecordOpts)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created record: %+v\n", domainRecord)
}