aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-30 16:56:41 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-30 16:56:41 +0530
commit4c94a14debab89ddb22e20beb3894d178062ce31 (patch)
tree87d942a6f187b067aba23c85b46e79e1e3eb6b91
parent6aaea4225d531a7b3ff5e21d12d35a7361aaf43b (diff)
reading authtoken from config file
-rw-r--r--mal/mal.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/mal/mal.go b/mal/mal.go
index 77940df..d29c572 100644
--- a/mal/mal.go
+++ b/mal/mal.go
@@ -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