Documentation
¶
Index ¶
- Variables
- func GetMD5FromFile(filepath string) (string, error)
- type APIError
- type AnonPerms
- type Client
- func (c *Client) AddLocation(ctx context.Context, nodeID string, loc Location) ([]Location, error)
- func (c *Client) ChownNode(ctx context.Context, nodeID, user string) (*DisplayAcl, error)
- func (c *Client) CreateNode(ctx context.Context, opts ...CreateOption) (*Node, error)
- func (c *Client) DeleteAcl(ctx context.Context, nodeID, aclType, users string) (*DisplayAcl, error)
- func (c *Client) DeleteAllLocations(ctx context.Context, nodeID string) error
- func (c *Client) DeleteLocation(ctx context.Context, nodeID, locationID string) ([]Location, error)
- func (c *Client) DeleteNode(ctx context.Context, id string) error
- func (c *Client) Download(ctx context.Context, nodeID string) (io.ReadCloser, error)
- func (c *Client) DownloadRange(ctx context.Context, nodeID string, seek, length int64) (io.ReadCloser, error)
- func (c *Client) DownloadToFile(ctx context.Context, nodeID, filepath string, opts ...DownloadOption) (int64, string, error)
- func (c *Client) DownloadURL(nodeID string) string
- func (c *Client) GetAcl(ctx context.Context, nodeID string) (*DisplayAcl, error)
- func (c *Client) GetDownloadURL(ctx context.Context, nodeID string) (*PreAuthResponse, error)
- func (c *Client) GetLocations(ctx context.Context, nodeID string) ([]Location, error)
- func (c *Client) GetNode(ctx context.Context, id string) (*Node, error)
- func (c *Client) GetNodeByMD5(ctx context.Context, md5sum string) (string, bool, error)
- func (c *Client) MakePublic(ctx context.Context, nodeID string) (*DisplayAcl, error)
- func (c *Client) PostFileLazy(ctx context.Context, filepath, filename string) (string, error)
- func (c *Client) PostFileWithAttributes(ctx context.Context, filepath, filename string, ...) (*Node, error)
- func (c *Client) PutAcl(ctx context.Context, nodeID, aclType, users string) (*DisplayAcl, error)
- func (c *Client) PutIndex(ctx context.Context, nodeID, indexName string) error
- func (c *Client) PutIndexQuery(ctx context.Context, nodeID, indexName string, force bool, column int) error
- func (c *Client) PutOrPostFile(ctx context.Context, filename, nodeid string, rank int, attrfile, ntype string, ...) (string, error)
- func (c *Client) Query(ctx context.Context, filters map[string]string, opts ...QueryOption) (*QueryResult, error)
- func (c *Client) QueryDistinct(ctx context.Context, field string, filters map[string]string) (interface{}, error)
- func (c *Client) QueryDistinctRaw(ctx context.Context, query url.Values) (interface{}, error)
- func (c *Client) QueryFull(ctx context.Context, filters map[string]string, opts ...QueryOption) (*QueryResult, error)
- func (c *Client) QueryRaw(ctx context.Context, query url.Values) (*QueryResult, error)
- func (c *Client) ServerInfo(ctx context.Context) (*ServerInfo, error)
- func (c *Client) SetToken(token string)
- func (c *Client) UnpackArchiveNode(ctx context.Context, nodeID, format, attrFile string) ([]Node, error)
- func (c *Client) UpdateAttributes(ctx context.Context, id string, attrFile string, ...) error
- func (c *Client) UpdateNode(ctx context.Context, id string, opts ...CreateOption) (*Node, error)
- func (c *Client) WaitFile(ctx context.Context, nodeID string, opts ...WaitOption) (*Node, error)
- func (c *Client) WaitIndex(ctx context.Context, nodeID, indexName string, opts ...WaitOption) (*IdxInfo, error)
- type CreateOption
- func WithAttributes(attrs map[string]interface{}) CreateOption
- func WithAttributesFile(path string) CreateOption
- func WithChecksumMD5(md5 string) CreateOption
- func WithCompression(format string) CreateOption
- func WithCopyAttributes() CreateOption
- func WithCopyData(nodeID string) CreateOption
- func WithCopyIndexes() CreateOption
- func WithExpiration(exp string) CreateOption
- func WithFile(r io.Reader, filename string) CreateOption
- func WithFileContent(content string) CreateOption
- func WithFileName(name string) CreateOption
- func WithFilePath(path string) CreateOption
- func WithPart(partNum int, r io.Reader, filename string) CreateOption
- func WithPartFile(partNum int, path string) CreateOption
- func WithParts(count int) CreateOption
- func WithPartsCompression(format string) CreateOption
- func WithRemoteURL(url string) CreateOption
- func WithRemoveExpiration() CreateOption
- func WithSubset(parentNodeID, parentIndex, subsetFile string) CreateOption
- func WithUnpackNode(nodeID, archiveFormat string) CreateOption
- func WithVirtualParts(nodeIDs []string) CreateOption
- type DisplayAcl
- type DownloadOption
- type File
- type IdxInfo
- type Linkage
- type Location
- type LockInfo
- type Node
- type Option
- type PartsList
- type PreAuthResponse
- type PublicAcl
- type QueryOption
- type QueryResult
- type ServerInfo
- type WaitOption
Constants ¶
This section is empty.
Variables ¶
var ( DefaultPollInterval = 30 * time.Second DefaultWaitTimeout = 1 * time.Hour )
Functions ¶
func GetMD5FromFile ¶
GetMD5FromFile computes the MD5 checksum of a file.
Types ¶
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 (*Client) AddLocation ¶
AddLocation adds a storage location to a node.
func (*Client) CreateNode ¶
CreateNode creates a new node with the given options.
func (*Client) DeleteAllLocations ¶
DeleteAllLocations removes all storage locations from a node.
func (*Client) DeleteLocation ¶
DeleteLocation removes a storage location from a node.
func (*Client) DeleteNode ¶
DeleteNode deletes a node by ID.
func (*Client) Download ¶
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 ¶
DownloadURL returns the direct download URL for a node (no pre-auth).
func (*Client) GetDownloadURL ¶
GetDownloadURL gets a pre-authenticated download URL for a node.
func (*Client) GetLocations ¶
GetLocations retrieves storage locations for a node.
func (*Client) GetNodeByMD5 ¶
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 ¶
MakePublic sets a node's read ACL to public.
func (*Client) PostFileLazy ¶
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) 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 ¶
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 ¶
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) 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 ¶
UpdateNode updates an existing node with the given options.
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 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 ¶
WithAuthType sets the authorization type (e.g. "mgrast", "OAuth").
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
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").
type QueryResult ¶
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.