feat: Inital commit

This commit is contained in:
2025-07-26 05:58:59 +00:00
commit 753d1c60ea
1849 changed files with 830533 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
package config
import (
"log"
"strings"
"github.com/spf13/viper"
)
type Config struct {
GCPProjectID string `mapstructure:"gcp_project_id"`
Telegram struct {
Token string `mapstructure:"token"`
ChatIDs []int64 `mapstructure:"chat_ids"`
} `mapstructure:"telegram"`
}
func Load() (Config, error) {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.SetEnvPrefix("CRAWLER")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
var cfg Config
if err := viper.ReadInConfig(); err != nil {
// If the error is that the file wasn't found, that's okay. Log it and continue.
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
log.Println("️ No 'config.yaml' file found. Relying on environment variables or flags.")
} else {
// For any other error (e.g., malformed YAML), return the error.
return cfg, err
}
}
if err := viper.Unmarshal(&cfg); err != nil {
return cfg, err
}
return cfg, nil
}