gcputils

package
v0.0.0-...-a0e9b24 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package gcputils provides utility functions for initializing Google API clients and services such as Google Drive and Google Slides. It simplifies the authentication process and service initialization using credentials and token caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCredentialCacheDir

func GetCredentialCacheDir() (string, error)

GetCredentialCacheDir returns $HOME/.credentials or an error if it does not exists

func InitDriveService

func InitDriveService(ctx context.Context, client *http.Client) *drive.Service

InitDriveService initializes a Google Drive service using the provided context and HTTP client.

Parameters:

  • ctx: The context for the service.
  • client: The HTTP client for authenticating requests.

Returns:

*drive.Service: A service for interacting with Google Drive.

Errors:

  • Logs a fatal error if the Drive service cannot be created.

func InitGoogleClient

func InitGoogleClient(credentials, tokenCacheFile string) *http.Client

InitGoogleClient initializes an HTTP client for accessing Google APIs using credentials from a JSON file and a cached token file. If the token is missing or expired, the function triggers the authentication process to obtain a new token, which is then saved for future use.

Parameters:

  • credentials: Path to the JSON file containing the client credentials.
  • tokenCacheFile: Path to the file where the authentication token is cached.

Returns:

*http.Client: An HTTP client configured for use with Google APIs.

Errors:

  • Logs a fatal error if the credentials file cannot be read or parsed.

func InitSlidesService

func InitSlidesService(ctx context.Context, client *http.Client) *slides.Service

InitSlidesService initializes a Google Slides service using the provided context and HTTP client.

Parameters:

  • ctx: The context for the service.
  • client: The HTTP client for authenticating requests.

Returns:

*slides.Service: A service for interacting with Google Slides.

Errors:

  • Logs a fatal error if the Slides service cannot be created.

Types

This section is empty.

Jump to

Keyboard shortcuts

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