diff options
author | Kevin Chabowski <kevin@kch42.de> | 2014-05-01 14:22:15 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2014-05-01 14:33:15 +0200 |
commit | 500af457c12a8c11c4b32301f6ab324248c4ccaa (patch) | |
tree | fdb4c474e6cc0e8717cee4edac875faefdb0f1f6 /links.go | |
parent | ac3aafafeef06bc38d1b980807786e2558edb2cb (diff) | |
download | startpage-500af457c12a8c11c4b32301f6ab324248c4ccaa.tar.gz startpage-500af457c12a8c11c4b32301f6ab324248c4ccaa.tar.bz2 startpage-500af457c12a8c11c4b32301f6ab324248c4ccaa.zip |
Introduced new config file format
Diffstat (limited to 'links.go')
-rw-r--r-- | links.go | 26 |
1 files changed, 7 insertions, 19 deletions
@@ -1,11 +1,8 @@ package main import ( - "bufio" + "errors" "html/template" - "log" - "os" - "strings" ) type Link struct { @@ -13,22 +10,13 @@ type Link struct { 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() +var links = []Link{} - 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])), - }) +func addLinkCmd(params []string) error { + if len(params) != 2 { + return errors.New("add-link needs 2 parameters: title url") } - return + links = append(links, Link{params[0], template.URL(params[1])}) + return nil } |