-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhandlers.go
80 lines (59 loc) · 1.61 KB
/
handlers.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"log"
"net"
"net/http"
"strconv"
"time"
)
func (s *server) handlePlainGet() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Print("handling new request")
repo, branch, files, err := parseGetRequest(r, s.param.proxy.FileMatching)
if err != nil {
log.Print(err)
log.Print("aborting request handling")
w.WriteHeader(http.StatusBadRequest)
return
}
if err := s.processMatching(repo, branch, files); err != nil {
log.Print(err)
http.NotFound(w, r)
return
}
w.WriteHeader(http.StatusOK)
log.Print("handling of request finished")
}
}
func (s *server) handleJSONPost() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Print("handling new request")
repos, branch, files, err := parseJSONRequest(r, s.param.proxy.FileMatching)
if err != nil {
log.Print(err)
log.Print("aborting request handling")
w.WriteHeader(http.StatusBadRequest)
return
}
for _, repo := range repos {
if err := s.processMatching(repo, branch, files); err != nil {
log.Print(err)
}
}
w.WriteHeader(http.StatusOK)
log.Print("handling of request finished")
}
}
func (s *server) handleReadiness() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if len(s.mappingHash) == 0 {
w.WriteHeader(http.StatusInternalServerError)
}
conn, _ := net.DialTimeout("tcp", net.JoinHostPort("", strconv.Itoa(s.param.proxy.port)), time.Millisecond*time.Duration(100))
if conn == nil {
w.WriteHeader(http.StatusInternalServerError)
}
conn.Close()
w.WriteHeader(http.StatusOK)
}
}