scanner

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeError jsonType = iota
	TypeObject
	TypeArray
	TypeString
	TypeNumber
	TypeBoolean
	TypeNull
	TypeUnknown
)

Variables

View Source
var (
	ErrUnexpectedEOF    = errors.New("unexpected EOF")
	ErrKeyNotFound      = errors.New("key not found")
	ErrIndexOutOfBounds = errors.New("index out of bounds")
	ErrToLessThanFrom   = errors.New("to index less than from index")
	ErrUnexpectedValue  = errors.New("unexpected value")
)

Functions

func Any

func Any(in []byte, pos int) (int, error)

Any returns the position of the end of the current element that begins at pos; handles any valid json element

func Array

func Array(in []byte, pos int) (int, error)

Array returns the position of the end of the array that begins at the position specified

func AsArray

func AsArray(in []byte, pos int) ([][]byte, error)

AsArray accepts an []byte encoded json array as an input and returns the array's elements

func Boolean

func Boolean(in []byte, pos int) (int, error)

Boolean matches a boolean at the specified position

func Expect

func Expect(in []byte, pos int, content ...byte) (int, error)

func FindIndex

func FindIndex(in []byte, pos, index int) ([]byte, error)

FindIndex accepts a JSON array and return the value of the element at the specified index

func FindKey

func FindKey(in []byte, pos int, k []byte) ([]byte, error)

FindKey accepts a JSON object and returns the value associated with the key specified

func FindKey2

func FindKey2(in []byte, k []byte) ([]byte, error)

FindKey2 accepts a JSON object and returns the value associated with the key specified

func FindRange

func FindRange(in []byte, pos, from, to int) ([]byte, error)

FindRange finds the elements of an array between the specified indexes; inclusive

func NewError

func NewError(pos int, b byte) error

func Null

func Null(in []byte, pos int) (int, error)

Null verifies the contents of bytes provided is a null starting as pos

func Number

func Number(in []byte, pos int) (int, error)

Number returns the end position of the number that begins at the specified pos

func Object

func Object(in []byte, pos int) (int, error)

Object returns the position of the end of the object that begins at the specified pos

func SkipSpace

func SkipSpace(in []byte, pos int) (int, error)

func String

func String(in []byte, pos int) (int, error)

String returns the position of the string that begins at the specified pos

func TypeOf

func TypeOf(in []byte, pos int) (jsonType, error)

TypeOf returns the type of the object at the current position or TypeUnknown if it cannot be determined.

func Value

func Value(in []byte, pos int) (jsonType, int, error)

Value returns the position of the end of the current element that begins at pos; handles any valid json element

Types

type JSONType

type JSONType jsonType

type Op

type Op interface {
	Apply([]byte) ([]byte, error)
}

Op defines a single transformation to be applied to a []byte

func Must

func Must(op Op, err error) Op

Must is a convenience method similar to template.Must

func Parse

func Parse(selector string) (Op, error)

Parse takes a string representation of a selector and returns the corresponding Op definition

func ParseArray

func ParseArray(key string) (Op, bool)

type OpErr

type OpErr struct {
	Pos     int
	Msg     string
	Content string
}

func (OpErr) Error

func (o OpErr) Error() string

type OpFunc

type OpFunc func([]byte) ([]byte, error)

OpFunc provides a convenient func type wrapper on Op

func Chain

func Chain(filters ...Op) OpFunc

Chain executes a series of operations in the order provided

func Dot

func Dot(key string) OpFunc

Dot extract the specific key from the map provided; to extract a nested value, use the Dot Op in conjunction with the Chain Op

func Index

func Index(index int) OpFunc

Index extracts a specific element from the array provided

func Range

func Range(from, to int) OpFunc

Range extracts a selection of elements from the array provided, inclusive

func (OpFunc) Apply

func (fn OpFunc) Apply(in []byte) ([]byte, error)

Apply executes the transformation defined by OpFunc

Jump to

Keyboard shortcuts

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