mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 02:47:04 +00:00
Former-commit-id: 0f0667f7e460dc241f3a8fcca50cc6caf228d081
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// file: controllers/movies_controller.go
|
||||
// file: controllers/movie_controller.go
|
||||
|
||||
package controllers
|
||||
|
||||
@@ -68,13 +68,12 @@ func (c *MovieController) PutBy(id int64) (models.Movie, error) {
|
||||
// Demo:
|
||||
// curl -i -X DELETE -u admin:password http://localhost:8080/movies/1
|
||||
func (c *MovieController) DeleteBy(id int64) interface{} {
|
||||
// delete the entry from the movies slice.
|
||||
wasDel := c.Service.DeleteByID(id)
|
||||
if wasDel {
|
||||
// and return the deleted movie's ID
|
||||
// return the deleted movie's ID
|
||||
return iris.Map{"deleted": id}
|
||||
}
|
||||
// here we can see that a method function can return any of those two types(map or int),
|
||||
// right here we can see that a method function can return any of those two types(map or int),
|
||||
// we don't have to specify the return type to a specific type.
|
||||
return iris.StatusBadRequest
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func main() {
|
||||
// Register our controllers.
|
||||
app.Controller("/hello", new(controllers.HelloController))
|
||||
|
||||
// Create our movie service (memory), we will bind it to the movies controller.
|
||||
// Create our movie service (memory), we will bind it to the movie controller.
|
||||
service := services.NewMovieServiceFromMemory(datasource.Movies)
|
||||
|
||||
app.Controller("/movies", new(controllers.MovieController),
|
||||
|
||||
@@ -24,7 +24,7 @@ type Movie struct {
|
||||
// simple checks can be added here.
|
||||
//
|
||||
// It's just a showcase,
|
||||
// imagine what possible this opens when you designing a bigger application.
|
||||
// imagine the potentials this feature gives when designing a bigger application.
|
||||
//
|
||||
// This is called where the return value from a controller's method functions
|
||||
// is type of `Movie`.
|
||||
|
||||
Reference in New Issue
Block a user