Skip to content

Commit c0f593d

Browse files
authored
refactor: Remove redundant local vars in examples (#3303)
1 parent 54eecb8 commit c0f593d

File tree

7 files changed

+10
-17
lines changed

7 files changed

+10
-17
lines changed

example/basicauth/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ func main() {
3131
username, _ := r.ReadString('\n')
3232

3333
fmt.Print("GitHub Password: ")
34-
bytePassword, _ := term.ReadPassword(int(os.Stdin.Fd()))
35-
password := string(bytePassword)
34+
password, _ := term.ReadPassword(int(os.Stdin.Fd()))
3635

3736
tp := github.BasicAuthTransport{
3837
Username: strings.TrimSpace(username),
39-
Password: strings.TrimSpace(password),
38+
Password: strings.TrimSpace(string(password)),
4039
}
4140

4241
client := github.NewClient(tp.Client())

example/codespaces/newreposecretwithxcrypto/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,
147147

148148
var boxKey [32]byte
149149
copy(boxKey[:], decodedPublicKey)
150-
secretBytes := []byte(secretValue)
151-
encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader)
150+
encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader)
152151
if err != nil {
153152
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
154153
}

example/codespaces/newusersecretwithxcrypto/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,
154154

155155
var boxKey [32]byte
156156
copy(boxKey[:], decodedPublicKey)
157-
secretBytes := []byte(secretValue)
158-
encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader)
157+
encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader)
159158
if err != nil {
160159
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
161160
}

example/newreposecretwithlibsodium/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,
142142
return nil, fmt.Errorf("base64.StdEncoding.DecodeString was unable to decode public key: %v", err)
143143
}
144144

145-
secretBytes := []byte(secretValue)
146-
encryptedBytes, exit := sodium.CryptoBoxSeal(secretBytes, decodedPublicKey)
145+
encryptedBytes, exit := sodium.CryptoBoxSeal([]byte(secretValue), decodedPublicKey)
147146
if exit != 0 {
148147
return nil, errors.New("sodium.CryptoBoxSeal exited with non zero exit code")
149148
}

example/newreposecretwithxcrypto/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string,
147147

148148
var boxKey [32]byte
149149
copy(boxKey[:], decodedPublicKey)
150-
secretBytes := []byte(secretValue)
151-
encryptedBytes, err := box.SealAnonymous([]byte{}, secretBytes, &boxKey, crypto_rand.Reader)
150+
encryptedBytes, err := box.SealAnonymous([]byte{}, []byte(secretValue), &boxKey, crypto_rand.Reader)
152151
if err != nil {
153152
return nil, fmt.Errorf("box.SealAnonymous failed with error %w", err)
154153
}

example/tagprotection/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ func main() {
3838
pattern = strings.TrimSpace(pattern)
3939

4040
fmt.Print("GitHub Token: ")
41-
byteToken, _ := term.ReadPassword(int(os.Stdin.Fd()))
41+
token, _ := term.ReadPassword(int(os.Stdin.Fd()))
4242
println()
43-
token := string(byteToken)
4443

4544
ctx := context.Background()
46-
client := github.NewClient(nil).WithAuthToken(token)
45+
client := github.NewClient(nil).WithAuthToken(string(token))
4746

4847
// create new tag protection
4948
if pattern != "" {

example/tokenauth/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ import (
2121

2222
func main() {
2323
fmt.Print("GitHub Token: ")
24-
byteToken, _ := term.ReadPassword(int(os.Stdin.Fd()))
24+
token, _ := term.ReadPassword(int(os.Stdin.Fd()))
2525
println()
26-
token := string(byteToken)
2726

2827
ctx := context.Background()
29-
client := github.NewClient(nil).WithAuthToken(token)
28+
client := github.NewClient(nil).WithAuthToken(string(token))
3029

3130
user, resp, err := client.Users.Get(ctx, "")
3231
if err != nil {

0 commit comments

Comments
 (0)