@@ -57,7 +57,10 @@ func main() {
5757	e.GET (" /" func (c echo.Context ) error  {
5858		return  c.String (http.StatusOK , " Hello, World!" 
5959	})
60- 	e.Run (standard.New (" :1323" 
60+ 	
61+ 	if  err  :=  e.Start (" :1323" nil  {
62+ 		e.Logger .Fatal (err.Error ())
63+ 	}
6164}
6265``` 
6366
@@ -85,8 +88,10 @@ e.DELETE("/users/:id", deleteUser)
8588func  getUser (c  echo .Context ) error  {
8689	//  User ID from path `users/:id`
8790	id  :=  c.Param (" id" 
91+ 	return  c.String (http.StatusOK , id)
8892}
8993``` 
94+ Browse to http://localhost:1323/users/Joe  and you should see 'Joe' on the page.
9095
9196### Query Parameters  
9297
@@ -97,9 +102,13 @@ func show(c echo.Context) error {
97102	//  Get team and member from the query string
98103	team  :=  c.QueryParam (" team" 
99104	member  :=  c.QueryParam (" member" 
105+ 	
106+ 	return  c.String (http.StatusOK , " team:" " , member:" 
100107}
101108``` 
102109
110+ Browse to http://localhost:1323/show?team=x-men&member=wolverine  and you should see 'team: x-men , member: wolverine ' on the page.
111+ 
103112### Form ` application/x-www-form-urlencoded `   
104113
105114` POST `  ` /save ` 
@@ -114,51 +123,70 @@ func save(c echo.Context) error {
114123	//  Get name and email
115124	name  :=  c.FormValue (" name" 
116125	email  :=  c.FormValue (" email" 
126+ 	
127+ 	return  c.String (http.StatusOK , " name:" " , email:" 
117128}
118129``` 
119130
131+ Run the following command.
132+ ``` sh 
133+ $ curl -F 
" name=Joe Smith"  -F 
" [email protected] "  http://localhost:1323/save
134+ // =
>  name:Joe Smith, email:
[email protected] 135+ ``` 
136+ 
120137### Form ` multipart/form-data `   
121138
122139` POST `  ` /save ` 
123140
124141name | value
125142:--- | :---
126143name | Joe Smith
127- 128144avatar | avatar
129145
130146``` go 
131147func  save (c  echo .Context ) error  {
132- 	//  Get name and email 
148+ 	//  Get name
133149	name  :=  c.FormValue (" name" 
134- 	email  :=  c.FormValue (" email" 
135150	//  Get avatar
136151	avatar , err  :=  c.FormFile (" avatar" 
137- 	if  err != nil  {
138- 		return  err
139- 	}
140- 
141- 	//  Source
142- 	src , err  :=  avatar.Open ()
143- 	if  err != nil  {
144- 		return  err
145- 	}
146- 	defer  src.Close ()
147- 
148- 	//  Destination
149- 	dst , err  :=  os.Create (avatar.Filename )
150- 	if  err != nil  {
151- 		return  err
152- 	}
153- 	defer  dst.Close ()
152+   	if  err != nil  {
153+  		return  err
154+  	}
155+  
156+  	//  Source
157+  	src , err  :=  avatar.Open ()
158+  	if  err != nil  {
159+  		return  err
160+  	}
161+  	defer  src.Close ()
162+  
163+  	//  Destination
164+  	dst , err  :=  os.Create (avatar.Filename )
165+  	if  err != nil  {
166+  		return  err
167+  	}
168+  	defer  dst.Close ()
169+  
170+  	//  Copy
171+  	if  _, err = io.Copy (dst, src); err != nil  {
172+   		return  err
173+   	}
174+ 
175+ 	return  c.HTML (http.StatusOK , " <b>Thank you! " " </b>" 
176+ }
177+ ``` 
154178
155- 	//  Copy
156- 	if  _, err = io.Copy (dst, src); err != nil  {
157- 		return  err
158- 	}
179+ Run the following command.
180+ ``` sh 
181+ $ curl -F " name=Joe Smith" " avatar=@/path/to/your/avatar.png" 
182+ // =>  < b> Thank you!  Joe Smith< /b> 
183+ ``` 
159184
160- 	return  c.HTML (http.StatusOK , " <b>Thank you!</b>" 
161- }
185+ To check the uploaded image, run the following command.
186+ ``` sh 
187+ cd  < project directory> 
188+ ls avatar.png
189+ // =>  avatar.png
162190``` 
163191
164192### Handling Request  
0 commit comments