看完后官方指導(dǎo)如何組織項目,并通過各種準備(1,2,3僅舉幾例)的例子和項目,我不禁懷疑是否我的結(jié)構(gòu)化方法我的REST的API的服務(wù)器應(yīng)用程序的結(jié)構(gòu)正確。API 的用途是什么?郵政 /auth/sign-in接受usernameandpassword并發(fā)出JWT (JSON Web Token)。得到 /auth/sign-out將 JWT 添加到黑名單以使身份驗證會話無效。得到 /resources檢索所有資源的列表。POST /resources(需要有效的 JWT 身份驗證)接受 JSON 正文,創(chuàng)建新資源并向所有人發(fā)送有關(guān)新資源的電子郵件和通知。我的項目是什么樣的目前我沒有創(chuàng)建任何庫。一切都在主包中,帶有路由的總體服務(wù)器設(shè)置等都在main.go. 我沒有去尋找 à la Rails 或 Django 的 MVC 模式,以避免僅僅為了它而使事情變得過于復(fù)雜。另外我的印象是它并不真正符合上面已經(jīng)提到的指南中描述的命令和庫的推薦結(jié)構(gòu)。auth.go # generates, validates JWT, etcauth-handler.go # Handles sign-in/out requests; includes middleware for required authenticationmailer.go # Provides methods to send out transactional email, loads correct template etc.main.go # set up routes, runs server; inits mailer and notification instance for the request contextmodels.go # struct definition for User, Resourcenotifications.go # Provides methods to publish push notificationsresource-handler.go # Handles request for resources, uses mailer and notifications instances for the POST request它應(yīng)該是什么樣子?路由應(yīng)該分開嗎?中間件呢?您如何處理與 3rd 方代碼的接口 - 想象一下mailer.go在概述的示例應(yīng)用程序中與 Mandrill 和notifications.goAmazon AWS SNS對話?
- 1 回答
- 0 關(guān)注
- 219 瀏覽
添加回答
舉報
0/150
提交
取消