-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (47 loc) · 1.27 KB
/
Copy pathmain.go
File metadata and controls
58 lines (47 loc) · 1.27 KB
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
package main
import (
"log"
"net/http"
"os"
"securityscan/api"
"securityscan/config"
)
func main() {
log.SetOutput(os.Stdout)
cfg := config.LoadConfig("main")
// init the db
cfg.InitDatabaseConfig("main")
defer config.CloseDB()
// register endpoints
// TODO: Check if i need to return if endpoint method is not POST
log.Println("Registering endpoints")
http.HandleFunc("/scan", func(w http.ResponseWriter, r *http.Request) {
log.Println("Request received at /scan")
w.Header().Set("Content-Type", "application/json")
if r.Method == http.MethodPost {
api.ScanHandler(w, r)
} else {
http.Error(w, "Invalid request method, only POST method allowed.", http.StatusMethodNotAllowed)
return
}
})
http.HandleFunc("/query", func(w http.ResponseWriter, r *http.Request) {
log.Println("Request received at /query")
if r.Method == http.MethodPost {
api.QueryHandler(w, r)
} else {
http.Error(w, "Invalid request method, only POST method allowed.", http.StatusMethodNotAllowed)
return
}
})
// manage server
server := &http.Server{
Addr: "0.0.0.0:8080",
Handler: nil,
}
log.Println("Server started on port 8080")
// TODO: should this be made HTTPS?
if err := server.ListenAndServe(); err != nil {
log.Fatalf("Server Error: %v", err)
}
}