work on /add - start fetching and trying to parse ?url=
This commit is contained in:
parent
fe41cc2405
commit
5f5e69a298
|
@ -7,6 +7,8 @@ import (
|
||||||
"github.com/dballard/transmet/user"
|
"github.com/dballard/transmet/user"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
"io/ioutil"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetFlashes(session *sessions.Session) map[string]interface{} {
|
func GetFlashes(session *sessions.Session) map[string]interface{} {
|
||||||
|
@ -53,8 +55,8 @@ func getPostHandler(getFn, postFn func(http.ResponseWriter, *http.Request)) func
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowTemplate(template string, w http.ResponseWriter, r *http.Request, user *user.User) {
|
func ShowTemplate(template string, w http.ResponseWriter, data map[string]interface{}) {
|
||||||
err := templates[template].Execute(w, map[string]interface{}{"user": user})
|
err := templates[template].Execute(w, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Exec err: ", err)
|
fmt.Println("Exec err: ", err)
|
||||||
}
|
}
|
||||||
|
@ -66,10 +68,8 @@ func LoginFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
session, _ := store.Get(r, "c_user")
|
session, _ := store.Get(r, "c_user")
|
||||||
flashes := GetFlashes(session)
|
flashes := GetFlashes(session)
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
err := templates["login"].Execute(w, map[string]interface{}{"flashes": flashes})
|
|
||||||
if err != nil {
|
ShowTemplate("login", w, map[string]interface{}{"flashes": flashes})
|
||||||
fmt.Println("Exec err: ", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// handler for login POST
|
// handler for login POST
|
||||||
|
@ -101,7 +101,22 @@ func LoginPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// ?url=
|
// ?url=
|
||||||
func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
func addFormHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
ShowTemplate("add", w, r, user)
|
var url = r.URL.Query().Get("url")
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error looking up link", url, ":", err)
|
||||||
|
} else {
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error reading link", url, ":", err)
|
||||||
|
} else {
|
||||||
|
re := regexp.MustCompile("< *[Tt][Ii][Tt][Ll][Ee] *>(.*)< *[Tt][Ii][Tt][Ll][Ee] *>")
|
||||||
|
title := re.FindStringSubmatch(string(body))
|
||||||
|
fmt.Println(title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ShowTemplate("add", w, map[string]interface{}{"user": user, "link": url})
|
||||||
}
|
}
|
||||||
|
|
||||||
func addPostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
func addPostHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{{template "flashes" .}}
|
{{template "flashes" .}}
|
||||||
<form class="form-add" action="/add" method="post" role="form" class="container col-form">
|
<form class="form-add" action="/add" method="post" role="form" class="container col-form">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-2">Link:</div><div class="col-xs-10"><input type="text" class="form-control" name="link" placeholder="Link"/></div>
|
<div class="col-xs-2">Link:</div><div class="col-xs-10"><input type="text" class="form-control" name="link" placeholder="Link" value="{{.link}}"/></div>
|
||||||
<div class="col-xs-2">Title:</div><div class="col-xs-10"><input type="text" class="form-control" name="title" placeholder="Title"/></div>
|
<div class="col-xs-2">Title:</div><div class="col-xs-10"><input type="text" class="form-control" name="title" placeholder="Title"/></div>
|
||||||
<div class="col-xs-2">Path:</div><div class="col-xs-10"><input type="text" class="form-control" name="path" placeholder="Path"/></div>
|
<div class="col-xs-2">Path:</div><div class="col-xs-10"><input type="text" class="form-control" name="path" placeholder="Path"/></div>
|
||||||
<div class="col-xs-2">Description:</div><div class="col-xs-10"><textarea class="form-control" name="description" placeholder="Description" rows="3" cols="80">{{.task.Description}}</textarea></div>
|
<div class="col-xs-2">Description:</div><div class="col-xs-10"><textarea class="form-control" name="description" placeholder="Description" rows="3" cols="80">{{.task.Description}}</textarea></div>
|
||||||
|
@ -11,4 +11,4 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
{{end}}
|
{{end}}
|
Loading…
Reference in New Issue