-
Notifications
You must be signed in to change notification settings - Fork 136
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
raul-brainattica
committed
Apr 16, 2015
1 parent
5761fcd
commit 77b2a36
Showing
8 changed files
with
75 additions
and
5 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
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
File renamed without changes.
File renamed without changes.
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,4 @@ | ||
{ | ||
"PrivateKeyPath": "/home/vagrant/go/src/api.jwt.auth/settings/keys/private_key", | ||
"PublicKeyPath": "/home/vagrant/go/src/api.jwt.auth/settings/keys/public_key.pub" | ||
} |
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,4 @@ | ||
{ | ||
"PrivateKeyPath": "/home/vagrant/go/src/api.jwt.auth/settings/keys/private_key", | ||
"PublicKeyPath": "/home/vagrant/go/src/api.jwt.auth/settings/keys/public_key.pub" | ||
} |
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,58 @@ | ||
package settings | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
) | ||
|
||
var environments = map[string]string{ | ||
"production": "settings/prod.json", | ||
"preproduction": "settings/pre.json", | ||
"tests": "../../settings/tests.json", | ||
} | ||
|
||
type Settings struct { | ||
PrivateKeyPath string | ||
PublicKeyPath string | ||
} | ||
|
||
var settings Settings = Settings{} | ||
var env = "preproduction" | ||
|
||
func Init() { | ||
env = os.Getenv("GO_ENV") | ||
if env == "" { | ||
fmt.Println("Warning: Setting preproduction environment due to lack of GO_ENV value") | ||
env = "preproduction" | ||
} | ||
LoadSettingsByEnv(env) | ||
} | ||
|
||
func LoadSettingsByEnv(env string) { | ||
content, err := ioutil.ReadFile(environments[env]) | ||
if err != nil { | ||
fmt.Println("Error while reading config file", err) | ||
} | ||
settings = Settings{} | ||
jsonErr := json.Unmarshal(content, &settings) | ||
if jsonErr != nil { | ||
fmt.Println("Error while parsing config file", jsonErr) | ||
} | ||
} | ||
|
||
func GetEnvironment() string { | ||
return env | ||
} | ||
|
||
func Get() Settings { | ||
if &settings == nil { | ||
Init() | ||
} | ||
return settings | ||
} | ||
|
||
func IsTestEnvironment() bool { | ||
return env == "tests" | ||
} |
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,4 @@ | ||
{ | ||
"PrivateKeyPath": "/home/vagrant/go/src/api.jwt.auth/settings/keys/private_key", | ||
"PublicKeyPath": "/home/vagrant/go/src/api.jwt.auth/settings/keys/public_key.pub" | ||
} |