-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.go
29 lines (26 loc) · 880 Bytes
/
handler.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
package main
import (
"fmt"
"github.com/satori/go.uuid"
log "github.com/sirupsen/logrus"
"net/http"
)
// HTTPClientTestHandler handles requests
type HTTPClientTestHandler struct {
Service Service
}
// ServeHTTP serves HTTP
func (handler HTTPClientTestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
u1 := uuid.NewV4()
serviceRequest := &ServiceRequest{RequestID: u1.String()}
log.WithField("requestid", serviceRequest.RequestID).Debug("About to do service.Call")
serviceResponse, err := handler.Service.Call(*serviceRequest)
log.WithField("requestid", serviceRequest.RequestID).Debug("Got response from service.Call")
if err != nil {
log.WithField("requestid", serviceRequest.RequestID).Error("Error calling service", err)
w.WriteHeader(500)
return
}
w.Header().Set("Content-Type", "application/json")
fmt.Fprint(w, serviceResponse.String())
}