shock

package module
v0.0.0-...-9419e65 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: BSD-2-Clause Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultPollInterval = 30 * time.Second
	DefaultWaitTimeout  = 1 * time.Hour
)

Functions

func GetMD5FromFile

func GetMD5FromFile(filepath string) (string, error)

GetMD5FromFile computes the MD5 checksum of a file.

Types

type APIError

type APIError struct {
	StatusCode int
	Errors     []string
}

APIError represents an error returned by the Shock API.

func (*APIError) Error

func (e *APIError) Error() string

type AnonPerms

type AnonPerms struct {
	Read   bool `json:"read"`
	Write  bool `json:"write"`
	Delete bool `json:"delete"`
}

AnonPerms represents anonymous user permissions.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a Shock API client.

func New

func New(baseURL string, opts ...Option) *Client

New creates a new Shock client for the given base URL.

func (*Client) AddLocation

func (c *Client) AddLocation(ctx context.Context, nodeID string, loc Location) ([]Location, error)

AddLocation adds a storage location to a node.

func (*Client) ChownNode

func (c *Client) ChownNode(ctx context.Context, nodeID, user string) (*DisplayAcl, error)

ChownNode changes the owner of a node.

func (*Client) CreateNode

func (c *Client) CreateNode(ctx context.Context, opts ...CreateOption) (*Node, error)

CreateNode creates a new node with the given options.

func (*Client) DeleteAcl

func (c *Client) DeleteAcl(ctx context.Context, nodeID, aclType, users string) (*DisplayAcl, error)

DeleteAcl removes users from an ACL type on a node.

func (*Client) DeleteAllLocations

func (c *Client) DeleteAllLocations(ctx context.Context, nodeID string) error

DeleteAllLocations removes all storage locations from a node.

func (*Client) DeleteLocation

func (c *Client) DeleteLocation(ctx context.Context, nodeID, locationID string) ([]Location, error)

DeleteLocation removes a storage location from a node.

func (*Client) DeleteNode

func (c *Client) DeleteNode(ctx context.Context, id string) error

DeleteNode deletes a node by ID.

func (*Client) Download

func (c *Client) Download(ctx context.Context, nodeID string) (io.ReadCloser, error)

Download streams a node's file data. The caller must close the returned ReadCloser.

func (*Client) DownloadRange

func (c *Client) DownloadRange(ctx context.Context, nodeID string, seek, length int64) (io.ReadCloser, error)

DownloadRange streams a byte range from a node's file.

func (*Client) DownloadToFile

func (c *Client) DownloadToFile(ctx context.Context, nodeID, filepath string, opts ...DownloadOption) (int64, string, error)

DownloadToFile downloads a node's file to a local path, optionally decompressing and computing MD5.

func (*Client) DownloadURL

func (c *Client) DownloadURL(nodeID string) string

DownloadURL returns the direct download URL for a node (no pre-auth).

func (*Client) GetAcl

func (c *Client) GetAcl(ctx context.Context, nodeID string) (*DisplayAcl, error)

GetAcl retrieves the ACL for a node.

func (*Client) GetDownloadURL

func (c *Client) GetDownloadURL(ctx context.Context, nodeID string) (*PreAuthResponse, error)

GetDownloadURL gets a pre-authenticated download URL for a node.

func (*Client) GetLocations

func (c *Client) GetLocations(ctx context.Context, nodeID string) ([]Location, error)

GetLocations retrieves storage locations for a node.

func (*Client) GetNode

func (c *Client) GetNode(ctx context.Context, id string) (*Node, error)

GetNode retrieves a node by ID.

func (*Client) GetNodeByMD5

func (c *Client) GetNodeByMD5(ctx context.Context, md5sum string) (string, bool, error)

GetNodeByMD5 searches for an existing node with the given MD5 checksum. Returns the node ID, whether a match was found, and any error.

func (*Client) MakePublic

func (c *Client) MakePublic(ctx context.Context, nodeID string) (*DisplayAcl, error)

MakePublic sets a node's read ACL to public.

func (*Client) PostFileLazy

