sources

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DankDir  = ".dank" // DankDir is the directory where dank-extract stores its data.
	CacheDir = "cache" // CacheDir is the directory under DankDir where dank-extract stores its cache files.
)

Variables

This section is empty.

Functions

func CheckCacheFile

func CheckCacheFile(filename string, maxAge time.Duration) ([]byte, error)

CheckCacheFile checks DankDir/cache for a file. Returns its bytes and error, if any. If the file is not found, it returns an error. If the file is older than maxAge, it returns an error.

func EnsureDankRoot

func EnsureDankRoot() error

EnsureDankRoot ensures the current DankRoot exists, creating it if needed. Returns an error, if any.

func FetchSocrata

func FetchSocrata[T any](cfg SocrataConfig, appToken string, maxCacheAge time.Duration) ([]T, error)

FetchSocrata fetches data from a Socrata API endpoint with caching and pagination. It handles the common pattern of: check cache, paginate requests, unmarshal, cache.

func GetDankCacheDir

func GetDankCacheDir() string

GetDankCacheDir returns the path to the CacheDir directory.

func GetDankCachePathname

func GetDankCachePathname(filename string) string

GetDankCachePathname returns the path to the given filename within the CacheDir.

func GetDankDir

func GetDankDir() string

GetDankDir returns the path to the DankDir directory.

func GetDankRoot

func GetDankRoot() string

GetDankRoot returns the current root directory.

func MakeCacheFile

func MakeCacheFile(filename string) (*os.File, error)

MakeCacheFile creates a cache file in the DankDir/cache directory and returns its handles. Returns nil with any error.

func SQLString

func SQLString(str string) string

SQLString escapes single quotes for use in SQL queries

func SetDankRoot

func SetDankRoot(root string)

SetDankRoot sets the root directory for dank-extract.

func WriteCSV

func WriteCSV[T CSVExportable](filename string, items []T) error

WriteCSV writes any slice of CSVExportable items to a CSV file

func WriteJSON

func WriteJSON[T any](filename string, items []T) error

WriteJSON writes any slice of items to a JSON file with pretty formatting

Types

type CSVExportable

type CSVExportable interface {
	CSVHeaders() string
	CSVValue() string
}

CSVExportable is an interface for types that can be exported to CSV

type SocrataConfig

type SocrataConfig struct {
	URL           string // API endpoint URL
	CacheFilename string // Filename for caching results
	OrderBy       string // Field to order by (required for pagination)
	BatchSize     int    // Records per request (default 5000, set higher to disable pagination)
}

SocrataConfig holds configuration for a Socrata API endpoint

Directories

Path Synopsis
us
ct

Jump to

Keyboard shortcuts

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