-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
60 lines (54 loc) · 1.13 KB
/
main.go
File metadata and controls
60 lines (54 loc) · 1.13 KB
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
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"context"
"io/ioutil"
"log"
"net/http"
"os"
"os/signal"
"strings"
"time"
)
func init() {
}
func imageHandler(wr http.ResponseWriter, r *http.Request) {
wr.Header().Set("Access-Control-Allow-Origin", acao)
switch r.RequestURI {
case "/single-image":
sharedImageHandler(wr, r)
case "/batch-images":
sharedBatchImageHandler(wr, r)
case "/delete-file":
deleteFileHandler(wr, r)
}
}
func defTables() {
b, e := ioutil.ReadFile(strings.Join([]string{"sql", "definition.sql"}, "/"))
if e != nil {
log.Println(e.Error())
os.Exit(1)
}
if _, e = db.Exec(string(b)); e != nil {
log.Println(e.Error())
}
}
func main() {
defTables()
//goconfig.Read(&config)
//log15.Debug("Parsed configuration", "config", config)
iSig := make(chan os.Signal, 1)
signal.Notify(iSig, os.Interrupt)
s3Client = s3Init()
s := http.Server{Addr: config.Server.Listen, Handler: http.HandlerFunc(imageHandler)}
go func() {
s.ListenAndServe()
}()
<-iSig
ctx, cc := context.WithTimeout(context.TODO(), time.Second*30)
defer cc()
log.Println("Shutdown called.")
if e := s.Shutdown(ctx); e != nil {
os.Exit(1)
}
os.Exit(0)
}