```go
// AppService routes
func (s *AppService) routes() {
// welcome msg
s.router.GET("/", s.welcome)
s.router.GET("/notes", s.GetAll)
s.router.POST("/notes", s.Create)
s.router.GET("/notes/:id", s.GetOne)
s.router.PUT("/notes/:id", s.Update)
s.router.DELETE("/notes/:id", s.Destroy)
}
...
// GetAll get all notes
func (s *AppService) GetAll(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
res := s.DB.Table("notes").Limit(1000).Get()
if len(res) < 1 {
toJSON(w, resNotOK(40006, false, errEmptyNotes.Error()))
} else {
toJSON(w, resOK(res))
}
}
func main() {
// create Service
server := NewAppService()
// add routes
server.routes()
// Run
log.Println("server run at http://localhost:8088")
log.Fatal(http.ListenAndServe(":8088", server.router))
}
```
GitHub Source Code:[**notes-api**](https://github.com/qclaogui/database/blob/master/examples/notes-api/app.go)
有疑问加站长微信联系(非本文作者)