controller

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package controller provides a base helper type. It holds some common behavior for all controllers to use.

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

The defaut context timeout

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller struct {

	// Target indicates on which URL or host the controller should connect
	Target string

	// ReportError is a callback, that is used for error handling at the
	// Service level.
	ReportError func(err error)

	// The logger to use for the controller. Having a logger per controller
	// allows to split and easily filters the console output.
	Logger *log.Logger
	// contains filtered or unexported fields
}

Controller is a base type for actual controllers. It is a common base and holds some behavior like error handling and context management

func NewController

func NewController(opt ControllerOptions) Controller

NewController builds a new controller. It setup a new logger using the provided prefix uppercased.

func (*Controller) BadRequest

func (c *Controller) BadRequest(err error, g *gin.Context)

BadRequest uses logAndReport with a http.StatusBadRequest status and a proper bad request message

func (*Controller) GetContext

func (c *Controller) GetContext(
	timeout ...time.Duration) (context.Context, context.CancelFunc)

GetContext is a wrapper around context.WithTimeout, with a default timeout value. An optional custom timeout value can be provided. Only the first custom timeout value will be used. If more than one parameter is given, it will fallback to the defaultTimeout value.

func (*Controller) InternalError

func (c *Controller) InternalError(err error, g *gin.Context)

InternalError uses logAndReport with a http.StatusInternalServerError and a proper internal error message

func (*Controller) Name

func (c *Controller) Name() string

type ControllerOptions

type ControllerOptions struct {
	// Name builder parameter
	Name string

	// Target builder parameter
	Target string

	// ReportError builder parameter
	ReportError func(err error)

	// Logger builder parameter
	Logger *log.Logger
}

ControllerOptions holds the base parameters needed to build a Controller

Directories

Path Synopsis
Package download aims to interact with the download job using Cloud and websocket features.
Package download aims to interact with the download job using Cloud and websocket features.
subscriber
Package subscribe is a helper that interacts with Pub/Sub Cloud feature.
Package subscribe is a helper that interacts with Pub/Sub Cloud feature.
Package search contains the music researcher controller.
Package search contains the music researcher controller.

Jump to

Keyboard shortcuts

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