summaryrefslogtreecommitdiff
path: root/paste
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2017-07-03 13:41:00 +0100
committerKatolaZ <katolaz@freaknet.org>2017-07-03 13:41:00 +0100
commit13c5a2ab438f2496370ef10e7df8096e30962b66 (patch)
tree0fdcd94c670000663f776c583f36f4be046377bf /paste
parent8f5b41695d0f2b291b4ce3e26ee24c5f26e04cfb (diff)
paste.Retrieve(). Small changes to the template
Diffstat (limited to 'paste')
-rw-r--r--paste/paste.go25
1 files changed, 23 insertions, 2 deletions
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
+}
+