-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (31 loc) · 762 Bytes
/
main.go
File metadata and controls
42 lines (31 loc) · 762 Bytes
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
package main
import (
"context"
"net"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/armagad/liblib/books"
"github.com/armagad/liblib/search"
)
var gob_filename = "library.dev.gob"
var port = ":4040"
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
// inv := inventory.NewService()
// img := image.NewService()
api := books.NewApi("books", gob_filename, []books.DecoratorService{})
defer api.Close()
mux := http.NewServeMux()
mux.HandleFunc(api.CollectionRoot, api.Handler)
mux.HandleFunc("/search/", search.HandleHttp())
srv := http.Server{Handler: mux, Addr: port}
l, _ := net.Listen("tcp", port)
defer l.Close()
go srv.Serve(l)
<-c
srv.Shutdown(context.Background())
println()
}