fetch

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheDir

func CacheDir(projectRoot string) string

CacheDir returns the default cache directory path (.alloy/fetch-cache/).

func FetchGraphQL

func FetchGraphQL(endpoint, query string) (interface{}, error)

FetchGraphQL sends a GraphQL query and returns the unwrapped data.

func FetchPluginSource

func FetchPluginSource(name string, config map[string]interface{}) (interface{}, error)

FetchPluginSource invokes the registered plugin source handler by name.

func FetchREST

func FetchREST(url string) (interface{}, error)

FetchREST fetches data from a REST endpoint and parses the JSON response.

func FetchRESTWithRefetch

func FetchRESTWithRefetch(url string, cacheDir string, refetch bool) (interface{}, error)

FetchRESTWithRefetch fetches from a REST endpoint, bypassing cache when refetch is true. On success the result is saved to cache so subsequent non-refetch calls can use it.

func GetCached

func GetCached(name, cacheDir string, ttl int) (interface{}, bool)

GetCached returns cached data if the TTL has not expired.

func GetCachedWithTTL

func GetCachedWithTTL(name, cacheDir string, ttlSeconds int) (interface{}, bool, error)

GetCachedWithTTL returns cached data only if it hasn't expired.

func ParseCSVResponse

func ParseCSVResponse(data []byte) ([]map[string]string, error)

ParseCSVResponse parses a CSV response body into rows of maps. First row is treated as headers.

func ParseXML

func ParseXML(data []byte) (map[string]interface{}, error)

ParseXML parses an XML response body into a map structure.

func RegisterPluginSource

func RegisterPluginSource(name string, handler PluginSourceHandler)

RegisterPluginSource registers a named plugin source handler.

func RegisteredPluginSources

func RegisteredPluginSources() []string

RegisteredPluginSources returns the names of all registered plugin source handlers.

func ResetPluginSources

func ResetPluginSources()

ResetPluginSources clears all registered plugin source handlers. Intended for test isolation.

func SaveCache

func SaveCache(name, cacheDir string, data interface{}) error

SaveCache writes fetched data to the cache directory.

func UnwrapGraphQLData

func UnwrapGraphQLData(raw map[string]interface{}) (interface{}, error)

UnwrapGraphQLData extracts the "data" field from a GraphQL JSON response.

Types

type FetchResult

type FetchResult struct {
	Data     interface{}
	CachedAt time.Time
	Source   string
}

FetchResult holds fetched data along with cache metadata.

type PluginSourceHandler

type PluginSourceHandler func(config map[string]interface{}) (interface{}, error)

PluginSourceHandler is a function provided by a plugin to fetch data.

Jump to

Keyboard shortcuts

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