Documentation
¶
Index ¶
- Constants
- Variables
- func EndpointPath(path string, endpoint string, query ...string) string
- func EndpointQuery(query ...string) (o string)
- func EndpointSelect(names ...string) string
- func MakeRequest[T any](t *GraphToken, method string, url string, requestBody io.Reader) (*T, error)
- func SendRequest[T any](t *GraphToken, request *http.Request) (*T, error)
- type ConflictBehaviour
- type DriveItem
- type ErrorResponse
- type GraphToken
- func (t *GraphToken) BuildRequest(method string, endpoint string, body io.Reader) (*http.Request, error)
- func (t *GraphToken) BuildRequestRaw(method string, uri string, body io.Reader) (*http.Request, error)
- func (t *GraphToken) CreateUploadSession(destPath string, params UploadSessionParams) (*UploadSessionResponse, error)
- func (t *GraphToken) DownloadDriveItem(item *DriveItem) (io.ReadCloser, error)
- func (t *GraphToken) GetDriveItem(path string, query ...string) (*DriveItem, error)
- func (t *GraphToken) GetDriveItemChildren(path string, query []string) (*ResponsePaginated[[]*DriveItem], error)
- func (t *GraphToken) ListFolder(path string) ([]*DriveItem, error)
- func (t *GraphToken) MakeRequest(method string, url string, body io.Reader, contentType ...string) (*http.Response, error)
- func (t *GraphToken) SendRequest(request *http.Request) (*http.Response, error)
- func (t *GraphToken) SyncFolder(remotePath string, localPath string, filterFn SyncFilterFn, ...) error
- func (t *GraphToken) UploadContent(r io.Reader, size int64, destPath string, params UploadSessionParams) (*DriveItem, error)
- func (t *GraphToken) UploadFile(file fs.File, destPath string, conflictBehaviour ConflictBehaviour) (*DriveItem, error)
- type Hashes
- type ResponsePaginated
- type SyncEvent
- type SyncEventBegin
- type SyncEventDelete
- type SyncEventEnd
- type SyncEventError
- type SyncEventFn
- type SyncEventProgress
- type SyncEventSkip
- type SyncFile
- type SyncFilterFn
- type UploadSessionParams
- type UploadSessionResponse
Constants ¶
const ( ConflictBehaviour_Rename = ConflictBehaviour("rename") ConflictBehaviour_Fail = ConflictBehaviour("fail") ConflictBehaviour_Replace = ConflictBehaviour("replace") )
Variables ¶
var ErrSyncLocalDirectory = errors.New("local file is directory")
var ErrSyncRemoteDirectory = errors.New("remote file is directory")
Functions ¶
func EndpointPath ¶
Helper function, creates URL from path and query.
func EndpointQuery ¶
func EndpointSelect ¶
Builds the "$select" query string from a list of wanted results
func MakeRequest ¶
func MakeRequest[T any](t *GraphToken, method string, url string, requestBody io.Reader) (*T, error)
Utility function for making requests. You supply the method, the endpoint (/me/drive/*) and the request body. Returns error responses from the API as a go error. Deserializes the result to whatever you want, using json.Unmarshal.
func SendRequest ¶
func SendRequest[T any](t *GraphToken, request *http.Request) (*T, error)
Types ¶
type ConflictBehaviour ¶
type ConflictBehaviour string
type DriveItem ¶
type DriveItem struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Size int64 `json:"size"`
WebURL string `json:"webUrl"`
Ctag string `json:"cTag"`
Etag string `json:"eTag"`
CreationDate string `json:"createdDateTime"`
ModifiedDate string `json:"lastModifiedDateTime"`
Root *struct{} `json:"root"`
DownloadURL string `json:"@content.downloadUrl"`
Audio *struct {
Album string `json:"album"`
AlbumArtist string `json:"albumArtist"`
Artist string `json:"Artist"`
Bitrate int `json:"bitrate"`
Composers string `json:"composers"`
Copyright string `json:"copyright"`
Disc int `json:"disc"`
DiscCount int `json:"discCount"`
Duration int `json:"duration"`
Genre string `json:"genre"`
HasDRM bool `json:"hasDrm"`
IsVariableBitrate bool `json:"isVariableBitrate"`
Title string `json:"title"`
Track int `json:"track"`
TrackCount int `json:"trackCount"`
Year int `json:"year"`
} `json:"audio"`
File *struct {
MimeType string `json:"mimeType"`
Hashes *Hashes `json:"hashes"`
} `json:"file"`
Folder *struct {
ChildCount int `json:"childCount"`
View *struct {
SortBy string `json:"sortBy"`
SortOrder string `json:"sortOrder"`
ViewType string `json:"viewType"`
} `json:"view"`
} `json:"folder"`
}
type ErrorResponse ¶
type ErrorResponse struct {
Outer struct {
Code string `json:"code"`
Message string `json:"message"`
Inner struct {
Date string `json:"date"`
RequestID string `json:"request-id"`
ClientRequestId string `json:"client-request-id"`
} `json:"innerError"`
} `json:"error"`
}
func (*ErrorResponse) Error ¶
func (err *ErrorResponse) Error() string
type GraphToken ¶
type GraphToken struct {
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
Scope string `json:"scope"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
// contains filtered or unexported fields
}
func CreateAccess ¶
func CreateAccess(clientID string, redirectURI string, refresh *GraphToken) (*GraphToken, error)
Main entrypoint for the GoneDrive package. With an access token, you can do pretty much everything you want in the API. The token passed in to be refreshed should be replaced after this call.
It is recommended to store and refresh tokens, rather than generating new tokens every time your program runs.
func (*GraphToken) BuildRequest ¶
func (t *GraphToken) BuildRequest(method string, endpoint string, body io.Reader) (*http.Request, error)
Builds a request object. You supply the method, the endpoint (/me/drive/*) and the request body. Authorization is taken care of when the request is returned.
func (*GraphToken) BuildRequestRaw ¶
func (t *GraphToken) BuildRequestRaw(method string, uri string, body io.Reader) (*http.Request, error)
Builds a request object. Authorization is taken care of when the request is returned.
func (*GraphToken) CreateUploadSession ¶
func (t *GraphToken) CreateUploadSession(destPath string, params UploadSessionParams) (*UploadSessionResponse, error)
func (*GraphToken) DownloadDriveItem ¶
func (t *GraphToken) DownloadDriveItem(item *DriveItem) (io.ReadCloser, error)
Downloads a DriveItem, and returns the file body. It is the responsibility of the caller to close the resulting reader.
func (*GraphToken) GetDriveItem ¶
func (t *GraphToken) GetDriveItem(path string, query ...string) (*DriveItem, error)
Get information about a single drive item
func (*GraphToken) GetDriveItemChildren ¶
func (t *GraphToken) GetDriveItemChildren(path string, query []string) (*ResponsePaginated[[]*DriveItem], error)
Runs a query to get all DriveItems within a folder. This returns the paginated response structure. Path should be WITHOUT leading/trailing slashes.
func (*GraphToken) ListFolder ¶
func (t *GraphToken) ListFolder(path string) ([]*DriveItem, error)
Lists all files in a given folder. Path should be WITHOUT leading/trailing slashes.
func (*GraphToken) MakeRequest ¶
func (t *GraphToken) MakeRequest(method string, url string, body io.Reader, contentType ...string) (*http.Response, error)
Utility function for making requests. You supply the method, the endpoint (/me/drive/*) and the request body. Returns error responses from the API as a go error.
Only the first value of contentType is used, the rest are ignored.
func (*GraphToken) SendRequest ¶
Sends a request object to the MS graph API. Returns error responses from the API as a go error.
func (*GraphToken) SyncFolder ¶
func (t *GraphToken) SyncFolder(remotePath string, localPath string, filterFn SyncFilterFn, eventFn SyncEventFn) error
A read-only sync of a given OneDrive folder. Downloads files that don't exist in local directory. Deletes files in local directory not found on OneDrive. Does not redownload existing (up-to-date) files.
func (*GraphToken) UploadContent ¶
func (t *GraphToken) UploadContent(r io.Reader, size int64, destPath string, params UploadSessionParams) (*DriveItem, error)
func (*GraphToken) UploadFile ¶
func (t *GraphToken) UploadFile(file fs.File, destPath string, conflictBehaviour ConflictBehaviour) (*DriveItem, error)
type ResponsePaginated ¶
type SyncEventBegin ¶
Begin upload/download. This event is sent whenever a download or upload is started. A corrosponding SyncEventEnd event will also be sent eventually. While the file is uploading/downloading, any number of SyncEventProgress events.
func (SyncEventBegin) String ¶
func (event SyncEventBegin) String() string
type SyncEventDelete ¶
type SyncEventDelete struct {
LocalPath string
}
Deleted local file.
func (SyncEventDelete) String ¶
func (event SyncEventDelete) String() string
type SyncEventEnd ¶
End upload/download. Once this event has been sent, no more events will be sent for this file.
func (SyncEventEnd) String ¶
func (event SyncEventEnd) String() string
type SyncEventError ¶
Error
func (SyncEventError) String ¶
func (event SyncEventError) String() string
type SyncEventFn ¶
type SyncEventFn func(event SyncEvent)
type SyncEventProgress ¶
type SyncEventProgress struct {
LocalPath string
RemotePath string
IsUpload bool
Size int64
Progress int64
}
Progress event.
func (SyncEventProgress) String ¶
func (event SyncEventProgress) String() string
type SyncEventSkip ¶
Skipped downloading file.
func (SyncEventSkip) String ¶
func (event SyncEventSkip) String() string
type SyncFilterFn ¶
type UploadSessionParams ¶
type UploadSessionParams struct {
ConflictBehaviour ConflictBehaviour
CreatedAt *time.Time
AccessedAt *time.Time
ModifiedAt *time.Time
}
func (*UploadSessionParams) MarshalJSON ¶
func (p *UploadSessionParams) MarshalJSON() ([]byte, error)