Skip to content

Commit

Permalink
Merge branch 'ory-master'
Browse files Browse the repository at this point in the history
from ory#1

This patch provides fixes for:

spf13#730
spf13#695
spf13#353
spf13#174
spf13#378
spf13#629
  • Loading branch information
荒野無燈 committed Aug 25, 2019
2 parents e697d55 + 3cea6e6 commit 75cf305
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 18 deletions.
11 changes: 11 additions & 0 deletions .circleci/config.yml
@@ -0,0 +1,11 @@
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.12
environment:
- GO111MODULE=on
working_directory: /go/src/github.com/ory/viper
steps:
- checkout
- run: go test -race -v ./...
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,4 +1,4 @@
go_import_path: github.com/spf13/viper
go_import_path: github.com/ory/viper

language: go

Expand Down
6 changes: 6 additions & 0 deletions Makefile
@@ -0,0 +1,6 @@
SHELL=/bin/bash -o pipefail

# Formats the code
.PHONY: format
format:
goreturns -w -local github.com/ory $$(listx .)
16 changes: 13 additions & 3 deletions README.md
@@ -1,7 +1,17 @@
![viper logo](https://cloud.githubusercontent.com/assets/173412/10886745/998df88a-8151-11e5-9448-4736db51020d.png)

[![CircleCI](https://circleci.com/gh/ory/viper/tree/master.svg?style=shield](https://circleci.com/gh/ory/viper/tree/master)

Go configuration with fangs!

> This is a fork. It resolves several issues that are left unresolved in [the upstream](https://github.com/ory/viper).
> Issues resolved and features added include:
>
> - Fixed race conditions when reloading configs.
> - Added `HasChanged(key string) bool` which returns true (once!) when a value has changed.
> - Make sure that `viper.AllSettings()` always returns `map[string]interface{}` which was not the case and incompatible
with de/encoders like `json`.

Many Go projects are built using Viper including:

* [Hugo](http://gohugo.io)
Expand All @@ -13,11 +23,11 @@ Many Go projects are built using Viper including:
* [doctl](https://github.com/digitalocean/doctl)
* [Clairctl](https://github.com/jgsqware/clairctl)

[![Build Status](https://travis-ci.org/spf13/viper.svg)](https://travis-ci.org/spf13/viper) [![Join the chat at https://gitter.im/spf13/viper](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/spf13/viper?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![GoDoc](https://godoc.org/github.com/spf13/viper?status.svg)](https://godoc.org/github.com/spf13/viper)
[![Build Status](https://travis-ci.org/ory/viper.svg)](https://travis-ci.org/ory/viper) [![Join the chat at https://gitter.im/ory/viper](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ory/viper?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![GoDoc](https://godoc.org/github.com/ory/viper?status.svg)](https://godoc.org/github.com/ory/viper)

## Install
```console
go get -u github.com/spf13/viper
go get -u github.com/ory/viper
```

## What is Viper?
Expand Down Expand Up @@ -384,7 +394,7 @@ viper.BindFlagValues("my-flags", fSet)
To enable remote support in Viper, do a blank import of the `viper/remote`
package:

`import _ "github.com/spf13/viper/remote"`
`import _ "github.com/ory/viper/remote"`

Viper will read a config string (as JSON, TOML, YAML, HCL or envfile) retrieved from a path
in a Key/Value store such as etcd or Consul. These values take precedence over
Expand Down
3 changes: 2 additions & 1 deletion go.mod
@@ -1,4 +1,4 @@
module github.com/spf13/viper
module github.com/ory/viper

require (
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
Expand Down Expand Up @@ -28,6 +28,7 @@ require (
github.com/spf13/jwalterweatherman v1.0.0
github.com/spf13/pflag v1.0.3
github.com/stretchr/testify v1.2.2
github.com/subosito/gotenv v1.1.1
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
github.com/ugorji/go v1.1.4 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -71,8 +71,6 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
Expand Down Expand Up @@ -117,6 +115,8 @@ github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnIn
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/subosito/gotenv v1.1.1 h1:TWxckSF6WVKWbo2M3tMqCtWa9NFUgqM1SSynxmYONOI=
github.com/subosito/gotenv v1.1.1/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4 h1:j4s+tAvLfL3bZyefP2SEWmhBzmuIlH/eqNuPdFPgngw=
Expand Down
3 changes: 2 additions & 1 deletion remote/remote.go
Expand Up @@ -11,8 +11,9 @@ import (
"io"
"os"

"github.com/spf13/viper"
crypt "github.com/xordataexchange/crypt/config"

"github.com/ory/viper"
)

type remoteConfigProvider struct{}
Expand Down
12 changes: 12 additions & 0 deletions stub/config.json
@@ -0,0 +1,12 @@
{
"foo": {
"bar": [
{
"baz": 1
},
{
"baz": 2
}
]
}
}
4 changes: 4 additions & 0 deletions stub/config.yaml
@@ -0,0 +1,4 @@
foo:
bar:
- baz: 1
- baz: 2
25 changes: 25 additions & 0 deletions util.go
Expand Up @@ -219,3 +219,28 @@ func deepSearch(m map[string]interface{}, path []string) map[string]interface{}
}
return m
}

// toMapStringInterface is a workaround for https://github.com/ory/viper/issues/730
// and https://github.com/go-yaml/yaml/issues/139
func toMapStringInterface(in interface{}) interface{} {
switch t := in.(type) {
case map[string]interface{}:
for k, v := range t {
t[k] = toMapStringInterface(v)
}
return t
case map[interface{}]interface{}:
nt := make(map[string]interface{})
for k, v := range t {
nt[fmt.Sprintf("%s", k)] = toMapStringInterface(v)
}
return nt
case []interface{}:
for k, v := range t {
t[k] = toMapStringInterface(v)
}
return t
default:
return in
}
}
20 changes: 20 additions & 0 deletions util_test.go
Expand Up @@ -13,6 +13,8 @@ package viper
import (
"reflect"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCopyAndInsensitiviseMap(t *testing.T) {
Expand Down Expand Up @@ -52,3 +54,21 @@ func TestCopyAndInsensitiviseMap(t *testing.T) {
t.Fatal("Input map changed")
}
}

func TestToMapStringInterface(t *testing.T) {
assert.EqualValues(
t,
map[string]interface{}{
"foo": "bar",
"items": map[string]interface{}{
"foo": "bar",
},
},
toMapStringInterface(map[string]interface{}{
"foo": "bar",
"items": map[interface{}]interface{}{
"foo": "bar",
},
}),
)
}

0 comments on commit 75cf305

Please sign in to comment.