parse

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package parse holds the string-to-value parsers for statute's duration, rate, and byte-size config fields. The functions are pure: they take a string and return a primitive or an error, with no dependency on the surface or resolved config types. Kept in internal/ so they are not part of the public API surface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Duration

func Duration(s string) (time.Duration, error)

Duration accepts every unit Go's time.ParseDuration accepts (ns, us, ms, s, m, h) plus "d" for days (24h) and "w" for weeks (7d). Days and weeks are de-sugared by string-rewriting before falling through to the stdlib parser, so they compose with the other units ("1w2d" works).

func DurationOr

func DurationOr(s string, fallback time.Duration) (time.Duration, error)

DurationOr parses s, or returns fallback when s is empty.

func Rate

func Rate(s string) (float64, error)

Rate parses a rate of the form "N/unit" into requests per second. Supported units: s, sec, second; m, min, minute; h, hr, hour.

func Size

func Size(s string) (int64, error)

Size parses a byte size like "1MB", "512KiB", or "256" into a count of bytes. Suffixes are case-insensitive. Decimal (KB/MB/GB) and binary (KiB/MiB/GiB) units are both accepted. Decimal units use powers of 1000; binary units use powers of 1024.

Types

This section is empty.

Jump to

Keyboard shortcuts

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