简体   繁体   中英

Why do I not get an error when running this, but I do get an error when running this `a,b := 2`?

I am very new to Go and a beginner to programming. I cam across this:

res, err := http.Get("URL_HERE")
if err != nil {
    log.Fatal(err)
}

Can anyone please help me understand this? Does http.Get return two values? Is err a pointer?

Yes, http.Get returns two values. The documentation of http.Get is here , and this is its signature:

func Get(url string) (resp *Response, err error)

err is a value of the error type, which is an interface so it could be nil . From its documentation :

The error built-in interface type is the conventional interface for representing an error condition, with the nil value representing no error.

I strongly suggest you start learning Go by completing the online tour , and then check out additional learning resources at https://learn.go.dev/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM