From 4c41d899ba0012a13e900340e27846423f9e4b17 Mon Sep 17 00:00:00 2001 From: Rogee Date: Wed, 4 Sep 2024 13:50:11 +0800 Subject: [PATCH] fix: issues --- config.yml | 4 ++-- config/config.go | 6 ++++++ main.go | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config.yml b/config.yml index 5727273..9707b3d 100644 --- a/config.yml +++ b/config.yml @@ -2,8 +2,8 @@ phone: "+17622696330" app_id: 29433191 app_hash: bc7a2f7b8893889ffa6115f5f0eac278 bot_token: -session_file: ./session.json -log_file: ./log.json +session_file: ~/.cache/exporter/session.json +log_file: /var/log/exporter/log.json output: /share/telegram/outputs max_size: 100MB dsn: "postgresql://postgres:xixi0202@10.1.1.3:5432/telegram_resource?sslmode=disable" diff --git a/config/config.go b/config/config.go index 0fae0a1..fd30dc1 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,8 @@ package config import ( + "path/filepath" + "github.com/pkg/errors" "github.com/spf13/viper" ) @@ -28,6 +30,10 @@ func (c *Config) GetMaxSize() uint { } func Load(path string) error { + path, err := filepath.Abs(path) + if err != nil { + return errors.Wrapf(err, "failed to get the absolute path of the config file %s", path) + } // Load the config file viper.SetConfigFile(path) viper.AutomaticEnv() diff --git a/main.go b/main.go index a48a198..0f29a1a 100644 --- a/main.go +++ b/main.go @@ -34,7 +34,7 @@ func main() { return internal.Close() }, } - rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "C", "config.yml", "config file") + rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "C", "/root/.exporter.yml", "config file") rootCmd.AddCommand( internal.LoginCmd(),