controllers

package
v0.0.0-...-29ef849 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	Service services.Counter
}

The Counter Controller. The controller instance is always the same and shared across requests, why? Because it contains a single field which binds to a static dependency. Service is a static dependency, why? Because it does not rely on iris.Context or any other dynamic dependency.

The `GetIncrement` method relies on a dynamic dependency, because it depends on the incoming request (access log). That input argument will be a new instance of accesslog.Fields on every single new request.

func (*Counter) Get

func (c *Counter) Get() models.CounterResponse

Get handles the GET */ path. Returns the current counter.

func (*Counter) HandleError

func (c *Counter) HandleError(ctx iris.Context, err error)

HandleError catches controller's methods and servetime dependency-injection errors.

func (*Counter) HandleHTTPError

func (c *Counter) HandleHTTPError(err mvc.Err, statusCode mvc.Code) models.ErrorResponse

HandleHTTPError catches HTTP Errors under the controller's party (prefix path).

Responds the http error with JSON.

func (*Counter) PostIncrement

func (c *Counter) PostIncrement(fields *accesslog.Fields) models.CounterResponse

PostIncrement handles the POST */increment of this controller's Party.

Responds the new counter value with JSON. Access a registered request-time dependency of *accesslog.Fields in order to set custom log fields (e.g. current 'counter') in the log file.

Jump to

Keyboard shortcuts

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