summaryrefslogtreecommitdiff
path: root/links.go
diff options
context:
space:
mode:
Diffstat (limited to 'links.go')
-rw-r--r--links.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/links.go b/links.go
new file mode 100644
index 0000000..f7bda76
--- /dev/null
+++ b/links.go
@@ -0,0 +1,34 @@
+package main
+
+import (
+ "bufio"
+ "html/template"
+ "log"
+ "os"
+ "strings"
+)
+
+type Link struct {
+ Title string
+ URL template.URL
+}
+
+func GetLinks() (links []Link) {
+ fh, err := os.Open(os.ExpandEnv("$HOME/.startpage-urls"))
+ if err != nil {
+ log.Printf("Couldn't read links: %s", err)
+ return
+ }
+ defer fh.Close()
+
+ scanner := bufio.NewScanner(fh)
+ for scanner.Scan() {
+ parts := strings.SplitN(scanner.Text(), "->", 2)
+ links = append(links, Link{
+ strings.TrimSpace(parts[0]),
+ template.URL(strings.TrimSpace(parts[1])),
+ })
+ }
+
+ return
+}