func (c *Client) PostFileLazy(ctx context.Context, filepath, filename string) (string, error)

PostFileLazy creates a node with a file, but first checks if a node with the same MD5 already exists. If so, returns the existing node ID. It caches MD5 checksums in .md5 files alongside the source file.

func (*Client) PostFileWithAttributes

func (c *Client) PostFileWithAttributes(ctx context.Context, filepath, filename string, nodeattr map[string]interface{}) (*Node, error)

PostFileWithAttributes creates a node with a file and attributes.

func (*Client) PutAcl

func (c *Client) PutAcl(ctx context.Context, nodeID, aclType, users string) (*DisplayAcl, error)

PutAcl adds users to an ACL type on a node.

func (*Client) PutIndex

func (c *Client) PutIndex(ctx context.Context, nodeID, indexName string) error

PutIndex creates or rebuilds an index on a node.

func (*Client) PutIndexQuery

func (c *Client) PutIndexQuery(ctx context.Context, nodeID, indexName string, force bool, column int) error

PutIndexQuery creates or rebuilds an index with options.

func (*Client) PutOrPostFile

func (c *Client) PutOrPostFile(ctx context.Context, filename, nodeid string, rank int, attrfile, ntype string, formopts map[string]string, nodeattr map[string]interface{}) (string, error)

PutOrPostFile provides backward compatibility with the old client. If nodeid is empty, creates a new node (POST); otherwise updates (PUT).

func (*Client) Query

func (c *Client) Query(ctx context.Context, filters map[string]string, opts ...QueryOption) (*QueryResult, error)

Query searches for nodes with basic field matching.

func (*Client) QueryDistinct

func (c *Client) QueryDistinct(ctx context.Context, field string, filters map[string]string) (interface{}, error)

QueryDistinct returns distinct values for a field.

func (*Client) QueryDistinctRaw

func (c *Client) QueryDistinctRaw(ctx context.Context, query url.Values) (interface{}, error)

QueryDistinctRaw performs a distinct query with pre-built url.Values (backward compatibility).

func (*Client) QueryFull

func (c *Client) QueryFull(ctx context.Context, filters map[string]string, opts ...QueryOption) (*QueryResult, error)

QueryFull searches for nodes with full querynode matching.

func (*Client) QueryRaw

func (c *Client) QueryRaw(ctx context.Context, query url.Values) (*QueryResult, error)

QueryRaw performs a query with pre-built url.Values (backward compatibility).

func (*Client) ServerInfo

func (c *Client) ServerInfo(ctx context.Context) (*ServerInfo, error)

ServerInfo retrieves server information from the root endpoint. The root endpoint returns a bare struct, not envelope-wrapped.

func (*Client) SetToken

func (c *Client) SetToken(token string)

SetToken updates the authentication token.

func (*Client) UnpackArchiveNode

func (c *Client) UnpackArchiveNode(ctx context.Context, nodeID, format, attrFile string) ([]Node, error)

UnpackArchiveNode unpacks an archive node into multiple nodes.

func (*Client) UpdateAttributes

func (c *Client) UpdateAttributes(ctx context.Context, id string, attrFile string, nodeattr map[string]interface{}) error

UpdateAttributes updates the attributes of an existing node.

func (*Client) UpdateNode

func (c *Client) UpdateNode(ctx context.Context, id string, opts ...CreateOption) (*Node, error)

UpdateNode updates an existing node with the given options.

func (*Client) WaitFile

func (c *Client) WaitFile(ctx context.Context, nodeID string, opts ...WaitOption) (*Node, error)

WaitFile polls until a node's file is no longer locked.

func (*Client) WaitIndex

func (c *Client) WaitIndex(ctx context.Context, nodeID, indexName string, opts ...WaitOption) (*IdxInfo, error)

WaitIndex polls until a node's index is no longer locked.

type CreateOption

type CreateOption func(*createConfig)

CreateOption configures a CreateNode/UpdateNode call.

func WithAttributes

func WithAttributes(attrs map[string]interface{}) CreateOption

WithAttributes sets node attributes from a map (serialized as JSON).

func WithAttributesFile

func WithAttributesFile(path string) CreateOption

