summaryrefslogtreecommitdiff
path: root/links.go
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2014-05-01 14:22:15 +0200
committerKevin Chabowski <kevin@kch42.de>2014-05-01 14:33:15 +0200
commit500af457c12a8c11c4b32301f6ab324248c4ccaa (patch)
treefdb4c474e6cc0e8717cee4edac875faefdb0f1f6 /links.go
parentac3aafafeef06bc38d1b980807786e2558edb2cb (diff)
downloadstartpage-500af457c12a8c11c4b32301f6ab324248c4ccaa.tar.gz
startpage-500af457c12a8c11c4b32301f6ab324248c4ccaa.tar.bz2
startpage-500af457c12a8c11c4b32301f6ab324248c4ccaa.zip
Introduced new config file format
Diffstat (limited to 'links.go')
-rw-r--r--links.go26
1 files changed, 7 insertions, 19 deletions
diff --git a/links.go b/links.go
index f7bda76..bd7b624 100644
--- a/links.go
+++ b/links.go
@@ -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
}