Ejemplo n.º 1
0
func articleHandler(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	id := vars["id"]
	article, _ := db.GetEntryByArticleID(id)
	c := template.HTML(article.Content)
	p := &Article{Article: article, Content: c}
	path, _ := utils.GetPath()
	t := template.Must(template.New("article.tmpl").ParseFiles(path + "/layouts/article.tmpl"))
	t.Execute(w, p)
}
Ejemplo n.º 2
0
// SyncImage, returns hasImage, isPortrait and error
func SyncImage(url string, uniquefilename string) (bool, bool, error) {
	hasimage := false
	if len(url) == 0 {
		return hasimage, true, nil
	}
	sizes := []string{"128", "512", "1024"}
	path, err := utils.GetPath()
	if err != nil {
		return hasimage, true, err
	}
	path += "/images/"
	os.Mkdir(path, os.ModePerm)
	filename := getFilename(url)
	picture, err := downloadPicture(path, filename, url)
	if err != nil {
		return hasimage, true, err
	}
	hasimage = true
	img := picture.Bounds()
	height := img.Dy()
	width := img.Dx()
	portrait := true
	if height < width {
		portrait = false
	}
	for _, size := range sizes {
		err = resizeImage(path, filename, uniquefilename, size)
		if err != nil {
			return hasimage, portrait, err
		}
	}
	err = os.Remove(path + filename)
	if err != nil {
		return hasimage, portrait, err
	}
	return hasimage, portrait, nil
}