filestorage-go

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0

README

filestorage-go: Go SDK for the Selectel File Storage API

Go.dev reference Go Report Card Build Status

Package filestorage-go provides Go SDK to work with the Selectel File Storage API.

The pkg/v1 import path identifies the first version of the SDK's public Go contract. It does not identify the remote API version; every request carries the API microversion 2.75.

The SDK accepts a regional endpoint, a project-scoped token, a User-Agent and an HTTP client from the caller. It does not perform Keystone authentication, poll for resource state transitions or retry requests on its own.

Documentation

The Go library documentation is available at go.dev.

What this library is capable of

You can use this library to work with the following objects of the Selectel File Storage API:

Getting started

Installation

You can install needed filestorage-go packages via go get command:

go get github.com/selectel/filestorage-go/pkg/v1/share github.com/selectel/filestorage-go/pkg/v1/shareaccess
Authentication

To work with the Selectel File Storage API you first need to:

Endpoints

The File Storage API endpoint is region-specific. Retrieve the endpoint of the sharev2 service type for the required region from the Identity catalog.

Usage example
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	v1 "github.com/selectel/filestorage-go/pkg/v1"
	"github.com/selectel/filestorage-go/pkg/v1/share"
	"github.com/selectel/filestorage-go/pkg/v1/shareaccess"
)

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

	// Token of the project and endpoint of the File Storage API in the required region.
	token := "gAAAAABeVNzu-..."
	endpoint := "<sharev2-endpoint-from-the-identity-catalog>"

	// Initialize the File Storage API client.
	client, err := v1.NewClient(v1.Config{
		Endpoint:  endpoint,
		Token:     token,
		UserAgent: "my-application/v1.0.0",
	})
	if err != nil {
		log.Fatal(err)
	}

	// Create an NFS share in a private network.
	created, _, err := share.Create(ctx, client, share.CreateOpts{
		ShareProto: "NFS",
		Size:       50,
		ShareType:  "basic.ru-9a",
		Name:       "test-share",
		NetworkID:  "<private-network-id>",
		SubnetID:   "<private-subnet-id>",
	})
	if err != nil {
		log.Fatal(err)
	}

	// The SDK does not wait: poll the share until it is available.
	current := created
	for current.Status != "available" {
		if current.Status == "error" {
			log.Fatalf("share %s entered status error", current.ID)
		}
		time.Sleep(10 * time.Second)

		if current, _, err = share.Get(ctx, client, created.ID); err != nil {
			log.Fatal(err)
		}
	}

	// Allow read-write access for a subnet.
	if _, _, err := shareaccess.Allow(ctx, client, created.ID, shareaccess.AllowOpts{
		AccessTo:    "10.0.0.0/24",
		AccessLevel: "rw",
	}); err != nil {
		log.Fatal(err)
	}

	// Print the paths to mount.
	locations, _, err := share.ListExportLocations(ctx, client, created.ID)
	if err != nil {
		log.Fatal(err)
	}

	for _, location := range locations {
		fmt.Println(location.Path)
	}
}

Directories

Path Synopsis
pkg
v1
Package v1 provides the client and common types for the Selectel File Storage SDK.
Package v1 provides the client and common types for the Selectel File Storage SDK.
v1/availabilityzone
Package availabilityzone lists the file storage availability zones of the region.
Package availabilityzone lists the file storage availability zones of the region.
v1/internal/testhttp
Package testhttp provides a recording HTTP client for the resource package tests.
Package testhttp provides a recording HTTP client for the resource package tests.
v1/message
Package message lists the user messages that the Selectel File Storage API records when an asynchronous operation on a resource fails, such as a share that enters the error status.
Package message lists the user messages that the Selectel File Storage API records when an asynchronous operation on a resource fails, such as a share that enters the error status.
v1/share
Package share provides share operations for the Selectel File Storage API.
Package share provides share operations for the Selectel File Storage API.
v1/shareaccess
Package shareaccess provides access rule operations for the Selectel File Storage API.
Package shareaccess provides access rule operations for the Selectel File Storage API.
v1/sharenetwork
Package sharenetwork reads the service share network that the Selectel Manila fork creates for each share.
Package sharenetwork reads the service share network that the Selectel Manila fork creates for each share.
v1/sharetype
Package sharetype lists the share types available to the project in the Selectel File Storage API.
Package sharetype lists the share types available to the project in the Selectel File Storage API.

Jump to

Keyboard shortcuts

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