Documentation
¶
Index ¶
- Constants
- Variables
- func Concat(values ...string) string
- type AuthToken
- type Client
- type ClientPool
- type Document
- type DocumentContent
- type DocumentLinks
- type DocumentWriter
- type Folder
- func (f *Folder) Document(c *Client, id int) (Document, error)
- func (f *Folder) DocumentByName(c *Client, name string) (Document, error)
- func (f *Folder) DocumentWriter(c *Client, name string) (w *DocumentWriter, err error)
- func (f *Folder) Documents(c *Client) (documents []Document, err error)
- func (f *Folder) Folder(c *Client, id int) (folder Folder, err error)
- func (f *Folder) FolderByName(c *Client, name string) (Folder, error)
- func (f *Folder) Folders(c *Client) (folders []Folder, err error)
- func (f *Folder) NewDocument(c *Client, name string, content io.Reader) error
- type FolderEmbedded
- type FolderLinks
- type Kind
- type Lener
- type Library
- type LibraryLinks
- type NewDocumentRequest
- type NewFolderRequest
- type NewLargeDocumentResponse
- type NewLargeDocumentResponseLinks
- type NotFound
- type Size
Constants ¶
const ( // PathSep is the character used to separate components of the ShareBase // path. PathSep = "\\" )
const ( // PhoenixTokenPrefix is the string prefixed to ShareBase's token value // within the Authorization header of every request. PhoenixTokenPrefix = "PHOENIX-TOKEN " )
Variables ¶
var ( // unauthorized response. ErrUnauthorized = errors.New("unauthorized") )
Functions ¶
Types ¶
type AuthToken ¶
type AuthToken struct {
// Token is the special authenticated value returned after a successful
// authentication request.
Token string
// UserName repeats the username authenticated.
UserName string
// UserID gets the unique integer identifier of this user in the ShareBase
// environment.
UserID int `json:"UserId"`
// ExpirationDate holds the time stamp when the authentication request
// expires.
ExpirationDate time.Time
}
AuthToken is the structure returned when authenticating with a username and password. The Token field is passed to NewClient to make requests to the ShareBase API.
func AuthTokenForUsernameAndPassword ¶
func AuthTokenForUsernameAndPassword(dataCenter, username, password string) (authToken AuthToken, err error)
AuthTokenForUsernameAndPassword gets a ShareBase AuthToken for the given username and password combination.
type Client ¶
type Client struct {
// DataCenter holds the URL that should prefix all non-absolute
// requests
DataCenter url.URL
// contains filtered or unexported fields
}
Client defines the client struct used to communicate with the ShareBase web API.
func (*Client) LibraryByName ¶
LibraryByName attepts to retrieve a library by its name.
func (*Client) NumRequests ¶
NumRequests returns the total number of requests issued to the ShareBase API through this client. It's useful for benchmarking to determine how many queries are consumed in case ShareBase ever switches to a per-request payment model. This total includes both successful and failed requests.
type ClientPool ¶
type ClientPool struct {
// contains filtered or unexported fields
}
ClientPool holds a pool of ShareBase clients. Clients for multiple data centers with multiple authentication tokens can be stored in the same pool. ClientPools have a mutex to make accessing and caching clients safe but clients themselves cannot be used concurrently.
func (*ClientPool) Cache ¶
func (p *ClientPool) Cache(c *Client)
Cache the given client in the pool. It is not necessary for the client to have been created from the pool. It is critical that the client not be used after it has been returned to the client pool. If a client is in any broken state, it should not be returned to the pool; simply request a new client.
type Document ¶
type Document struct {
// DocumentID holds the unique ID of the document in ShareBase.
DocumentID int `json:"DocumentId"`
// DocumentName holds the name of the document in its parent.
DocumentName string
// DateModified stores the date that the Document was last modified.
DateModified time.Time
// Hash is a base-64 encoded SHA-1 hash of the file's contents.
Hash []byte
// Links holds links that the document has to other ShareBase objects.
Links DocumentLinks
}
Document represents a single document in ShareBase.
type DocumentContent ¶
type DocumentContent struct {
*Document
io.ReadCloser
Length int64
ContentType string
ContentDisposition string
}
DocumentContent unsurprisingly holds the content of the document. It must be closed.
func (DocumentContent) Close ¶
func (d DocumentContent) Close() error
Close wraps the io.ReadCloser's Close function but adds more context to the message.
func (DocumentContent) Len ¶
func (d DocumentContent) Len() int64
Len gets the document content's length as an int64 (A normal int isn't large enough on a 32-bit platform for file sizes >2GiB).
type DocumentLinks ¶
type DocumentLinks struct {
// Self holds a link back to the current object.
Self string
// Content holds a link to the document's content.
Content string
}
DocumentLinks holds a set of links to other objects.
type DocumentWriter ¶
type DocumentWriter struct {
*Client
*Folder
NewLargeDocumentResponse
// contains filtered or unexported fields
}
DocumentWriter is returned by a folder's DocumentWriter function. It implements the io.Writer interface and takes its written data and writes it to ShareBase. A DocumentWriter must be closed after using it!
func (*DocumentWriter) Close ¶
func (w *DocumentWriter) Close() error
Close finalizes the document upload.
type Folder ¶
type Folder struct {
// FolderID is the unique ID of the folder in ShareBase.
FolderID int `json:"FolderId"`
// FolderName holds the name of the folder within its parent (i.e. not the
// full path).
FolderName string
// LibraryID holds the ID of the library in which this folder resides.
LibraryID int `json:"LibraryId"`
// Links holds the folder's links to other objects.
Links FolderLinks
// Embedded holds nested objects that might be embedded in the folder.
Embedded FolderEmbedded
}
Folder represents a folder in the ShareBase API.
func (*Folder) DocumentByName ¶
DocumentByName attempts to retrieve a document from the folder by its document name.
func (*Folder) DocumentWriter ¶
func (f *Folder) DocumentWriter(c *Client, name string) (w *DocumentWriter, err error)
DocumentWriter creates a new document writer with the given document name under the current folder. The DocumentWriter must be closed after writing!
func (*Folder) FolderByName ¶
FolderByName gets a child folder from the current folder by its name.
type FolderEmbedded ¶
type FolderEmbedded struct {
// Documents holds a slice of documents within the folder.
Documents []Document
// Folders holds a slice of folders within this folder.
Folders []Folder
}
FolderEmbedded holds an embedded.
type FolderLinks ¶
type FolderLinks struct {
// Self is the link to the same folder.
Self string
// Folders holds a link to this folder's subfolders.
Folders string
// Documents holds a link to this folder's nested documents.
Documents string
Shares string
}
FolderLinks are the links specific to a folder.
type Kind ¶
type Kind string
Kind is used when wrapping any ShareBase object to indicate what kind it is.
type Lener ¶
type Lener interface {
// Len gets the length of the type's storage in bytes.
Len() int
}
Lener is implemented by types that have a Len method returning their length in bytes. It is used by the Folder.NewDocument function that picks the recommended upload type based on the file size.
type Library ¶
type Library struct {
// LibraryID is the library's unique ID in ShareBase.
LibraryID int `json:"LibraryId"`
// LibraryName is the library's name.
LibraryName string
// IsPrivate is true for personal libraries and false otherwise.
IsPrivate bool
// Links holds the library's links to other resources.
Links LibraryLinks
}
Library is a library in ShareBase.
func (*Library) FolderByName ¶
FolderByName gets a folder within the library by its name.
type LibraryLinks ¶
type LibraryLinks struct {
// Self is the library link.
Self string
// Folders is the URL that gets the folders within the library.
Folders string
}
LibraryLinks holds the URLs that a Library's Links attribute has.
type NewDocumentRequest ¶
type NewDocumentRequest struct {
// DocumentName is the name of the document to be created in a folder.
DocumentName string
}
NewDocumentRequest is marshaled when creating a new document.
type NewFolderRequest ¶
type NewFolderRequest struct {
// FolderPath holds the full path to the folder with the path components
// separated by backslashes.
FolderPath string
}
NewFolderRequest is used by the NewFolder function to create a new folder.
type NewLargeDocumentResponse ¶
type NewLargeDocumentResponse struct {
Links NewLargeDocumentResponseLinks
Identifier uuid.UUID
FileName string
CurrentSize uint64
VolumeID int `json:"VolumeId"`
}
NewLargeDocumentResponse is a JSON response returned when creating a large document in ShareBase.
type NewLargeDocumentResponseLinks ¶
type NewLargeDocumentResponseLinks struct {
Location string
}
NewLargeDocumentResponseLinks is the embedded Links struct returned inside of the NewLargeDocumentResponse struct.
type Size ¶
type Size int64
Size defines a file size in bytes
const ( // SmallFileCutoff is the file size limit under which ShareBase's // recommended small file upload method is used and above which ShareBase's // large file upload method is used. SmallFileCutoff Size = 5 * M // PatchSize is the size of patches made to a large file upload. // ShareBase's recommendation is 512K and not to exceed 2M, so I'm going // to go with the power of 2 between them. PatchSize Size = 512 * K )