Documentation
¶
Overview ¶
Package docs provides functionality for interacting with Google Docs API.
This package includes a client for authenticating with Google Docs API using OAuth2, retrieving document content, and converting documents to various formats (Markdown, plain text).
The package handles:
- OAuth2 authentication with token caching
- Document retrieval via Google Docs API
- Document metadata retrieval via Google Drive API
- Document content conversion to Markdown and plain text formats
Example usage:
client, err := docs.NewClient(context.Background())
if err != nil {
log.Fatal(err)
}
doc, err := client.GetDocument("1ABC123xyz")
if err != nil {
log.Fatal(err)
}
markdown, err := DocumentToMarkdown(doc)
if err != nil {
log.Fatal(err)
}
Index ¶
- func DocumentToMarkdown(doc *docs.Document) (string, error)
- func DocumentToPlainText(doc *docs.Document) (string, error)
- func HasToken() bool
- func HasTokenForAccount(account string) bool
- func HasTokenForAccountWithProvider(account string, provider google.TokenProvider) bool
- type Client
- func NewClient(ctx context.Context) (*Client, error)
- func NewClientForAccount(ctx context.Context, account string) (*Client, error)
- func NewClientForAccountWithProvider(ctx context.Context, account string, tokenProvider google.TokenProvider) (*Client, error)
- func NewClientWithProvider(ctx context.Context, provider google.TokenProvider) (*Client, error)
- func (c *Client) Account() string
- func (c *Client) GetDocument(documentID string) (*docs.Document, error)
- func (c *Client) GetDocumentAsMarkdown(documentID string) (string, error)
- func (c *Client) GetDocumentAsPlainText(documentID string) (string, error)
- func (c *Client) GetFileMetadata(fileID string) (*DocumentMetadata, error)
- type DocumentMetadata
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DocumentToMarkdown ¶
DocumentToMarkdown converts a Google Doc to Markdown format Supports both legacy documents (with doc.Body) and new tabbed documents (with doc.Tabs)
func DocumentToPlainText ¶
DocumentToPlainText extracts plain text from a Google Doc Supports both legacy documents (with doc.Body) and new tabbed documents (with doc.Tabs)
func HasToken ¶
func HasToken() bool
HasToken checks if a valid OAuth token exists for the default account
func HasTokenForAccount ¶ added in v0.0.8
HasTokenForAccount checks if a valid OAuth token exists for the specified account
func HasTokenForAccountWithProvider ¶ added in v0.0.27
func HasTokenForAccountWithProvider(account string, provider google.TokenProvider) bool
HasTokenForAccountWithProvider checks if a valid OAuth token exists for the specified account
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Google Docs and Drive API services
func NewClient ¶
NewClient creates a new Google Docs client with OAuth2 authentication for the default account Returns an error if no valid token exists - use HasToken() to check first
func NewClientForAccount ¶ added in v0.0.8
NewClientForAccount creates a new Google Docs client with OAuth2 authentication for a specific account Uses the default file-based token provider for backward compatibility
func NewClientForAccountWithProvider ¶ added in v0.0.27
func NewClientForAccountWithProvider(ctx context.Context, account string, tokenProvider google.TokenProvider) (*Client, error)
NewClientForAccountWithProvider creates a new Google Docs client with OAuth2 authentication for a specific account The OAuth token is retrieved from the provided token provider
func NewClientWithProvider ¶ added in v0.0.27
NewClientWithProvider creates a new Google Docs client with OAuth2 authentication for the default account using the provided token provider
func (*Client) Account ¶ added in v0.0.8
Account returns the account name this client is associated with
func (*Client) GetDocument ¶
GetDocument retrieves a Google Doc's content by document ID This method automatically fetches all tabs to support documents with multiple tabs (introduced Oct 2024)
func (*Client) GetDocumentAsMarkdown ¶
GetDocumentAsMarkdown converts a Google Doc to Markdown format
func (*Client) GetDocumentAsPlainText ¶
GetDocumentAsPlainText extracts plain text from a Google Doc
func (*Client) GetFileMetadata ¶
func (c *Client) GetFileMetadata(fileID string) (*DocumentMetadata, error)
GetFileMetadata retrieves metadata for any Google Drive file
type DocumentMetadata ¶
type DocumentMetadata struct {
ID string `json:"id"`
Name string `json:"name"`
MimeType string `json:"mimeType"`
CreatedTime string `json:"createdTime"`
ModifiedTime string `json:"modifiedTime"`
Size int64 `json:"size,omitempty"`
Owners []User `json:"owners,omitempty"`
}
DocumentMetadata represents metadata about a Google Drive file