-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
51 lines (43 loc) · 1015 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"flag"
"fmt"
"log"
"net/http"
)
func main() {
port := flag.Int("port", 1234, "port to listen on")
path := flag.String("path", "/syslog/", "path to listen on")
certPath := flag.String("cert", "", "certificate file")
keyPath := flag.String("key", "", "key file")
flag.Parse()
s := NewServer(*port, *path, *certPath, *keyPath)
s.Start()
}
func NewServer(port int, path, certPath, keyPath string) *server {
mux := http.NewServeMux()
mux.HandleFunc(path, echoHandler)
srv := &http.Server{
Handler: mux,
Addr: fmt.Sprintf(":%d", port),
}
return &server{
certPath: certPath,
keyPath: keyPath,
srv: srv,
}
}
type server struct {
certPath string
keyPath string
srv *http.Server
}
func (s *server) Start() {
log.Fatal(s.srv.ListenAndServeTLS(s.certPath, s.keyPath))
}
func echoHandler(_ http.ResponseWriter, r *http.Request) {
bytes := make([]byte, 1024)
byteCount, _ := r.Body.Read(bytes)
r.Body.Close()
fmt.Printf("%s\n", bytes[:byteCount])
}