I have a block of code which hardcodes the URL required for REST API that I am consuming. What I would like to do is, use the two flags to dynamically generate the URL. For example, something to the effect of:
response, err := http.Get("https://swapi.co/api/%s/1", resourcePtr)
My current code is as follows:
func main() {
resourcePtr := flag.String("resource", "", "a string")
idPtr := flag.Int("id", 1, "an int")
flag.Parse()
response, err := http.Get("https://swapi.co/api/planets/1")
if err != nil {
fmt.Printf("HTTP request failed with error %s
", err)
} else {
data, _ := ioutil.ReadAll(response.Body)
fmt.Println(string(data))
}
}
Thanks in advance!