-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpHandle.go
More file actions
42 lines (34 loc) · 732 Bytes
/
httpHandle.go
File metadata and controls
42 lines (34 loc) · 732 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
37
38
39
40
41
42
package main
import (
"fmt"
"net/http"
log "github.com/sirupsen/logrus"
)
func route(pattern string,
payload interface{},
handler func(Hook) bool) {
log.Printf(pattern)
http.HandleFunc(pattern, func(w http.ResponseWriter, req *http.Request) {
defer req.Body.Close()
err := unmarshal(req.Body, &payload)
if err != nil {
fmt.Fprintf(w, something)
return
}
loadConfig()
msg := ""
for _, hook := range config.Hooks {
if handler(hook) {
msg = fmt.Sprintf(executed, hook.Repo, hook.Branch)
log.Infof("success: %s\n", msg)
msg += "`" + hook.Shell + "`"
executeShell(hook.Shell)
}
}
if len(msg) < 1 {
log.Info(nothingToDo)
msg = nothingToDo
}
fmt.Fprintf(w, msg)
})
}