Documentation ¶
Index ¶
- Variables
- func AddRoute(engine *gin.Engine, route *Route)
- func CtxOutStr(ctxOutputs ...string) string
- func FuncStr(name string, ctxDependencies ...string) string
- func MakeGinHandlerFunc(ch *Chain, lgr Logger) gin.HandlerFunc
- func StageName(usesInParam bool, name string, ctxDependencies []string, ctxOutputs []string, ...) string
- type Chain
- type ChainExecutionError
- type DefaultLogger
- type H
- type JSONResponse
- type Logger
- type Response
- type Route
- type Stage
- func Bind(obj any) *Stage
- func CtxGet(key string) *Stage
- func CtxSet(key string) *Stage
- func FieldValue(key string) *Stage
- func If(cond func(any, *gin.Context) bool, then *Chain, els *Chain) *Stage
- func QueryParam(key string) *Stage
- func S(name string, f func(any, *gin.Context, Logger) (any, error)) *Stage
- func ToObjectID() *Stage
- func ToTime(layout string) *Stage
- func ToTimeInLocation(ctxTimezoneName string, layout string) *Stage
- func URLParam(key string) *Stage
- type StageError
Constants ¶
This section is empty.
Variables ¶
var ( BR = http.StatusBadRequest ISR = http.StatusInternalServerError )
var ErrNotFound = errors.New("not found")
Functions ¶
func CtxOutStr ¶
CtxOutStr generates a string such as ` => ["ctxOutVar1"], ["ctxOutVar2"]` from the inputs CtxOutStr("ctxOutVar1", "ctxOutVar2")
func FuncStr ¶
FuncStr generates a string such as `my_stage_name(["ctxVar1"], ["ctxVar2"])` from the inputs FuncStr("my_stage_name", "ctxVar1", "ctxVar2")
func MakeGinHandlerFunc ¶
func MakeGinHandlerFunc(ch *Chain, lgr Logger) gin.HandlerFunc
func StageName ¶
func StageName(usesInParam bool, name string, ctxDependencies []string, ctxOutputs []string, returnsAValue bool) string
StageName generates a string such as ` => my_stage_name(["ctxVar"]) => ["newCtxVar"]` from the inputs StageName(true, "my_stage_name", []string{"ctxVar"}, []string{"newCtxVar"}, false)
Types ¶
type Chain ¶
func First ¶
Pipelines should be defined by sending the first Stage in to the First function and then each following Stage into the Then function. The pipeline definition should read like:
pipeline := First(stage0).Then(stage1).Then(stage2) ...
or alternatively:
pipeline := First( stage0).Then( stage1).Then( stage2) ...
func InParallel ¶
func InSequence ¶
InSequence concatenates together multiple chains defined by the above First+Then method.
func (*Chain) Catch ¶
Catch can be used to optionally override a stage's E function like:
pipeline := First( stage0).Then( stage1).Catch(http.StatusBadRequest, "stage1 failed").Then( stage2) ...
func (*Chain) CatchError ¶
func (ch *Chain) CatchError(E func(err error) *StageError) *Chain
type ChainExecutionError ¶
type ChainExecutionError struct {
StageError *StageError
}
func (ChainExecutionError) Error ¶
func (e ChainExecutionError) Error() string
type DefaultLogger ¶
type DefaultLogger struct {
Logger
}
func (DefaultLogger) LogMessage ¶
func (l DefaultLogger) LogMessage(msg string)
func (DefaultLogger) LogStageComplete ¶
func (DefaultLogger) LogStageError ¶
func (l DefaultLogger) LogStageError(e *StageError)
func (DefaultLogger) LogStageStart ¶
func (l DefaultLogger) LogStageStart(print string, in any)
type JSONResponse ¶
TODO: Replace the Response and StageError types with this single type
type Stage ¶
type Stage struct { P func() string // Printed name of the stage, for logging F func(any, *gin.Context, Logger) (any, error) // Function to execute. Optional logger for stages that nest chains. E func(error) *StageError // Network error to return for F's error // contains filtered or unexported fields }
Stage is a step in a request pipeline. Stages are connected together as double-linked lists by n and l. When a pipeline is run, it executes each Stage's F function. The input to F is the output of the last Stage plus the request's context. The output of F is, in turn, passed into the next Stage. When F returns an error, it is passed in to the E function, which generates the HTTP status code and JSON response data that should be returned in the network response. The last Stage of a pipeline should return a *Response as the output of F. When a stage completes, P() will be logged to the console with the results of the stage.
func FieldValue ¶
func QueryParam ¶
func S ¶
S creates a generic stage that executes the given function. E's default code is http.StatusBadRequest since that is common.
func ToObjectID ¶
func ToObjectID() *Stage
func ToTime ¶
ToTime - Converts in to time.Time for the UTC timezone. in must be a string matching the given layout. It is equivalent to calling ToTimeInLocation with ctxTimezoneName = "".
func ToTimeInLocation ¶
ToTimeInLocation - Converts in to time.Time. in must be a string. It will be parsed per the given timezone and layout. If ctxTimezoneName is "" or its value has not been set in the context, UTC will be used.