I'm a newbie to go and trying to make a call to cyberark to grab a secret and trying to figure out on how to parametrize the token value.This value is derived from another rest API call that will happen before this API call. So I wanted to pass that response from the other API call and pass in here as token. Below is my code; I tried creating a variable for the token response I get from the other API call to be able to be used here, but running into different formatting errors like newline in string error and so on.
package main import ("fmt""net/http""io/ioutil" ) func main() { url := "https://secrets.com/password" method := "GET" client := &http.Client {} req, err := http.NewRequest(method, url, nil) if err != nil { fmt.Println(err) return } req.Header.Add("Accept-Encoding", "base64") req.Header.Add("Authorization", "Token token=\"eyJwcm90ZWN0ZWQiOiJleU\"") req.Header.Add("Accept", "application/json") res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) }