Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
environment configuration (#15)
Browse files Browse the repository at this point in the history
* environment configuration

* simplify

* fix test

* small fix
  • Loading branch information
jenchik authored and im-kulikov committed Feb 27, 2019
1 parent 0063555 commit e50bbc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions helium.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
stdlog "log"
"os"
"reflect"
"strings"

"github.com/im-kulikov/helium/logger"
"github.com/im-kulikov/helium/module"
Expand Down Expand Up @@ -47,12 +48,13 @@ func New(cfg *Settings, mod module.Module) (*Helium, error) {
if cfg.Prefix == "" {
cfg.Prefix = cfg.Name
}
cfg.Prefix = strings.ToUpper(cfg.Prefix)

if tmp := os.Getenv("HELIUM_CONFIG"); tmp != "" {
if tmp := os.Getenv(cfg.Prefix + "_CONFIG"); tmp != "" {
cfg.File = tmp
}

if tmp := os.Getenv("HELIUM_CONFIG_TYPE"); tmp != "" {
if tmp := os.Getenv(cfg.Prefix + "_CONFIG_TYPE"); tmp != "" {
cfg.Type = tmp
}

Expand Down
8 changes: 5 additions & 3 deletions helium_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ func TestHelium(t *testing.T) {

defer os.Remove(tmpFile.Name()) // clean up

os.Setenv("HELIUM_CONFIG", tmpFile.Name())
os.Setenv("HELIUM_CONFIG_TYPE", "toml")
os.Setenv("ABC_CONFIG", tmpFile.Name())
os.Setenv("ABC_CONFIG_TYPE", "toml")

h, err := New(&Settings{}, module.Module{
h, err := New(&Settings{
Name: "Abc",
}, module.Module{
{Constructor: func(cfg *settings.Core) App {
c.So(cfg.File, ShouldEqual, tmpFile.Name())
c.So(cfg.Type, ShouldEqual, "toml")
Expand Down

0 comments on commit e50bbc7

Please sign in to comment.