sheetsdb

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MPL-2.0-no-copyleft-exception Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sheetsdb provides generic Google Sheets fetchers backed by a config-indexed workbook pattern. It does not provide an Updater: Sheets are read-only sources.

Index

Constants

View Source
const DefaultTimeout = 30 * time.Second
View Source
const MaxSourceBytes = 16 << 20

Variables

View Source
var ErrSourceNotConfigured = errors.New("source not configured")
View Source
var ErrSourceNotFound = errors.New("source not found")

Functions

func NormalizeConfigKey

func NormalizeConfigKey(value string) string

NormalizeConfigKey lowercases, trims, and applies collection aliases.

func NormalizeEnvironmentKey

func NormalizeEnvironmentKey(value string) string

NormalizeEnvironmentKey normalizes an environment key by lowercasing, trimming, and stripping an optional env: prefix.

Types

type Config

type Config struct {
	Rows []ConfigRow
}

Config is the typed config-tab result. Rows stay ordered so duplicate keys can be detected instead of silently resolved by map iteration.

func LoadConfig

func LoadConfig(ctx context.Context, indexURL string, client *http.Client) (Config, error)

LoadConfig fetches and caches the workbook config tab using a process-wide cache.

func (Config) Environment

func (c Config) Environment(name string) (string, bool, bool)

Environment returns a normalized environment value. Both NAME and env:NAME forms are accepted.

func (Config) EnvironmentValues

func (c Config) EnvironmentValues() (map[string]string, error)

EnvironmentValues returns ALL_CAPS and env:-prefixed config values.

func (Config) SourceURL

func (c Config) SourceURL(key string) (string, bool, bool)

SourceURL returns the configured URL/path for a source key.

type ConfigCache

type ConfigCache struct {
	// contains filtered or unexported fields
}

ConfigCache provides thread-safe, once-only loading of a workbook's config tab.

func (*ConfigCache) Load

func (c *ConfigCache) Load(ctx context.Context, indexURL string, client *http.Client) (Config, error)

Load fetches the config tab if not already loaded.

type ConfigRow

type ConfigRow struct {
	Description string `json:"description"`
	Key         string `json:"key"`
	Value       string `json:"value"`
}

ConfigRow is the required shape of the workbook's index tab.

type IndexedFetcher

type IndexedFetcher[T any] struct {
	IndexURL string
	Key      string
	Client   *http.Client
	Config   *ConfigCache
}

IndexedFetcher resolves a source tab URL from the workbook's config tab, then fetches and decodes that tab into T.

func (*IndexedFetcher[T]) Fetch

func (f *IndexedFetcher[T]) Fetch(ctx context.Context) ([]T, error)

func (*IndexedFetcher[T]) Init

func (f *IndexedFetcher[T]) Init(ctx context.Context) ([]rowsync.Message, error)

type OptionalIndexedFetcher

type OptionalIndexedFetcher[T any] struct{ Indexed IndexedFetcher[T] }

OptionalIndexedFetcher treats a missing config source as an empty source.

func (*OptionalIndexedFetcher[T]) Fetch

func (f *OptionalIndexedFetcher[T]) Fetch(ctx context.Context) ([]T, error)

func (*OptionalIndexedFetcher[T]) Init

type WebFetcher

type WebFetcher[T any] struct {
	URL    string
	Format string
	Client *http.Client
}

WebFetcher fetches one Google Sheets tab (or local CSV/TSV file) and decodes it into T. T should use json tags, and nullable source cells should use csvx fields.

func (*WebFetcher[T]) Fetch

func (f *WebFetcher[T]) Fetch(ctx context.Context) ([]T, error)

func (*WebFetcher[T]) Init

func (f *WebFetcher[T]) Init(ctx context.Context) ([]rowsync.Message, error)

Jump to

Keyboard shortcuts

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