From 13c5a2ab438f2496370ef10e7df8096e30962b66 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 3 Jul 2017 13:41:00 +0100 Subject: paste.Retrieve(). Small changes to the template --- paste/paste.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'paste') diff --git a/paste/paste.go b/paste/paste.go index ce06f6a..a55a3b3 100644 --- a/paste/paste.go +++ b/paste/paste.go @@ -7,6 +7,8 @@ import( "os" "io/ioutil" "errors" + "bufio" + "strings" ) @@ -44,9 +46,28 @@ func Store(title, date, content, dest_dir string) (string, error) { } -//func Retrieve(URI string) (title, date, content string) { +func Retrieve(URI string) (title, date, content string, err error) { + f_cont, err := os.Open(URI) + defer f_cont.Close() -//} + if err == nil { + stuff := bufio.NewScanner(f_cont) + // The first line contains the title + stuff.Scan() + title = strings.Trim(strings.Split(stuff.Text(), ":")[1], " ") + stuff.Scan() + date = strings.Trim(strings.Join(strings.Split(stuff.Text(), ":")[1:], ":"), " ") + for stuff.Scan() { + content += stuff.Text() + } + } else { + + return "", "", "", errors.New("Cannot retrieve paste!!!") + } + + return title, date, content, nil +} + -- cgit v1.2.3