Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidCredentials = errors.New("bernard: invalid credentials")
ErrInvalidCredentials can occur when the wrong authentication scopes are used, the access token does not have access to the specified resource, or the token is simply invalid or expired.
var ErrNetwork = errors.New("bernard: network related error")
ErrNetwork is the result of a networking error while contacting the Google Drive API. This error is only thrown on status codes not equal to 200, 401 and 500.
var ErrNotFound = errors.New("bernard: cannot find Shared Drive")
ErrNotFound only occurs when the provided auth does not have access to the Shared Drive or if the Shared Drive does not exist.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
Authenticator represents any struct which can create an access token on demand
type Bernard ¶
type Bernard struct {
// contains filtered or unexported fields
}
Bernard is a synchronisation backend for Google Drive.
func New ¶
func New(auth Authenticator, store ds.Datastore, opts ...Option) *Bernard
New creates a new instance of Bernard
type Hook ¶
Hook allows the injection of functions between the fetch and datastore operations.
The hook provides the changes as provided by Google, which could contain data anomalies.
The first hook parameter, Drive, always provides the ID of the Drive. If the name of the Drive is changed in a partial sync, the drive.Name will be updated to reflect the new value. If the name did not change, then drive.Name is an empty string.
The second parameter, files, contains all the updated files in their new state.
The third parameter, folders, contains all the updated folders in their new state. Sometimes Google says a folder has changed when it actually has not. If you want to be sure that the folder changed, compare the old datastore state versus the new state as provided in this slice of folders.
The fourth parameter, removed, contains all the removed files and folders by ID. Google does not provide the last known state the files and folders were in. So to check the state of the removed items, use the datastore to get their last-known state.
type Option ¶
type Option func(*Bernard)
An Option can override some of the default Bernard values.
func WithClient ¶
WithClient allows one to override the default HTTP client.
func WithJSONDecoder ¶
func WithJSONDecoder(d jsonDecoder) Option
WithJSONDecoder allows one to replace Go's default JSON decoding with a more memory-efficient and quicker solution.
func WithPreRequestHook ¶
func WithPreRequestHook(preHook func()) Option
WithPreRequestHook allows one to apply rate-limiting before every request.
This function is called before fetching the authentication token to prevent tokens from expiring when a rate-limit is applied.
func WithSafeSleep ¶
WithSafeSleep allows one to sleep between the pageToken fetch and the full sync. Setting this between 1 and 5 minutes prevents any data from going rogue when changes are actively being made to the Shared Drive.
The default value of safeSleep is set at 0.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package datastore provides the file and folder representations used in Bernard.
|
Package datastore provides the file and folder representations used in Bernard. |
sqlite
Package sqlite provides a reference implementation of a Bernard datastore.
|
Package sqlite provides a reference implementation of a Bernard datastore. |