June 2017
Intermediate to advanced
400 pages
10h 32m
English
Go request and response objects are largely shareable between clients and handlers. This code takes a request obtained by a Proxy struct that satisfies a Handler interface. The main.go file is using Handle instead of HandleFunc used elsewhere. Once the request is available, it's modified to prepend Proxy.BaseURL for the request which the client then dispatches. Lastly, the response is copied back to the ResponseWriter interface. This includes all headers, the body, and the status.
We can also add some additional features such as basic auth for requests, token management, and more if needed. This can be useful for token management where the proxy manages sessions for a JavaScript or other client application.
Read now
Unlock full access