-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 627a462
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
|
||
[[constraint]] | ||
name = "github.com/spf13/viper" | ||
version = "1.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[database] | ||
hostname = "localhost" | ||
port = 5432 | ||
username = "postgres" | ||
password = "" | ||
|
||
[output] | ||
file = "out.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
type DatabaseConfig struct { | ||
Host string `mapstructure:"hostname"` | ||
Port string | ||
User string `mapstructure:"username"` | ||
Pass string `mapstructure:"password"` | ||
} | ||
|
||
type OutputConfig struct { | ||
File string | ||
} | ||
|
||
type Config struct { | ||
Db DatabaseConfig `mapstructure:"database"` | ||
Out OutputConfig `mapstructure:"output"` | ||
} | ||
|
||
func main() { | ||
v := viper.New() | ||
v.SetConfigName("config") | ||
v.AddConfigPath(".") | ||
if err := v.ReadInConfig(); err != nil { | ||
fmt.Printf("couldn't load config: %s", err) | ||
os.Exit(1) | ||
} | ||
var c Config | ||
if err := v.Unmarshal(&c); err != nil { | ||
fmt.Printf("couldn't read config: %s", err) | ||
} | ||
fmt.Printf("host=%s port=%s user=%s pass=%s\n", c.Db.Host, c.Db.Port, c.Db.User, c.Db.Pass) | ||
fmt.Printf("output=%s\n", c.Out.File) | ||
fmt.Printf("%#v", c) | ||
} |