From d2ff3c10db94382124f2c4cbe74d695fc664eb22 Mon Sep 17 00:00:00 2001
From: Jeevanandam M
Date: Sat, 19 Aug 2017 11:19:07 -0700
Subject: [PATCH 1/9] test case update
---
config_test.go | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/config_test.go b/config_test.go
index fb7e5c6..eae98cd 100644
--- a/config_test.go
+++ b/config_test.go
@@ -215,6 +215,12 @@ func TestStringList(t *testing.T) {
build {
# Valid exclude patterns refer: https://golang.org/pkg/path/filepath/#Match
excludes = ["*_test.go", ".*", "*.bak", "*.tmp", "vendor"]
+
+ keys = [
+ "X3pGTSOuJeEVw989IJ/cEtXUEmy52zs1TZQrU06KUKg=",
+ "MHJYVThihUrJcxW6wcqyOISTXIsInsdj3xK8QrZbHec=",
+ "GGekerhihUrJcxW6wcqyOISTXIsInsdj3xK8QrZbHec=",
+ ]
}`)
lst1, found1 := cfg.StringList("build.excludes")
@@ -225,6 +231,10 @@ build {
lst2, found2 := cfg.StringList("name")
assert.False(t, found2)
assert.True(t, len(lst2) == 0)
+
+ v, f := cfg.StringList("build.keys")
+ assert.True(t, f)
+ assert.True(t, len(v) == 3)
}
func TestIntAndInt64List(t *testing.T) {
From ad963194bb47b6298138b2dc104648149515459a Mon Sep 17 00:00:00 2001
From: Jeevanandam M
Date: Thu, 14 Sep 2017 14:10:03 -0700
Subject: [PATCH 2/9] added go1.9 to travis build
---
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.travis.yml b/.travis.yml
index 8abb1ed..5a59fa2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,7 +11,7 @@ branches:
go:
- 1.8
- - 1.8.x
+ - 1.9
- tip
go_import_path: aahframework.org/config.v0
From c1851e22e7a3ac7ea6fdf3c7877c1d0ef92c49a3 Mon Sep 17 00:00:00 2001
From: Jeevanandam M
Date: Wed, 7 Mar 2018 21:20:31 -0800
Subject: [PATCH 3/9] year update
[ci skip]
---
LICENSE | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LICENSE b/LICENSE
index 491ce72..02ad2ea 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2016-2017 Jeevanandam M., https://myjeeva.com
+Copyright (c) 2016-2018 Jeevanandam M., https://myjeeva.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
From c319476439cee9726dee3bed47cc423116cc67ed Mon Sep 17 00:00:00 2001
From: Jeevanandam M
Date: Wed, 28 Mar 2018 19:49:59 -0700
Subject: [PATCH 4/9] travis build config update
---
.travis.yml | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 5a59fa2..4d5ad6d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,17 +7,16 @@ branches:
# skip tags build, we are building branch and master that is enough for
# consistenty check and release. Let's use Travis CI resources optimally
# for aah framework.
- - /^v[0-9]\.[0-9]/
+ - /^v[0-9.]+$/
go:
- - 1.8
- 1.9
+ - "1.10"
- tip
go_import_path: aahframework.org/config.v0
install:
- - git config --global http.https://aahframework.org.followRedirects true
- go get -t -v ./...
script:
From 0e9878199cd9862fe0c4bd67ee25040809216d0c Mon Sep 17 00:00:00 2001
From: Jeevanandam M
Date: Mon, 23 Apr 2018 09:56:59 -0700
Subject: [PATCH 5/9] added version file and new empty config method
---
config.go | 9 ++++++---
version.go | 8 ++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
create mode 100644 version.go
diff --git a/config.go b/config.go
index 95d5454..77864d0 100644
--- a/config.go
+++ b/config.go
@@ -18,11 +18,14 @@ import (
"aahframework.org/forge.v0"
)
-// Version no. of aahframework.org/config library
-var Version = "0.4.2"
-
var errKeyNotFound = errors.New("config: not found")
+// NewEmptyConfig method returns aah empty config instance.
+func NewEmptyConfig() *Config {
+ cfg, _ := ParseString("")
+ return cfg
+}
+
// Config handles the configuration values and enables environment profile's,
// merge, etc. Also it provide nice and handly methods for accessing config values.
// Internally `aah config` uses `forge syntax` developed by `https://github.com/brettlangdon`.
diff --git a/version.go b/version.go
new file mode 100644
index 0000000..550e98d
--- /dev/null
+++ b/version.go
@@ -0,0 +1,8 @@
+// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
+// go-aah/config source code and usage is governed by a MIT style
+// license that can be found in the LICENSE file.
+
+package config
+
+// Version no. of aahframework.org/config library
+var Version = "0.5.0-edge"
From feeaeeb1d31fd6778020680c1cce58d7120b32b7 Mon Sep 17 00:00:00 2001
From: Jeevanandam M
Date: Mon, 23 Apr 2018 09:57:25 -0700
Subject: [PATCH 6/9] travis build config update
---
.travis.yml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 4d5ad6d..234899f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,8 +10,8 @@ branches:
- /^v[0-9.]+$/
go:
- - 1.9
- - "1.10"
+ - 1.9.x
+ - 1.10.x
- tip
go_import_path: aahframework.org/config.v0
From 1fd9d22ac52019edf1adbf94e52c10953b9cbf27 Mon Sep 17 00:00:00 2001
From: Jeevanandam M
Date: Sat, 12 May 2018 16:02:25 -0700
Subject: [PATCH 7/9] go-aah/aah#156 integrate config lib with VFS
---
config.go | 96 +++++++++++++++++++++++++++++---------------------
config_test.go | 29 +++++++--------
2 files changed, 68 insertions(+), 57 deletions(-)
diff --git a/config.go b/config.go
index 77864d0..c26175b 100644
--- a/config.go
+++ b/config.go
@@ -1,5 +1,5 @@
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
-// go-aah/config source code and usage is governed by a MIT style
+// aahframework.org/config source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
// Package config is nice and handy layer built around `forge` config syntax;
@@ -14,18 +14,26 @@ import (
"fmt"
"strings"
- "aahframework.org/essentials.v0"
"aahframework.org/forge.v0"
+ "aahframework.org/vfs.v0"
)
var errKeyNotFound = errors.New("config: not found")
-// NewEmptyConfig method returns aah empty config instance.
-func NewEmptyConfig() *Config {
+//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+// Package methods
+//______________________________________________________________________________
+
+// NewEmpty method returns aah empty config instance.
+func NewEmpty() *Config {
cfg, _ := ParseString("")
return cfg
}
+//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+// Config type and methods
+//______________________________________________________________________________
+
// Config handles the configuration values and enables environment profile's,
// merge, etc. Also it provide nice and handly methods for accessing config values.
// Internally `aah config` uses `forge syntax` developed by `https://github.com/brettlangdon`.
@@ -63,6 +71,9 @@ func (c *Config) HasProfile(profile string) bool {
// IsProfileEnabled returns true of profile enabled otherwise false
func (c *Config) IsProfileEnabled() bool {
+ if c == nil {
+ return false
+ }
return len(c.profile) > 0
}
@@ -206,9 +217,9 @@ func (c *Config) Get(key string) (interface{}, bool) {
return c.get(key)
}
-//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// List methods
-//___________________________________
+//______________________________________________________________________________
// StringList method returns the string slice value for the given key.
// Eaxmple:-
@@ -303,9 +314,9 @@ func (c *Config) Int64List(key string) ([]int64, bool) {
return values, true
}
-//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
-// Setter methods
-//___________________________________
+//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+// Config Setter methods
+//______________________________________________________________________________
// SetString sets the given value string for config key
// First it tries to get value within enabled profile
@@ -380,36 +391,33 @@ func (c *Config) ToJSON() string {
return "{}"
}
-//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
-// Configuration loading methods
-//___________________________________
+//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+// Config load/parse methods
+//______________________________________________________________________________
-// LoadFile loads the configuration given config file
+// LoadFile loads the configuration from given config file.
func LoadFile(file string) (*Config, error) {
- if !ess.IsFileExists(file) {
- return nil, fmt.Errorf("configuration does not exists: %v", file)
- }
-
- setting, err := forge.ParseFile(file)
- if err != nil {
- return nil, err
- }
+ return VFSLoadFile(nil, file)
+}
- return &Config{
- cfg: setting,
- }, nil
+// VFSLoadFile loads the configuration from given vfs and config file.
+func VFSLoadFile(fs *vfs.VFS, file string) (*Config, error) {
+ setting, err := loadFile(fs, file)
+ return &Config{cfg: setting}, err
}
-// LoadFiles loads the configuration given config files and
-// does merging of configuration in the order they are given
+// LoadFiles loads the configuration from given config files.
+// It does merging of configuration in the order they are given.
func LoadFiles(files ...string) (*Config, error) {
+ return VFSLoadFiles(nil, files...)
+}
+
+// VFSLoadFiles loads the configuration from given config vfs and files.
+// It does merging of configuration in the order they are given.
+func VFSLoadFiles(fs *vfs.VFS, files ...string) (*Config, error) {
settings := forge.NewSection()
for _, file := range files {
- if !ess.IsFileExists(file) {
- return nil, fmt.Errorf("configuration does not exists: %v", file)
- }
-
- setting, err := forge.ParseFile(file)
+ setting, err := loadFile(fs, file)
if err != nil {
return nil, err
}
@@ -419,9 +427,7 @@ func LoadFiles(files ...string) (*Config, error) {
}
}
- return &Config{
- cfg: settings,
- }, nil
+ return &Config{cfg: settings}, nil
}
// ParseString parses the configuration values from string
@@ -430,15 +436,19 @@ func ParseString(cfg string) (*Config, error) {
if err != nil {
return nil, err
}
-
- return &Config{
- cfg: setting,
- }, nil
+ return &Config{cfg: setting}, nil
}
-//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
-// Unexported methods
-//___________________________________
+//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
+// Config unexported methods
+//______________________________________________________________________________
+
+func loadFile(fs *vfs.VFS, file string) (*forge.Section, error) {
+ if _, err := vfs.Stat(fs, file); err != nil {
+ return nil, fmt.Errorf("configuration does not exists: %v", file)
+ }
+ return forge.VFSParseFile(fs, file)
+}
func (c *Config) prepareKey(key string) string {
if c.IsProfileEnabled() {
@@ -475,6 +485,10 @@ func (c *Config) getListValue(key string) (*forge.List, bool) {
}
func (c *Config) getraw(key string) (forge.Value, bool) {
+ if c == nil || c.cfg == nil {
+ return nil, false
+ }
+
v, err := c.cfg.Resolve(key)
if err != nil {
return nil, false // not found
diff --git a/config_test.go b/config_test.go
index eae98cd..c108665 100644
--- a/config_test.go
+++ b/config_test.go
@@ -16,7 +16,7 @@ import (
)
func TestKeysAndKeysByPath(t *testing.T) {
- cfg := initFile(t, join(getTestdataPath(), "test.cfg"))
+ cfg := initFile(t, join(testdataBaseDir(), "test.cfg"))
keys := cfg.Keys()
assert.True(t, ess.IsSliceContainsString(keys, "prod"))
assert.True(t, ess.IsSliceContainsString(keys, "dev"))
@@ -37,7 +37,7 @@ func TestKeysAndKeysByPath(t *testing.T) {
}
func TestGetSubConfig(t *testing.T) {
- cfg := initFile(t, join(getTestdataPath(), "test.cfg"))
+ cfg := initFile(t, join(testdataBaseDir(), "test.cfg"))
prod, found1 := cfg.GetSubConfig("prod")
assert.NotNil(t, prod)
@@ -64,7 +64,7 @@ func TestGetSubConfig(t *testing.T) {
}
func TestIsExists(t *testing.T) {
- cfg := initFile(t, join(getTestdataPath(), "test.cfg"))
+ cfg := initFile(t, join(testdataBaseDir(), "test.cfg"))
found := cfg.IsExists("prod.string")
assert.True(t, found)
@@ -77,7 +77,7 @@ func TestIsExists(t *testing.T) {
}
func TestStringValues(t *testing.T) {
- cfg := initFile(t, join(getTestdataPath(), "test.cfg"))
+ cfg := initFile(t, join(testdataBaseDir(), "test.cfg"))
v1, _ := cfg.String("string")
assert.Equal(t, "a string", v1)
@@ -100,7 +100,7 @@ func TestStringValues(t *testing.T) {
}
func TestIntValues(t *testing.T) {
- bytes, _ := ioutil.ReadFile(join(getTestdataPath(), "test.cfg"))
+ bytes, _ := ioutil.ReadFile(join(testdataBaseDir(), "test.cfg"))
cfg := initString(t, string(bytes))
v1, _ := cfg.Int("int")
@@ -136,7 +136,7 @@ func TestIntValues(t *testing.T) {
}
func TestFloatValues(t *testing.T) {
- cfg := initFile(t, join(getTestdataPath(), "test.cfg"))
+ cfg := initFile(t, join(testdataBaseDir(), "test.cfg"))
v1, _ := cfg.Float32("float32")
assert.Equal(t, float32(32.2), v1)
@@ -180,7 +180,7 @@ func TestFloatValues(t *testing.T) {
}
func TestBoolValues(t *testing.T) {
- bytes, _ := ioutil.ReadFile(join(getTestdataPath(), "test.cfg"))
+ bytes, _ := ioutil.ReadFile(join(testdataBaseDir(), "test.cfg"))
cfg := initString(t, string(bytes))
v1, _ := cfg.Bool("truevalue")
@@ -263,7 +263,7 @@ func TestIntAndInt64List(t *testing.T) {
}
func TestProfile(t *testing.T) {
- cfg := initFile(t, join(getTestdataPath(), "test.cfg"))
+ cfg := initFile(t, join(testdataBaseDir(), "test.cfg"))
t.Log(cfg.cfg.Keys())
@@ -276,9 +276,7 @@ func TestProfile(t *testing.T) {
}
func TestConfigLoadNotExists(t *testing.T) {
- testdataPath := getTestdataPath()
-
- _, err := LoadFile(join(testdataPath, "not_exists.cfg"))
+ _, err := LoadFile(join(testdataBaseDir(), "not_exists.cfg"))
assert.True(t, strings.HasPrefix(err.Error(), "configuration does not exists:"))
_, err = ParseString(`
@@ -336,7 +334,7 @@ prod {
}
func TestLoadFiles(t *testing.T) {
- testdataPath := getTestdataPath()
+ testdataPath := testdataBaseDir()
cfg, err := LoadFiles(
join(testdataPath, "test-1.cfg"),
@@ -371,7 +369,7 @@ func TestLoadFiles(t *testing.T) {
}
func TestNestedKeyWithProfile(t *testing.T) {
- testdataPath := getTestdataPath()
+ testdataPath := testdataBaseDir()
cfg, err := LoadFiles(join(testdataPath, "test-4.cfg"))
assert.FailNowOnError(t, err, "loading failed")
@@ -399,7 +397,7 @@ func TestNestedKeyWithProfile(t *testing.T) {
}
func TestConfigSetValues(t *testing.T) {
- testdataPath := getTestdataPath()
+ testdataPath := testdataBaseDir()
cfg, err := LoadFiles(join(testdataPath, "test-4.cfg"))
assert.FailNowOnError(t, err, "loading failed")
@@ -429,7 +427,6 @@ func initString(t *testing.T, configStr string) *Config {
func initFile(t *testing.T, file string) *Config {
cfg, err := LoadFile(file)
assert.FailNowOnError(t, err, "")
-
return cfg
}
@@ -438,7 +435,7 @@ func setProfileForTest(t *testing.T, cfg *Config, profile string) {
assert.FailNowOnError(t, err, "")
}
-func getTestdataPath() string {
+func testdataBaseDir() string {
wd, _ := os.Getwd()
return filepath.Join(wd, "testdata")
}
From 52bec49310fcbe6757f15eec30833fbf432b4b52 Mon Sep 17 00:00:00 2001
From: Jeevanandam M
Date: Sat, 12 May 2018 16:44:27 -0700
Subject: [PATCH 8/9] added before install setup for build
---
.travis.yml | 3 +++
1 file changed, 3 insertions(+)
diff --git a/.travis.yml b/.travis.yml
index 234899f..75096d1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,6 +16,9 @@ go:
go_import_path: aahframework.org/config.v0
+before_install:
+ - bash <(curl -s https://aahframework.org/base-before-install) "essentials vfs forge"
+
install:
- go get -t -v ./...
From 96e36cdf40fc0eb6ea87b8814fb6491144a747fa Mon Sep 17 00:00:00 2001
From: Jeevanandam M
Date: Wed, 20 Jun 2018 21:55:11 -0700
Subject: [PATCH 9/9] readme update for v0.5.0 release and build config update
---
.travis.yml | 2 +-
README.md | 22 ++++++++++++----------
version.go | 4 ++--
3 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 75096d1..928f462 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -11,7 +11,7 @@ branches:
go:
- 1.9.x
- - 1.10.x
+ - 1.x
- tip
go_import_path: aahframework.org/config.v0
diff --git a/README.md b/README.md
index 0b62f4c..2deeb1f 100644
--- a/README.md
+++ b/README.md
@@ -1,19 +1,21 @@
-# config - aah framework
+
+
+
Config Library by aah framework
+
+
+
+
-[![Build Status](https://travis-ci.org/go-aah/config.svg?branch=master)](https://travis-ci.org/go-aah/config) [![codecov](https://codecov.io/gh/go-aah/config/branch/master/graph/badge.svg)](https://codecov.io/gh/go-aah/config/branch/master) [![Go Report Card](https://goreportcard.com/badge/aahframework.org/config.v0)](https://goreportcard.com/report/aahframework.org/config.v0)
-[![Version](https://img.shields.io/badge/version-0.4.2-blue.svg)](https://github.com/go-aah/config/releases/latest) [![GoDoc](https://godoc.org/aahframework.org/config.v0?status.svg)](https://godoc.org/aahframework.org/config.v0) [![License](https://img.shields.io/github/license/go-aah/config.svg)](LICENSE) [![Twitter](https://img.shields.io/badge/twitter-@aahframework-55acee.svg)](https://twitter.com/aahframework)
+`config` library is powerful and flexible to configuration file/structure. It internally uses `forge` library developed by [@brettlangdon](htpps://github.com/brettlangdon) and adds further functionality to it. Syntax is very similar to Typesafe HOCON :satisfied:. Config library is used across the aah framework.
-***v0.4.2 [released](https://github.com/go-aah/config/releases/latest) and tagged on Jul 30, 2017***
+### News
-`config` library is powerful and flexible for configuration purpose. It's thin layer around `forge` config syntax which is very similar to Typesafe HOCON syntax :satisfied:. aah framework and it's modules is powered with `aah/config` library.
+ * `v0.5.0` [released](https://github.com/go-aah/config/releases/latest) and tagged on Jun 20, 2018.
-*`config` developed for aah framework. However it's an independent library, can be used separately with any `Go` language project. Feel free to use it.*
+## Installation
-# Installation
-#### Stable Version - Production Ready
```bash
-# install the library
go get -u aahframework.org/config.v0
```
-Visit official website https://aahframework.org to learn more.
+Visit official website https://aahframework.org to learn more about `aah` framework.
diff --git a/version.go b/version.go
index 550e98d..f75db91 100644
--- a/version.go
+++ b/version.go
@@ -1,8 +1,8 @@
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
-// go-aah/config source code and usage is governed by a MIT style
+// aahframework.org/config source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package config
// Version no. of aahframework.org/config library
-var Version = "0.5.0-edge"
+var Version = "0.5.0"