-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
49 lines (39 loc) · 871 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"github.com/smancke/gogallery/imglib"
"github.com/smancke/gogallery/service"
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
func main() {
lib := openLib()
s := &http.Server{
Addr: service.Cfg("address"),
Handler: service.Handler(lib)}
go func() {
log.Printf("starting up at %v", service.Cfg("address"))
log.Fatal(s.ListenAndServe())
os.Exit(1)
}()
waitForTermination(func() {
lib.Close()
})
}
func waitForTermination(callback func()) {
sigc := make(chan os.Signal)
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
log.Printf("Got singal '%v' .. exit more or less greacefully now", <-sigc)
callback()
log.Printf("Done.")
os.Exit(0)
}
func openLib() *imglib.ImageLibrary {
db := &imglib.ImageLibrary{}
if err := db.Open(service.Cfg("galleryDir")); err != nil {
log.Fatal(err.Error())
}
return db
}