Handle err + minor refactor

This commit is contained in:
Neeraj Gupta 2023-09-22 10:55:33 +05:30
parent 235face771
commit 490e145053

View file

@ -4,8 +4,9 @@ import (
"crypto/rand" "crypto/rand"
"errors" "errors"
"fmt" "fmt"
"github.com/zalando/go-keyring"
"log" "log"
"github.com/zalando/go-keyring"
) )
func GetOrCreateClISecret() []byte { func GetOrCreateClISecret() []byte {
@ -18,13 +19,14 @@ func GetOrCreateClISecret() []byte {
key := make([]byte, 32) key := make([]byte, 32)
_, err = rand.Read(key) _, err = rand.Read(key)
if err != nil { if err != nil {
// handle error here log.Fatal(fmt.Errorf("error generating key: %w", err))
} }
keySetErr := keyring.Set("ente-cli-cli", "ghost", string(key)) secret = string(key)
keySetErr := keyring.Set("ente-cli-cli", "ghost", string(secret))
if keySetErr != nil { if keySetErr != nil {
log.Fatal(fmt.Errorf("error setting password in keyring: %w", keySetErr)) log.Fatal(fmt.Errorf("error setting password in keyring: %w", keySetErr))
} }
secret = string(key)
} }
return []byte(secret) return []byte(secret)
} }