forked from campoy/justforfunc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
36 lines (29 loc) · 765 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
package main
import (
"encoding/json"
"fmt"
"net/http"
"sync"
"github.com/sirupsen/logrus"
)
func main() {
http.HandleFunc("/", handle)
logrus.Fatal(http.ListenAndServe(":8080", nil))
}
var prPool = sync.Pool{
New: func() interface{} { return new(pullRequest) },
}
type pullRequest struct {
PullRequest struct{ ID int } `json:"pull_request"`
}
func handle(w http.ResponseWriter, r *http.Request) {
data := prPool.Get().(*pullRequest)
defer prPool.Put(data)
data.PullRequest.ID = 0
if err := json.NewDecoder(r.Body).Decode(data); err != nil {
logrus.Errorf("could not decode request: %v", err)
http.Error(w, "could not decode request", http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "pull request id: %d", data.PullRequest.ID)
}