mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Former-commit-id: 0f0667f7e460dc241f3a8fcca50cc6caf228d081
This commit is contained in:
parent
82b5a1d4ed
commit
7ab607aab2
|
@ -471,7 +471,7 @@ type Movie struct {
|
||||||
// simple checks can be added here.
|
// simple checks can be added here.
|
||||||
//
|
//
|
||||||
// It's just a showcase,
|
// 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
|
// This is called where the return value from a controller's method functions
|
||||||
// is type of `Movie`.
|
// is type of `Movie`.
|
||||||
|
@ -700,7 +700,7 @@ func (s *MovieMemoryService) GetAll() []models.Movie {
|
||||||
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// file: controllers/movies_controller.go
|
// file: controllers/movie_controller.go
|
||||||
|
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
|
@ -770,7 +770,6 @@ func (c *MovieController) PutBy(id int64) (models.Movie, error) {
|
||||||
// Demo:
|
// 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 *MovieController) DeleteBy(id int64) interface{} {
|
func (c *MovieController) DeleteBy(id int64) interface{} {
|
||||||
// delete the entry from the movies slice.
|
|
||||||
wasDel := c.Service.DeleteByID(id)
|
wasDel := c.Service.DeleteByID(id)
|
||||||
if wasDel {
|
if wasDel {
|
||||||
// and return the deleted movie's ID
|
// and return the deleted movie's ID
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// file: controllers/movies_controller.go
|
// file: controllers/movie_controller.go
|
||||||
|
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
|
@ -68,13 +68,12 @@ func (c *MovieController) PutBy(id int64) (models.Movie, error) {
|
||||||
// Demo:
|
// 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 *MovieController) DeleteBy(id int64) interface{} {
|
func (c *MovieController) DeleteBy(id int64) interface{} {
|
||||||
// delete the entry from the movies slice.
|
|
||||||
wasDel := c.Service.DeleteByID(id)
|
wasDel := c.Service.DeleteByID(id)
|
||||||
if wasDel {
|
if wasDel {
|
||||||
// and return the deleted movie's ID
|
// return the deleted movie's ID
|
||||||
return iris.Map{"deleted": 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.
|
// we don't have to specify the return type to a specific type.
|
||||||
return iris.StatusBadRequest
|
return iris.StatusBadRequest
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ func main() {
|
||||||
// Register our controllers.
|
// Register our controllers.
|
||||||
app.Controller("/hello", new(controllers.HelloController))
|
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)
|
service := services.NewMovieServiceFromMemory(datasource.Movies)
|
||||||
|
|
||||||
app.Controller("/movies", new(controllers.MovieController),
|
app.Controller("/movies", new(controllers.MovieController),
|
||||||
|
|
|
@ -24,7 +24,7 @@ type Movie struct {
|
||||||
// simple checks can be added here.
|
// simple checks can be added here.
|
||||||
//
|
//
|
||||||
// It's just a showcase,
|
// 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
|
// This is called where the return value from a controller's method functions
|
||||||
// is type of `Movie`.
|
// is type of `Movie`.
|
||||||
|
|
4
faq.md
4
faq.md
|
@ -55,7 +55,7 @@ You can find all type aliases and their original package import statements at th
|
||||||
|
|
||||||
Iris may have reached version 8, but we're not stopping there. We have many feature ideas on our board that we're anxious to add and other innovative web development solutions that we're planning to build into Iris.
|
Iris may have reached version 8, but we're not stopping there. We have many feature ideas on our board that we're anxious to add and other innovative web development solutions that we're planning to build into Iris.
|
||||||
|
|
||||||
## Can I found a job if I learn how to use Iris?
|
## Can I find a job if I learn how to use Iris?
|
||||||
|
|
||||||
Yes, not only because you will learn Golang in the same time, but there are some positions
|
Yes, not only because you will learn Golang in the same time, but there are some positions
|
||||||
open for Iris-specific developers the time we speak.
|
open for Iris-specific developers the time we speak.
|
||||||
|
@ -79,5 +79,3 @@ https://github.com/kataras/iris/issues/646
|
||||||
By normal people like you, who help us by donating small or larger amounts of money.
|
By normal people like you, who help us by donating small or larger amounts of money.
|
||||||
|
|
||||||
Help this project to continue deliver awesome and unique features with the higher code quality as possible by donating any amount via [PayPal](https://www.paypal.me/kataras)!
|
Help this project to continue deliver awesome and unique features with the higher code quality as possible by donating any amount via [PayPal](https://www.paypal.me/kataras)!
|
||||||
|
|
||||||
[![](https://www.paypalobjects.com/webstatic/paypalme/images/pp_logo_small.png)](https://www.paypal.me/kataras)
|
|
|
@ -71,10 +71,10 @@ func (b *binder) lookup(elem reflect.Type) (fields []field.Field) {
|
||||||
matcher := func(elemField reflect.StructField) bool {
|
matcher := func(elemField reflect.StructField) bool {
|
||||||
// If the controller's field is interface then check
|
// If the controller's field is interface then check
|
||||||
// if the given binded value implements that interface.
|
// if the given binded value implements that interface.
|
||||||
// i.e MovieController { service services.MoviesController /* interface */ }
|
// i.e MovieController { Service services.MoviesController /* interface */ }
|
||||||
// app.Controller("/", new(MovieController),
|
// app.Controller("/", new(MovieController),
|
||||||
// services.NewMovieMemoryController(...))
|
// services.NewMovieMemoryService(...))
|
||||||
// *MovieMemoryService type
|
// services.NewMovieMemoryService returns a *MovieMemoryService
|
||||||
// that implements the MovieService interface.
|
// that implements the MovieService interface.
|
||||||
if elemField.Type.Kind() == reflect.Interface {
|
if elemField.Type.Kind() == reflect.Interface {
|
||||||
return value.Type().Implements(elemField.Type)
|
return value.Type().Implements(elemField.Type)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user