-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
40 lines (30 loc) · 858 Bytes
/
commands.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
package api_server
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/urfave/cli"
)
func ServeAction(cliCtx *cli.Context) error {
dbConnectionString := cliCtx.Args().Get(0)
port := cliCtx.Args().Get(1)
apiServer := new(APIServer)
err := apiServer.Initialize(dbConnectionString, port)
if err != nil {
return err
}
go apiServer.Serve()
log.Printf("Listening on port %s\n", port)
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, syscall.SIGTERM)
signal.Notify(signalChannel, syscall.SIGINT)
<-signalChannel
return nil
}
var ServeCommand = cli.Command{
Name: "serve",
Usage: "Listens for and serves query requests for the indexer on the provided port, using the provided PostgreSQL connection.",
ArgsUsage: "Provide a PostgreSQL connection string, and a port number.",
Action: ServeAction,
}