util

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2021 License: BSD-2-Clause Imports: 14 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 is the error returned by CheckTag for an empty tag.
	ErrTagEmpty = errors.New("A tag cannot be empty")
	// ErrTagInvalid is the error returned by CheckTag for an invalid tag.
	ErrTagInvalid = errors.New("Invalid tag, should match (Letter|_)(Letter|_|Number)*")
)

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 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, colOn, colOff string)

IndentStringIn 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 JSONPointer added in v1.8.0

func JSONPointer(v interface{}, pointer string) (interface{}, 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]interface{} or []interface{} values. All other types fail to be searched.

func SliceToBuffer

func SliceToBuffer(buf *bytes.Buffer, items []reflect.Value) *bytes.Buffer

SliceToBuffer 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 interface{}) 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().

func UnmarshalJSON added in v1.1.1

func UnmarshalJSON(buf []byte, target interface{}) error

UnmarshalJSON is a custom json.Unmarshal function allowing to handle placeholders not enclosed in strings. It relies on json.SyntaxError errors detected before any memory allocation. So the performance should not be too bad, avoiding to implement our own JSON parser...

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