-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from HarrisChu/feat_add_env
add env to process the statement
- Loading branch information
Showing
5 changed files
with
67 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package common | ||
|
||
import "github.com/kelseyhightower/envconfig" | ||
|
||
type Environment struct { | ||
NebulaStmtPrefix string `envconfig:"STMT_PREFIX" ` | ||
} | ||
|
||
var nebulaEnv *Environment | ||
|
||
func getEnv() { | ||
var env Environment | ||
err := envconfig.Process("nebula", &env) | ||
if err != nil { | ||
panic(err) | ||
} | ||
nebulaEnv = &env | ||
} | ||
|
||
func init() { | ||
getEnv() | ||
} | ||
|
||
func ProcessStmt(stmt string) string { | ||
if nebulaEnv.NebulaStmtPrefix != "" { | ||
stmt = nebulaEnv.NebulaStmtPrefix + " " + stmt | ||
} | ||
return stmt | ||
} |
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,20 @@ | ||
package common | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestEnv(t *testing.T) { | ||
os.Setenv("NEBULA_STMT_PREFIX", "nebula") | ||
getEnv() | ||
assert.Equal(t, "nebula", nebulaEnv.NebulaStmtPrefix) | ||
} | ||
|
||
func TestProcessStmt(t *testing.T) { | ||
os.Setenv("NEBULA_STMT_PREFIX", "nebula") | ||
getEnv() | ||
assert.Equal(t, "nebula stmt", ProcessStmt("stmt")) | ||
} |
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