July 2017
Beginner to intermediate
358 pages
10h 54m
English
In Chapter 2, Designing a Great API, we looked at the X-Request-ID header, which allows us to mark all the service calls for an individual request with the same ID so that we can query them later. This is an incredibly important concept when it comes to debugging a request because it can really help you understand why a service may be failing or misbehaving by looking at the tree of requests and the parameters passed to them. If you take a look at the handlers/correlation.go file, we can implement this quite simply:
func (c *correlationHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { if r.Header.Get("X-Request-ID") == "" { r.Header.Set("X-Request-ID", uuid.New().String()) } c.next.ServeHTTP(rw, ...Read now
Unlock full access