-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
60 lines (51 loc) · 1.37 KB
/
main.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
package main
import (
"context"
"crypto/tls"
"flag"
"fmt"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/golang/glog"
"github.com/gorilla/mux"
)
const (
port = "8080"
)
var (
tlscert, tlskey string
)
func main() {
flag.StringVar(&tlscert, "tlsCertFile", "certs/ca.crt", "File containing the x509 Certificate for HTTPS.")
flag.StringVar(&tlskey, "tlsKeyFile", "certs/ca.key", "File containing the x509 private key to --tlsCertFile.")
flag.Parse()
certs, err := tls.LoadX509KeyPair(tlscert, tlskey)
if err != nil {
glog.Errorf("Filed to load key pair: %v", err)
}
server := &http.Server{
Addr: fmt.Sprintf(":%v", port),
TLSConfig: &tls.Config{Certificates: []tls.Certificate{certs}},
}
cs := CasbinServerHandler{}
router := mux.NewRouter()
router.HandleFunc("/validate", cs.serve)
if err := server.ListenAndServeTLS("", ""); err != nil {
glog.Error("Server error", err)
}
go func() {
if err := server.ListenAndServeTLS("", ""); err != nil {
glog.Errorf("Failed to listen and serve webhook server: %v", err)
}
}()
glog.Info("Server running listening in port: ", port)
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
<-signalChan
glog.Info("Shutting down webhook server...")
if err := server.Shutdown(context.Background()); err != nil {
glog.Error("Unable to shutdown the server", err)
}
}