Created
March 28, 2021 18:27
-
-
Save irwins/619ffce1822a4ff7cc2c84d3fed11c40 to your computer and use it in GitHub Desktop.
Get random user in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
) | |
func main() { | |
formatPtr := flag.String("format", "json", "format result expected. options are: Json,prettyJson,Yaml & Xml") | |
collSizePtr := flag.String("collectionSize", "1", "Maximum size of the result collection returned") | |
flag.Parse() | |
resp, err := http.Get("https://randomuser.me/api/?format="+*formatPtr+"&results="+*collSizePtr) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(string(body)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
./randomuser -format=yaml -collectionSize=2