Update README_CN.md

Former-commit-id: 1edea8d809b5c1f77ddb198a4d0f5b6123e8e788
This commit is contained in:
Yale 2017-11-09 10:10:59 +08:00 committed by GitHub
parent ed71632e25
commit 064741d487

View File

@ -288,7 +288,7 @@ type Movie struct {
Poster string `json:"poster"` Poster string `json:"poster"`
} }
// movies 对象模拟数据 // movies 对象模拟数据
var movies = []Movie{ var movies = []Movie{
{ {
Name: "Casablanca", Name: "Casablanca",
@ -339,38 +339,38 @@ type MoviesController struct {
mvc.C mvc.C
} }
// Get returns list of the movies // 返回 movies列表
// Demo: // 例子:
// curl -i http://localhost:8080/movies // curl -i http://localhost:8080/movies
func (c *MoviesController) Get() []Movie { func (c *MoviesController) Get() []Movie {
return movies return movies
} }
// GetBy returns a movie // GetBy 返回一个 movie
// Demo: // 例子:
// curl -i http://localhost:8080/movies/1 // curl -i http://localhost:8080/movies/1
func (c *MoviesController) GetBy(id int) Movie { func (c *MoviesController) GetBy(id int) Movie {
return movies[id] return movies[id]
} }
// PutBy updates a movie // PutBy 更新一个 movie
// Demo: // 例子:
// curl -i -X PUT -F "genre=Thriller" -F "poster=@/Users/kataras/Downloads/out.gif" http://localhost:8080/movies/1 // curl -i -X PUT -F "genre=Thriller" -F "poster=@/Users/kataras/Downloads/out.gif" http://localhost:8080/movies/1
func (c *MoviesController) PutBy(id int) Movie { func (c *MoviesController) PutBy(id int) Movie {
// get the movie    // 获取一个 movie
m := movies[id] m := movies[id]
// get the request data for poster and genre    // 获取一个poster文件
file, info, err := c.Ctx.FormFile("poster")    file, info, err := c.Ctx.FormFile("poster")
if err != nil { if err != nil {
c.Ctx.StatusCode(iris.StatusInternalServerError) c.Ctx.StatusCode(iris.StatusInternalServerError)
return Movie{} return Movie{}
} }
file.Close() // we don't need the file    file.Close()           // 我们不需要这个文件
poster := info.Filename // imagine that as the url of the uploaded file...    poster := info.Filename // 比如这就是上传的文件url
genre := c.Ctx.FormValue("genre") genre := c.Ctx.FormValue("genre")
// update the poster    // 更新poster
m.Poster = poster m.Poster = poster
m.Genre = genre m.Genre = genre
movies[id] = m movies[id] = m
@ -378,19 +378,21 @@ func (c *MoviesController) PutBy(id int) Movie {
return m return m
} }
// DeleteBy deletes a movie // DeleteBy 删除一个 movie
// Demo: // 例子:
// curl -i -X DELETE -u admin:password http://localhost:8080/movies/1 // curl -i -X DELETE -u admin:password http://localhost:8080/movies/1
func (c *MoviesController) DeleteBy(id int) iris.Map { func (c *MoviesController) DeleteBy(id int) iris.Map {
// delete the entry from the movies slice    //从movies slice中删除索引
deleted := movies[id].Name    deleted := movies[id].Name
movies = append(movies[:id], movies[id+1:]...) movies = append(movies[:id], movies[id+1:]...)
// and return the deleted movie's name    // 返回删除movie的名称
return iris.Map{"deleted": deleted}    return iris.Map{"deleted": deleted}
} }
``` ```
### Quick MVC Tutorial #3 ### MVC 快速指南 3
Nothing stops you from using your favorite **folder structure**. Iris is a low level web framework, it has got MVC first-class support but it doesn't limit your folder structure, this is your choice. Nothing stops you from using your favorite **folder structure**. Iris is a low level web framework, it has got MVC first-class support but it doesn't limit your folder structure, this is your choice.