-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathremove_api.go
47 lines (40 loc) · 981 Bytes
/
remove_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"os"
"strings"
)
// remove API key
func removeAPIKey() {
fmt.Println("Are you sure you want to remove your API key? (y/n):")
var confirmation string
fmt.Scanln(&confirmation)
if strings.ToLower(confirmation) == "y" {
fileInfo, err := os.Stat(apiKeyFile)
if err != nil {
fmt.Printf("Error getting API key file info: %v\n", err)
return
}
file, err := os.OpenFile(apiKeyFile, os.O_WRONLY, 0644)
if err != nil {
fmt.Printf("Error opening API key file: %v\n", err)
return
}
zeroBytes := make([]byte, fileInfo.Size())
_, err = file.Write(zeroBytes)
if err != nil {
fmt.Printf("Error overwriting API key file with zeroes: %v\n", err)
return
}
file.Close()
err = os.Remove(apiKeyFile)
if err != nil {
fmt.Printf("Error removing API key file: %v\n", err)
} else {
fmt.Println("API key removed successfully. Exiting...")
os.Exit(0)
}
} else {
fmt.Println("API key removal canceled.")
}
}