Documentation
¶
Index ¶
- func FetchOnce(ctx context.Context, url string, opts ...HTTPOption) ([]byte, error)
- func FormatAxisValue(v float64, width int) string
- func FormatValue(v float64) string
- func LTTB(data []float64, threshold int) []float64
- func MinMaxDecimate(data []float64, threshold int) []float64
- func Uniq[T comparable](input []T) []T
- func UniqStrings(input []string) []string
- type Format
- type HTTPOption
- type HTTPSource
- type Reader
- type ReaderOption
- type Ring
- func (r *Ring) Cap() int
- func (r *Ring) Last(n int) []float64
- func (r *Ring) Latest() (float64, bool)
- func (r *Ring) Len() int
- func (r *Ring) Position() int64
- func (r *Ring) Push(v float64)
- func (r *Ring) PushBatch(values []float64)
- func (r *Ring) Reset()
- func (r *Ring) Since(since int64) (values []float64, pos int64)
- func (r *Ring) Stats() Stats
- func (r *Ring) StatsLast(n int) Stats
- func (r *Ring) Values() []float64
- type Row
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchOnce ¶ added in v0.5.0
FetchOnce performs a single HTTP GET and returns the body. Useful for the `--url` mode when polling isn't needed (e.g. one-shot snapshot).
func FormatAxisValue ¶ added in v0.5.0
FormatAxisValue is like FormatValue but right-pads to a fixed width for aligned Y-axis display.
func FormatValue ¶ added in v0.5.0
FormatValue produces a human-friendly string for a numeric value, using SI suffixes for large numbers and scientific notation for very small ones.
func LTTB ¶ added in v0.5.0
LTTB implements the Largest Triangle Three Buckets algorithm by Sveinn Steinarsson (2013). Given a series of N points, it returns a series of `threshold` points that visually preserves the original's shape — peaks, dips, and inflection points are kept, while runs of similar values are thinned out. This is what Grafana, Plotly, and most production charting libraries use for time-series downsampling.
If threshold >= len(data) or threshold < 3, the original is returned unchanged.
Runtime: O(n). Allocates one slice of size `threshold`.
func MinMaxDecimate ¶ added in v0.5.0
MinMaxDecimate is a faster but lower-quality alternative to LTTB. It splits the input into `threshold/2` buckets and keeps the min and max of each. Useful when you want extremes preserved but don't care about visual fidelity of the curve between them — e.g. audio waveforms.
func Uniq ¶
func Uniq[T comparable](input []T) []T
Uniq returns a new slice with duplicates removed, preserving the order of first occurrence. Works for any comparable type.
func UniqStrings ¶ added in v0.5.0
UniqStrings is a convenience alias for string slices.
Types ¶
type Format ¶ added in v0.5.0
type Format int
Format describes the detected or forced input format.
func ParseFormat ¶ added in v0.5.0
ParseFormat converts a CLI string to a Format constant.
type HTTPOption ¶ added in v0.5.0
type HTTPOption func(*HTTPSource)
HTTPOption configures an HTTPSource.
func HTTPHeader ¶ added in v0.5.0
func HTTPHeader(key, value string) HTTPOption
HTTPHeader adds a request header (call multiple times for multiple headers). Useful for Authorization tokens, content negotiation, etc.
func HTTPInterval ¶ added in v0.5.0
func HTTPInterval(d time.Duration) HTTPOption
HTTPInterval sets the polling interval. Defaults to 5 seconds.
func HTTPTimeout ¶ added in v0.5.0
func HTTPTimeout(d time.Duration) HTTPOption
HTTPTimeout sets the per-request timeout. Defaults to 10 seconds.
type HTTPSource ¶ added in v0.5.0
type HTTPSource struct {
// contains filtered or unexported fields
}
HTTPSource polls an HTTP endpoint at a fixed interval and exposes the responses as an io.Reader stream. Each response body becomes one line in the stream (newline-appended), so a JSON-emitting endpoint looks identical to a streaming NDJSON pipe.
Usage:
src := datadash.NewHTTPSource(ctx, "https://api.example.com/metrics",
datadash.HTTPInterval(5*time.Second))
reader := datadash.NewReader(src, datadash.WithFormat(datadash.FormatJSON))
func NewHTTPSource ¶ added in v0.5.0
func NewHTTPSource(ctx context.Context, url string, opts ...HTTPOption) *HTTPSource
NewHTTPSource starts a polling goroutine and returns a source that can be passed to NewReader. The poll loop terminates when ctx is cancelled or the reader side is closed.
func (*HTTPSource) Close ¶ added in v0.5.0
func (s *HTTPSource) Close() error
Close stops the polling goroutine.
type Reader ¶ added in v0.5.0
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps a buffered scanner and produces Rows.
func NewReader ¶ added in v0.5.0
func NewReader(r io.Reader, opts ...ReaderOption) *Reader
NewReader creates a streaming row reader. By default it auto-detects the format and delimiter from the first line of input.
func (*Reader) Format ¶ added in v0.5.0
Format returns the resolved format (after at least one Read call).
type ReaderOption ¶ added in v0.5.0
type ReaderOption func(*Reader)
ReaderOption configures a Reader.
func WithDelimiter ¶ added in v0.5.0
func WithDelimiter(d string) ReaderOption
WithDelimiter overrides the auto-detected delimiter for CSV/TSV.
func WithFormat ¶ added in v0.5.0
func WithFormat(f Format) ReaderOption
WithFormat forces a specific input format instead of auto-detecting.
func WithJSONFields ¶ added in v0.5.0
func WithJSONFields(fields []string) ReaderOption
WithJSONFields specifies dot-path fields to extract from JSON objects. If empty, all top-level numeric fields are auto-discovered.
func WithLabelMode ¶ added in v0.5.0
func WithLabelMode(mode string) ReaderOption
WithLabelMode sets how the X-axis label is derived.
"first" — use the first column as a label (default for multi-column) "time" — use wall-clock time as the label "none" — no labels
type Ring ¶ added in v0.5.0
type Ring struct {
// contains filtered or unexported fields
}
Ring is a fixed-capacity circular buffer for streaming time-series data. Write operations use atomic counters under a write lock for safety; read operations take a shared lock so multiple consumers can snapshot concurrently without blocking each other.
func NewRing ¶ added in v0.5.0
NewRing allocates a ring buffer that holds at most capacity values. If capacity <= 0 it defaults to 4096.
func (*Ring) Last ¶ added in v0.5.0
Last returns the most recent n values in chronological order. If n exceeds the current fill, all values are returned.
func (*Ring) Latest ¶ added in v0.5.1
Latest returns the most recently pushed value and true, or (0, false) if the ring is empty.
func (*Ring) Len ¶ added in v0.5.0
Len returns the number of elements currently in the buffer. Lock-free.
func (*Ring) Position ¶ added in v0.5.0
Position returns the total number of values ever pushed to the ring (monotonically increasing — never wraps within practical lifetimes). Lock-free.
func (*Ring) PushBatch ¶ added in v0.5.0
PushBatch appends multiple values in a single lock acquisition.
func (*Ring) Since ¶ added in v0.5.0
Since returns every value written at or after the absolute position `since`, in chronological order, along with the new high-water mark to pass on the next call.
If `since` is older than the oldest value still in the buffer, the result starts from the oldest available value (i.e. `since` is silently advanced to `pos - len`). If no new values are available, returns (nil, currentPos).
This is the right tool for streaming consumers (sparklines, log tails, etc.) that need to receive every value exactly once even as the ring overflows.
func (*Ring) Stats ¶ added in v0.5.0
Stats computes summary statistics over the current buffer contents. Returns a zero Stats if the buffer is empty.



