skynet

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2020 License: MIT Imports: 12 Imported by: 3

README

Skynet Go SDK

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 (
	// DefaultPortalURL is the default URL of the portal to use.
	DefaultPortalURL = "https://siasky.net"

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

Variables

View Source
var (
	// DefaultGetBlocklistOptions contains the default get blocklist options.
	DefaultGetBlocklistOptions = GetBlocklistOptions{
		Options: DefaultOptions("/skynet/blocklist"),
	}

	// DefaultUpdateBlocklistOptions contains the default update blocklist
	// options.
	DefaultUpdateBlocklistOptions = GetBlocklistOptions{
		Options: DefaultOptions("/skynet/blocklist"),
	}
)
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 (
	// DefaultPinOptions contains the default pin options
	DefaultPinOptions = PinOptions{
		Options: DefaultOptions("/skynet/pin"),
	}

	// DefaultUnpinOptions contains the default unpin options.
	DefaultUnpinOptions = UnpinOptions{
		Options:               DefaultOptions(""),
		EndpointPathUnpinDir:  "/renter/dir",
		EndpointPathUnpinFile: "/renter/delete",
	}
)
View Source
var (
	// DefaultGetPortalsOptions contains the default get portals options.
	DefaultGetPortalsOptions = GetPortalsOptions{
		Options: DefaultOptions("/skynet/portals"),
	}

	// DefaultUpdatePortalsOptions contains the default update portals
	// options.
	DefaultUpdatePortalsOptions = GetPortalsOptions{
		Options: DefaultOptions("/skynet/portals"),
	}
)
View Source
var (
	// DefaultConvertOptions contains the default convert options.
	DefaultConvertOptions = ConvertOptions{
		Options: DefaultOptions("/skynet/skyfile"),
	}
)
View Source
var (
	// DefaultGetStatsOptions contains the default get stats options.
	DefaultGetStatsOptions = GetStatsOptions{
		Options: DefaultOptions("/skynet/stats"),
	}
)
View Source
var (
	// DefaultLsOptions conains the default ls options.
	DefaultLsOptions = LsOptions{
		Options:            DefaultOptions(""),
		EndpointPathLsDir:  "/renter/dir",
		EndpointPathLsFile: "/renter/file",
	}
)
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 AddSkykey

func AddSkykey(skykey string, opts AddSkykeyOptions) error

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

func Convert

func Convert(srcSiaPath, destSiaPath string, opts ConvertOptions) (string, error)

Convert converts an existing siafile to a skyfile and skylink.

func Download

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

Download downloads generic data.

func DownloadFile

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

DownloadFile downloads a file from Skynet to path.

func GetBlocklist

func GetBlocklist(opts GetBlocklistOptions) ([]string, error)

GetBlocklist returns the list of hashed merkleroots that are blocklisted.

func GetStats

func GetStats(opts GetStatsOptions) error

GetStats returns statistical information about Skynet, e.g. number of files uplaoded.

func Ls

func Ls(siaPath string, opts LsOptions) error

Ls returns the list of files and/or directories at the given path.

func Metadata

func Metadata(skylink string, opts MetadataOptions) error

Metadata downloads metadata from the given skylink.

func Pin

func Pin(skylink, destSiaPath string, opts PinOptions) error

Pin pins the file associated with this skylink by re-uploading an exact copy.

func Unpin

func Unpin(siaPath string, opts UnpinOptions) error

Unpin unpins the pinned skyfile or directory at the given siapath.

func UpdateBlocklist

func UpdateBlocklist(additions, removals []string, opts UpdateBlocklistOptions) error

UpdateBlocklist updates the list of skylinks that should be blocklisted from Skynet. This function can be used to both add and remove skylinks from the blocklist.

func UpdatePortals

func UpdatePortals(additions []Portal, removals []string, opts UpdatePortalsOptions) error

UpdatePortals updates the list of known portals. This function can be used to both add and remove portals from the list. Removals are provided in the form of addresses.

func Upload

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

Upload uploads the given generic data and returns the skylink.

func UploadDirectory

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

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

func UploadFile

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

UploadFile uploads a file to Skynet and returns the skylink.

Types

type AddSkykeyOptions

type AddSkykeyOptions struct {
	Options
}

AddSkykeyOptions contains the options used for addskykey.

type ConvertOptions

type ConvertOptions struct {
	Options
}

ConvertOptions contains the options used for convert.

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 GetBlocklistOptions

type GetBlocklistOptions struct {
	Options
}

GetBlocklistOptions contains the options used for get blocklist.

type GetPortalsOptions

type GetPortalsOptions struct {
	Options
}

GetPortalsOptions contains the options used for get portals.

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 GetStatsOptions

type GetStatsOptions struct {
	Options
}

GetStatsOptions contains the options used for get stats.

type LsOptions

type LsOptions struct {
	Options
	EndpointPathLsDir  string
	EndpointPathLsFile string
}

LsOptions contains the options used for ls.

type MetadataOptions

type MetadataOptions struct {
	Options
}

MetadataOptions contains the options used for getting metadata.

type Options

type Options struct {
	// PortalURL is the URL of the portal to use.
	PortalURL string
	// 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 PinOptions

type PinOptions struct {
	Options
}

PinOptions contains the options used for pin.

type Portal

type Portal struct {
	// Address is the IP or domain name and the port of the portal. Must be
	// a valid network address.
	Address string
	// Public indicates whether the portal can be accessed publicly or not.
	Public bool
}

Portal contains information about a known portal.

func GetPortals

func GetPortals(opts GetPortalsOptions) ([]Portal, error)

GetPortals returns the list of known Skynet portals.

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.

func CreateSkykey

func 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 GetSkykeyByID

func GetSkykeyByID(id string, opts GetSkykeyOptions) (Skykey, error)

GetSkykeyByID returns the given skykey given its ID.

func GetSkykeyByName

func GetSkykeyByName(name string, opts GetSkykeyOptions) (Skykey, error)

GetSkykeyByName returns the given skykey given its name.

func GetSkykeys

func GetSkykeys(opts GetSkykeysOptions) ([]Skykey, error)

GetSkykeys returns a list of all skykeys.

type UnpinOptions

type UnpinOptions struct {
	Options
	EndpointPathUnpinDir  string
	EndpointPathUnpinFile string
}

UnpinOptions contains the options used for unpin.

type UpdateBlocklistOptions

type UpdateBlocklistOptions struct {
	Options
}

UpdateBlocklistOptions contains the options used for update blocklist.

type UpdatePortalsOptions

type UpdatePortalsOptions struct {
	Options
}

UpdatePortalsOptions contains the options used for update portals.

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