generic

package module
v0.0.0-...-276682b Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2016 License: MIT Imports: 2 Imported by: 0

README

generic

Package generic provides structured data handling library like JSON.

Document

Documentation

Overview

Package generic provides structured data handling library like JSON.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor struct {
	// contains filtered or unexported fields
}

func Must

func Must(cur *Cursor, err error) *Cursor

func NewCursor

func NewCursor(root *interface{}) *Cursor

func (*Cursor) Delete

func (c *Cursor) Delete()

func (*Cursor) Index

func (c *Cursor) Index(keys ...interface{}) (nextCursor *Cursor, err error)
Example
package main

import (
	"encoding/json"
	"fmt"
	"github.com/go-library/generic"
	"log"
)

func main() {
	var (
		err error
		v   interface{}
		c   *generic.Cursor
	)

	stream := `{"results": [{"name": "foo" }]}`

	err = json.Unmarshal([]byte(stream), &v)
	if err != nil {
		log.Fatal(err)
	}

	c = generic.NewCursor(&v)
	generic.Must(c.Index("results", 0, "name")).Set("bar")

	fmt.Println(generic.Must(c.Index("results", 0, "name")))
	fmt.Printf("%+v\n", v)

}
Output:

bar
map[results:[map[name:bar]]]

func (*Cursor) Interface

func (c *Cursor) Interface() interface{}

GETTERS

func (*Cursor) IsValid

func (c *Cursor) IsValid() bool

func (*Cursor) Keys

func (c *Cursor) Keys() (keys []string)

func (*Cursor) Len

func (c *Cursor) Len() int

func (*Cursor) Push

func (c *Cursor) Push(values ...interface{})

func (*Cursor) Set

func (c *Cursor) Set(value interface{})

func (*Cursor) SetIndex

func (c *Cursor) SetIndex(keys ...interface{}) (nextCursor *Cursor, err error)

func (*Cursor) Slice

func (c *Cursor) Slice(i, j int) (nextCursor *Cursor)

func (*Cursor) Slice3

func (c *Cursor) Slice3(i, j, k int) (nextCursor *Cursor)

func (*Cursor) String

func (c *Cursor) String() string

type GenericError

type GenericError struct {
	// contains filtered or unexported fields
}

func Error

func Error(args ...interface{}) GenericError

func Errorf

func Errorf(format string, args ...interface{}) GenericError

func (GenericError) Error

func (e GenericError) Error() string

type M

type M map[string]interface{}

type S

type S []interface{}

Jump to

Keyboard shortcuts

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