Documentation
¶
Index ¶
- Constants
- Variables
- type TraceID
- type TracedClient
- func (tc TracedClient) Create(ctx context.Context, name, parentID string, isDir bool) (file *drive.File, err error)
- func (tc TracedClient) DeleteByID(ctx context.Context, id, parentID string) (err error)
- func (tc TracedClient) DownloadByID(ctx context.Context, id string) (*bytes.Buffer, error)
- func (tc TracedClient) FindFile(ctx context.Context, name string, qStrings ...string) (string, error)
- func (tc TracedClient) GetByID(ctx context.Context, id, fields string) (f *drive.File, err error)
- func (tc TracedClient) ListFiles(ctx context.Context, parentID string, fields string, ...) error
- func (tc TracedClient) NewChild() TracedClient
- func (tc TracedClient) UpdateMediaByID(ctx context.Context, id string, r io.Reader) (f *drive.File, err error)
Constants ¶
const ( // The magic id for root directory. RootID = "root" // The magic mime type for folders. FolderMimeType = "application/vnd.google-apps.folder" // The q string used for folders. FolderQString = `mimeType = '` + FolderMimeType + `'` // The q string used for non-folders. NotFolderQString = `mimeType != '` + FolderMimeType + `'` )
Magic constants defined by Drive API.
const (
PageSize = 50
)
Default page size used by list calls.
Variables ¶
var ErrBreak = errors.New("break list")
ErrBreak is an error can be used in ListFiles to break the list early.
Functions ¶
This section is empty.
Types ¶
type TraceID ¶
type TraceID uint64
TraceID is a hopefully unique id to represent a trace
func NewTraceID ¶
func NewTraceID() TraceID
NewTraceID returns a new, random, and non-zero trace id.
type TracedClient ¶
type TracedClient struct { *drive.Service Logger *zap.SugaredLogger // contains filtered or unexported fields }
TracedClient represents a group of Drive API calls with an authorized Drive client and a trace id.
One trace can and usually does contain multiple API calls.
func NewTracedClient ¶
func NewTracedClient(client *drive.Service, logger *zap.SugaredLogger) TracedClient
NewTracedClient creates a new, top level trace.
logger arg is optional. If it's nil, top level logger will be used as the base.
func (TracedClient) Create ¶
func (tc TracedClient) Create(ctx context.Context, name, parentID string, isDir bool) (file *drive.File, err error)
Create creates a new file/directory under parent with given name.
func (TracedClient) DeleteByID ¶
func (tc TracedClient) DeleteByID(ctx context.Context, id, parentID string) (err error)
DeleteByID removes the given parent id from the file's parents list.
Note that for directories this also deletes all its contents. It's caller's responsibility to ensure that it's empty.
func (TracedClient) DownloadByID ¶
DownloadByID downloads the file content by its id.
func (TracedClient) FindFile ¶
func (tc TracedClient) FindFile(ctx context.Context, name string, qStrings ...string) (string, error)
FindFile finds the file or directory on Drive by it's full path.
func (TracedClient) GetByID ¶
func (tc TracedClient) GetByID(ctx context.Context, id, fields string) (f *drive.File, err error)
GetByID gets the file metadata by its id.
func (TracedClient) ListFiles ¶
func (tc TracedClient) ListFiles( ctx context.Context, parentID string, fields string, callback func(f *drive.File) error, qStrings ...string, ) error
ListFiles list all files under a directory.
func (TracedClient) NewChild ¶
func (tc TracedClient) NewChild() TracedClient
NewChild creates a new child trace.
func (TracedClient) UpdateMediaByID ¶
func (tc TracedClient) UpdateMediaByID(ctx context.Context, id string, r io.Reader) (f *drive.File, err error)
UpdateMediaByID updates the file content by its id.