utils

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ArraySeparator = "|"

ArraySeparator joins the elements of an array of scalars inside a single CSV cell.

Variables

View Source
var MaxResponseMB int64 = 256
View Source
var RequestTimeout = 5 * time.Minute

Functions

func ConvertToCSV added in v2.2.0

func ConvertToCSV(body []byte) (string, error)

ConvertToCSV renders a JSON API response as CSV text.

A top-level JSON array becomes one row per element, which is what the bulk endpoints return; any other response becomes a single row. Nested objects are flattened into dotted column names ("location.city"). An array whose elements are all scalars is joined into one cell with ArraySeparator; an array holding objects keeps a column per element instead ("routes.0.prefix"), so its fields stay addressable. Columns are the union of the keys of every row, sorted, so the same response always produces the same file.

func ConvertToXML

func ConvertToXML(data interface{}) string

func DecryptString

func DecryptString(cipherText string) (string, error)

func EncryptString

func EncryptString(plain string) (string, error)

func Get added in v2.1.1

func Get(apiURL string) ([]byte, error)

func OutputFilePath added in v2.2.0

func OutputFilePath(name, extension string) string

OutputFilePath works out the file an --output-file value should write to. The extension is appended only when the name does not already end in it, so "results" and "results.csv" both save to results.csv and neither doubles up.

An extension that does not match is left in place rather than swapped, so --output-file results.json with --output csv writes results.json.csv. That keeps the name the caller gave and never silently retargets a different file. The comparison ignores case, so results.CSV is accepted as it stands.

func PostJSON

func PostJSON(apiURL string, payload interface{}, headers map[string]string) ([]byte, error)

func PrintAsTable

func PrintAsTable(data interface{}, indent int)

func ToTitle

func ToTitle(s string) string

func ValidateRequestLimits added in v2.1.2

func ValidateRequestLimits() error

Types

This section is empty.

Jump to

Keyboard shortcuts

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