controller

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package controller holds application controllers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller - controller related struct

func New

func New(service Service) *Controller

New - Instantiates a new Controller. Requires a Service.

func (*Controller) DeleteUser

func (c *Controller) DeleteUser(w http.ResponseWriter, r *http.Request)

DeleteUser - Handles a user deletion. Requires the user ID to be removed. Returns OK or an error in case of failure.

func (*Controller) GetUser

func (c *Controller) GetUser(w http.ResponseWriter, r *http.Request)

GetUser - Handles a get user request. Requires a URL parameter ID. Returns a user ID or an error in case of failure.

func (*Controller) Mux added in v0.4.3

func (c *Controller) Mux() *mux.Router

Mux - Initializes routing and returns a Router.

func (*Controller) NewUser

func (c *Controller) NewUser(w http.ResponseWriter, r *http.Request)

NewUser - Handles a user creation request. Requires a user data JSON body. Returns the created user or an error in case of failure.

func (*Controller) UpdateUser

func (c *Controller) UpdateUser(w http.ResponseWriter, r *http.Request)

UpdateUser - Handles a user update request. Requires the user ID to update and a user data JSON body. Returns the updated user or an error in case of failure.

type Service

type Service interface {
	FindUser(ctx context.Context, id string) (model.User, error)
	CreateUser(ctx context.Context, user model.User) (model.User, error)
	UpdateUser(ctx context.Context, user model.User) (model.User, error)
	DeleteUser(ctx context.Context, id string) error
}

Service abstracts the service layer.

Jump to

Keyboard shortcuts

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