sweb

package module
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 14 Imported by: 0

README

sweb-go-sdk

CI Go Reference Go Report Card

A Go client for the SpaceWeb (sweb.ru) hosting API.

The API speaks JSON-RPC 2.0 over HTTPS. This SDK wraps the transport (envelope, Bearer auth, error handling) and exposes typed operations grouped into services. It is the shared foundation for the sweb CLI and a future Terraform provider.

Install

go get github.com/sanchpet/sweb-go-sdk

Usage

package main

import (
	"context"
	"fmt"

	sweb "github.com/sanchpet/sweb-go-sdk"
)

func main() {
	ctx := context.Background()

	// 1. Exchange credentials for a token (unauthenticated endpoint).
	tmp := sweb.New()
	token, err := tmp.CreateToken(ctx, "login", "password")
	if err != nil {
		panic(err)
	}

	// 2. Use the token for authenticated calls.
	c := sweb.New(sweb.WithToken(token))

	vpsList, err := c.VPS.List(ctx)
	if err != nil {
		panic(err)
	}
	fmt.Println(vpsList)
}

Status

Early. The transport (JSON-RPC envelope, auth, error handling) is covered by tests. Resource result types (VPS list, available config, create) are provisional and will be firmed up against recorded API responses.

License

MIT — see LICENSE.

Documentation

Overview

Package sweb is a Go client for the SpaceWeb (sweb.ru) hosting API.

The API speaks JSON-RPC 2.0 over HTTPS POST. Client is a facade: New wires the per-service clients (vps, ip, dns, …) over one shared transport and exposes them as fields (e.g. Client.VPS), preserving every call site. The transport (envelope, Bearer auth with transparent token refresh, error handling) lives in internal/transport, so it is unimportable by external consumers.

SpaceWeb issues short-lived session tokens and has no refresh-token flow. Use WithCredentials so the client transparently re-exchanges login+password for a fresh token when the session expires.

Index

Constants

View Source
const DefaultBaseURL = transport.DefaultBaseURL

DefaultBaseURL is the production SpaceWeb API root.

Variables

View Source
var (
	// WithBaseURL overrides the API root (useful for tests / staging).
	WithBaseURL = transport.WithBaseURL
	// WithToken sets the Bearer token used for authenticated endpoints.
	WithToken = transport.WithToken
	// WithHTTPClient injects a custom *http.Client (timeouts, transport, test server).
	WithHTTPClient = transport.WithHTTPClient
	// WithCredentials enables transparent token refresh: when a call fails because
	// the session token expired, the client exchanges login+password for a fresh
	// token (getToken) and retries once. Pair with WithOnTokenRefresh to persist it.
	WithCredentials = transport.WithCredentials
	// WithOnTokenRefresh registers a callback invoked with the new token whenever
	// the client refreshes it — e.g. to cache it in an OS keyring.
	WithOnTokenRefresh = transport.WithOnTokenRefresh
)

The functional options, re-exported from the transport.

Functions

This section is empty.

Types

type Client

type Client struct {

	// VPS groups VPS operations (endpoint /vps).
	VPS *vps.Service
	// IP groups IP operations (endpoint /vps/ip): local network + public IPs.
	IP *ip.Service
	// Backup groups local backup operations (endpoint /vps/backup).
	Backup *backup.Service
	// RemoteBackup groups cloud backup operations (endpoint /vps/remoteBackup).
	RemoteBackup *remotebackup.Service
	// DNS groups DNS-zone operations (endpoint /domains/dns).
	DNS *dns.Service
	// Domains groups domain/subdomain operations (endpoint /domains).
	Domains *domains.Service
	// Balancer groups load-balancer operations (endpoint /balancer).
	Balancer *balancer.Service
	// DBaaS groups managed-database operations (endpoint /dbaas).
	DBaaS *dbaas.Service
	// SSL groups VPS SSL-certificate operations (endpoint /vps/ssl).
	SSL *ssl.Service
	// Monitoring groups monitoring-tariff operations (endpoint /monitoring).
	Monitoring *monitoring.Service
	// MonitoringChecks groups monitoring-check operations (endpoint /monitoring/checks).
	MonitoringChecks *checks.Service
	// MonitoringContacts groups monitoring-contact operations (endpoint /monitoring/contacts).
	MonitoringContacts *contacts.Service
	// contains filtered or unexported fields
}

Client talks to the SpaceWeb JSON-RPC API. Construct it with New. It is a facade: each field is a service client sharing one transport.

func New

func New(opts ...Option) *Client

New builds a Client. A token (WithToken) and/or credentials (WithCredentials) are optional but required for authenticated endpoints.

func (*Client) CreateToken

func (c *Client) CreateToken(ctx context.Context, login, password string) (string, error)

CreateToken exchanges a login + password for a personal access token via the unauthenticated endpoint (/notAuthorized/, method getToken). The returned token is then supplied via WithToken for authenticated calls.

func (*Client) Token added in v0.1.3

func (c *Client) Token() string

Token returns the current Bearer token (which may have been refreshed).

type Option

type Option = transport.Option

Option configures a Client. Options are defined in the transport and re-exported here so callers keep using sweb.WithToken(…) etc.

Directories

