-
Notifications
You must be signed in to change notification settings - Fork 1
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 #10 from gender-equality-community/override_messages
Override messages
- Loading branch information
Showing
15 changed files
with
133 additions
and
248 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
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 was deleted.
Oops, something went wrong.
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,44 @@ | ||
package main | ||
|
||
import "os" | ||
|
||
var ( | ||
// Greeting response is sent when a recipient sends a message sends us a greeting | ||
greetingResponse = Lookup("GREETING", "Hello, my name is Ada. What's on your mind?") | ||
|
||
// Thank You response is sent when a recipient sends us a message and is capped at a max of 1 per 30 mins | ||
thankyouResponse = Lookup("THANK_YOU", "Thank you for your message, please provide as much information as you're comfortable sharing and I'll get back to you as soon as I can.") | ||
|
||
// Disclaimer response is sent to ensure recipients don't send us stuff we can't deal with. | ||
disclaimerResponse = Lookup("DISCLAIMER", "DISCLAIMER: This is not an incident reporting service. If you believe you're being subjected to bullying, harassment, or misconduct then I cannot escalate on your behalf but I can advise you on your next steps.") | ||
|
||
// DB is the location, on disk, of the database to use | ||
db = MustLookup("DATABASE") | ||
|
||
// Redis Address is the network address of the redis instance to use | ||
redisAddr = MustLookup("REDIS_ADDR") | ||
) | ||
|
||
// Lookup accepts an environment variable name and a default value. | ||
// If the variable exists and is set, then Lookup returns that, | ||
// otherwise Lookup returns the default value | ||
func Lookup(v, d string) string { | ||
s, ok := os.LookupEnv(v) | ||
if ok { | ||
return s | ||
} | ||
return d | ||
} | ||
|
||
// MustLookup accepts and enviroment variable nae and returns | ||
// the value of that. | ||
// | ||
// Should the var be unset or empty, MustLookup panics | ||
func MustLookup(v string) (s string) { | ||
s = os.Getenv(v) | ||
if s == "" { | ||
panic("Environment variable " + v + " is empty or unset") | ||
} | ||
|
||
return | ||
} |
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestLookup(t *testing.T) { | ||
got := Lookup("__AN_UNSET_KEY_HOPEFULLY", "<3") | ||
if got != "<3" { | ||
t.Errorf("unexpected value %q", got) | ||
} | ||
} | ||
|
||
func TestLookup_Exists(t *testing.T) { | ||
os.Setenv("__THIS_KEY_HAS_A_VALUE", "<3") | ||
|
||
got := Lookup("__THIS_KEY_HAS_A_VALUE", "blahblahblah") | ||
if got != "<3" { | ||
t.Errorf("unexpected value %q", got) | ||
} | ||
} | ||
|
||
func TestMustLookup(t *testing.T) { | ||
defer func() { | ||
err := recover() | ||
if err == nil { | ||
t.Error("expected panic, received none") | ||
} | ||
}() | ||
|
||
MustLookup("__AN_UNSET_KEY_HOPEFULLY") | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
Oops, something went wrong.