58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
func managerIndexView(w http.ResponseWriter, r * http.Request) {
|
|
var err error
|
|
|
|
defer func() {
|
|
if err != nil {
|
|
errlog.Println(err)
|
|
return500(w,r)
|
|
err = nil
|
|
return
|
|
}
|
|
} ()
|
|
|
|
context := Context{
|
|
Comics: nil,
|
|
Title: "Black Ram Comics Manager",
|
|
}
|
|
|
|
comics, err := allComics()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
for i, comic := range comics {
|
|
context.Comics = append(context.Comics, struct {
|
|
No int
|
|
Title string
|
|
Date string
|
|
Image string
|
|
}{
|
|
Title: comic.Title,
|
|
No: i+1,
|
|
Date: comic.DateTime,
|
|
Image: comic.Image,
|
|
})
|
|
}
|
|
|
|
err = executeTemplate(w, "manager", context)
|
|
}
|
|
|
|
func managerEditView(w http.ResponseWriter, r * http.Request) {
|
|
}
|
|
|
|
func startManager(address string, port int, dbPath string, mediaPath string) error {
|
|
http.HandleFunc("/", managerIndexView)
|
|
http.HandleFunc("/edit/", managerEditView)
|
|
|
|
uri := fmt.Sprintf("%s:%d", address, port)
|
|
log.Println("listening to http://" + uri)
|
|
return http.ListenAndServe(uri, logRequest(http.DefaultServeMux))
|
|
} |