Skip to content

Commit edc6026

Browse files
initial commit
1 parent 501b3ba commit edc6026

8 files changed

+1009
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

.travis.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
language: go
2+
sudo: false
3+
dist: trusty
4+
go:
5+
- 1.x
6+
- 1.9.x
7+
- 1.8.x
8+
- master
9+
10+
env:
11+
DEP_VER=0.4.1
12+
CONSUL_VER=1.0.7
13+
PATH=$HOME/bin:$PATH
14+
15+
install:
16+
- dep ensure
17+
18+
before_install:
19+
- wget "https://releases.hashicorp.com/consul/${CONSUL_VER}/consul_${CONSUL_VER}_linux_amd64.zip"
20+
- mkdir -p $HOME/bin
21+
- unzip -d $HOME/bin consul_${CONSUL_VER}_linux_amd64.zip
22+
- wget "https://github.com/golang/dep/releases/download/v$DEP_VER/dep-linux-amd64"
23+
- cp dep-linux-amd64 $HOME/bin/dep
24+
- chmod 755 $HOME/bin/*
25+
26+
script:
27+
- go test
28+
- go install

Gopkg.lock

+84
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[[constraint]]
29+
name = "github.com/hashicorp/consul"
30+
version = "1.0.7"
31+
32+
[[constraint]]
33+
name = "github.com/stretchr/testify"
34+
version = "1.2.1"
35+
36+
[prune]
37+
go-tests = true
38+
unused-packages = true

README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
2+
[![Go Report Card](https://goreportcard.com/badge/github.com/myENA/consul-decoder)](https://goreportcard.com/report/github.com/myENA/consul-decoder)
3+
[![GoDoc](https://godoc.org/github.com/myENA/consul-decoder?status.svg)](https://godoc.org/github.com/myENA/consul-decoder)
4+
[![Build Status](https://travis-ci.org/myENA/consul-decoder.svg?branch=master)](https://travis-ci.org/myENA/consul-decoder)
5+
6+
7+
Package decoder - this unmarshals or decodes values from a consul KV store into a struct. The following types are supported:
8+
9+
* Integer (int/int8/int16/int32/int64)
10+
* Unsigned (uint/uint8/uint16/uint32/uint64)
11+
* Float (float64/float32)
12+
* time.Duration
13+
* net.IP
14+
* net.IPMask
15+
* struct - nested struct by default implies a consul folder with the same name.
16+
if the tag modifier "json" is encountered, then the value of in the KV
17+
is unmarshaled as json using json.Unmarshal
18+
19+
* slice - the type can be most of the supported types, except another slice.
20+
* map - the key must be a string, the value can be anything but another map.
21+
22+
Struct tags
23+
By default, the decoder packages looks for the struct tag "decoder". However, this can be overridden inside the Decoder struct as shown below. For the purposes of examples, we'll stick with the default "decoder" tag.
24+
25+
26+
```go
27+
28+
struct Foo {
29+
30+
// populate the value from key "whatever" into FooField1
31+
FooField1 string `decoder:"whatever"`
32+
33+
// skip populating FooField2, "-" signals skip
34+
FooField2 string `decoder:"-"`
35+
36+
// this looks for a folder named FooField3
37+
// and maps keys inside to the keys / values of the map. string
38+
// is the only valid key type, though the map value can be most any
39+
// of the other types supported by this package. Notable exception
40+
// map, as nested maps are not allowed. You can, however, have a
41+
// map[string]SomeStruct.
42+
FooField3 map[string]string
43+
44+
// this looks for a folder named FooField4 (case insensitive)
45+
// this is similar to the map example above, but it ignores the keys
46+
// inside and maps the values in-order into the slice. nested slices
47+
// are not allowed, i.e., [][]string.
48+
FooField4 []string
49+
50+
// this interprets the value of foofield5 as json data and
51+
// will send it to json.Unmarshal from encoding/json package.
52+
FooField5 *SomeStruct `decoder:"foofield5,json"`
53+
54+
}
55+
```

0 commit comments

Comments
 (0)