编辑代码

package main

import "fmt"

type Author struct {
    Name  string
    Email string
}

func (a *Author) setName(name string) {
    a.Name = name
}

func (a *Author) setEmail(email string) {
    a.Email = email
}

type Book struct {
    Title  string
    Author Author
}

func (b *Book) setTitle(title string) {
    b.Title = title
}

func (b *Book) setAuthorName(name string) {
    b.Author.setName(name)
}

func (b *Book) setAuthorEmail(email string) {
    b.Author.setEmail(email)
}

func main() {
    book := Book{
        Title: "The Go Programming Language",
        Author: Author{
            Name:  "Alan A. A. Donovan",
            Email: "alan@example.com",
        },
    }

    book.setTitle("Go语言程序设计")
    book.setAuthorName("肖建良")
    book.setAuthorEmail("go@qq.com")

    fmt.Printf("%+v\n", book)
}