-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathdb.go
More file actions
53 lines (50 loc) · 1003 Bytes
/
db.go
File metadata and controls
53 lines (50 loc) · 1003 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"os"
"path"
"github.com/adrg/xdg"
)
func (a *App) initFile(fileName, t string) {
folderName := "restmate"
folderPath := path.Join(xdg.DataHome, folderName)
filePath := path.Join(folderPath, fileName)
writeStr := `[]`
if t == "db" {
a.db = filePath
}
if t == "env" {
a.env = filePath
}
if t == "jar" {
a.jarFile = filePath
}
if t == "settings" {
a.settings = filePath
writeStr = `{"theme": ""}`
}
if t == "session" {
a.session = filePath
}
if _, err := os.Stat(filePath); err == nil {
return
} else if !os.IsNotExist(err) {
fmt.Println("Error checking settings file:", err)
return
}
if err := os.MkdirAll(folderPath, 0755); err != nil {
fmt.Println("Error creating folder:", err)
return
}
file, err := os.Create(filePath)
if err != nil {
fmt.Println("Error creating file:", err)
return
}
defer file.Close()
_, err = file.WriteString(writeStr)
if err != nil {
fmt.Println("Error writing to file:", err)
return
}
}