methods in go code example
Example: go method
package main
import (
"fmt"
)
type Author interface {
getAuthor(name string) string
}
type Book struct {
Name string
}
func (m Book) getAuthor(name string) string {
return m.Name + name
}
func authorName(ctx Book) {
fmt.Println(ctx.getAuthor("doe"))
}
func main() {
var book Book
book.Name = "john"
authorName(book)
}