cti

package
v0.0.0-...-45318bc Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec interface {
	Encode(key string, o Object) error
	Decode(key string, o Object) error
}
var DefaultCodec Codec

type Error

type Error struct {
	Encoding string
	Op       string
	Key      string
	Err      error
	Next     *Error
	// contains filtered or unexported fields
}

func (*Error) As

func (e *Error) As(target interface{}) bool

func (*Error) Chain

func (e *Error) Chain(err error) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Format

func (e *Error) Format(s fmt.State, verb rune)

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Field

type Field struct {
	Key      string
	Encoding string
	Value    interface{}
}

func (Field) Put

func (f Field) Put(key string, o Object) error

type Fields

type Fields []Field

func (*Fields) Append

func (f *Fields) Append(key string, o Object) error

func (Fields) Keys

func (f Fields) Keys() []string

func (Fields) Len

func (f Fields) Len() int

func (Fields) Less

func (f Fields) Less(i, j int) bool

func (Fields) Object

func (f Fields) Object() Object

func (Fields) Sort

func (f Fields) Sort() Fields

func (Fields) Swap

func (f Fields) Swap(i, j int)

type Func

type Func func(key string, parent Object) error

func Value

func Value(v interface{}, encoding ...string) Func

type Object

type Object map[string]struct {
	Encoding string      `json:"e,omitempty" yaml:"e,omitempty"`
	Value    interface{} `json:"v,omitempty" yaml:"v,omitempty"`
	Children Object      `json:"c,omitempty" yaml:"c,omitempty"`
}

func Make

func Make(v interface{}) Object

func MakeFile

func MakeFile(path string) (Object, error)

func (Object) At

func (o Object) At(key string, fn Func) error

func (Object) Copy

func (o Object) Copy() Object

func (Object) Decode

func (o Object) Decode(c Codec) error

func (Object) Encode

func (o Object) Encode(c Codec) error

func (Object) Fields

func (o Object) Fields() Fields

func (Object) ForEach

func (o Object) ForEach(fn Func) error

func (Object) Keys

func (o Object) Keys() []string

func (Object) Merge

func (o Object) Merge(u Object) Object

func (Object) Put

func (o Object) Put(key string, fn Func) error
Example
obj := make(cti.Object)

obj.Put("/foo/bar", cti.Value(`{"key":[{"name":true},{"name":1}]}`))

if err := obj.Decode(nil); err != nil {
	log.Fatalf("obj.Decode()=%+v", err)
}

obj.Put("/foo/bar/key/1/args", cti.Value("--foo=bar --key=20"))

if err := obj.Decode(nil); err != nil {
	log.Fatalf("obj.Decode()=%+v", err)
}

obj.WriteTo(os.Stderr)

p, err := yaml.Marshal(obj.Value())
if err != nil {
	log.Fatalf("yaml.Marshal()=%+v", err)
}

fmt.Printf("%s\n", p)
Output:

foo:
    bar:
        key:
            - name: true
            - args:
                --foo: bar
                --key: 20
              name: 1

func (Object) ReverseWalk

func (o Object) ReverseWalk(fn Func) error

func (Object) Schema

func (o Object) Schema() Object

func (Object) Shake

func (o Object) Shake() Object

func (Object) String

func (o Object) String() string

func (Object) Value

func (o Object) Value() interface{}

func (Object) Walk

func (o Object) Walk(fn Func) error

func (Object) WriteTab

func (o Object) WriteTab(w io.Writer) (n int64, err error)

func (Object) WriteTo

func (o Object) WriteTo(w io.Writer) (int64, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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