WithAttributesFile sets node attributes from a JSON file. Ignored if WithAttributes was already used.

func WithChecksumMD5

func WithChecksumMD5(md5 string) CreateOption

WithChecksumMD5 sets the expected MD5 checksum for verification.

func WithCompression

func WithCompression(format string) CreateOption

WithCompression sets compression format ("gzip" or "bzip2").

func WithCopyAttributes

func WithCopyAttributes() CreateOption

WithCopyAttributes copies attributes from the source node.

func WithCopyData

func WithCopyData(nodeID string) CreateOption

WithCopyData copies data from the specified source node.

func WithCopyIndexes

func WithCopyIndexes() CreateOption

WithCopyIndexes copies indexes from the source node.

func WithExpiration

func WithExpiration(exp string) CreateOption

WithExpiration sets the expiration for the node.

func WithFile

func WithFile(r io.Reader, filename string) CreateOption

WithFile sets the upload file from an io.Reader.

func WithFileContent

func WithFileContent(content string) CreateOption

WithFileContent sets the upload file from string content.

func WithFileName

func WithFileName(name string) CreateOption

WithFileName sets the filename for the node.

func WithFilePath

func WithFilePath(path string) CreateOption

WithFilePath sets the upload file from a local file path.

func WithPart

func WithPart(partNum int, r io.Reader, filename string) CreateOption

WithPart uploads a single part from an io.Reader.

func WithPartFile

func WithPartFile(partNum int, path string) CreateOption

WithPartFile uploads a single part from a file path.

func WithParts

func WithParts(count int) CreateOption

WithParts initializes a parts node with the given number of parts.

func WithPartsCompression

func WithPartsCompression(format string) CreateOption

WithPartsCompression sets the compression format for a parts node.

func WithRemoteURL

func WithRemoteURL(url string) CreateOption

WithRemoteURL sets a remote URL for the node to fetch.

func WithRemoveExpiration

func WithRemoveExpiration() CreateOption

WithRemoveExpiration removes the expiration from the node.

func WithSubset

func WithSubset(parentNodeID, parentIndex, subsetFile string) CreateOption

WithSubset creates a subset node from a parent node's index.

func WithUnpackNode

func WithUnpackNode(nodeID, archiveFormat string) CreateOption

WithUnpackNode unpacks an archive node.

func WithVirtualParts

func WithVirtualParts(nodeIDs []string) CreateOption

WithVirtualParts creates a virtual node from the given node IDs.

type DisplayAcl

type DisplayAcl struct {
	Owner  string    `json:"owner"`
	Read   []string  `json:"read"`
	Write  []string  `json:"write"`
	Delete []string  `json:"delete"`
	Public PublicAcl `json:"public"`
}

DisplayAcl represents access control for a node.

type DownloadOption

type DownloadOption func(*downloadConfig)

DownloadOption configures a DownloadToFile call.

func WithComputeMD5

func WithComputeMD5() DownloadOption

WithComputeMD5 enables MD5 checksum computation during download.

func WithUncompress

func WithUncompress(method string) DownloadOption

WithUncompress sets the decompression method for downloads (e.g. "gzip").

type File

type File struct {
	Name         string            `json:"name"`
	Size         int64             `json:"size"`
	Checksum     map[string]string `json:"checksum"`
	Format       string            `json:"format"`
	Virtual      bool              `json:"virtual"`
	VirtualParts []string          `json:"virtual_parts"`
	CreatedOn    time.Time         `json:"created_on"`
	Locked       *LockInfo         `json:"locked"`
}

File represents file metadata within a node.

type IdxInfo

type IdxInfo struct {
	TotalUnits  int64     `json:"total_units"`
	AvgUnitSize int64     `json:"average_unit_size"`
	CreatedOn   time.Time `json:"created_on"`
	Locked      *LockInfo `json:"locked"`
}

IdxInfo represents index metadata.

type Linkage

type Linkage struct {
	Type      string   `json:"relation"`
	Ids       []string `json:"ids"`
	Operation string   `json:"operation"`
}

Linkage represents a relationship between nodes.

type Location

