Go Routine

Concurrency in Go with calling API requests

Get to know goroutine.

Photo by Priscilla Du Preez on Unsplash

We’ll go over some API requests without go concurrency. For example we want to get data from

"https://www.ncbi.nlm.nih.gov/gene/?term=" + gene

Doing so without concurrency

Will cost

31.525466019s

So how do we use go concurrency?

first we need to create waitgroup

wg := sync.WaitGroup{}

Then before move into the go routine, we need to add

wg.Add(1)

Outside the for loop of routines, we wait

wg.Wait()

That’s it.

Running the code will only take

4.967423025s

Happy coding guys ~~~

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store