Missing Filed or Method

var client := http.Client

For whatever reason this code is giving the error message missing variable or initialization. Can someone enlighten me on why? I’m not understanding what I have done wrong

>Solution :

In Go we use := or var = for initializing variables. In your case you can re-write it to be:

var client = http.Client{}

or

client := http.Client{}

Either of these will trigger type inference of the variable. You can use var with a type to explicitly declare a type as well. In your case if you wanted to enforce the type you could write:

var client http.Client = http.Client{}

Leave a Reply