helper

package
v0.4.5-beta Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJsonRequest

func DecodeJsonRequest(r *http.Request, interfaceRef interface{}) error

Decode JSON request in a selected struct

func RunJob

func RunJob(job Job)

RunJob executes the handler of the given job once or more than once. If retryCount is 0 or less, the job handler will be run just once, otherwise it will be run 1 time plus the value of retryCount (worst case scenario).

func ValidateRequest

func ValidateRequest(data interface{}, response http.ResponseWriter) bool

ValidateRequest incoming request

func View

func View(path string, w http.ResponseWriter, content *interface{})

View Render specific view

Types

type Job

type Job struct {
	// The handler being executed by the job.
	Handler JobHandler
	// Arguments of the job.
	Args []byte
	// The handler that could be will be processed if the job is run successfully.
	DidSucceed JobResponseHandler
	// The handler that could be will be processed if the job is run, but returns an error.
	DidFail JobResponseHandler
	// The handler that could be will be processed if the job does not return in less than a certain amount of time.
	DidTimeOut JobResponseHandler
	// Indicates the timeout for the execution of the job handler.
	// If not defined, this value will be set to 10 seconds.
	// If the value is set to something equal or lower to 0, it
	// will be set to 10 seconds.
	Timeout time.Duration
	// The number of times that a job should be executed in case of timeout (not error).
	// If set to 0 or less, the job will be executed just once.
	RetryCount int
}

Job structure defines a job that should be run with the RunJob function.

type JobHandler

type JobHandler = func([]byte) error

JobHandler defines the signature of the function that should be executed. by a job

type JobResponse

type JobResponse struct {
	// The error that may be returned by running a job.
	Error error
	// The flag that indicates if the job was run, regardless of the result.
	// If false, this flag indicates a timeout error, which will be reflected by Error.
	Completed bool
}

JobResponse represents the response of a long running job.

type JobResponseHandler

type JobResponseHandler = func(error)

JobResponseHandler defines the signature of a function that should be used to handle one of the possible responses of a job (success, failure, timeout).

Jump to

Keyboard shortcuts

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