You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.5 KiB
73 lines
1.5 KiB
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.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.TrimSuffix(f.Name(), ".jpg")})
|
|
}
|
|
}
|
|
}
|