-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
36 lines (29 loc) · 785 Bytes
/
main.go
File metadata and controls
36 lines (29 loc) · 785 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
package main
import (
"context"
"net"
"github.com/szykol/http/pkg/http"
"github.com/szykol/http/pkg/log"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logger := log.NewLogger(log.NewZapCfg())
ctx = log.WithContext(ctx, logger)
listener, err := net.Listen("tcp", "0.0.0.0:1337")
if err != nil {
panic(err)
}
server := http.NewServer()
server.AddHandler("POST", "/echo", func(w http.ResponseWriter, r *http.Request) {
if _, err := w.Write(r.Payload); err != nil {
logger.Errorw("error handling request", "error", err)
return
}
logger.Debugw("Successfully written data")
})
server.AddHandler("GET", "/test", func(w http.ResponseWriter, r *http.Request) {
_ = w.SetStatus(200)
})
server.Run(ctx, listener)
}