controllers

package
v10.6.6+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2018 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HelloController

type HelloController struct{}

HelloController is our sample controller it handles GET: /hello and GET: /hello/{name}

func (*HelloController) Get

func (c *HelloController) Get() mvc.Result

Get will return a predefined view with bind data.

`mvc.Result` is just an interface with a `Dispatch` function. `mvc.Response` and `mvc.View` are the built'n result type dispatchers you can even create custom response dispatchers by implementing the `github.com/kataras/iris/hero#Result` interface.

func (*HelloController) GetBy

func (c *HelloController) GetBy(name string) mvc.Result

GetBy returns a "Hello {name}" response. Demos: curl -i http://localhost:8080/hello/iris curl -i http://localhost:8080/hello/anything

type MovieController

type MovieController struct {
	// Our MovieService, it's an interface which
	// is binded from the main application.
	Service services.MovieService
}

MovieController is our /movies controller.

func (*MovieController) DeleteBy

func (c *MovieController) DeleteBy(id int64) interface{}

DeleteBy deletes a movie. Demo: curl -i -X DELETE -u admin:password http://localhost:8080/movies/1

func (*MovieController) Get

func (c *MovieController) Get() (results []datamodels.Movie)

Get returns list of the movies. Demo: curl -i http://localhost:8080/movies

The correct way if you have sensitive data:

func (c *MovieController) Get() (results []viewmodels.Movie) {
	data := c.Service.GetAll()

	for _, movie := range data {
		results = append(results, viewmodels.Movie{movie})
	}
	return
}

otherwise just return the datamodels.

func (*MovieController) GetBy

func (c *MovieController) GetBy(id int64) (movie datamodels.Movie, found bool)

GetBy returns a movie. Demo: curl -i http://localhost:8080/movies/1

func (*MovieController) PutBy

func (c *MovieController) PutBy(ctx iris.Context, id int64) (datamodels.Movie, error)

PutBy updates a movie. Demo: curl -i -X PUT -F "genre=Thriller" -F "poster=@/Users/kataras/Downloads/out.gif" http://localhost:8080/movies/1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL