比如 我要把Beahavior 放到叫interfaces的目录,结构体Dog单独放一个叫model的目录,Eat放到 其它目录文件实现。怎么做呢?
```go
package main
import (
"fmt"
)
// 定义接口
type Beahavior interface {
Run() string
Eat(thing string) string
}
type Dog struct {
Name string
}
func (d * Dog) Eat(thing string ) string {
return "hello i am eating "+thing
}
func (d * Dog) Run() string {
return "hello i am running"
}
func main() {
d := Dog{Name:"旺财"}
res := d.Eat("apple")
fmt.Println(res)
}
```
比如 下面好像行不通,提示无法解析model.Dog
demo/model/s.go //demo是根目录
```go
import "demo/model"
func (d * model.Dog) Eat(thing string ) string {
return "hello i am eating "+thing
}
```
有疑问加站长微信联系(非本文作者)