controllers

package
v10.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 9, 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 UserController

type UserController struct {
	// context is auto-binded by Iris on each request,
	// remember that on each incoming request iris creates a new UserController each time,
	// so all fields are request-scoped by-default, only dependency injection is able to set
	// custom fields like the Service which is the same for all requests (static binding)
	// and the Session which depends on the current context (dynamic binding).
	Ctx iris.Context

	// Our UserService, it's an interface which
	// is binded from the main application.
	Service services.UserService

	// Session, binded using dependency injection from the main.go.
	Session *sessions.Session
}

UserController is our /user controller. UserController is responsible to handle the following requests: GET /user/register POST /user/register GET /user/login POST /user/login GET /user/me All HTTP Methods /user/logout

func (*UserController) AnyLogout

func (c *UserController) AnyLogout()

AnyLogout handles All/Any HTTP Methods for: http://localhost:8080/user/logout.

func (*UserController) GetLogin

func (c *UserController) GetLogin() mvc.Result

GetLogin handles GET: http://localhost:8080/user/login.

func (*UserController) GetMe

func (c *UserController) GetMe() mvc.Result

GetMe handles GET: http://localhost:8080/user/me.

func (*UserController) GetRegister

func (c *UserController) GetRegister() mvc.Result

GetRegister handles GET: http://localhost:8080/user/register.

func (*UserController) PostLogin

func (c *UserController) PostLogin() mvc.Result

PostLogin handles POST: http://localhost:8080/user/register.

func (*UserController) PostRegister

func (c *UserController) PostRegister() mvc.Result

PostRegister handles POST: http://localhost:8080/user/register.

type UsersController

type UsersController struct {
	// Optionally: context is auto-binded by Iris on each request,
	// remember that on each incoming request iris creates a new UserController each time,
	// so all fields are request-scoped by-default, only dependency injection is able to set
	// custom fields like the Service which is the same for all requests (static binding).
	Ctx iris.Context

	// Our UserService, it's an interface which
	// is binded from the main application.
	Service services.UserService
}

UsersController is our /users API controller. GET /users | get all GET /users/{id:long} | get by id PUT /users/{id:long} | update by id DELETE /users/{id:long} | delete by id Requires basic authentication.

func (*UsersController) DeleteBy

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

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

func (*UsersController) Get

func (c *UsersController) Get() (results []datamodels.User)

Get returns list of the users. Demo: curl -i -u admin:password http://localhost:8080/users

The correct way if you have sensitive data:

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

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

otherwise just return the datamodels.

func (*UsersController) GetBy

func (c *UsersController) GetBy(id int64) (user datamodels.User, found bool)

GetBy returns a user. Demo: curl -i -u admin:password http://localhost:8080/users/1

func (*UsersController) PutBy

func (c *UsersController) PutBy(id int64) (datamodels.User, error)

PutBy updates a user. Demo: curl -i -X PUT -u admin:password -F "username=kataras" -F "password=rawPasswordIsNotSafeIfOrNotHTTPs_You_Should_Use_A_client_side_lib_for_hash_as_well" http://localhost:8080/users/1

Jump to

Keyboard shortcuts

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