-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: command line arguments implementation
- Loading branch information
Sergey Kutovoy
committed
Mar 20, 2024
1 parent
33a8a22
commit d093f1b
Showing
7 changed files
with
87 additions
and
77 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 |
---|---|---|
@@ -1,48 +1,18 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"strconv" | ||
) | ||
"marzban-exporter/models" | ||
|
||
var ( | ||
Port = getEnv("METRICS_PORT", "9090") | ||
ProtectedMetrics = getEnvAsBool("METRICS_PROTECTED", false) | ||
MetricsUsername = getEnv("METRICS_USERNAME", "metricsUser") | ||
MetricsPassword = getEnv("METRICS_PASSWORD", "MetricsVeryHardPassword") | ||
UpdateInterval = getEnvAsInt("UPDATE_INTERVAL", 30) | ||
TimeZone = getEnv("TIMEZONE", "UTC") | ||
InactivityTime = getEnvAsInt("INACTIVITY_TIME", 2) | ||
BaseURL = getEnv("MARZBAN_BASE_URL", "") | ||
ApiUsername = getEnv("MARZBAN_USERNAME", "") | ||
ApiPassword = getEnv("MARZBAN_PASSWORD", "") | ||
"github.com/alecthomas/kong" | ||
) | ||
|
||
func getEnv(key, defaultValue string) string { | ||
value, exists := os.LookupEnv(key) | ||
if !exists { | ||
return defaultValue | ||
} | ||
return value | ||
} | ||
|
||
func getEnvAsInt(key string, defaultValue int) int { | ||
valueStr := getEnv(key, "") | ||
if valueStr == "" { | ||
return defaultValue | ||
} | ||
|
||
value, err := strconv.Atoi(valueStr) | ||
if err != nil { | ||
return defaultValue | ||
} | ||
return value | ||
} | ||
var CLIConfig models.CLI | ||
|
||
func getEnvAsBool(key string, defaultValue bool) bool { | ||
valStr := getEnv(key, "") | ||
if val, err := strconv.ParseBool(valStr); err == nil { | ||
return val | ||
} | ||
return defaultValue | ||
func Parse() { | ||
ctx := kong.Parse(&CLIConfig, | ||
kong.Name("marzban-exporter"), | ||
kong.Description("A command-line application for exporting Marzban metrics."), | ||
) | ||
// Use ctx if needed | ||
_ = ctx | ||
} |
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