utils

package
v0.0.0-...-15de22a Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: MIT Imports: 8 Imported by: 1 module, 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

This section is empty.

Variables

View Source
var (
	// ErrInvalidJSON is returned when the input is not valid JSON
	ErrInvalidJSON = errors.New("invalid JSON input")
)

Functions

func GetEnv

func GetEnv(key, fallback string) string

func GetEnvAsInt

func GetEnvAsInt(key string, fallback int) int

func ReadAndTrim

func ReadAndTrim(r io.Reader, v interface{}, opts TrimOptions) error

ReadAndTrim reads from an io.Reader, trims the JSON using gjson/sjson, and unmarshals it into the provided value.

func TrimJSON

func TrimJSON(jsonStr string, opts TrimOptions) (string, bool, error)

TrimJSON takes a JSON string and trims whitespace from string values at the specified paths. Returns the trimmed JSON and a boolean indicating if any modifications were made.

func TrimJSONBytes

func TrimJSONBytes(data []byte, opts TrimOptions) ([]byte, bool, error)

TrimJSONBytes is like TrimJSON but works with byte slices

func UnmarshalAndTrim

func UnmarshalAndTrim(data []byte, v interface{}, opts TrimOptions) error

UnmarshalAndTrim unmarshals JSON data into a struct while trimming string fields

Types

type TrimOptions

type TrimOptions struct {
	// Paths to trim with gjson path syntax
	// See: https://github.com/tidwall/gjson#path-syntax
	Paths []string
}

TrimOptions configures the JSON trimming behavior

Jump to

Keyboard shortcuts

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