skynet

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: MIT Imports: 14 Imported by: 1

README

Skynet Go SDK

Go Build Status Contributors License

An SDK for integrating Skynet into Go applications.

Documentation

For documentation complete with examples, please see the Skynet SDK docs.

Documentation

Index

Constants

View Source
const (
	// DefaultSkynetPortalURL is the default URL of the Skynet portal to use in
	// the absence of configuration.
	DefaultSkynetPortalURL = "https://siasky.net"

	// URISkynetPrefix is the URI prefix for Skynet.
	URISkynetPrefix = "sia://"
)

Variables

View Source
var (
	// DefaultDownloadOptions contains the default download options.
	DefaultDownloadOptions = DownloadOptions{
		Options: DefaultOptions("/"),

		SkykeyName: "",
		SkykeyID:   "",
	}

	// DefaultMetadataOptions contains the default getting metadata options.
	DefaultMetadataOptions = MetadataOptions{
		Options: DefaultOptions("/"),
	}
)
View Source
var (
	// DefaultAddSkykeyOptions contains the default addskykey options.
	DefaultAddSkykeyOptions = AddSkykeyOptions{
		Options: DefaultOptions("/skynet/addskykey"),
	}
	// DefaultCreateSkykeyOptions contains the default createskykey options.
	DefaultCreateSkykeyOptions = CreateSkykeyOptions{
		Options: DefaultOptions("/skynet/createskykey"),
	}
	// DefaultGetSkykeyOptions contains the default skykey GET options.
	DefaultGetSkykeyOptions = GetSkykeyOptions{
		Options: DefaultOptions("/skynet/skykey"),
	}
	// DefaultGetSkykeysOptions contains the default skykeys options.
	DefaultGetSkykeysOptions = GetSkykeysOptions{
		Options: DefaultOptions("/skynet/skykeys"),
	}
)
View Source
var (
	// DefaultUploadOptions contains the default upload options.
	DefaultUploadOptions = UploadOptions{
		Options: DefaultOptions("/skynet/skyfile"),

		PortalFileFieldName:          "file",
		PortalDirectoryFileFieldName: "files[]",
		CustomFilename:               "",
		CustomDirname:                "",
		SkykeyName:                   "",
		SkykeyID:                     "",
	}
)
View Source
var (
	// ErrResponseError is the error for a response with a status code >= 400.
	ErrResponseError = errors.New("error response")
)

Functions

func DefaultPortalURL

func DefaultPortalURL() string

DefaultPortalURL selects the default portal URL to use when initializing a client. May involve network queries to several candidate portals.

TODO: This will be smarter. See https://github.com/NebulousLabs/skynet-docs/issues/21.

Types

type AddSkykeyOptions

type AddSkykeyOptions struct {
	Options
}

AddSkykeyOptions contains the options used for addskykey.

type CreateSkykeyOptions

type CreateSkykeyOptions struct {
	Options
}

CreateSkykeyOptions contains the options used for createskykey.

type CreateSkykeyResponse

type CreateSkykeyResponse Skykey

CreateSkykeyResponse contains the response for creating a skykey.

type DownloadOptions

type DownloadOptions struct {
	Options

	// SkykeyName is the name of the skykey used to encrypt the upload.
	SkykeyName string
	// SkykeyID is the ID of the skykey used to encrypt the upload.
	SkykeyID string
}

DownloadOptions contains the options used for downloads.

type ErrorResponse

type ErrorResponse struct {
	// Message is the error message of the response.
	Message string `json:"message"`
}

ErrorResponse contains the response for an error.

type GetSkykeyOptions

type GetSkykeyOptions struct {
	Options
}

GetSkykeyOptions contains the options used for skykey GET.

type GetSkykeyResponse

type GetSkykeyResponse Skykey

GetSkykeyResponse contains the response for getting a skykey.

type GetSkykeysOptions

type GetSkykeysOptions struct {
	Options
}

GetSkykeysOptions contains the options used for skykeys GET.

type GetSkykeysResponse

type GetSkykeysResponse struct {
	// Skykeys is the returned list of skykeys.
	Skykeys []Skykey `json:"skykeys"`
}

GetSkykeysResponse contains the response for listing skykeys.

type MetadataOptions

type MetadataOptions struct {
	Options
}

MetadataOptions contains the options used for getting metadata.

type Options

