1. type write interface {
    2. puts()
    3. }
    4. type member struct {
    5. name string
    6. age int
    7. }
    8. func NewMember(name string, age int) *member {
    9. return &member{
    10. name: name,
    11. age: age,
    12. }
    13. }
    14. func (m *member) puts() {
    15. fmt.Println(m.name)
    16. }
    17. func (m *member) readSth() {
    18. fmt.Println(m.age)
    19. }
    20. func testPutsAndRead(write write) {
    21. if m, ok := write.(interface{ readSth() }); ok {
    22. m.readSth()
    23. }
    24. write.puts()
    25. }
    26. var _ write = (*member)(nil)
    27. func main() {
    28. m := NewMember("test Name", 19)
    29. testPutsAndRead(m)
    30. }