util

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrJSONPointerInvalid         = "invalid JSON pointer"
	ErrJSONPointerKeyNotFound     = "key not found"
	ErrJSONPointerArrayNoIndex    = "array but not an index in JSON pointer"
	ErrJSONPointerArrayOutOfRange = "out of array range"
	ErrJSONPointerArrayBadType    = "not a map nor an array"
)

Variables

View Source
var ErrTagEmpty = errors.New("A tag cannot be empty")

ErrTagEmpty is the error returned by CheckTag for an empty tag.

View Source
var ErrTagInvalid = errors.New("Invalid tag, should match (Letter|_)(Letter|_|Number)*")

ErrTagInvalid is the error returned by CheckTag for an invalid tag.

Functions

func CheckTag added in v1.1.1

func CheckTag(tag string) error

CheckTag checks that tag is a valid tag (see operator Tag) or not.

func IndentColorizeStringIn added in v1.13.0

func IndentColorizeStringIn(w io.Writer, str, indent, colOn, colOff string)

IndentColorizeStringIn indents str lines (from 2nd one = 1st line is not indented) by indent and write it to w. Before each end of line, colOff is inserted, and after each indent on new line, colOn is inserted.

func IndentString

func IndentString(str, indent string) string

IndentString indents str lines (from 2nd one = 1st line is not indented) by indent.

func IndentStringIn added in v1.2.0

func IndentStringIn(w io.Writer, str, indent string)

IndentStringIn indents str lines (from 2nd one = 1st line is not indented) by indent and write it to w.

func JSONPointer added in v1.8.0

func JSONPointer(v any, pointer string) (any, error)

JSONPointer returns the value corresponding to JSON pointer pointer in v as RFC 6901 specifies it. To be searched, v has to contains map[string]any or []any values. All other types fail to be searched.

func SliceToString added in v1.13.0

func SliceToString(buf *strings.Builder, items []reflect.Value) *strings.Builder

SliceToString stringifies items slice into buf then returns buf.

func TernRune

func TernRune(cond bool, a, b rune) rune

TernRune returns a if cond is true, b otherwise.

func TernStr

func TernStr(cond bool, a, b string) string

TernStr returns a if cond is true, b otherwise.

func ToString

func ToString(val any) string

ToString does its best to stringify val.

func TypeFullName added in v1.8.0

func TypeFullName(t reflect.Type) string

TypeFullName returns the t type name with packages fully visible instead of the last package part in t.String().

Types

type JSONPointerError added in v1.8.0

type JSONPointerError struct {
	Type    string
	Pointer string
}

func (*JSONPointerError) Error added in v1.8.0

func (e *JSONPointerError) Error() string

Jump to

Keyboard shortcuts

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