-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
35 lines (31 loc) · 858 Bytes
/
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
package main
import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
webhook "application-standards-validating-merge-security/pkg/webhook"
)
const (
tlsKeyName = "tls.key"
tlsCertName = "tls.crt"
)
func HealthCheck(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Health Check is OK...")
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/validate", webhook.Validate)
mux.HandleFunc("/mutate", webhook.Mutate)
mux.HandleFunc("/health", HealthCheck)
if certDir := os.Getenv("CERT_DIR"); certDir != "" {
certFile := filepath.Join(certDir, tlsCertName)
keyFile := filepath.Join(certDir, tlsKeyName)
log.Println("serving https on 0.0.0.0:8000")
log.Fatal(http.ListenAndServeTLS(":8000", certFile, keyFile, mux))
} else {
log.Println("serving http on 0.0.0.0:8000")
log.Fatal(http.ListenAndServe(":8000", mux))
}
}