From d25cb0b579122362a6759e981d1cf9f6458e9959 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sun, 2 Mar 2014 15:48:54 +0100 Subject: Initial commit --- links.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 links.go (limited to 'links.go') 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 +} -- cgit v1.2.3-54-g00ecf