【发布时间】:2021-07-28 08:45:51
【问题描述】:
【问题讨论】:
标签: go import subdirectory
【问题讨论】:
标签: go import subdirectory
go.mod:
module family
father\father.go:
package father
type Dad struct { Age int }
father\son\son.go:
package main
import (
"family/father"
"fmt"
)
func main() {
d := father.Dad{40}
fmt.Println(d)
}
【讨论】:
package father
type Father struct {
Name string `json:"name"`
Job string `json:"job"`
}
2.father/son/son.go
package son
import (
"fmt"
"github.com/yaocanwei/demo/father"
)
type Son struct {
father.Father
Hobby string `json:"hobby"`
}
func (son *Son) EchoJob() string {
return fmt.Sprintf("%s", son.Father.Job)
}
3.main.go
package main
import (
"fmt"
"github.com/yaocanwei/demo/father/son"
)
func main() {
s := &son.Son{}
s.Job = "senior engineer"
fmt.Println(s.EchoJob())
}
【讨论】: