From cbdcbef1217315a581e593b4cb51c8ef2ec00767 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 3 Oct 2024 14:08:12 +0300 Subject: [PATCH] refactor: Remove redundant local vars in examples --- example/basicauth/main.go | 5 ++--- example/codespaces/newreposecretwithxcrypto/main.go | 3 +-- example/codespaces/newusersecretwithxcrypto/main.go | 3 +-- example/newreposecretwithlibsodium/main.go | 3 +-- example/newreposecretwithxcrypto/main.go | 3 +-- example/tagprotection/main.go | 5 ++--- example/tokenauth/main.go | 5 ++--- 7 files changed, 10 insertions(+), 17 deletions(-) diff --git a/example/basicauth/main.go b/example/basicauth/main.go index 97bc078ad46..c23f81fc896 100644 --- a/example/basicauth/main.go +++ b/example/basicauth/main.go @@ -31,12 +31,11 @@ func main() { username, _ := r.ReadString('\n') fmt.Print("GitHub Password: ") - bytePassword, _ := term.ReadPassword(int(os.Stdin.Fd())) - password := string(bytePassword) + password, _ := term.ReadPassword(int(os.Stdin.Fd())) tp := github.BasicAuthTransport{ Username: strings.TrimSpace(username), - Password: strings.TrimSpace(password), + Password: strings.TrimSpace(string(password)), } client := github.NewClient(tp.Client()) diff --git a/example/codespaces/newreposecretwithxcrypto/main.go b/example/codespaces/newreposecretwithxcrypto/main.go index f0f7ea53d49..3cef6e8e1c2 100644 --- a/example/codespaces/newreposecretwithxcrypto/main.go +++ b/example/codespaces/newreposecretwithxcrypto/main.go @@ -147,8 +147,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string, var boxKey [32]byte copy(boxKey[:], decodedPublicKey) - secretBytes := []byte(secretValue) - encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader) + encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader) if err != nil { return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err) } diff --git a/example/codespaces/newusersecretwithxcrypto/main.go b/example/codespaces/newusersecretwithxcrypto/main.go index 367d32ac3c9..c25aa794430 100644 --- a/example/codespaces/newusersecretwithxcrypto/main.go +++ b/example/codespaces/newusersecretwithxcrypto/main.go @@ -154,8 +154,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string, var boxKey [32]byte copy(boxKey[:], decodedPublicKey) - secretBytes := []byte(secretValue) - encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader) + encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader) if err != nil { return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err) } diff --git a/example/newreposecretwithlibsodium/main.go b/example/newreposecretwithlibsodium/main.go index 5a5eccdc94f..bc754bdf041 100644 --- a/example/newreposecretwithlibsodium/main.go +++ b/example/newreposecretwithlibsodium/main.go @@ -142,8 +142,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string, return nil, fmt.Errorf("base64.StdEncoding.DecodeString was unable to decode public key: %v", err) } - secretBytes := []byte(secretValue) - encryptedBytes, exit := sodium.CryptoBoxSeal(secretBytes, decodedPublicKey) + encryptedBytes, exit := sodium.CryptoBoxSeal([]byte(secretValue), decodedPublicKey) if exit != 0 { return nil, errors.New("sodium.CryptoBoxSeal exited with non zero exit code") } diff --git a/example/newreposecretwithxcrypto/main.go b/example/newreposecretwithxcrypto/main.go index 5e792d5f608..48f16b1c363 100644 --- a/example/newreposecretwithxcrypto/main.go +++ b/example/newreposecretwithxcrypto/main.go @@ -147,8 +147,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string, var boxKey [32]byte copy(boxKey[:], decodedPublicKey) - secretBytes := []byte(secretValue) - encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader) + encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader) if err != nil { return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err) } diff --git a/example/tagprotection/main.go b/example/tagprotection/main.go index d0fde28a5f1..c66f4f67941 100644 --- a/example/tagprotection/main.go +++ b/example/tagprotection/main.go @@ -38,12 +38,11 @@ func main() { pattern = strings.TrimSpace(pattern) fmt.Print("GitHub Token: ") - byteToken, _ := term.ReadPassword(int(os.Stdin.Fd())) + token, _ := term.ReadPassword(int(os.Stdin.Fd())) println() - token := string(byteToken) ctx := context.Background() - client := github.NewClient(nil).WithAuthToken(token) + client := github.NewClient(nil).WithAuthToken(string(token)) // create new tag protection if pattern != "" { diff --git a/example/tokenauth/main.go b/example/tokenauth/main.go index 25b0f2aaba8..a10dc3bbca4 100644 --- a/example/tokenauth/main.go +++ b/example/tokenauth/main.go @@ -21,12 +21,11 @@ import ( func main() { fmt.Print("GitHub Token: ") - byteToken, _ := term.ReadPassword(int(os.Stdin.Fd())) + token, _ := term.ReadPassword(int(os.Stdin.Fd())) println() - token := string(byteToken) ctx := context.Background() - client := github.NewClient(nil).WithAuthToken(token) + client := github.NewClient(nil).WithAuthToken(string(token)) user, resp, err := client.Users.Get(ctx, "") if err != nil {