Airtable
Airtable API Client for Go
Install / Use
/learn @brianloveswords/AirtableREADME
airtable
Go package for interacting with the Airtable API.
License
Install
$ go get github.com/brianloveswords/airtable
API Documentation
See airtable package documentation on godoc.org
Example Usage
package main
import (
"fmt"
"strings"
"time"
"github.com/brianloveswords/airtable"
)
type PublicDomainBookRecord struct {
airtable.Record // provides ID, CreatedTime
Fields struct {
Title string `json:"Book Title"`
Author string
Publication time.Time `json:"Publication Date"`
FullText string
Rating int
Tags airtable.MultiSelect
}
}
// String shows the book record like "<title> by <author> [<rating>]"
func (r *PublicDomainBookRecord) String() string {
f := r.Fields
return fmt.Sprintf("%s by %s %s", f.Title, f.Author, r.Rating())
}
// Rating outputs a rating like [***··]
func (r *PublicDomainBookRecord) Rating() string {
var (
max = 5
rating = r.Fields.Rating
stars = strings.Repeat("*", rating)
dots = strings.Repeat("·", max-rating)
)
return fmt.Sprintf("[%s%s]", stars, dots)
}
func Example() {
// Create the Airtable client with your APIKey and BaseID for the
// base you want to interact with.
client := airtable.Client{
APIKey: "keyXXXXXXXXXXXXXX",
BaseID: "appwNa5g4gHCVZQPm",
}
books := client.Table("Public Domain Books")
bestBooks := []PublicDomainBookRecord{}
books.List(&bestBooks, &airtable.Options{
// The whole response would be huge because of FullText so we
// should just get the title and author. NOTE: even though the
// field is called "Book Title" in the JSON, we should use field
// by the name we defined it in our struct.
Fields: []string{"Title", "Author", "Rating"},
// Only get books with a rating that's 4 or higher.
Filter: `{Rating} >= 4`,
// Let's sort from highest to lowest rating, then by author
Sort: airtable.Sort{
{"Rating", airtable.SortDesc},
{"Author", airtable.SortAsc},
},
})
fmt.Println("Best Public Domain Books:")
for _, bookRecord := range bestBooks {
fmt.Println(bookRecord.String())
}
// Let's prune our library of books we aren't super into.
badBooks := []PublicDomainBookRecord{}
books.List(&badBooks, &airtable.Options{
Fields: []string{"Title", "Author", "Rating"},
Filter: `{Rating} < 3`,
})
for _, badBook := range badBooks {
fmt.Println("deleting", badBook)
books.Delete(&badBook)
}
}
Contributing
TBD
Related Skills
node-connect
350.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
350.8kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
110.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.8kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
