Skip to content

Commit

Permalink
refactor: env vars to enverant
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Jun 8, 2024
1 parent 76eb7b1 commit a1e48cc
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 50 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/chromedriver
/data/*
!/data/.gitkeep
settings.json
.terraform/
*.svg.bkp
config
Expand All @@ -16,3 +15,7 @@ __debug_bin
cover.out
go.work*
.venv/
!.vscode
.vscode/enverant.json
!.vscode/enverant.example.json
!.vscode/settings.json
10 changes: 10 additions & 0 deletions .vscode/enverant.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// "SCRAPPY_PLAYER_URL": "**********", // Not required for dev env if u use "DEV_ENV_MOCK_API": "true"
// "SCRAPPY_BASE_URL": "**********", // Not required for dev env if u use "DEV_ENV_MOCK_API": "true"
// "DARK_TEST_REGENERATE": "false",
"DEV_ENV": "true",
"DEV_ENV_MOCK_API": "true",
"DARKBOT_LOG_LEVEL": "INFO",
"CONFIGURATOR_DBNAME": "dev",
"DISCORDER_BOT_TOKEN": "**********" // Get your own app token at https://discord.com/developers/applications
}
27 changes: 0 additions & 27 deletions .vscode/settings.example.json

This file was deleted.

9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"go.testFlags": [
"-v"
],
"go.testEnvVars": {},
"go.testTimeout": "30000s",
"editor.formatOnSave": true,
"terminal.integrated.env.linux": {}
}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
- If you are me, then just use your dev env inviting link you already created:

- https://discord.com/api/oauth2/authorize?client_id=1071516990348460033&permissions=8&scope=bot
- Ensure you have set [Environment variables](./.vscode/settings.example.json) documented in .vscode

- Ensure you have set necessary [Environment variables](./.vscode/enverant.example.json) in your own enverant.json file or as real environment variables
- [App specific configurations](./app/settings/main.go) can be found here.
- Install golang of version no less than it is mention in [test.yml file](.github/workflows/test.yml)
- Launch app as `go run . run` (see `go run . --help` for other available commands)
Expand Down
5 changes: 2 additions & 3 deletions app/forumer/forum_post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (

"github.com/darklab8/fl-darkbot/app/forumer/forum_types"
"github.com/darklab8/fl-darkbot/app/settings/logus"

"github.com/darklab8/go-utils/utils"
"github.com/darklab8/go-utils/utils/utils_os"

"github.com/stretchr/testify/assert"
)
Expand All @@ -25,7 +24,7 @@ func FixtureLatestThread() *forum_types.LatestThread {
}

func FixtureDetailedRequester() func(mt MethodType, u forum_types.Url) (*QueryResult, error) {
detailed_post_content_filepath := filepath.Join(utils.GetCurrentFolder().ToString(), "test_data", "detailed_post_content.html")
detailed_post_content_filepath := filepath.Join(utils_os.GetCurrentFolder().ToString(), "test_data", "detailed_post_content.html")
if _, err := os.Stat(detailed_post_content_filepath); err != nil {
query, err := NewQuery("GET", "https://discoverygc.com/forums/showthread.php?tid=200175&action=lastpost")
logus.Log.CheckFatal(err, "failed to create mock data")
Expand Down
5 changes: 2 additions & 3 deletions app/forumer/forum_threads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (

"github.com/darklab8/fl-darkbot/app/forumer/forum_types"
"github.com/darklab8/fl-darkbot/app/settings/logus"

"github.com/darklab8/go-utils/utils"
"github.com/darklab8/go-utils/utils/utils_os"

"github.com/stretchr/testify/assert"
)

func FixtureMockedThreadsRequester() func(mt MethodType, u forum_types.Url) (*QueryResult, error) {
thread_post_content_filepath := filepath.Join(utils.GetCurrentFolder().ToString(), "test_data", "latest_threads.html")
thread_post_content_filepath := filepath.Join(utils_os.GetCurrentFolder().ToString(), "test_data", "latest_threads.html")
if _, err := os.Stat(thread_post_content_filepath); err != nil {
query, err := NewQuery("GET", ThreadPageURL)
logus.Log.CheckFatal(err, "failed to create mock data")
Expand Down
30 changes: 16 additions & 14 deletions app/settings/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/darklab8/fl-darkbot/app/settings/logus"
"github.com/darklab8/fl-darkbot/app/settings/types"

"github.com/darklab8/go-utils/utils"
"github.com/darklab8/go-utils/utils/utils_env"
"github.com/darklab8/go-utils/utils/enverant"
"github.com/darklab8/go-utils/utils/utils_os"
"github.com/darklab8/go-utils/utils/utils_settings"
)

Expand Down Expand Up @@ -35,25 +35,27 @@ var Env DarkbotEnv
func init() {
logus.Log.Info("attempt to load settings")

envs := utils_env.NewEnvConfig()
envs := enverant.NewEnverant(
enverant.WithEnvFile(utils_os.GetCurrentFolder().Dir().Dir().Join(".vscode", "enverant.json").ToString()),
)
Env = DarkbotEnv{
UtilsEnvs: utils_settings.Envs,
DevEnvMockApi: envs.GetEnvBoolWithDefault("DEV_ENV_MOCK_API", true),
ScrappyBaseUrl: envs.GetEnvWithDefault("SCRAPPY_BASE_URL", ""),
ScrappyPlayerUrl: envs.GetEnvWithDefault("SCRAPPY_PLAYER_URL", ""),
ScrappyBaseAttackUrl: envs.GetEnvWithDefault("SCRAPPY_BASE_ATTACK_URL", "https://discoverygc.com/forums/showthread.php?tid=110046&action=lastpost"),
DevEnvMockApi: envs.GetBoolOr("DEV_ENV_MOCK_API", true),
ScrappyBaseUrl: envs.GetStrOr("SCRAPPY_BASE_URL", ""),
ScrappyPlayerUrl: envs.GetStrOr("SCRAPPY_PLAYER_URL", ""),
ScrappyBaseAttackUrl: envs.GetStrOr("SCRAPPY_BASE_ATTACK_URL", "https://discoverygc.com/forums/showthread.php?tid=110046&action=lastpost"),

DiscorderBotToken: envs.GetEnvWithDefault("DISCORDER_BOT_TOKEN", ""),
DiscorderBotToken: envs.GetStrOr("DISCORDER_BOT_TOKEN", ""),

ConfiguratorDbname: envs.GetEnvWithDefault("CONFIGURATOR_DBNAME", "dev"),
ConfiguratorDbname: envs.GetStrOr("CONFIGURATOR_DBNAME", "dev"),

ConsolerPrefix: envs.GetEnvWithDefault("CONSOLER_PREFIX", ";"),
ProfilingEnabled: envs.GetEnvBoolWithDefault("PROFILING", false),
ConsolerPrefix: envs.GetStrOr("CONSOLER_PREFIX", ";"),
ProfilingEnabled: envs.GetBoolOr("PROFILING", false),

ScrappyLoopDelay: envs.GetIntWithDefault("SCRAPPY_LOOP_DELAY", 10),
ViewerLoopDelay: envs.GetIntWithDefault("VIEWER_LOOP_DELAY", 10),
ScrappyLoopDelay: envs.GetIntOr("SCRAPPY_LOOP_DELAY", 10),
ViewerLoopDelay: envs.GetIntOr("VIEWER_LOOP_DELAY", 10),
}
Workdir = filepath.Dir(filepath.Dir(utils.GetCurrentFolder().ToString()))
Workdir = filepath.Dir(filepath.Dir(utils_os.GetCurrentFolder().ToString()))
Dbpath = NewDBPath(Env.ConfiguratorDbname)

if !Env.DevEnvMockApi {
Expand Down

0 comments on commit a1e48cc

Please sign in to comment.