-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapplication.go
72 lines (52 loc) · 1.44 KB
/
application.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
type Application struct {
application string
loginName string
login string
password string
comment string
}
func (a Application) toCSV(delimiter string) string {
return "Applications" + delimiter + a.application + delimiter + delimiter + a.login + delimiter + a.password + "\n"
}
func readApps(scanner *bufio.Scanner) []Application {
var appRet []Application // list of websites to be returned
for scanner.Scan() {
text := scanner.Text()
if text == "Notes" {
return appRet
}
if text == "" || text == "---" {
continue
}
app := Application{}
app.application = text[strings.Index(text, ":")+2:]
readLine(scanner, &text)
app.loginName = text[strings.Index(text, ":")+2:]
readLine(scanner, &text)
app.login = text[strings.Index(text, ":")+2:]
readLine(scanner, &text)
app.password = text[strings.Index(text, ":")+2:]
readLine(scanner, &text)
app.comment = text[strings.Index(text, ":")+2:]
// append the website to the list of websites
appRet = append(appRet, app)
}
return appRet
}
func addAppsToFile(apps []Application, delimiter string, needChange *[]toChange, outputFile *os.File) {
for _, a := range apps {
if strings.Contains(a.password, delimiter) {
*needChange = append(*needChange, toChange{a.application, ""})
continue
}
outputFile.WriteString(a.toCSV(delimiter))
}
fmt.Println("Apps added to", outputFile.Name())
}