Documentation
¶
Overview ¶
Package drive is a client for the Microsoft Graph drive API: the files and folders of OneDrive accounts and SharePoint document libraries. Every item operation addresses a drive by id; GetUserDrive, GetSiteDrive and ListSiteDrives resolve one.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) CreateFolder(ctx context.Context, driveId string, parentId string, name string, ...) (*drive_item.DriveItem, error)
- func (c *Client) DeleteItem(ctx context.Context, driveId string, itemId string, ...) error
- func (c *Client) EnsureFolderPath(ctx context.Context, driveId string, path string, ...) (*drive_item.DriveItem, error)
- func (c *Client) GetDrive(ctx context.Context, driveId string, options ...fetch_config.Option) (*graph_drive.Drive, error)
- func (c *Client) GetItem(ctx context.Context, driveId string, itemId string, ...) (*drive_item.DriveItem, error)
- func (c *Client) GetItemByPath(ctx context.Context, driveId string, path string, ...) (*drive_item.DriveItem, error)
- func (c *Client) GetSiteByPath(ctx context.Context, hostname string, sitePath string, ...) (*site.Site, error)
- func (c *Client) GetSiteDrive(ctx context.Context, siteId string, options ...fetch_config.Option) (*graph_drive.Drive, error)
- func (c *Client) GetUserDrive(ctx context.Context, userId string, options ...fetch_config.Option) (*graph_drive.Drive, error)
- func (c *Client) ListChildren(ctx context.Context, driveId string, folderId string, ...) ([]*drive_item.DriveItem, error)
- func (c *Client) ListSiteDrives(ctx context.Context, siteId string, options ...fetch_config.Option) ([]*graph_drive.Drive, error)
- func (c *Client) MoveItem(ctx context.Context, driveId string, itemId string, newParentId string, ...) (*drive_item.DriveItem, error)
- func (c *Client) UploadFile(ctx context.Context, driveId string, parentId string, name string, data []byte, ...) (*drive_item.DriveItem, error)
Constants ¶
const RootItemId = "root"
RootItemId addresses a drive's root folder wherever an item id is taken.
const ( // SimpleUploadLimit is the largest file UploadFile sends in one request; // larger files go through an upload session. SimpleUploadLimit = 4 << 20 )
Variables ¶
var ( // ErrNotFolder is returned when an item a folder was expected at is a file. ErrNotFolder = errors.New("not a folder") // ErrUnexpectedUploadStatus is returned when Graph completes an upload // session before its last chunk was sent. ErrUnexpectedUploadStatus = errors.New("unexpected upload chunk status") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(options ...drive_config.Option) *Client
func (*Client) CreateFolder ¶
func (c *Client) CreateFolder( ctx context.Context, driveId string, parentId string, name string, options ...create_folder_config.Option, ) (*drive_item.DriveItem, error)
CreateFolder creates a folder called name in the folder identified by parentId (RootItemId for the root). By default an existing item of that name fails the call with 409 Conflict.
func (*Client) DeleteItem ¶
func (c *Client) DeleteItem(ctx context.Context, driveId string, itemId string, options ...fetch_config.Option) error
DeleteItem moves the item identified by itemId to the recycle bin.
func (*Client) EnsureFolderPath ¶
func (c *Client) EnsureFolderPath(ctx context.Context, driveId string, path string, options ...fetch_config.Option) (*drive_item.DriveItem, error)
EnsureFolderPath returns the folder at the drive-relative path, creating it and any missing ancestors. A folder created concurrently by someone else is used as found.
func (*Client) GetDrive ¶
func (c *Client) GetDrive(ctx context.Context, driveId string, options ...fetch_config.Option) (*graph_drive.Drive, error)
GetDrive retrieves the drive identified by driveId.
func (*Client) GetItem ¶
func (c *Client) GetItem(ctx context.Context, driveId string, itemId string, options ...fetch_config.Option) (*drive_item.DriveItem, error)
GetItem retrieves the item identified by itemId.
func (*Client) GetItemByPath ¶
func (c *Client) GetItemByPath(ctx context.Context, driveId string, path string, options ...fetch_config.Option) (*drive_item.DriveItem, error)
GetItemByPath retrieves the item at the drive-relative path (e.g. "Reports/2026/q3.xlsx"); an empty path is the root folder.
func (*Client) GetSiteByPath ¶
func (c *Client) GetSiteByPath(ctx context.Context, hostname string, sitePath string, options ...fetch_config.Option) (*site.Site, error)
GetSiteByPath retrieves the SharePoint site at sitePath (e.g. "sites/Finance") on hostname (e.g. "contoso.sharepoint.com"); an empty sitePath is the root site.
func (*Client) GetSiteDrive ¶
func (c *Client) GetSiteDrive(ctx context.Context, siteId string, options ...fetch_config.Option) (*graph_drive.Drive, error)
GetSiteDrive retrieves the default document library of the SharePoint site identified by siteId.
func (*Client) GetUserDrive ¶
func (c *Client) GetUserDrive(ctx context.Context, userId string, options ...fetch_config.Option) (*graph_drive.Drive, error)
GetUserDrive retrieves the OneDrive of the user identified by userId (an object id or a user principal name).
func (*Client) ListChildren ¶
func (c *Client) ListChildren(ctx context.Context, driveId string, folderId string, options ...fetch_config.Option) ([]*drive_item.DriveItem, error)
ListChildren retrieves all items in the folder identified by folderId (RootItemId for the root). Subfolders are the items with Folder set.
func (*Client) ListSiteDrives ¶
func (c *Client) ListSiteDrives(ctx context.Context, siteId string, options ...fetch_config.Option) ([]*graph_drive.Drive, error)
ListSiteDrives retrieves all document libraries of the SharePoint site identified by siteId.
func (*Client) MoveItem ¶
func (c *Client) MoveItem( ctx context.Context, driveId string, itemId string, newParentId string, options ...move_item_config.Option, ) (*drive_item.DriveItem, error)
MoveItem moves the item identified by itemId into the folder identified by newParentId (RootItemId for the root) within the same drive.
func (*Client) UploadFile ¶
func (c *Client) UploadFile( ctx context.Context, driveId string, parentId string, name string, data []byte, options ...upload_config.Option, ) (*drive_item.DriveItem, error)
UploadFile stores data as the file called name in the folder identified by parentId (RootItemId for the root). Files up to SimpleUploadLimit go in one request, larger ones through a resumable upload session. By default an existing item of that name fails the call with 409 Conflict; pass conflict_behavior.Replace to overwrite it as a new version.