Path Synopsis
api-spec
coverage command
Command coverage measures, per API object, how many of its JSON-RPC methods the SDK implements, and writes a human-readable report to api-spec/COVERAGE.md.
Command coverage measures, per API object, how many of its JSON-RPC methods the SDK implements, and writes a human-readable report to api-spec/COVERAGE.md.
gen command
Command gen regenerates the OpenRPC snapshot under api-spec/openrpc/.
Command gen regenerates the OpenRPC snapshot under api-spec/openrpc/.
Package apierr holds the SDK's API-level error type.
Package apierr holds the SDK's API-level error type.
Package backup groups local (on-node) backup operations (endpoint /vps/backup): list/create/restore/remove, attach/detach a backup as a disk, and the auto-backup schedule.
Package backup groups local (on-node) backup operations (endpoint /vps/backup): list/create/restore/remove, attach/detach a backup as a disk, and the auto-backup schedule.
Package balancer groups load-balancer operations (endpoint /balancer): list/isCreateEnable/getAvailableConfig plus the create/edit/remove lifecycle.
Package balancer groups load-balancer operations (endpoint /balancer): list/isCreateEnable/getAvailableConfig plus the create/edit/remove lifecycle.
Package dbaas groups managed-database (DBaaS) operations (endpoint /dbaas): listing clusters, the create-page config/constructor lookups, the promotional first-order flow, and cluster/database lifecycle (create/edit/remove/delete).
Package dbaas groups managed-database (DBaaS) operations (endpoint /dbaas): listing clusters, the create-page config/constructor lookups, the promotional first-order flow, and cluster/database lifecycle (create/edit/remove/delete).
Package dns groups DNS-zone operations (endpoint /domains/dns): read the zone (Records, ZoneFile) and edit records by type (Main/MX/SRV/NS/TXT).
Package dns groups DNS-zone operations (endpoint /domains/dns): read the zone (Records, ZoneFile) and edit records by type (Main/MX/SRV/NS/TXT).
Package domains groups domain and subdomain operations (endpoint /domains): read the account's domains (List, Info, Subdomains), check/price registration and transfer, and mutate the domain lifecycle (register, move-in, prolong, remove, redirect, subdomain CRUD).
Package domains groups domain and subdomain operations (endpoint /domains): read the account's domains (List, Info, Subdomains), check/price registration and transfer, and mutate the domain lifecycle (register, move-in, prolong, remove, redirect, subdomain CRUD).
Package flex holds the tolerant JSON scalar types the SpaceWeb API forces on every consumer: the API quotes numeric fields inconsistently (bare 1, quoted "1024", or null) and even returns money as int-or-float, so a plain int/float panics on real payloads.
Package flex holds the tolerant JSON scalar types the SpaceWeb API forces on every consumer: the API quotes numeric fields inconsistently (bare 1, quoted "1024", or null) and even returns money as int-or-float, so a plain int/float panics on real payloads.
internal
transport
Package transport is the internal JSON-RPC spine of the SDK: it owns the Client (HTTP transport, envelope, Bearer auth with transparent token refresh, and error mapping) and the functional Options that configure it.
Package transport is the internal JSON-RPC spine of the SDK: it owns the Client (HTTP transport, envelope, Bearer auth with transparent token refresh, and error mapping) and the functional Options that configure it.
Package ip groups IP operations (endpoint /vps/ip): the account private (local) network and public/additional IP management.
Package ip groups IP operations (endpoint /vps/ip): the account private (local) network and public/additional IP management.
Package monitoring groups the monitoring-service subscription operations (endpoint /monitoring): enable, disable, and change the monitoring tariff, and list the available plans.
Package monitoring groups the monitoring-service subscription operations (endpoint /monitoring): enable, disable, and change the monitoring tariff, and list the available plans.
checks
Package checks groups the monitoring-check operations (endpoint /monitoring/checks): list and inspect checks, read the reference dictionaries (types, intervals, ports, keyword modes), create/edit checks, toggle them on and off individually or in bulk, remove them, and read check history.
Package checks groups the monitoring-check operations (endpoint /monitoring/checks): list and inspect checks, read the reference dictionaries (types, intervals, ports, keyword modes), create/edit checks, toggle them on and off individually or in bulk, remove them, and read check history.
contacts
Package contacts groups the monitoring-contact operations (endpoint /monitoring/contacts): list contacts, add/edit/delete email, phone, and Telegram contacts, and drive the Telegram verification flow.
Package contacts groups the monitoring-contact operations (endpoint /monitoring/contacts): list contacts, add/edit/delete email, phone, and Telegram contacts, and drive the Telegram verification flow.
Package remotebackup groups cloud (off-node) backup operations (endpoint /vps/remoteBackup): list/create/remove, edit the comment, and restore into the source or a different VPS.
Package remotebackup groups cloud (off-node) backup operations (endpoint /vps/remoteBackup): list/create/remove, edit the comment, and restore into the source or a different VPS.
Package ssl groups VPS SSL-certificate operations (endpoint /vps/ssl): list the account's certificates, browse and order the certificate catalogue, download an issued certificate archive, and manage a certificate's auto-prolongation and lifecycle.
Package ssl groups VPS SSL-certificate operations (endpoint /vps/ssl): list the account's certificates, browse and order the certificate catalogue, download an issued certificate archive, and manage a certificate's auto-prolongation and lifecycle.
Package vps groups VPS operations (endpoint /vps): the VPS lifecycle (create/remove/rename/changePlan/copy/reinstall), power control, the configurator lookups, the first-order flow, load graphs, logs, and the getAvailableConfig catalog.
Package vps groups VPS operations (endpoint /vps): the VPS lifecycle (create/remove/rename/changePlan/copy/reinstall), power control, the configurator lookups, the first-order flow, load graphs, logs, and the getAvailableConfig catalog.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL