scan

package
v0.0.0-...-c0a320a Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2017 License: MIT Imports: 6 Imported by: 0

README

go-scan

Build Status Coverage Status

Easily way to get the elements via xpath like string

Usage

var js = strings.NewReader(`
{
	"foo": {
		"bar": [
			{
				"faz": true,
				"moo": ["goo", "mar"]
			},
			{
				"maz": true,
				"moo": ["foo", "bar"]
			}
		],
	}
}
`)
var s []string
scan.ScanJSON(js, "/foo/bar[1]/moo", &s) // s should be ["foo", "bar"]

Install

go get github.com/mattn/go-scan

License

MIT: http://mattn.mit-license.org/2013

Author

Yasuhiro Matsumoto (mattn.jp@gmail.com)

Documentation

Overview

Example
package main

import (
	"checkup/Godeps/_workspace/src/github.com/mattn/go-scan"
	"fmt"
	"strings"
)

var js = strings.NewReader(`
{
	"foo": {
		"bar": [
			{
				"baz": "bbb",
				"noo": 3 
			},
			{
				"maz": true,
				"moo": ["foo", "bar"]
			}
		],
		"boo": {
			"bag": "ddd",
			"bug": "ccc"
		}
	}
}
`)

func main() {
	var s []string
	if err := scan.ScanJSON(js, "/foo/bar[1]/moo", &s); err != nil {
		println(err.Error())
	}
	fmt.Println(s[0]) // should be "foo"
	fmt.Println(s[1]) // should be "bar"
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scan

func Scan(v interface{}, t interface{}) (err error)

Scan work to scan any type to specified type

func ScanJSON

func ScanJSON(r io.Reader, p string, t interface{}) (err error)

ScanJSON work as same sa ScanTree. it allow to give Reader.

func ScanTree

func ScanTree(v interface{}, p string, t interface{}) (err error)

ScanTree work to scan value to specified value with the path

Types

type Any

type Any interface{}

Any provide interface to scan any types.

Jump to

Keyboard shortcuts

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