Documentation
¶
Overview ¶
Package utils holds small, dependency-free helpers shared across pkg/ and internal/. It must never import internal/ (pkg/ stays internal-free), so it carries no 2dph domain types.
Index ¶
- func DoJSON(ctx context.Context, client *http.Client, method, url string, body, dest any, ...) error
- func GetJSON(ctx context.Context, client *http.Client, url string, dest any, ...) error
- func Or(s, def string) string
- func Root() string
- func SafeSegment(s string) string
- func Snippet(s string, n int) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoJSON ¶
func DoJSON(ctx context.Context, client *http.Client, method, url string, body, dest any, opts ...func(*http.Request)) error
DoJSON performs an HTTP request with an optional JSON body, checks for a 2xx status, and decodes the JSON response into dest (a pointer). A nil body sends no payload; a nil dest skips decoding. opts let callers set headers (e.g. Basic auth). The error carries the HTTP status and a short body snippet so callers can surface remote errors verbatim.
func GetJSON ¶
func GetJSON(ctx context.Context, client *http.Client, url string, dest any, opts ...func(*http.Request)) error
GetJSON is DoJSON with the GET method and no request body.
func Root ¶
func Root() string
Root locates the 2dph project root: the KB_ROOT env var, or walking up from the working directory for a `.git` or `var` marker. It returns "." if nothing is found. This is the single source of truth for repo-root resolution so pkg/repo and internal/chat share one implementation.
func SafeSegment ¶
SafeSegment turns an arbitrary id/name into a safe single path segment: path separators and control characters are replaced, runs collapsed, and the result is truncated. It never returns an empty string for non-empty input, so callers can use it directly as a directory or file component.
Types ¶
This section is empty.