I'm creating a reverse proxy in Golang and I'm having trouble trying to grab online examples on how to add HTTP headers to an API call.
Here is my API call:
package handlers
import (
"fmt"
"io/ioutil"
"log"
"net/http"
)
func (s *Server) getApiCall(w http.ResponseWriter, r *http.Request) {
resp, err := http.Get("https://url.com")
if err != nil {
log.Fatalln(err)
}
//We Read the response body on the line below.
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
//Convert the body to type string
sb := string(body)
log.Printf(sb)
fmt.Fprintf(w, sb)
}
Where in my function can I add an Authorization
header with the a Bearer <TOKEN>
as its value?
I'm new with Go, to my understanding this should be enough code, but if you need more detail about my backend just add a comment in what needs clarification.