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 關注
- 166 瀏覽
添加回答
舉報