GDriveGoKit
GDriveGoKit is a lightweight, SDK-style Go library designed to simplify integrations with the Google Drive API v3. It handles the complexities of OAuth2 flows, recursive folder management, and concurrent uploads so you can focus on your application logic.

Features
- OAuth2 Ready: Built-in token caching and automated authorization flows.
- Smart Folders: Automatic recursive folder creation (e.g.,
a/b/c). Reuses existing folders to prevent duplicates.
- MIME Detection: Automatic content-type detection if not explicitly provided.
- High Performance: Concurrent batch uploads with per-file error tracking.
- Context-Aware: Fully supports
context.Context for timeouts and cancellations.
Installation
go get [github.com/4CHILL3S101/gdrivegokit](https://github.com/4CHILL3S101/gdrivegokit)
Prerequisites
-Google Cloud Setup:
Create a project in the Google Cloud Console.
Enable the Google Drive API.
Create OAuth Client ID credentials (select "Desktop App").
Download the JSON file and rename it to credentials.json.
Authentication Flow
First Run: The library generates an authorization URL in the terminal.
Consent: Follow the URL, log in, and paste the resulting code back into the terminal.
Persistence: The token is saved locally (e.g., token.json).
Future Runs: Authentication happens automatically using the cached token.
Quick Start
package main
import (
"context"
"fmt"
"os"
"[github.com/4CHILL3S101/gdrivegokit](https://github.com/4CHILL3S101/gdrivegokit)"
)
func main() {
ctx := context.Background()
// 1. Load Google OAuth credentials
creds, err := os.ReadFile("credentials.json")
if err != nil {
panic(err)
}
// 2. Setup token provider (handles caching)
tokenProvider := &gdrivegokit.FileTokenProvider{
Path: "token.json",
}
// 3. Initialize Uploader
uploader, err := gdrivegokit.NewUploader(ctx, creds, tokenProvider)
if err != nil {
panic(err)
}
// 4. Upload (Folders are created automatically)
fileID, err := uploader.UploadFile(
"example.png",
"users/123/images",
"image/png", // Leave empty for auto-detection
)
if err != nil {
fmt.Printf("Upload failed: %v\n", err)
return
}
fmt.Printf("Success! File ID: %s\n", fileID)
}
Concurrent Batch Upload
files := []string{"doc1.pdf", "doc2.pdf", "image1.png"}
// Uploads all files concurrently to the specified path
results := uploader.UploadFilesBatch(
files,
"backups/october",
"", // Auto-detect MIME type
)
for fileName, res := range results {
if res.Err != nil {
fmt.Printf(" %s failed: %v\n", fileName, res.Err)
} else {
fmt.Printf(" %s uploaded -> ID: %s\n", fileName, res.FileID)
}
}
Automatic Folder Management
- You can use nested paths directly without pre-creating them in Drive:
users/123/images
backups/2026/january
How it works:
The library splits the path.
It checks if users exists, then 123, then images.
It creates only the missing segments and returns the final folder ID.
API Reference
NewUploader
func NewUploader(ctx context.Context, creds []byte, tp TokenProvider) (*Uploader, error)
Initializes the Google Drive client. Requires OAuth2 credentials and a token storage strategy.
#UploadFile
func (u *Uploader) UploadFile(filePath, folderPath, mimeType string) (string, error)
Uploads a single file. Returns the Google Drive File ID.
#UploadFilesBatch
func (u *Uploader) UploadFilesBatch(paths []string, folderPath, mimeType string) map[string]UploadResult
Performs concurrent uploads. Returns a map where the key is the file path and the value is an UploadResult containing the FileID or Err.
License
Distributed under the MIT License. See LICENSE for more information.