jsonutil

package
v0.0.0-...-af4311f Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConflict

func IsConflict(dst VariableMap, objs ...VariableMap) bool

IsConflict check whether objs are conflict with dst

Types

type JSONType

type JSONType string

JSONType defines type of JSON

const (
	// ObjectType is json snippet warpped by {}
	ObjectType JSONType = "object"

	// ArrayType is json snippet warpped by []
	ArrayType JSONType = "array"

	// StringType is json snippet of string
	// Value of variable with this type is not warpped by quote
	StringType JSONType = "string"

	// NumberType is json snippet which is number
	NumberType JSONType = "number"

	// BooleanType is json snippet which is bool
	BooleanType JSONType = "boolean"

	// NullType is json snippet means null
	NullType JSONType = "null"
)

type Measurable

type Measurable interface {
	// Len returns variable length
	// if variable can't be measured, return -1
	Len() int
}

Measurable defines interface to return object length

type MergeOption

type MergeOption int

MergeOption defines option of merge function

const (
	// CombineOption will make variable with same name be an array
	CombineOption MergeOption = iota
	// OverwriteOption will let variable replace the before one
	OverwriteOption
	// DeepOverwriteOption will try to combine array and map
	// both array: deep overwrite element one by one
	// both map: deep overwrite element one by one
	// others: just replace the before one
	DeepOverwriteOption
	// ConflictOption will return error if conflict occurred
	ConflictOption
)

type VarFilter

type VarFilter func(key string) bool

VarFilter defines a function to check whether var will be filtered

type Variable

type Variable interface {
	// Name returns variable name
	Name() string
	// Unmarshal will unmarshal the variable to an object
	Unmarshal(obj interface{}) error
	// String will returns the string value
	String() string
	// Select get subpath of variable
	Select(selector ...string) (Variable, error)

	// Type returns variable type
	Type() JSONType
}

Variable defines variable which can unmarshal to an object

func GetVariable

func GetVariable(rawJSON []byte, name string, selector ...string) (Variable, error)

GetVariable returns a variable from raw json

func NewIntVariable

func NewIntVariable(name string, value int64) Variable

NewIntVariable returns a variable with value s

func NewNullVariable

func NewNullVariable() Variable

NewNullVariable returns a null variable

func NewStringVariable

func NewStringVariable(name, value string) Variable

NewStringVariable returns a variable with value s

type VariableArray

type VariableArray interface {
	// Variable is Variable interface
	Variable

	// Measurable defines Len function
	Measurable

	// Append append Variable into array
	Append(v Variable)
	// Get gets Variable from array
	Get(i int) Variable
	// Set sets Variable into array
	Set(i int, v Variable)
	// Slice returns slice from array
	Slice(i, k int) VariableArray
	// contains filtered or unexported methods
}

VariableArray defines array variable

func NewVariableArray

func NewVariableArray(name string, vs []Variable) VariableArray

NewVariableArray returns array variable

type VariableMap

type VariableMap interface {
	// Variable is Variable interface
	Variable

	// Measurable defines Len function
	Measurable

	// Get gets Variable from map
	Get(s string) (Variable, bool)
	// Set sets Variable into map
	Set(s string, v Variable)
	// Delete delete Variable from map
	Delete(s string)
	// Keys returns variable map keys
	Keys() []string

	// Copy copies and returns a new VariableMap
	Copy() VariableMap
	// contains filtered or unexported methods
}

VariableMap defines variable map

func Merge

func Merge(dst VariableMap, opt MergeOption, isNew bool, objs ...VariableMap) (VariableMap, error)

Merge merges VariableMaps objs into VariableMap dst by differernt options

func MergeWithFilter

func MergeWithFilter(dst VariableMap, opt MergeOption, isNew bool, filter VarFilter, objs ...VariableMap) (VariableMap, error)

MergeWithFilter merges filtered variables of VariableMaps objs into VariableMap dst by differernt options

func NewVariableMap

func NewVariableMap(name string, vs map[string]Variable) VariableMap

NewVariableMap returns a new VariableMap

Jump to

Keyboard shortcuts

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