我的代码如下所示:
应用程序.go
package main
import (
"github.com/go-martini/martini"
)
func main() {
app := martini.Classic()
app.Group("/books", func(r martini.Router) {
r.Get("/:id", getBooks)
r.Post("/new", newBook)
r.Put("/update/:id", updateBook)
r.Delete("/delete/:id", deleteBook)
})
app.RunOnAddr(":8080")
}
main.go
package main
import "github.com/go-martini/martini"
func getBooks() string {
return "get books api called"
}
func newBook() string {
return "Psot book api called"
}
func updateBook(params martini.Params) string {
return "put api called " + params["id"]
}
func deleteBook(params martini.Params) string {
return "delete api called " + params["id"]
}
但不知何故,当我运行代码时,它给了我以下错误:
./app.go:16:17: undefined: getBooks
./app.go:17:18: undefined: newBook
./app.go:18:24: undefined: updateBook
./app.go:19:27: undefined: deleteBook
那么有没有办法解决这个问题呢?
项目结构如下:
goProject
---->app.go
---->main.go