-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.go
More file actions
49 lines (40 loc) · 824 Bytes
/
Copy pathparser.go
File metadata and controls
49 lines (40 loc) · 824 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
package parser
import (
"fmt"
"os"
"strings"
)
// IsLocal - Check if a link is foreign or local
func IsLocal(link string, domain string) bool {
if link[0] == '/' {
return true
}
if strings.Contains(link, "://"+domain) {
return true
}
return false
}
// AppendToFile - Append a url to the file
func AppendToFile(url string) {
f, err := os.OpenFile("data.txt", os.O_APPEND|os.O_WRONLY, 0666)
if err != nil {
fmt.Println(err)
}
n, nerr := f.WriteString(url + "\n")
if nerr != nil {
fmt.Println(nerr)
fmt.Println(n)
}
f.Close()
}
// SetupFile - Setup our data output file if it's missing
func SetupFile() {
if _, err := os.Stat("data.txt"); os.IsNotExist(err) {
f, ferr := os.Create("data.txt")
if ferr != nil {
fmt.Println(ferr)
}
fmt.Println("Data File Created!")
f.Close()
}
}