fix: issues

This commit is contained in:
Rogee
2024-09-04 13:50:11 +08:00
parent 9b136810bc
commit 4c41d899ba
3 changed files with 9 additions and 3 deletions

View File

@@ -2,8 +2,8 @@ phone: "+17622696330"
app_id: 29433191 app_id: 29433191
app_hash: bc7a2f7b8893889ffa6115f5f0eac278 app_hash: bc7a2f7b8893889ffa6115f5f0eac278
bot_token: bot_token:
session_file: ./session.json session_file: ~/.cache/exporter/session.json
log_file: ./log.json log_file: /var/log/exporter/log.json
output: /share/telegram/outputs output: /share/telegram/outputs
max_size: 100MB max_size: 100MB
dsn: "postgresql://postgres:xixi0202@10.1.1.3:5432/telegram_resource?sslmode=disable" dsn: "postgresql://postgres:xixi0202@10.1.1.3:5432/telegram_resource?sslmode=disable"

View File

@@ -1,6 +1,8 @@
package config package config
import ( import (
"path/filepath"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@@ -28,6 +30,10 @@ func (c *Config) GetMaxSize() uint {
} }
func Load(path string) error { 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 // Load the config file
viper.SetConfigFile(path) viper.SetConfigFile(path)
viper.AutomaticEnv() viper.AutomaticEnv()

View File

@@ -34,7 +34,7 @@ func main() {
return internal.Close() 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( rootCmd.AddCommand(
internal.LoginCmd(), internal.LoginCmd(),