Minty
Minty

Reputation: 1241

Extreme noob query about interface

With reference to this code

How to interpret this code?

(*http.ResponseWriter)(nil)

Is it type assertion or something else? I dont understand.

Also can interfaces have pointers?

Thanks

Upvotes: 0

Views: 85

Answers (1)

thwd
thwd

Reputation: 24808

It's a nil pointer.

nil pointers have a type, in this case it's *http.ResponseWriter.

Edit to answer question in comment section:

The reason for doing this is that inject (Martini's dependency injector) maps an interface type to an implementation of that interface through MapTo.

As it's really only interested in the interface's type (as second argument), a nil pointer is enough.

Upvotes: 1

Related Questions