File: README.md

package info (click to toggle)
golang-github-mcuadros-go-lookup 0.0~git20171110.5650f26-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 68 kB
  • sloc: makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,257 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
go-lookup [![Build Status](https://travis-ci.org/mcuadros/go-lookup.png?branch=master)](https://travis-ci.org/mcuadros/go-lookup) [![GoDoc](http://godoc.org/github.com/mcuadros/go-lookup?status.png)](http://godoc.org/github.com/mcuadros/go-lookup)
==============================

Small library on top of reflect for make lookups to Structs or Maps. Using a very simple DSL you can access to any property, key or value of any value of Go.

Installation
------------

The recommended way to install go-lookup

```
go get github.com/mcuadros/go-lookup
```

Example
-------

```go
type Cast struct {
  Actor, Role string
}

type Serie struct {
  Cast []Cast
}

series := map[string]Serie{
  "A-Team": {Cast: []Cast{
    {Actor: "George Peppard", Role: "Hannibal"},
    {Actor: "Dwight Schultz", Role: "Murdock"},
    {Actor: "Mr. T", Role: "Baracus"},
    {Actor: "Dirk Benedict", Role: "Faceman"},
  }},
}

q := "A-Team.Cast.Role"
value, _ := LookupString(series, q)
fmt.Println(q, "->", value.Interface())
// A-Team.Cast.Role -> [Hannibal Murdock Baracus Faceman]

q = "A-Team.Cast[0].Actor"
value, _ = LookupString(series, q)
fmt.Println(q, "->", value.Interface())
// A-Team.Cast[0].Actor -> George Peppard
```

License
-------

MIT, see [LICENSE](LICENSE)