-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
37 lines (28 loc) · 730 Bytes
/
Copy pathutils.go
File metadata and controls
37 lines (28 loc) · 730 Bytes
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
package main
import (
"errors"
"fmt"
"os"
)
var CONF_DIR string
func init() {
home, _ := os.UserHomeDir()
CONF_DIR = fmt.Sprintf("%s/.utok", home)
// Ignore errors: it just means the directory exists..
os.Mkdir(CONF_DIR, 0755)
}
func writeFile(name string, data []byte) error {
return os.WriteFile(fmt.Sprintf("%s/%s", CONF_DIR, name), data, 0600)
}
func readFile(name string) ([]byte, error) {
return os.ReadFile(fmt.Sprintf("%s/%s", CONF_DIR, name))
}
func fileExists(name string) bool {
if _, err := os.Stat(fmt.Sprintf("%s/%s", CONF_DIR, name)); errors.Is(err, os.ErrNotExist) {
return false
}
return true
}
func removeFile(name string) error {
return os.Remove(fmt.Sprintf("%s/%s", CONF_DIR, name))
}