1 回答

TA贡献2016条经验 获得超9个赞
我为您的场景创建了一个示例结构,如下所示:
假设项目结构如下所示:
project-villa/ //Name of your Project
model/
-user.go //this file will contain your User Structure
repository/
-post.go //this file will hold your Post structure and the rest piece of code
handler/
driver/
main.go
Step1:- 初始化模块
go mod init project-villa
或者
go mod init github.com/user-name/project-villa
mod 将管理模块依赖本身。无论如何,如果没有,您可以显式导入它。它看起来像这样:
github.com/random/project-villa/models
type Post struct {
URL string `json:"url,omitempty"`
Caption string `json:"caption,omitempty"`
Likes []models.User `json:"likes,omitempty"` //you can use it like this
}
作为参考,您可以按照官方 go dev 的链接。在这里你会得到Importing packages from your module.
- 1 回答
- 0 关注
- 141 浏览
添加回答
举报