Documentation
¶
Index ¶
- Variables
- func GetEnv(key, fallback string) string
- func GetEnvAsInt(key string, fallback int) int
- func ReadAndTrim(r io.Reader, v interface{}, opts TrimOptions) error
- func TrimJSON(jsonStr string, opts TrimOptions) (string, bool, error)
- func TrimJSONBytes(data []byte, opts TrimOptions) ([]byte, bool, error)
- func UnmarshalAndTrim(data []byte, v interface{}, opts TrimOptions) error
- type TrimOptions
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 GetEnvAsInt ¶
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
Click to show internal directories.
Click to hide internal directories.