Beispiel #1
0
func newLink(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	pbr, _ := util.GetPubber(c)
	switch r.Method {
	case "POST":
		url := r.FormValue("url")
		linkId := util.ShortenLink(c, url)
		link := util.Link{
			Short:   linkId,
			Created: time.Now(),
			URL:     url,
			Data:    util.LinkData{},
		}
		l, err := link.Save(c)
		if err != nil {
			c.Infof("NewLink Error: %v\n", err)
		}
		if pbr.Email != "" { // TODO: Change to be list of link-keys
			pbr.Links = append(pbr.Links, *l)
			pbr.Save(c)
		}
		c.Infof("Link: %v\n", link)
		fwdUrl := fmt.Sprintf("/link/%s", l.Short)
		http.Redirect(w, r, fwdUrl, http.StatusFound)
		break
	case "GET":
		page := util.Page{Pubber: *pbr}
		buff := renderTemplate(w, "new", page)
		if buff != nil {
			w.Write(buff)
		}
	}
}
Beispiel #2
0
func root(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	pubr, _ := util.GetPubber(c)
	page := util.Page{Pubber: *pubr}
	buff := renderTemplate(w, "index", page)
	if buff != nil {
		w.Write(buff)
	}
}
Beispiel #3
0
func showProfile(w http.ResponseWriter, r *http.Request, c appengine.Context) {
	pbr, _ := util.GetPubber(c)
	/*for _, link := range pbr.Links {
		link.Short = link.Key(c).Encode()
		c.Infof("Encoded: %s\n", link.Key(c).Encode())
	} //Consider Encoding for privacy? */
	page := util.Page{Pubber: *pbr}
	buff := renderTemplate(w, "user", page)
	if buff != nil {
		w.Write(buff)
	}
}
Beispiel #4
0
func linkHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	pbr, _ := util.GetPubber(c)
	vars := mux.Vars(r)
	linkId := vars["link"]
	link := util.GetLink(c, linkId)
	c.Infof("LINK: %v\n", util.EmptyLink)
	page := util.Page{Pubber: *pbr, Content: *link}
	buff := renderTemplate(w, "link", page)
	if buff != nil {
		w.Write(buff)
	}
}