package main import ( "log" "net/http" "html/template" "io/ioutil" "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.Handle("/blog", handleBlog) // http.Handle("/about", handleAbout) // http.Handle("/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") // for _, f := range readPictureNames("inc/thumbs") { // fmt.Printf("%s, ", f) // } t, _ := template.ParseFiles("tmpl/layouts/base.html", "tmpl/index.html", "tmpl/header.html") t.Execute(w, exhibit) } func handleBlog(w http.ResponseWriter, r *http.Request) { } func handleAbout(w http.ResponseWriter, r *http.Request) { } func handleContact(w http.ResponseWriter, r *http.Request) { } 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.Trim(f.Name(), ".jpg")}) } } }