Skip to content

Commit 98c4c20

Browse files
authored
renames DTO struct (#354)
A DTO (Data Transfer Object) is meant to either: - Represent data received from the client in requests. - Represent data sent to the client in responses. A struct that is used for internal business logic is not normally named "DTO".
1 parent 746da2d commit 98c4c20

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

website/docs/guide/binding.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ Consider what will happen if your bound struct has an Exported field `IsAdmin bo
109109
In this example we define a `User` struct type with field tags to bind from `json`, `form`, or `query` request data:
110110

111111
```go
112-
type User struct {
112+
type UserDTO struct {
113113
Name string `json:"name" form:"name" query:"name"`
114114
Email string `json:"email" form:"email" query:"email"`
115115
}
116116

117-
type UserDTO struct {
117+
type User struct {
118118
Name string
119119
Email string
120120
IsAdmin bool
@@ -125,13 +125,13 @@ And a handler at the POST `/users` route binds request data to the struct:
125125

126126
```go
127127
e.POST("/users", func(c echo.Context) (err error) {
128-
u := new(User)
128+
u := new(UserDTO)
129129
if err := c.Bind(u); err != nil {
130130
return c.String(http.StatusBadRequest, "bad request")
131131
}
132132

133133
// Load into separate struct for security
134-
user := UserDTO{
134+
user := User{
135135
Name: u.Name,
136136
Email: u.Email,
137137
IsAdmin: false // avoids exposing field that should not be bound

0 commit comments

Comments
 (0)