go-sdk

module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0

README

MWS Cloud Platform Go SDK

PkgGoDev Go Report Card Last Commit Go Version

MWS Cloud Platform SDK for Go.

⚠️ SDK is under active development and may make breaking changes.

Installation

go get go.mws.cloud/go-sdk/mws

Getting Started

To get started, you need to setup project with Go modules and install the MWS Go SDK dependency. This example demonstrates how to list virtual machines inside the project (see runnable example).

Setup Project

mkdir my-mws-project
cd my-mws-project
go mod init my-mws-project

Install SDK

go get go.mws.cloud/go-sdk/mws

Write Code

Write the following code to main.go file:

package main

import (
	"context"
	"fmt"
	"log"

	"go.mws.cloud/util-toolset/pkg/utils/ptr"

	computeclient "go.mws.cloud/go-sdk/service/compute/client"
	computesdk "go.mws.cloud/go-sdk/service/compute/sdk"
	"go.mws.cloud/go-sdk/mws"
)

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

	// Use the default loader to load configuration. It will load configuration
	// from the environment variables and sensible defaults. You can override
	// logic using [mws.LoadSDKOption] functional options. Check the [mws.Load]
	// and [mws.Config] for more details.
	sdk, err := mws.Load(ctx)
	if err != nil {
		log.Fatalln("loading sdk error:", err)
	}
	defer sdk.Close(ctx)

	// Create a new virtual machine client using the provided SDK.
	client, err := computesdk.NewVirtualMachine(ctx, sdk)
	if err != nil {
		log.Panicln("creating client error:", err)
	}

	// List virtual machines with the page size limit.
	virtualMachines, err := client.ListVirtualMachines(ctx, computeclient.ListVirtualMachinesRequest{
		PageSize: ptr.Get(10),
	})
	if err != nil {
		log.Panicln("listing virtual machines error:", err)
	}

	// Print the virtual machine identifiers.
	fmt.Println("Virtual Machines:")
	for _, vm := range virtualMachines.GetItems() {
		fmt.Println(vm.GetMetadata().GetId())
	}
}

Compile and Run

Before running the code, make sure you have set project and IAM token in the environment variables:

export MWS_PROJECT="your-project"
export MWS_TOKEN="$(mws iam create-token)"

Run the code:

go run main.go

Output:

Virtual Machines:
compute/projects/your-project/virtualMachines/vm-1
compute/projects/your-project/virtualMachines/vm-2

Configuration

MWS Go SDK requires configuration, like credentials and project identifier. You can provide this information using environment variables and functional options.

Environment Variables
  • MWS_BASE_ENDPOINT - MWS Cloud Platform API base endpoint (default: https://api.mwsapis.ru).
  • MWS_PROJECT - Default project identifier.
  • MWS_ZONE - Default zone identifier (default: ru-central1-a).
  • MWS_TOKEN - IAM token for authentication. If not empty, it will be used in all client requests that require authentication.
  • MWS_SERVICE_ACCOUNT_AUTHORIZED_KEY_PATH - Path to the service account authorized key file used for authentication. Has no effect if MWS_TOKEN is not empty.
  • MWS_TIMEOUT - Timeout for all client requests (default: 5s).
  • MWS_LOG_LEVEL - If set, enables SDK operations logging at the specified level. Available levels: debug, info, warn, error, fatal.
Functional Options

You can also configure SDK using functional options mws.LoadSDKOption, for example:

sdk, err := mws.LoadSDK(
	mws.WithDefaultProject("my-project"),
	mws.WithDefaultZone("ru-central1-a"),
	mws.WithTimeout(5 * time.Second),
)

Note that functional options have highest priority and overrides behavior based on the environment variables and configuration defaults.

Examples

Check more examples in the examples directory.

Documentation

Get Help

Ask for help using the MWS Cloud Platform Support Center.

Creators

Created and maintained by MWS Cloud Platform.

Directories

Path Synopsis
Package examples provides a collection of example code snippets and usage patterns for the SDK.
Package examples provides a collection of example code snippets and usage patterns for the SDK.
internal
mws
Package mws provides the SDK and related types and utilities.
Package mws provides the SDK and related types and utilities.
credentials
Package credentials provides utilities for credentials retrieval and management.
Package credentials provides utilities for credentials retrieval and management.
credentials/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
endpoints
Package endpoints provides resolvers for service API endpoints.
Package endpoints provides resolvers for service API endpoints.
endpoints/mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
errors
Package errors provides types and utilities for API errors.
Package errors provides types and utilities for API errors.
iam
Package iam provides types and utilities for IAM services.
Package iam provides types and utilities for IAM services.
page
Package page provides utilities for working with paginated API responses.
Package page provides utilities for working with paginated API responses.
retry
Package retry provides implementations for retry mechanisms.
Package retry provides implementations for retry mechanisms.
wait
Package wait provides utilities for waiting for resource state changes.
Package wait provides utilities for waiting for resource state changes.
pkg
apimodels/cidraddress
Package cidraddress provides types and utilities for working with CIDR addresses.
Package cidraddress provides types and utilities for working with CIDR addresses.
apimodels/email
Package email provides types for working with email addresses.
Package email provides types for working with email addresses.
apimodels/ipaddress
Package ipaddress provides types and utilities for working with IP addresses.
Package ipaddress provides types and utilities for working with IP addresses.
apimodels/macaddress
Package macaddress provides types and utilities for working with MAC addresses.
Package macaddress provides types and utilities for working with MAC addresses.
apimodels/sensitive
Package sensitive provides types and utilities for working with sensitive data such as passwords, tokens, or other confidential information.
Package sensitive provides types and utilities for working with sensitive data such as passwords, tokens, or other confidential information.
apimodels/units/bitrate
Package bitrate provides functionality for working with bitrates.
Package bitrate provides functionality for working with bitrates.
apimodels/units/bytesize
Package bytesize provides functionality for working with byte sizes.
Package bytesize provides functionality for working with byte sizes.
apimodels/units/duration
Package duration provides types and utilities for working with durations.
Package duration provides types and utilities for working with durations.
apimodels/units/errors
Package errors provides common errors related to units.
Package errors provides common errors related to units.
apimodels/units/frequency
Package frequency provides functionality for working with frequencies.
Package frequency provides functionality for working with frequencies.
apimodels/units/largenumber
Package largenumber provides functionality for working with large numbers.
Package largenumber provides functionality for working with large numbers.
apimodels/units/throughput
Package throughput provides functionality for working with throughput.
Package throughput provides functionality for working with throughput.
backoff
Package backoff provides backoff mechanisms for retrying operations.
Package backoff provides backoff mechanisms for retrying operations.
clock
Package clock provides an interface for time-related operations, allowing for easier testing and mocking.
Package clock provides an interface for time-related operations, allowing for easier testing and mocking.
clock/fakeclock
Package fakeclock provides a fake clock implementation for testing purposes.
Package fakeclock provides a fake clock implementation for testing purposes.
context/metadata
Package metadata provides types and utilities for working with incoming and outgoing request metadata.
Package metadata provides types and utilities for working with incoming and outgoing request metadata.
context/values
Package values provides utilities for managing key-value pairs in a context.
Package values provides utilities for managing key-value pairs in a context.
http
Package http provides batteries included HTTP client for the SDK service clients.
Package http provides batteries included HTTP client for the SDK service clients.
resources/interfaces
Package interfaces provides interfaces for resource references and IDs.
Package interfaces provides interfaces for resource references and IDs.
resources/models
Package models provides models for resource references and IDs.
Package models provides models for resource references and IDs.
service

Jump to

Keyboard shortcuts

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