diff options
author | Kevin Chabowski <kevin@kch42.de> | 2014-03-02 15:48:54 +0100 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2014-03-02 15:48:54 +0100 |
commit | d25cb0b579122362a6759e981d1cf9f6458e9959 (patch) | |
tree | 8f3ce3c8116540864877d15502b2a36ca82ef8a7 /links.go | |
download | startpage-d25cb0b579122362a6759e981d1cf9f6458e9959.tar.gz startpage-d25cb0b579122362a6759e981d1cf9f6458e9959.tar.bz2 startpage-d25cb0b579122362a6759e981d1cf9f6458e9959.zip |
Initial commit
Diffstat (limited to 'links.go')
-rw-r--r-- | links.go | 34 |
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 +} |