I am working on a cli-type application which requires getting data from a third-party API .
with javascript:
const request=new Promiss((resolve, reject)=>{
})
so if I understand, we have an event queue and event loop, and even the loop keeps checking if the async operation is done, if it’s done it fulfils the promises.
now with go lang :
func (a *App) VerifyApiKey(apiKey string) bool {
req, err := http.NewRequest(http.MethodGet, host+"/accounts", nil)
if err != nil {
return false
}
req.Header.Add("Authorization", "Bearer "+apiKey)
fmt.Println(apiKey)
resp, err := http.DefaultClient.Do(req)
defer resp.Body.Close()
response, err := io.ReadAll(resp.Body)
if err != nil {
return false
}
fmt.Println(string(response))
if resp.StatusCode == http.StatusOK {
return true
}
return false
}
How does this work? go doesn’t have an event queue or loop, it’s based on channels, what’s happening behind the scenes?