-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (32 loc) · 772 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
package main
import (
"fmt"
"net/http"
log "github.com/sirupsen/logrus"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {
page := r.URL.Path[1:]
data, ok := r.URL.Query()["data"]
if !ok {
data = []string{"no data received"}
}
log.WithFields(log.Fields{
"page": page,
"data": data,
}).Info("new request received")
}
func main() {
f, err := os.OpenFile("/var/log/xss.json", os.O_APPEND | os.O_CREATE | os.O_RDWR, 0666)
if err != nil {
fmt.Printf("error opening log file: %v", err)
}
defer f.Close()
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(f)
log.SetLevel(log.DebugLevel)
http.HandleFunc("/", handler)
fmt.Print("application started")
log.Info("application started")
log.Fatal(http.ListenAndServe(":80", nil))
}