If a bird looks like a duck and walks up like a duck, it is called a duck;
The interface in golang means the above. If you define a struct, the methods and attributes in it are the same as those in the interface, you can say that this struct implements this interface and the code on it
Package mainimport ("FMT") type s struct {// defines an S type, with an attribute I is int I int} func (this * s) Get () int {// get method to obtain the I property return this. i} func (this * s) Put (v int) {// set the I attribute this. I = V} type I interface {// defines an interface type, which contains the get method and put method get () intput (INT)} func main () {var S // apply for an S variable, which is a value of the S Type F (& S)} func F (My I) {// here, my saves the value of the interface type. Because s implements I, although I is passed, it can be used as the S type. put (1, 999) FMT. println (my. get ())}
Go interface understanding