Skip to content

Commit

Permalink
Improve configure
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuswilms committed Feb 25, 2025
1 parent d73f330 commit 5041f42
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# TOBEY_USER_AGENT="Tobey/0"

# Enable dynamic re-configuration during run time. By default disabled.
# TOBEY_DYNAMIC_CONFIG=yes
# TOBEY_DYNAMIC_CONFIG=true

# DSN specifying where crawl results should be stored, by default no results are stored. Here we store results
# in the "results" directory, relative to the current working directory.
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cache
tobey
.env
.vscode
12 changes: 9 additions & 3 deletions configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ func configure() {
flag.IntVar(&flagPort, "port", 0, "Port to bind the HTTP server to")
flag.Parse()

if os.Getenv("TOBEY_DEBUG") == "true" {
if isForgivingTrue(os.Getenv("TOBEY_DEBUG")) {
Debug = true
slog.Info("Debug mode enabled.")
}
if os.Getenv("TOBEY_SKIP_CACHE") == "true" {
if isForgivingTrue(os.Getenv("TOBEY_SKIP_CACHE")) {
SkipCache = true
slog.Info("Skipping cache.")
}
Expand Down Expand Up @@ -56,7 +57,7 @@ func configure() {
slog.Info("Using custom user agent.", "user_agent", UserAgent)
}

if v := os.Getenv("TOBEY_DYNAMIC_CONFIG"); v == "true" || v == "yes" || v == "y" || v == "on" {
if isForgivingTrue(os.Getenv("TOBEY_DYNAMIC_CONFIG")) {
DynamicConfig = true
slog.Info("Dynamic configuration enabled!")
}
Expand All @@ -75,3 +76,8 @@ func configure() {
slog.Info("High Frequency Metrics (Pulse) enabled.")
}
}

func isForgivingTrue(v string) bool {
v = strings.ToLower(v)
return v == "true" || v == "yes" || v == "y" || v == "on"
}
2 changes: 1 addition & 1 deletion examples/.env.example.factorial
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
TOBEY_USER_AGENT="WebsiteStandardsBot/1.0"

# Enable dynamic re-configuration during run time. By default disabled.
TOBEY_DYNAMIC_CONFIG=yes
TOBEY_DYNAMIC_CONFIG=true

# DSN specifying where crawl results should be stored, by default no results are stored. Here we store results
# in the "results" directory, relative to the current working directory.
Expand Down

0 comments on commit 5041f42

Please sign in to comment.