Commit d609f274 authored by email's avatar email

feat: compose response data

parent d6418f5f
...@@ -7,7 +7,7 @@ type User struct { ...@@ -7,7 +7,7 @@ type User struct {
OpenId string `json:"openId"` OpenId string `json:"openId"`
Name string `json:"name"` Name string `json:"name"`
Password string Password string `json:"-"`
} }
type UserCreate struct { type UserCreate struct {
......
...@@ -40,7 +40,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) { ...@@ -40,7 +40,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(user); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create user response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create user response").SetInternal(err)
} }
...@@ -88,7 +88,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) { ...@@ -88,7 +88,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(user); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create user response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal create user response").SetInternal(err)
} }
......
package server
func composeResponse(data interface{}) interface{} {
type R struct {
Data interface{} `json:"data"`
}
return R{
Data: data,
}
}
...@@ -27,7 +27,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) { ...@@ -27,7 +27,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(memo); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo response").SetInternal(err)
} }
...@@ -52,7 +52,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) { ...@@ -52,7 +52,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(memo); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo response").SetInternal(err)
} }
...@@ -69,7 +69,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) { ...@@ -69,7 +69,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(list); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo list response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo list response").SetInternal(err)
} }
...@@ -93,7 +93,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) { ...@@ -93,7 +93,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(memo); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo response").SetInternal(err)
} }
......
...@@ -53,7 +53,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) { ...@@ -53,7 +53,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(resource); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(resource)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut response").SetInternal(err)
} }
...@@ -70,7 +70,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) { ...@@ -70,7 +70,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(list); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal resource list response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal resource list response").SetInternal(err)
} }
......
...@@ -26,7 +26,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) { ...@@ -26,7 +26,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(shortcut); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(shortcut)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut response").SetInternal(err)
} }
...@@ -51,7 +51,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) { ...@@ -51,7 +51,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(shortcut); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(shortcut)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut response").SetInternal(err)
} }
...@@ -68,7 +68,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) { ...@@ -68,7 +68,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(list); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(list)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut list response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut list response").SetInternal(err)
} }
...@@ -89,7 +89,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) { ...@@ -89,7 +89,7 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(shortcut); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(shortcut)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal shortcut response").SetInternal(err)
} }
......
...@@ -21,7 +21,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) { ...@@ -21,7 +21,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(user); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal user response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal user response").SetInternal(err)
} }
...@@ -46,7 +46,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) { ...@@ -46,7 +46,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(user); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal user response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal user response").SetInternal(err)
} }
...@@ -72,7 +72,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) { ...@@ -72,7 +72,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(user); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(user)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal user response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal user response").SetInternal(err)
} }
......
...@@ -41,7 +41,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) { ...@@ -41,7 +41,7 @@ func (s *Server) registerWebhookRoutes(g *echo.Group) {
} }
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8) c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := json.NewEncoder(c.Response().Writer).Encode(memo); err != nil { if err := json.NewEncoder(c.Response().Writer).Encode(composeResponse(memo)); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo response").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal memo response").SetInternal(err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment