Documentation
¶
Overview ¶
Package http provides a source.Reader implementation that fetches scripts via HTTP(S). It is suitable for retrieving scripts from web servers, CDN endpoints, REST APIs, or any HTTP-accessible resource.
Construction:
src, err := http.New(ctx,
http.WithBaseURL("https://api.example.com/scripts/"),
http.WithTimeout(10*time.Second),
http.WithHeader("Authorization", "Bearer token"),
)
Hot-reload detection compares the response body's checksum (CRC32) against the value recorded by the most recent Load.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("http source: not found")
ErrNotFound is returned (wrapped) by Load when the HTTP endpoint responds with a 404 status code. Detect with errors.Is(err, ErrNotFound) or the convenience helper IsNotFound.
Functions ¶
func IsNotFound ¶
IsNotFound reports whether err represents a 404 response. Equivalent to errors.Is(err, ErrNotFound).
Types ¶
type Option ¶
type Option func(*configOptions)
Option configures a Reader. Pass to New.
func WithBaseURL ¶
WithBaseURL sets the base URL that keys are resolved against. The key is appended to the base URL to form the full request URL.
Example: WithBaseURL("https://api.example.com/scripts/") + key "main.lua"
-> GET https://api.example.com/scripts/main.lua
func WithHTTPClient ¶
WithHTTPClient injects a custom *http.Client. When set, WithTimeout is ignored (the caller controls the client's timeout).
func WithHeader ¶
WithHeader adds or overrides an HTTP header sent with every request. Multiple calls accumulate headers.
func WithPrefix ¶
WithPrefix sets a key prefix that is transparently prepended to every key before it is resolved against the base URL. Useful when all scripts share a common path segment.
Leading slashes are stripped; no trailing slash normalization is applied (the base URL should handle that).
func WithTimeout ¶
WithTimeout sets the HTTP client timeout (default 30s).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader fetches scripts via HTTP.
All exported methods are safe for concurrent use. Reader implements the source.ReadWatcher interface.
func New ¶
New creates an HTTP-backed Reader. WithBaseURL is required; all other settings are optional.
func (*Reader) Close ¶
Close releases the underlying HTTP client. The default http.Client has no resources to release, so this is a no-op; the method exists to satisfy the source.Reader interface.
func (*Reader) Load ¶
Load fetches the URL via HTTP GET and returns the response body as a string. Context cancellation propagates to the underlying request.
A 404 response is reported as a wrapped ErrNotFound. Non-2xx responses (other than 404) are reported as errors.
func (*Reader) Watch ¶
Watch returns a channel that signals when the content at the URL identified by `key` changes. It polls the URL every 5 seconds, computes the CRC32 checksum of the response body, and sends a signal when the checksum differs from the one recorded during the last Load.
The returned channel is closed when the context is cancelled. Callers should re-Load the script after receiving from the channel.