/
smartimages.go
46 lines (40 loc) · 1.25 KB
/
smartimages.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
package main
import (
"fmt"
"net/http"
"github.com/gorilla/pat"
"github.com/prasmussen/smartimages/config"
"github.com/prasmussen/smartimages/handler"
"github.com/prasmussen/smartimages/image"
"github.com/prasmussen/smartimages/log"
)
func main() {
// Load config file
cfg, err := config.Load()
if err != nil {
fmt.Println(err)
return
}
// Instantiate logger
logger, err := log.New(cfg.LogFile)
if err != nil {
fmt.Println(err)
return
}
pool := image.NewImagePool(cfg.ImageDir)
handlers := handler.New(pool, logger)
router := pat.New()
router.Get("/images/{uuid}/file", handlers.GetImageFile())
router.Get("/images/{uuid}", handlers.GetImage())
router.Get("/images", handlers.ListImages())
router.Delete("/images/{uuid}", handlers.DeleteImage())
router.Post("/images/{uuid}", handlers.ImageAction())
router.Post("/images", handlers.CreateImage())
router.Put("/images/{uuid}/file", handlers.AddImageFile())
router.Get("/ping", handlers.Ping())
http.Handle("/", router)
fmt.Printf("Listening for http connections on %s\n", cfg.Listen)
if err := http.ListenAndServe(cfg.Listen, nil); err != nil {
fmt.Println(err)
}
}