sweb

package module
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 30 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

	// Mail groups shared-hosting email operations (endpoint /vh/mail).
	Mail *mail.Service
	// HostingDB groups shared-hosting database operations (endpoint /vh/hosting).
	HostingDB *hosting.Service
	// Sites groups shared-hosting website operations (endpoint /sites).
	Sites *sites.Service
	// VHSSL groups shared-hosting SSL-certificate operations (endpoint /vh/ssl).
	VHSSL *vhssl.Service
	// VHBackup groups shared-hosting account-backup operations (endpoint /vh/backup).
	VHBackup *vhbackup.Service
	// Cron groups shared-hosting crontab operations (endpoint /vh/cron).
	Cron *cron.Service
	// DDoSGuard groups DDoS-Guard operations (endpoint /vh/ddg).
	DDoSGuard *ddg.Service
	// HostingLoad groups shared-hosting server-load operations (endpoint /vh/load).
	HostingLoad *load.Service
	// SSH groups shared-hosting SSH-toggle operations (endpoint /vh/utils).
	SSH *ssh.Service
	// DiskUsage groups shared-hosting disk-usage operations (endpoint /vh/utils/diskUsage).
	DiskUsage *diskusage.Service
	// Tariff groups tariff / server-info operations (endpoint /tariff).
	Tariff *tariff.Service
	// Pay groups billing operations (endpoint /pay).
	Pay *pay.Service
	// Persons groups domain-registrant-person operations (endpoint /domains/persons).
	Persons *persons.Service
	// Bonus groups domain-bonus operations (endpoint /domains/bonus).
	Bonus *bonus.Service
	// PartnerProgram groups partner-program operations (endpoint /vh/partnerProgram).
	PartnerProgram *partner.Service
	// ReferralProgram groups referral-program operations (endpoint /vh/referralProgram).
	ReferralProgram *referral.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).
