docs

package
v0.0.46 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func DocumentToMarkdown

func DocumentToMarkdown(doc *docs.Document) (string, error)

DocumentToMarkdown converts a Google Doc to Markdown format Supports both legacy documents (with doc.Body) and new tabbed documents (with doc.Tabs)

func DocumentToPlainText

func DocumentToPlainText(doc *docs.Document) (string, error)

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

func HasTokenForAccount(account string) bool

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

func NewClient(ctx context.Context) (*Client, error)

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

func NewClientForAccount(ctx context.Context, account string) (*Client, error)

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

func NewClientWithProvider(ctx context.Context, provider google.TokenProvider) (*Client, error)

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

func (c *Client) Account() string

Account returns the account name this client is associated with

func (*Client) GetDocument

func (c *Client) GetDocument(documentID string) (*docs.Document, error)

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

func (c *Client) GetDocumentAsMarkdown(documentID string) (string, error)

GetDocumentAsMarkdown converts a Google Doc to Markdown format

func (*Client) GetDocumentAsPlainText

func (c *Client) GetDocumentAsPlainText(documentID string) (string, error)

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

type User

type User struct {
	DisplayName  string `json:"displayName"`
	EmailAddress string `json:"emailAddress"`
}

User represents a Google Drive user

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL