-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (37 loc) · 856 Bytes
/
Copy pathmain.go
File metadata and controls
42 lines (37 loc) · 856 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 (
"flag"
"os"
"os/signal"
"syscall"
"github.com/roceb/gedis/client"
"github.com/roceb/gedis/server"
)
var (
cli *client.Client
srv *server.Server
)
func main() {
// creates chan to reviece stop signal
stop := make(chan os.Signal, 1)
// registers the given channel to receive notifications of the specified signals.
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
// adds -cli flag and sets it to false
args := flag.Bool("cli", false, "To activate client")
// parse for -cli flag
flag.Parse()
// checks if cli is true to start cli, if false starts server
switch *args {
case true:
cli = client.NewClient()
default:
srv = server.NewServer()
}
// send stop signal through chan
// using a select here because I would like to add more chans in future
select {
case <-stop:
cli.Stop()
srv.Stop()
}
}