-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
34 lines (27 loc) · 858 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main
import (
"flag"
"fmt"
"log"
libhttp "net/http"
"photosplatter/assets"
"photosplatter/gallery"
"photosplatter/http"
)
var path = flag.String("path", "", "path to the directory containing images")
var port = flag.Int("port", 8080, "http port")
func main() {
flag.Parse()
gal, err := gallery.NewDiskBacked(*path)
if err != nil {
log.Fatalf(err.Error())
}
go gal.ScanForChanges()
mux := libhttp.NewServeMux()
mux.Handle("/images/", libhttp.StripPrefix("/images/", libhttp.FileServer(libhttp.Dir(*path))))
mux.Handle("/assets/", libhttp.StripPrefix("/assets/", libhttp.FileServer(libhttp.FS(assets.Assets))))
mux.HandleFunc("/", http.Index)
mux.HandleFunc("/api/photos", http.AllPhotos(&gal))
fmt.Printf("Listening on http://0.0.0.0:%d\n", *port)
log.Fatal(libhttp.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", *port), mux))
}