-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
69 lines (54 loc) · 1.63 KB
/
web.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"flag"
"net/http"
"os"
"os/signal"
"github.com/golang/glog"
)
var (
qdrantAddr = flag.String("qdrant-addr", "qdrant:6334",
"The address of the qdrant server to connect to.")
qdrantColl = flag.String("qdrant-coll", "photos",
"The name of the qdrant collection to use.")
embeddingsServiceBaseUrl = flag.String("mbed", "http://localhost:8082/",
"The base address of the service calculating embeddings for queries.")
photosRootDir = flag.String("photos", "",
"The root directory where the photos are located.")
)
func main() {
flag.Parse()
glog.Infof("Trying to connect to qdrant at '%s', using collection '%s' ...",
*qdrantAddr, *qdrantColl)
// TODO: validate flags
srv, err := newServerContext(*qdrantAddr,
*qdrantColl,
*embeddingsServiceBaseUrl,
*photosRootDir)
if nil != err {
glog.Exitf("Failed to connect to qdrant collection: %v", err)
}
defer srv.conn.Close()
publicSrv := NewPublicServer(srv)
internalSrv := NewInternalServer(srv)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Kill, os.Interrupt)
glog.Infof("Running public HTTP server at '%s' ...", publicSrv.Addr)
go serveHTTP(publicSrv)
glog.Infof("Running internal HTTP server at '%s' ...", internalSrv.Addr)
go serveHTTP(internalSrv)
defer internalSrv.Close()
defer publicSrv.Close()
s := <-c
glog.V(0).Info("Got signal:", s)
}
func serveHTTP(server *http.Server) {
if err := server.ListenAndServe(); nil != err {
if errors.Is(err, http.ErrServerClosed) {
glog.Infof("Server at '%s' successfully shut down.", server.Addr)
return
}
glog.Exitf("Failed to listen at '%s': %v", server.Addr, err)
}
}