package main import ( "html/template" "io/ioutil" "log" "net/http" "strings" // "fmt" ) // var t = template.Must(template.ParseFiles("tmpl/layouts/base.html", "tmpl/index.html", "tmpl/blog.html", "tmpl/about.html", "tmpl/contact.html", )) func main() { http.HandleFunc("/", handleIndex) http.HandleFunc("/blog", handleBlog) http.HandleFunc("/about", handleAbout) http.HandleFunc("/contact", handleContact) http.Handle("/inc/", http.StripPrefix("/inc/", http.FileServer(http.Dir("inc")))) log.Fatalln(http.ListenAndServe(":8080", nil)) } type Picture struct { Name string Author string Size string Tools string Date string Price float32 Desc string BlogLink string } type Exhibition struct { Pics []Picture } func handleIndex(w http.ResponseWriter, r *http.Request) { var exhibit Exhibition exhibit.parsePictures("./inc/images") t, _ := template.ParseFiles("tmpl/layouts/index.html", "tmpl/gallery.html", "tmpl/header.html") t.Execute(w, exhibit) } func handleBlog(w http.ResponseWriter, r *http.Request) { t, _ := template.ParseFiles("tmpl/layouts/base.html", "tmpl/soon.html", "tmpl/header.html") t.Execute(w, nil) } func handleAbout(w http.ResponseWriter, r *http.Request) { t, _ := template.ParseFiles("tmpl/layouts/base.html", "tmpl/soon.html", "tmpl/header.html") t.Execute(w, nil) } func handleContact(w http.ResponseWriter, r *http.Request) { t, _ := template.ParseFiles("tmpl/layouts/base.html", "tmpl/soon.html", "tmpl/header.html") t.Execute(w, nil) } func (ex *Exhibition) parsePictures(dir string) { files, err := ioutil.ReadDir(dir) if err != nil { log.Fatal(err) } for _, f := range files { if !f.IsDir() { ex.Pics = append(ex.Pics, Picture{Name: strings.TrimSuffix(f.Name(), ".jpg")}) } } }