如何正确引用项目包?我有以下文件夹结构:
/sbp
/models.go
/controllers.go
/main.go
在main.go
我想从sbp.controllers
. 我似乎找不到正确引用它的方法
main.go
package main
import (
"net/http"
...
"github.com/pressly/chi"
)
var sess = session.Must(session.NewSession(&aws.Config{
Region: aws.String("ap-southeast-1"),
}))
var dynamo = dynamodb.New(sess)
func main() {
r := chi.NewRouter()
r.Get("/", GetInvestments) // How do I call sbp.controller.GetInvestments?
r.Post("/", AddInvestment)
http.ListenAndServe(":8080", r)
}
sbp/controller.go
package sbp
import (
"net/http"
"time"
"github.com/pressly/chi/render"
)
// AddInvestment Adds an investment
func AddInvestment(w http.ResponseWriter, r *http.Request) {
...
}
// GetInvestments Gets list of investments
func GetInvestments(w http.ResponseWriter, r *http.Request) {
...
}
我尝试导入“sbp/controller”,甚至“github.com/jiewmeng/finance/sbp/controller”,但它们似乎是自动删除了我的 VSCode,所以我认为它无效?