diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-09-30 16:56:41 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-09-30 16:56:41 +0530 |
commit | 4c94a14debab89ddb22e20beb3894d178062ce31 (patch) | |
tree | 87d942a6f187b067aba23c85b46e79e1e3eb6b91 /mal/mal.go | |
parent | 6aaea4225d531a7b3ff5e21d12d35a7361aaf43b (diff) |
reading authtoken from config file
Diffstat (limited to 'mal/mal.go')
-rw-r--r-- | mal/mal.go | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -25,6 +25,8 @@ import ( u "github.com/MikunoNaka/MAL2Go/v4/user" ua "github.com/MikunoNaka/MAL2Go/v4/user/anime" um "github.com/MikunoNaka/MAL2Go/v4/user/manga" + "github.com/spf13/viper" + "strings" ) var ( @@ -41,10 +43,13 @@ var ( // init() would kill the program prematurely on `macli login` command func Init() { - if Secret == "" { - Secret = auth.GetToken() + // Secret preference: flag -> conf file -> system keyring + if strings.TrimSpace(Secret) == "" { + if Secret = viper.GetString("auth.token"); strings.TrimSpace(Secret) == "" { + Secret = auth.GetToken() + } } - tk := "Bearer " + Secret + tk := "Bearer " + strings.TrimSpace(Secret) // initialise MAL2Go Client(s) animeClient.AuthToken = tk |