open-consul/vendor/github.com/stretchr/objx
Matt Keeler ac78c23021
Implement data filtering of some endpoints (#5579)
Fixes: #4222 

# Data Filtering

This PR will implement filtering for the following endpoints:

## Supported HTTP Endpoints

- `/agent/checks`
- `/agent/services`
- `/catalog/nodes`
- `/catalog/service/:service`
- `/catalog/connect/:service`
- `/catalog/node/:node`
- `/health/node/:node`
- `/health/checks/:service`
- `/health/service/:service`
- `/health/connect/:service`
- `/health/state/:state`
- `/internal/ui/nodes`
- `/internal/ui/services`

More can be added going forward and any endpoint which is used to list some data is a good candidate.

## Usage

When using the HTTP API a `filter` query parameter can be used to pass a filter expression to Consul. Filter Expressions take the general form of:

```
<selector> == <value>
<selector> != <value>
<value> in <selector>
<value> not in <selector>
<selector> contains <value>
<selector> not contains <value>
<selector> is empty
<selector> is not empty
not <other expression>
<expression 1> and <expression 2>
<expression 1> or <expression 2>
```

Normal boolean logic and precedence is supported. All of the actual filtering and evaluation logic is coming from the [go-bexpr](https://github.com/hashicorp/go-bexpr) library

## Other changes

Adding the `Internal.ServiceDump` RPC endpoint. This will allow the UI to filter services better.
2019-04-16 12:00:15 -04:00
..
.codeclimate.yml Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
.gitignore Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
.travis.yml Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
accessors.go Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
constants.go Update vendoring from go mod. (#5566) 2019-03-26 17:50:42 -04:00
conversions.go Update vendoring from go mod. (#5566) 2019-03-26 17:50:42 -04:00
doc.go Add missing vendor dep github.com/stretchr/objx 2018-06-14 09:42:13 -07:00
Gopkg.lock Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
Gopkg.toml Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
LICENSE Add missing vendor dep github.com/stretchr/objx 2018-06-14 09:42:13 -07:00
map.go Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
mutations.go Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
README.md Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
security.go Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
Taskfile.yml Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00
tests.go Add missing vendor dep github.com/stretchr/objx 2018-06-14 09:42:13 -07:00
type_specific_codegen.go Update vendoring from go mod. (#5566) 2019-03-26 17:50:42 -04:00
value.go Implement data filtering of some endpoints (#5579) 2019-04-16 12:00:15 -04:00

Objx

Build Status Go Report Card Maintainability Test Coverage Sourcegraph GoDoc

Objx - Go package for dealing with maps, slices, JSON and other data.

Get started:

Overview

Objx provides the objx.Map type, which is a map[string]interface{} that exposes a powerful Get method (among others) that allows you to easily and quickly get access to data within the map, without having to worry too much about type assertions, missing data, default values etc.

Pattern

Objx uses a preditable pattern to make access data from within map[string]interface{} easy. Call one of the objx. functions to create your objx.Map to get going:

m, err := objx.FromJSON(json)

NOTE: Any methods or functions with the Must prefix will panic if something goes wrong, the rest will be optimistic and try to figure things out without panicking.

Use Get to access the value you're interested in. You can use dot and array notation too:

 m.Get("places[0].latlng")

Once you have sought the Value you're interested in, you can use the Is* methods to determine its type.

 if m.Get("code").IsStr() { // Your code... }

Or you can just assume the type, and use one of the strong type methods to extract the real value:

m.Get("code").Int()

If there's no value there (or if it's the wrong type) then a default value will be returned, or you can be explicit about the default value.

 Get("code").Int(-1)

If you're dealing with a slice of data as a value, Objx provides many useful methods for iterating, manipulating and selecting that data. You can find out more by exploring the index below.

Reading data

A simple example of how to use Objx:

// Use MustFromJSON to make an objx.Map from some JSON
m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`)

// Get the details
name := m.Get("name").Str()
age := m.Get("age").Int()

// Get their nickname (or use their name if they don't have one)
nickname := m.Get("nickname").Str(name)

Ranging

Since objx.Map is a map[string]interface{} you can treat it as such. For example, to range the data, do what you would expect:

m := objx.MustFromJSON(json)
for key, value := range m {
  // Your code...
}

Installation

To install Objx, use go get:

go get github.com/stretchr/objx

Staying up to date

To update Objx to the latest version, run:

go get -u github.com/stretchr/objx

Supported go versions

We support the lastest two major Go versions, which are 1.8 and 1.9 at the moment.

Contributing

Please feel free to submit issues, fork the repository and send pull requests!