-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow local config with .forego (#56)
See #32 gotenv can read simple yaml file so we don't need to use a read yaml parse. The value in forego file will be set as default value, if we set flag or env value, it will override the value in forego file
- Loading branch information
Showing
5 changed files
with
80 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,24 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/ddollar/forego/Godeps/_workspace/src/github.com/subosito/gotenv" | ||
"os" | ||
) | ||
|
||
type Config map[string]string | ||
|
||
func ReadConfig(filename string) (Config, error) { | ||
if _, err := os.Stat(filename); os.IsNotExist(err) { | ||
return make(Config), nil | ||
} | ||
fd, err := os.Open(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer fd.Close() | ||
config := make(Config) | ||
for key, val := range gotenv.Parse(fd) { | ||
config[key] = val | ||
} | ||
return config, nil | ||
} |
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,11 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestReadOptionFile(t *testing.T) { | ||
config_file := "./fixtures/options/.forego" | ||
_, err := ReadConfig(config_file) | ||
if err != nil { | ||
t.Fatalf("Could not read config file: %s", err) | ||
} | ||
} |
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,3 @@ | ||
procfile: Procfile.dev | ||
concurrency: foo=2,bar=3 | ||
port: 15000 |
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
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