Implement CheckCle Microservice Operation

A Go-based microservice for service operations including ICMP ping, DNS resolution, and TCP connectivity
This commit is contained in:
Tola Leng
2025-06-19 17:49:30 +07:00
parent 89572c44b7
commit d3ea5dc77c
36 changed files with 2895 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
package config
import (
"os"
"strconv"
"time"
)
type Config struct {
Port string
DefaultCount int
DefaultTimeout time.Duration
MaxCount int
MaxTimeout time.Duration
EnableLogging bool
// PocketBase configuration (no auth required)
PocketBaseEnabled bool
PocketBaseURL string
}
func Load() *Config {
cfg := &Config{
Port: getEnv("PORT", "8091"),
DefaultCount: getEnvInt("DEFAULT_COUNT", 4),
DefaultTimeout: getEnvDuration("DEFAULT_TIMEOUT", 3*time.Second),
MaxCount: getEnvInt("MAX_COUNT", 20),
MaxTimeout: getEnvDuration("MAX_TIMEOUT", 30*time.Second),
EnableLogging: getEnvBool("ENABLE_LOGGING", true),
// PocketBase settings (no credentials needed)
PocketBaseEnabled: getEnvBool("POCKETBASE_ENABLED", true),
PocketBaseURL: getEnv("POCKETBASE_URL", ""),
}
return cfg
}
func getEnv(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}
func getEnvInt(key string, defaultValue int) int {
if value := os.Getenv(key); value != "" {
if intValue, err := strconv.Atoi(value); err == nil {
return intValue
}
}
return defaultValue
}
func getEnvDuration(key string, defaultValue time.Duration) time.Duration {
if value := os.Getenv(key); value != "" {
if duration, err := time.ParseDuration(value); err == nil {
return duration
}
}
return defaultValue
}
func getEnvBool(key string, defaultValue bool) bool {
if value := os.Getenv(key); value != "" {
if boolValue, err := strconv.ParseBool(value); err == nil {
return boolValue
}
}
return defaultValue
}