Re: [go-nuts] Re: Go interface

2016-10-28 Thread Arafath M
Thanks for the replies. Sincerely, Arafath M On Fri, Oct 28, 2016 at 6:25 AM, Henry wrote: > Hi, > > I usually use the following pattern when creating a type. In your case, it > would be as follows: > > interface Animal { > Eat() > Travel() > } > > interface Mammal { > Animal > NoOfLegs

[go-nuts] Re: Go interface

2016-10-27 Thread Henry
Hi, I usually use the following pattern when creating a type. In your case, it would be as follows: interface Animal { Eat() Travel() } interface Mammal { Animal NoOfLegs() int } //Note this is unexported struct mammalImpl { //implementation here } //Mammal constructor. This will no

Re: [go-nuts] Re: Go interface

2016-10-27 Thread Rob Pike
Cleaner and a little more explicit, making it more obvious what's being asserted (although a comment would be welcome): var _ Animal = MammalInt(nil) // if pointer var _ Animal = MammalInt{} // if just a struct On Thu, Oct 27, 2016 at 10:08 AM, Tamás Gulácsi wrote: > It's very easy to ensure s

[go-nuts] Re: Go interface

2016-10-27 Thread Tamás Gulácsi
It's very easy to ensure sth implements an interface: ``` var _ = Animal(MammalInt(nil)) // if pointer var _ = Animal(MammalInt{}) // if just a struct ``` 2016. október 27., csütörtök 9:11:04 UTC+2 időpontban Arafath M a következőt írta: > > Hi, > > Using interface is easy in Go. But, while stud

Re: [go-nuts] Re: Go interface

2016-10-27 Thread Arafath M
Thanks Volker. It works fine. Below is the example I tried, after doing *go get -u -v golang.org/x/tools/cmd/guru * *Command:* guru implements C:\Go\src\net\http\server.go:#2538 *Result:* C:\Go\src\net\http\server.go:86:6: interface type ResponseWriter C:\Go\sr

[go-nuts] Re: Go interface

2016-10-27 Thread Volker Dobler
There is guru (golang.org/x/tools/cmd/guru) which can answer this question if it really comes up (I rarely feel the need to know all type implementing flag.Getter). V. Am Donnerstag, 27. Oktober 2016 09:11:04 UTC+2 schrieb Arafath M: > > Hi, > > Using interface is easy in Go. But, while studying