type Options struct {
	// EndpointPath is the relative URL path of the portal endpoint to
	// contact.
	EndpointPath string

	// APIKey is the API password to use for authentication.
	APIKey string
	// CustomUserAgent is the custom user agent to use.
	CustomUserAgent string
	// contains filtered or unexported fields
}

Options contains options used for connecting to a Skynet portal and endpoint.

func DefaultOptions

func DefaultOptions(endpointPath string) Options

DefaultOptions returns the default options with the given endpoint path.

type Skykey

type Skykey struct {
	Skykey string `json:"skykey"`
	Name   string `json:"name"`
	ID     string `json:"id"`
	Type   string `json:"type"`
}

Skykey contains information about a skykey.

type SkynetClient

type SkynetClient struct {
	PortalURL string
	Options   Options
}

SkynetClient is the Skynet Client which can be used to access Skynet.

func New

func New() SkynetClient

New creates a new Skynet Client which can be used to access Skynet.

func NewCustom

func NewCustom(portalURL string, customOptions Options) SkynetClient

NewCustom creates a new Skynet Client with a custom portal URL and options. Pass in "" for the portal to let the function select one for you.

func (*SkynetClient) AddSkykey

func (sc *SkynetClient) AddSkykey(skykey string, opts AddSkykeyOptions) error

AddSkykey stores the given base-64 encoded skykey with the skykey manager.

func (*SkynetClient) CreateSkykey

func (sc *SkynetClient) CreateSkykey(name, skykeyType string, opts CreateSkykeyOptions) (Skykey, error)

CreateSkykey returns a new skykey created and stored under the given name with the given type. skykeyType can be either "public-id" or "private-id".

func (*SkynetClient) Download

func (sc *SkynetClient) Download(skylink string, opts DownloadOptions) (io.ReadCloser, error)

Download downloads generic data.

func (*SkynetClient) DownloadFile

func (sc *SkynetClient) DownloadFile(path, skylink string, opts DownloadOptions) (err error)

DownloadFile downloads a file from Skynet to path.

func (*SkynetClient) GetSkykeyByID

func (sc *SkynetClient) GetSkykeyByID(id string, opts GetSkykeyOptions) (Skykey, error)

GetSkykeyByID returns the given skykey given its ID.

func (*SkynetClient) GetSkykeyByName

func (sc *SkynetClient) GetSkykeyByName(name string, opts GetSkykeyOptions) (Skykey, error)

GetSkykeyByName returns the given skykey given its name.

func (*SkynetClient) GetSkykeys

func (sc *SkynetClient) GetSkykeys(opts GetSkykeysOptions) ([]Skykey, error)

GetSkykeys returns a list of all skykeys.

func (*SkynetClient) Metadata

func (sc *SkynetClient) Metadata(skylink string, opts MetadataOptions) error

Metadata downloads metadata from the given skylink.

func (*SkynetClient) Upload

func (sc *SkynetClient) Upload(uploadData UploadData, opts UploadOptions) (skylink string, err error)

Upload uploads the given generic data and returns the skylink.

func (*SkynetClient) UploadDirectory

func (sc *SkynetClient) UploadDirectory(path string, opts UploadOptions) (skylink string, err error)

UploadDirectory uploads a local directory to Skynet and returns the skylink.

func (*SkynetClient) UploadFile

func (sc *SkynetClient) UploadFile(path string, opts UploadOptions) (skylink string, err error)

UploadFile uploads a file to Skynet and returns the skylink.

type UploadData

type UploadData map[string]io.Reader

UploadData contains data to upload, indexed by filenames.

type UploadOptions

type UploadOptions struct {
	Options

	// PortalFileFieldName is the fieldName for files on the portal.
	PortalFileFieldName string
	// PortalDirectoryFileFieldName is the fieldName for directory files on
	// the portal.
	PortalDirectoryFileFieldName string

	// CustomFilename is the custom filename to use for the upload. If this
	// is empty, the filename of the file being uploaded will be used by
	// default.
	CustomFilename string
	// CustomDirname is the custom name of the directory. If this is empty,
	// the base name of the directory being uploaded will be used by
	// default.
	CustomDirname string

	// SkykeyName is the name of the skykey used to encrypt the upload.
	SkykeyName string
	// SkykeyID is the ID of the skykey used to encrypt the upload.
	SkykeyID string
}

UploadOptions contains the options used for uploads.

type UploadResponse

type UploadResponse struct {
	// Skylink is the returned skylink.
	Skylink string `json:"skylink"`
}

UploadResponse contains the response for uploads.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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