Documentation ¶
Index ¶
- Variables
- func UseCompression(b bool) func(*defaultFlow)
- func WithInputData(inputData InputData) func(*defaultFlow)
- func WithQueryParamKey(key string) func(*defaultFlow)
- func WithQueryParamValue(value string) func(*defaultFlow)
- type Action
- type ActionName
- type Actions
- type BeforeEachActionExecutionContext
- type Context
- type ExecutionContext
- type Flow
- type FlowBuilder
- type FlowDB
- type FlowError
- type FlowModel
- type FlowName
- type FlowResult
- type HookAction
- type HookExecutionContext
- type InitializationContext
- type Input
- type InputData
- type InputError
- type Link
- type LinkCategory
- type LinkTarget
- type Response
- type ResponseAction
- type ResponseActions
- type ResponseAllowedValue
- type ResponseAllowedValues
- type ResponseError
- type ResponseInput
- type ResponseInputs
- type ResponseLink
- type ResponseLinks
- type StateName
- type SubFlowBuilder
- type SubFlows
Constants ¶
This section is empty.
Variables ¶
var ( ErrorTechnical = NewFlowError("technical_error", "Something went wrong.", http.StatusInternalServerError) ErrorFlowExpired = NewFlowError("flow_expired_error", "The flow has expired.", http.StatusGone) ErrorFlowDiscontinuity = NewFlowError("flow_discontinuity_error", "The flow can't be continued.", http.StatusInternalServerError) ErrorOperationNotPermitted = NewFlowError("operation_not_permitted_error", "The operation is not permitted.", http.StatusForbidden) ErrorFormDataInvalid = NewFlowError("form_data_invalid_error", "Form data invalid.", http.StatusBadRequest) )
Predefined flow error types
var ( ErrorValueMissing = NewInputError("value_missing_error", "The value is missing.") ErrorValueInvalid = NewInputError("value_invalid_error", "The value is invalid.") ErrorValueTooLong = NewInputError("value_too_long_error", "The value is too long.") ErrorValueTooShort = NewInputError("value_too_short_error", "The value is too short.") )
Predefined input error types
Functions ¶
func UseCompression ¶
func UseCompression(b bool) func(*defaultFlow)
UseCompression causes the flow data to be compressed before stored to the db.
func WithInputData ¶
func WithInputData(inputData InputData) func(*defaultFlow)
WithInputData sets the InputData for flowExecutionOptions.
func WithQueryParamKey ¶
func WithQueryParamKey(key string) func(*defaultFlow)
WithQueryParamKey sets the ActionName for flowExecutionOptions.
func WithQueryParamValue ¶
func WithQueryParamValue(value string) func(*defaultFlow)
WithQueryParamValue sets the ActionName for flowExecutionOptions.
Types ¶
type Action ¶
type Action interface { GetName() ActionName // Get the action name. GetDescription() string // Get the action description. Initialize(InitializationContext) // Initialize the action. Execute(ExecutionContext) error // Execute the action. }
Action defines the interface for flow actions.
type BeforeEachActionExecutionContext ¶
type BeforeEachActionExecutionContext interface {
// contains filtered or unexported methods
}
type ExecutionContext ¶
type ExecutionContext interface {
// contains filtered or unexported methods
}
ExecutionContext is a shorthand for actionExecutionContinuationContext within flow execution method.
type Flow ¶
type Flow interface { // Execute executes the flow using the provided FlowDB and options. // It returns the result of the flow execution and an error if any. Execute(db FlowDB, opts ...func(*defaultFlow)) (FlowResult, error) // ResultFromError converts an error into a FlowResult. ResultFromError(err error) FlowResult // Set sets a value with the given key in the flow context. Set(string, interface{}) // contains filtered or unexported methods }
Flow represents a flow.
type FlowBuilder ¶
type FlowBuilder interface { TTL(ttl time.Duration) FlowBuilder State(stateName StateName, actions ...Action) FlowBuilder InitialState(stateNames ...StateName) FlowBuilder ErrorState(stateName StateName) FlowBuilder BeforeState(stateName StateName, hooks ...HookAction) FlowBuilder AfterState(stateName StateName, hooks ...HookAction) FlowBuilder AfterFlow(flowName FlowName, hooks ...HookAction) FlowBuilder Debug(enabled bool) FlowBuilder SubFlows(subFlows ...subFlow) FlowBuilder Build() (Flow, error) MustBuild() Flow BeforeEachAction(hooks ...HookAction) FlowBuilder AfterEachAction(hooks ...HookAction) FlowBuilder }
func NewFlow ¶
func NewFlow(name FlowName) FlowBuilder
NewFlow creates a new defaultFlowBuilder that builds a new flow available under the specified path.
type FlowDB ¶
type FlowDB interface { GetFlow(flowID uuid.UUID) (*FlowModel, error) CreateFlow(flowModel FlowModel) error UpdateFlow(flowModel FlowModel) error }
FlowDB is the interface for interacting with the flow database.
type FlowError ¶
type FlowError interface { Wrap(error) FlowError Status() int // contains filtered or unexported methods }
FlowError is an interface representing flow-related errors.
func NewFlowError ¶
NewFlowError creates a new FlowError instance.
type FlowModel ¶
type FlowModel struct { ID uuid.UUID // Unique ID of the flow. Data string // Stash data associated with the flow. CSRFToken string // Current CSRF token Version int // Version of the flow. ExpiresAt time.Time // Expiry time of the flow. CreatedAt time.Time // Creation time of the flow. UpdatedAt time.Time // Update time of the flow. }
FlowModel represents the database model for a flow.
type FlowResult ¶
FlowResult interface defines methods for obtaining response and status.
type HookAction ¶
type HookAction interface {
Execute(HookExecutionContext) error
}
HookAction defines the interface for a hook action.
type HookExecutionContext ¶
type InitializationContext ¶
type InitializationContext interface {
// contains filtered or unexported methods
}
InitializationContext is a shorthand for actionInitializationContext within the flow initialization method.
type Input ¶
type Input interface { MinLength(minLength int) Input MaxLength(maxLength int) Input Required(b bool) Input Hidden(b bool) Input Preserve(b bool) Input AllowedValue(name string, value interface{}) Input TrimSpace(b bool) Input LowerCase(b bool) Input // contains filtered or unexported methods }
Input defines the interface for input fields.
func BooleanInput ¶
BooleanInput creates a new input field of boolean type.
func EmailInput ¶
EmailInput creates a new input field of email type.
func NumberInput ¶
NumberInput creates a new input field of number type.
func PasswordInput ¶
PasswordInput creates a new input field of password type.
func StringInput ¶
StringInput creates a new input field of string type.
type InputData ¶
type InputData struct { InputDataMap map[string]interface{} `json:"input_data"` CSRFToken string `json:"csrf_token"` }
InputData holds input data in JSON format.
type InputError ¶
type InputError interface { Wrap(error) InputError // contains filtered or unexported methods }
InputError is an interface representing input-related errors.
func NewInputError ¶
func NewInputError(code, message string) InputError
NewInputError creates a new InputError instance.
type Link ¶
type Link interface { Target(LinkTarget) Link // contains filtered or unexported methods }
Link defines the interface for links.
type LinkTarget ¶
type LinkTarget string
LinkTarget represents the html target attribute.
const ( LinkTargetSelf LinkTarget = "_self" LinkTargetBlank LinkTarget = "_blank" LinkTargetParent LinkTarget = "_parent" LinkTargetTop LinkTarget = "_top" )
Link targets enumeration.
type Response ¶
type Response struct { Name StateName `json:"name"` Status int `json:"status"` Payload interface{} `json:"payload,omitempty"` CSRFToken string `json:"csrf_token"` Actions ResponseActions `json:"actions"` Error *ResponseError `json:"error,omitempty"` Links ResponseLinks `json:"links"` }
Response represents the response of an action execution.
type ResponseAction ¶
type ResponseAction struct { Href string `json:"href"` Inputs ResponseInputs `json:"inputs"` Name ActionName `json:"action"` Description string `json:"description"` }
ResponseAction represents a link to an action.
type ResponseActions ¶
type ResponseActions map[ActionName]ResponseAction
ResponseActions is a collection of ResponseAction instances.
type ResponseAllowedValue ¶
type ResponseAllowedValue struct { Value interface{} `json:"value"` Text string `json:"name"` }
type ResponseAllowedValues ¶
type ResponseAllowedValues []*ResponseAllowedValue
type ResponseError ¶
type ResponseError struct { Code string `json:"code"` Message string `json:"message"` Cause *string `json:"cause,omitempty"` Internal *string `json:"-"` }
ResponseError represents an error for public exposure.
type ResponseInput ¶
type ResponseInput struct { Name string `json:"name"` Type inputType `json:"type"` Value interface{} `json:"value,omitempty"` MinLength *int `json:"min_length,omitempty"` MaxLength *int `json:"max_length,omitempty"` Required *bool `json:"required,omitempty"` Hidden *bool `json:"hidden,omitempty"` Error *ResponseError `json:"error,omitempty"` AllowedValues *ResponseAllowedValues `json:"allowed_values,omitempty"` }
ResponseInput represents an input field for public exposure.
type ResponseInputs ¶
type ResponseInputs map[string]*ResponseInput
ResponseInputs represents a collection of ResponseInput instances.
type ResponseLink ¶
type ResponseLink struct { Name string `json:"name"` // tos, privacy, google, apple, microsoft, login, registration ... // how can we insert custom oauth provider here Href string `json:"href"` Category LinkCategory `json:"category"` // oauth, legal, other, ... Target LinkTarget `json:"target"` // can be used to add the target of the a-tag e.g. _blank }
ResponseLink represents a link for public exposure.
type ResponseLinks ¶
type ResponseLinks []ResponseLink
ResponseLinks is a collection of Link instances.
type SubFlowBuilder ¶
type SubFlowBuilder interface { State(stateName StateName, actions ...Action) SubFlowBuilder BeforeState(stateName StateName, hooks ...HookAction) SubFlowBuilder AfterState(stateName StateName, hooks ...HookAction) SubFlowBuilder SubFlows(subFlows ...subFlow) SubFlowBuilder Build() (subFlow, error) MustBuild() subFlow }
func NewSubFlow ¶
func NewSubFlow(name FlowName) SubFlowBuilder
NewSubFlow creates a new SubFlowBuilder.