bonus
Package bonus groups domain-bonus operations (endpoint /domains/bonus): read the account's domain bonuses (Index), list purchasable bonus packages (GetList), and buy a package (Buy).
Package bonus groups domain-bonus operations (endpoint /domains/bonus): read the account's domain bonuses (Index), list purchasable bonus packages (GetList), and buy a package (Buy).
persons
Package persons groups domain-registrant-person operations (endpoint /domains/persons): list the account's registrant contacts (List), read one in full (Info), and create an individual/sole-proprietor (CreateFizIP) or a legal entity (CreateJur).
Package persons groups domain-registrant-person operations (endpoint /domains/persons): list the account's registrant contacts (List), read one in full (Info), and create an individual/sole-proprietor (CreateFizIP) or a legal entity (CreateJur).
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 pay groups billing operations (endpoint /pay): the account balance and status (index/getBalance), autopayment/deferment state, payment recommendations and upcoming payments, the runway to blocking (getRemainsDate/getRemainsDays), and the reserves currently holding funds.
Package pay groups billing operations (endpoint /pay): the account balance and status (index/getBalance), autopayment/deferment state, payment recommendations and upcoming payments, the runway to blocking (getRemainsDate/getRemainsDays), and the reserves currently holding funds.
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 sites groups shared-hosting website operations (endpoint /sites): the read side (index/getSiteInfo/getBackEndsList) plus the add/edit/del and changeDomainSite/changeBackEnd mutations.
Package sites groups shared-hosting website operations (endpoint /sites): the read side (index/getSiteInfo/getBackEndsList) plus the add/edit/del and changeDomainSite/changeBackEnd mutations.
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 tariff groups the hosting-account tariff and server-info reads (endpoint /tariff): index (current plan and real resource usage) and serverInfo (the node the account lives on).
Package tariff groups the hosting-account tariff and server-info reads (endpoint /tariff): index (current plan and real resource usage) and serverInfo (the node the account lives on).
vh
backup
Package backup groups shared-hosting account-backup operations (endpoint /vh/backup): listing daily backups, browsing their file/MySQL contents, and the restore/receive/download lifecycle over an account's files and databases.
Package backup groups shared-hosting account-backup operations (endpoint /vh/backup): listing daily backups, browsing their file/MySQL contents, and the restore/receive/download lifecycle over an account's files and databases.
cron
Package cron groups shared-hosting crontab operations (endpoint /vh/cron): listing the account's cron tasks plus the add/edit/remove lifecycle.
Package cron groups shared-hosting crontab operations (endpoint /vh/cron): listing the account's cron tasks plus the add/edit/remove lifecycle.
ddg
Package ddg groups shared-hosting DDoS-Guard operations (endpoint /vh/ddg): list the domains and their protection state, read the enable page's catalogue, count the account's domains for pagination, quote the service price (per current plan and for the tariff-change widget), and enable/disable protection per domain.
Package ddg groups shared-hosting DDoS-Guard operations (endpoint /vh/ddg): list the domains and their protection state, read the enable page's catalogue, count the account's domains for pagination, quote the service price (per current plan and for the tariff-change widget), and enable/disable protection per domain.
diskusage
Package diskusage groups disk-usage (quota scan) operations (endpoint /vh/utils/diskUsage): reading the per-backend quota breakdown and the scan-task state, triggering a new scan, and managing the over-quota notification email.
Package diskusage groups disk-usage (quota scan) operations (endpoint /vh/utils/diskUsage): reading the per-backend quota breakdown and the scan-task state, triggering a new scan, and managing the over-quota notification email.
hosting
Package hosting groups shared-hosting database operations (endpoint /vh/hosting): listing the account's MySQL/PgSQL databases, the MySQL and PgSQL create/delete/change-password lifecycle, MySQL import/backup and remote access rules, comment editing, and the temporary PhpMyAdmin user.
Package hosting groups shared-hosting database operations (endpoint /vh/hosting): listing the account's MySQL/PgSQL databases, the MySQL and PgSQL create/delete/change-password lifecycle, MySQL import/backup and remote access rules, comment editing, and the temporary PhpMyAdmin user.
load
Package load groups shared-hosting server-load statistics (endpoint /vh/load): listing the periods for which load data exists and fetching a period's load table (per-day CPU/MySQL usage plus the plan's level thresholds and a CSV export).
Package load groups shared-hosting server-load statistics (endpoint /vh/load): listing the periods for which load data exists and fetching a period's load table (per-day CPU/MySQL usage plus the plan's level thresholds and a CSV export).
mail
Package mail groups SpaceWeb shared-hosting email operations (endpoint /vh/mail): the account's mail domains and mailboxes, mailbox lifecycle (create/drop/password/comment/antispam), autoreply and SPF toggles, forwarding and delivery (mailing) lists, the domain-level mail collector, per-mailbox white/black lists, and domain DKIM/SenderVerify/AutoDiscover.
Package mail groups SpaceWeb shared-hosting email operations (endpoint /vh/mail): the account's mail domains and mailboxes, mailbox lifecycle (create/drop/password/comment/antispam), autoreply and SPF toggles, forwarding and delivery (mailing) lists, the domain-level mail collector, per-mailbox white/black lists, and domain DKIM/SenderVerify/AutoDiscover.
partner
Package partner groups partner-program operations (endpoint /vh/partnerProgram): the referral catalog (standard/VIP hosting plans, the VPS OS/panel configurator) and order placement, becoming a partner and filling requisites, advertising materials, the partner's client roster and per-client card / event / finance logs, reward withdrawal, and referral-site statistics.
Package partner groups partner-program operations (endpoint /vh/partnerProgram): the referral catalog (standard/VIP hosting plans, the VPS OS/panel configurator) and order placement, becoming a partner and filling requisites, advertising materials, the partner's client roster and per-client card / event / finance logs, reward withdrawal, and referral-site statistics.
referral
Package referral groups referral-program operations (endpoint /vh/referralProgram): listing the account's referral sites plus the add/confirm/remove lifecycle.
Package referral groups referral-program operations (endpoint /vh/referralProgram): listing the account's referral sites plus the add/confirm/remove lifecycle.
ssh
Package ssh groups the shared-hosting SSH-access toggle (endpoint /vh/utils): turning SSH access on for a fixed period and turning it off.
Package ssh groups the shared-hosting SSH-access toggle (endpoint /vh/utils): turning SSH access on for a fixed period and turning it off.
ssl
Package ssl groups shared-hosting SSL-certificate operations (endpoint /vh/ssl): list the account's certificates, browse the certificate catalogue, download an issued certificate archive, manage a certificate's auto-prolongation and lifecycle, and install a free Let's Encrypt certificate.
Package ssl groups shared-hosting SSL-certificate operations (endpoint /vh/ssl): list the account's certificates, browse the certificate catalogue, download an issued certificate archive, manage a certificate's auto-prolongation and lifecycle, and install a free Let's Encrypt certificate.
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