From 4c94a14debab89ddb22e20beb3894d178062ce31 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Fri, 30 Sep 2022 16:56:41 +0530 Subject: reading authtoken from config file --- mal/mal.go | 11 ++++++++--- 1 file 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 -- cgit v1.2.3