{"modulePath":"github.com/datatug/datatug-cli","version":"v0.67.0","isLatest":false,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpsource\n\nPackage httpsource translates a datatug project's HTTP-type QueryDefs into a dalgo2http-backed dal.DB: one dalgo2http.Collection per query (see BuildCollection for the translation and its sensible-default policy for RowsPath/KeyField, since the QueryDef JSON schema does not yet carry those explicitly), snapshot fallback wired to the project's fixtures/http/ directory (see fixtureFS for how its flatly-named fixture files are bridged to dalgo2http's per-request snapshot keying), live-then-snapshot mode.\n\nThis package is pkg/dbcopy/url.go's http:// / https:// backend (see parseHTTPSource there); it has no dependency on dbcopy and can also be used directly by a caller — a server endpoint handler, a future datatug-cli command — that wants an HTTP-sourced dal.DB for a project.\n\n## Functions\n\n```go\nfunc BuildCollection(def *datatug.QueryDef, urlTemplate string, sample map[string]any) (dalgo2http.Collection, error)\n```\nBuildCollection translates one HTTP QueryDef into a dalgo2http.Collection.\n\nurlTemplate is the sibling .query.http file's content (see LoadURLTemplate). sample, when non-nil, is the query's recorded fixture body (see readFixtureSample) decoded as JSON; it is used ONLY to infer the RowsPath and KeyField defaults documented on inferRowsPath/inferKeyField — never to shape any other field of the returned descriptor, and a nil sample degrades to those functions' no-sample answers rather than failing.\n\n```go\nfunc ContextWithDispatch(ctx context.Context, mode dalgo2http.Mode, offline bool, timeout time.Duration) context.Context\n```\nContextWithDispatch returns ctx carrying explicit HTTP-source dispatch options for Open to read instead of its own defaults.\n\n  - mode == \"\" keeps Open's own default (dalgo2http.ModeLive — see Open's doc comment for why that default changed from ModeLiveThenSnapshot).\n  - offline, when true, makes Open wire a Client that fails every live request without ever dialing (see offlineTransport) — \\`datatug serve --http-offline\\`'s mechanism.\n  - timeout, when \u003e 0, overrides BuildCollection's own defaultTimeout for every collection Open builds from projectDir.\n\n```go\nfunc LoadURLTemplate(projectDir, folderPath, id string) (string, error)\n```\nLoadURLTemplate reads the URL template for the HTTP query id found in folderPath (as returned by LoadHTTPQueries), trimming surrounding whitespace (the sibling .query.http files in the demo project end with a trailing newline).\n\n```go\nfunc Open(ctx context.Context, projectDir string, opts ...Option) (dal.DB, error)\n```\nOpen builds a dal.DB from every HTTP QueryDef declared under \\\u003cprojectDir\u003e/queries/\\*\\*. It fails with an error naming projectDir when no HTTP QueryDef is found there: an http(s):// db-copy source with nothing to serve is a configuration mistake (the wrong project path, most often), not a validly-empty database.\n\n```go\nfunc SnapshotIdentity(projectDir, queryID string) (id string, recordedAt time.Time, ok bool)\n```\nSnapshotIdentity reports the stable identity pkg/server/endpoints' exec/run\\_query uses for the one recorded snapshot this demo project ships per HTTP query — see fixtureFS's own doc comment for why there is exactly one, independent of the parameter value actually requested. The identity is \"\\\u003cqueryID\u003e@\\\u003crecordedAt RFC3339\u003e\" (lead assumption 2026-09-10, pending founder confirmation — see the contract amendment in spec/features/core-investigation-loop/api-contract.md): stable across process restarts (recordedAt never changes without a new fixture file replacing the old one), and the exact string a client must echo back as ExecutionRequest.SnapshotID to select this snapshot explicitly (api-contract.md \"mode:snapshot and a configured snapshotId\"). ok is false when projectDir has no recorded fixture for queryID (fixtures/http/\\\u003cqueryID\u003e.json does not exist), in which case id and recordedAt are the zero value and must not be used.\n\n## Types\n\n```go\ntype LoadedQuery struct {\n\tDef        *datatug.QueryDef\n\tFolderPath string\n}\n```\nLoadedQuery is one HTTP-type QueryDef found by LoadHTTPQueries, together with the folder it was found in (relative to \\\u003cprojectDir\u003e/queries) — needed to locate its sibling URL-template file alongside it.\n\n```go\nfunc LoadHTTPQueries(projectDir string) ([]LoadedQuery, error)\n```\nLoadHTTPQueries scans \\\u003cprojectDir\u003e/queries/\\*\\* for \\*.query.json files declaring \"type\": \"HTTP\", parsing each into a datatug.QueryDef.\n\nThis reads project files directly with encoding/json rather than going through pkg/datatug-core/storage/filestore's generic project-item store, for two reasons: that store's loader does not read a query's sibling text-body file back into QueryDef.Text (only the SAVE path writes it — see store\\_queries\\_saver.go; LoadURLTemplate below is this package's own replacement for that missing read), and pulling in the full store abstraction (which also knows about SQL/GraphQL queries, folders, and project-wide caching) for a read-only, HTTP-only scan would add a much larger dependency surface than this package needs.\n\n```go\ntype Option func(*openOptions)\n```\nOption configures Open. The zero value of every Option's underlying config is production-safe; only AllowInsecureLoopback (see its doc comment) changes behavior, and only when a caller passes it explicitly.\n\n```go\nfunc AllowInsecureLoopback() Option\n```\nAllowInsecureLoopback is a TEST-ONLY Open Option: every dalgo2http.Collection Open builds from projectDir gets Collection.InsecureAllowLoopback set (dal-go/dalgo2http v0.2.0's escape hatch — URLTemplate may then use http://, and the guarded dialer may dial a loopback address, but ONLY when the host is literally loopback; every other blocked address class stays blocked). It exists so this package's own tests, and other packages' tests that drive the same sourceURL -\u003e pkg/dbcopy -\u003e httpsource.Open pipeline in-process (see pkg/dbcopy's BackendRef.OpenForTest and pkg/secureread's Executor.RunStructuredInsecureForTest), can exercise a live-then-snapshot HTTP source against a loopback httptest.Server or an intentionally-unreachable loopback address (e.g. 127.0.0.1:1) — WITHOUT any project descriptor file ever being able to request this itself: the field is set here, in Go code, from an explicit caller opt-in, never from anything LoadHTTPQueries/LoadURLTemplate read off disk. NEVER pass this outside test code.\n\n```go\ntype Result struct {\n\tRecords    []record.Record\n\tProvenance dalgo2http.Provenance\n}\n```\nResult is what ExecuteQuery returns: the rows a query produced, and the Provenance (live vs snapshot) dalgo2http observed while producing them.\n\npkg/secureread's Result.Limitations is the natural home for this once it lands (per the stream brief); until then this is the small bridge value a caller — a server endpoint handler, a future secureread integration — reads and forwards into whatever its own result/Limitations shape needs.\n\n```go\nfunc ExecuteQuery(ctx context.Context, db dal.DB, q dal.Query) (Result, error)\n```\nExecuteQuery runs q against db and returns both its rows and the Provenance dalgo2http observed while running it.\n\ndb need not be a database Open returned — ExecuteQuery works against any dal.DB — but Provenance is only ever populated when the backend actually reports one (today, only a dalgo2http-backed db does). Result's zero Provenance value is indistinguishable from \"not observed\" by design: a caller forwarding it into a Limitations-style note should treat an unpopulated Provenance as \"nothing to report\", not as \"this was live\".\n\n","path":"github.com/datatug/datatug-cli/pkg/httpsource","name":"httpsource","synopsis":"Package httpsource translates a datatug project's HTTP-type QueryDefs into a dalgo2http-backed dal.DB: one dalgo2http.Collection per query (see BuildCollection for the translation and its sensible-default policy for RowsPath/KeyField, since the QueryDef JSON schema does not yet carry those explicitly), snapshot fallback wired to the project's fixtures/http/ directory (see fixtureFS for how its flatly-named fixture files are bridged to dalgo2http's per-request snapshot keying), live-then-snapshot mode.","isRedistributable":true}