type Location struct {
	ID            string     `json:"id"`
	Stored        bool       `json:"stored,omitempty"`
	RequestedDate *time.Time `json:"requestedDate,omitempty"`
}

Location represents a storage location for a node.

type LockInfo

type LockInfo struct {
	CreatedOn time.Time `json:"created_on"`
	Error     string    `json:"error"`
}

LockInfo represents a lock on a file or index.

type Node

type Node struct {
	Id           string              `json:"id"`
	Version      string              `json:"version"`
	File         File                `json:"file"`
	Attributes   interface{}         `json:"attributes"`
	Indexes      map[string]*IdxInfo `json:"indexes"`
	VersionParts map[string]string   `json:"version_parts"`
	Tags         []string            `json:"tags"`
	Linkages     []Linkage           `json:"linkage"`
	Priority     int                 `json:"priority"`
	CreatedOn    time.Time           `json:"created_on"`
	LastModified time.Time           `json:"last_modified"`
	Expiration   time.Time           `json:"expiration"`
	Type         string              `json:"type"`
	Parts        *PartsList          `json:"parts"`
	Locations    []Location          `json:"locations"`
	Restore      bool                `json:"restore"`
}

Node represents a Shock data node.

type Option

type Option func(*Client)

Option configures a Client.

func WithAuthType

func WithAuthType(authType string) Option

WithAuthType sets the authorization type (e.g. "mgrast", "OAuth").

func WithDebug

func WithDebug(debug bool) Option

WithDebug enables debug logging to stderr.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithToken

func WithToken(token string) Option

WithToken sets the authentication token.

type PartsList

type PartsList struct {
	Count       int        `json:"count"`
	Length      int        `json:"length"`
	VarLen      bool       `json:"varlen"`
	Parts       [][]string `json:"parts"`
	Compression string     `json:"compression"`
}

PartsList represents the parts metadata of a node.

type PreAuthResponse

type PreAuthResponse struct {
	Url       string `json:"url"`
	ValidTill string `json:"validtill"`
	Format    string `json:"format"`
	Filename  string `json:"filename"`
	Files     int    `json:"files"`
	Size      int64  `json:"size"`
}

PreAuthResponse represents a pre-authenticated download URL response.

type PublicAcl

type PublicAcl struct {
	Read   bool `json:"read"`
	Write  bool `json:"write"`
	Delete bool `json:"delete"`
}

PublicAcl represents public access flags.

type QueryOption

type QueryOption func(*queryConfig)

QueryOption configures a Query call.

func WithDirection

func WithDirection(dir string) QueryOption

WithDirection sets the sort direction ("asc" or "desc").

func WithLimit

func WithLimit(n int) QueryOption

WithLimit sets the maximum number of results.

func WithOffset

func WithOffset(n int) QueryOption

WithOffset sets the starting offset.

func WithOrder

func WithOrder(field string) QueryOption

WithOrder sets the field to sort by.

type QueryResult

type QueryResult struct {
	Nodes      []Node
	Limit      int
	Offset     int
	TotalCount int
}

QueryResult holds the result of a node query.

type ServerInfo

type ServerInfo struct {
	AttributeIndexes []string  `json:"attribute_indexes"`
	Contact          string    `json:"contact"`
	ID               string    `json:"id"`
	Auth             []string  `json:"auth"`
	AnonPerms        AnonPerms `json:"anonymous_permissions"`
	Resources        []string  `json:"resources"`
	ServerTime       string    `json:"server_time"`
	Type             string    `json:"type"`
	URL              string    `json:"url"`
	Uptime           string    `json:"uptime"`
	Version          string    `json:"version"`
}

ServerInfo represents the root resource response from the Shock server.

type WaitOption

type WaitOption func(*waitConfig)

WaitOption configures WaitFile/WaitIndex.

func WithPollInterval

func WithPollInterval(d time.Duration) WaitOption

WithPollInterval sets the polling interval.

func WithWaitTimeout

func WithWaitTimeout(d time.Duration) WaitOption

WithWaitTimeout sets the maximum wait time.

Jump to

Keyboard shortcuts

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