Documentation ¶
Index ¶
- Constants
- func CheckResponseStatus(request *RestRequest, statusCodes []int) error
- func DefaultClient(connectionSettings ConnectionSettings, state *State) (*http.Client, error)
- func WarnOrError(actionState *action.State, logEntry *logger.LogEntry, failOnError bool, ...)
- type AppData
- type AppSelection
- type AppSelectionCore
- type AppSelectionModeEnum
- type AppsResp
- type ArtifactEntry
- type ArtifactListDict
- type ArtifactMap
- func (am *ArtifactMap) AddSpace(space elasticstructs.Space)
- func (am *ArtifactMap) DeleteApp(AppGUID string)
- func (am *ArtifactMap) DeleteStream(streamName string)
- func (am *ArtifactMap) EmptyApps()
- func (am *ArtifactMap) FillAppsUsingDocListEntries(docListEntries []*enigma.DocListEntry) error
- func (am *ArtifactMap) FillAppsUsingName(appData *AppData) error
- func (am *ArtifactMap) FillAppsUsingTitle(appData *AppData) error
- func (am *ArtifactMap) FillSpaces(spaces []elasticstructs.Space)
- func (am *ArtifactMap) FillStreams(streamList []elasticstructs.Collection)
- func (am *ArtifactMap) GetAppID(appName string) (string, error)
- func (am *ArtifactMap) GetItemId(appName string) (string, error)
- func (am *ArtifactMap) GetRandomApp(sessionState *State) (ArtifactEntry, error)
- func (am *ArtifactMap) GetRoundRobin(sessionState *State) (ArtifactEntry, error)
- func (am *ArtifactMap) GetSpaceByID(spaceID string) (*elasticstructs.Space, error)
- func (am *ArtifactMap) GetSpaceByName(spaceName string) (*elasticstructs.Space, error)
- func (am *ArtifactMap) GetStreamID(streamName string) (string, error)
- func (am *ArtifactMap) Json() ([]byte, error)
- func (am *ArtifactMap) LogMap(entry *logger.LogEntry) error
- func (am *ArtifactMap) LookupAppGUID(sessionState *State, guid string) (*ArtifactEntry, error)
- func (am *ArtifactMap) LookupAppTitle(sessionState *State, title string) (*ArtifactEntry, error)
- type ConnectionSettings
- type DuplicateKeyError
- type Event
- type HeaderJar
- type IConnection
- type IDMap
- type PendingHandler
- type ReqOptions
- type RestHandler
- func (handler *RestHandler) DecPending(request *RestRequest)
- func (handler *RestHandler) FireOffGet(url string, actionState *action.State, failOnError bool) *RestRequest
- func (handler *RestHandler) FireOffGetWithCallback(url string, actionState *action.State, failOnError bool, ...) *RestRequest
- func (handler *RestHandler) GetAsync(url string, actionState *action.State, logEntry *logger.LogEntry, ...) *RestRequest
- func (handler *RestHandler) GetAsyncWithCallback(url string, actionState *action.State, logEntry *logger.LogEntry, ...) *RestRequest
- func (handler *RestHandler) GetSync(url string, actionState *action.State, logEntry *logger.LogEntry, ...) (*RestRequest, error)
- func (handler *RestHandler) GetSyncWithCallback(url string, actionState *action.State, logEntry *logger.LogEntry, ...) (*RestRequest, error)
- func (handler *RestHandler) IncPending()
- func (handler *RestHandler) PostAsync(url string, actionState *action.State, logEntry *logger.LogEntry, ...) *RestRequest
- func (handler *RestHandler) PostAsyncWithCallback(url string, actionState *action.State, logEntry *logger.LogEntry, ...) *RestRequest
- func (handler *RestHandler) QueueRequest(actionState *action.State, failOnError bool, request *RestRequest, ...)
- func (handler *RestHandler) QueueRequestWithCallback(actionState *action.State, failOnError bool, request *RestRequest, ...)
- func (handler *RestHandler) SetClient(client *http.Client)
- func (handler *RestHandler) WaitForPending()
- type RestMethod
- type RestRequest
- type SessionVariables
- type SpaceNotFoundError
- type State
- func (state *State) BaseContext() context.Context
- func (state *State) Cancel()
- func (state *State) ContextChangeList() (context.Context, *enigma.ChangeLists)
- func (state *State) ContextWithTimeout(ctx context.Context) (context.Context, context.CancelFunc)
- func (state *State) DeRegisterEvent(handle int)
- func (state *State) DeRegisterEvents(handles []int)
- func (state *State) DeregisterAllEvents()
- func (state *State) Disconnect()
- func (state *State) GetSessionVariable(localData interface{}) SessionVariables
- func (state *State) IsAbortTriggered() bool
- func (state *State) QueueRequest(f func(ctx context.Context) error, actionState *action.State, failOnError bool, ...)
- func (state *State) QueueRequestWithCallback(f func(ctx context.Context) error, actionState *action.State, failOnError bool, ...)
- func (state *State) Randomizer() *randomizer.Randomizer
- func (state *State) RegisterEvent(handle int, event func(ctx context.Context, actionState *action.State) error, ...)
- func (state *State) ReplaceSessionVariables(input *SyncedTemplate) (string, error)
- func (state *State) ReplaceSessionVariablesWithLocalData(input *SyncedTemplate, localData interface{}) (string, error)
- func (state *State) ReqContext() (context.Context, *enigma.ChangeLists, context.CancelFunc)
- func (state *State) Reset(ctx context.Context)
- func (state *State) SendRequest(actionState *action.State, f func(ctx context.Context) error) error
- func (state *State) SendRequestRaw(actionState *action.State, ...) (json.RawMessage, error)
- func (state *State) SetLogEntry(entry *logger.LogEntry)
- func (state *State) SetRandomizer(rnd *randomizer.Randomizer, force bool)
- func (state *State) TrafficLogger() enigmahandlers.ITrafficLogger
- func (state *State) TriggerContextChanges(ctx context.Context, actionState *action.State)
- func (state *State) TriggerEvents(actionState *action.State, chHandles, clHandles []int)
- func (state *State) WSFailed()
- func (state *State) Wait(actionState *action.State) bool
- type SyncedTemplate
- func (syn *SyncedTemplate) Execute(writer io.Writer, data interface{}) error
- func (syn SyncedTemplate) MarshalJSON() ([]byte, error)
- func (input *SyncedTemplate) ReplaceWithoutSessionVariables(data interface{}) (string, error)
- func (syn *SyncedTemplate) String() string
- func (syn SyncedTemplate) TreatAs() string
- func (syn *SyncedTemplate) UnmarshalJSON(arg []byte) error
- type Transport
Constants ¶
const ( // DefaultTimeout per request timeout DefaultTimeout = 300 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func CheckResponseStatus ¶
func CheckResponseStatus(request *RestRequest, statusCodes []int) error
CheckResponseStatus validates that a response has acceptable
func DefaultClient ¶
func DefaultClient(connectionSettings ConnectionSettings, state *State) (*http.Client, error)
DefaultClient creates client instance with default client settings
Types ¶
type AppData ¶
type AppData struct {
Data []AppsResp `json:"data"`
}
AppData struct to unmarshal list app response
type AppSelection ¶
type AppSelection struct { AppSelectionCore // contains filtered or unexported fields }
AppSelection contains the selected app for the current session
func NewAppSelection ¶
func NewAppSelection(appMode AppSelectionModeEnum, app string, list []string) (*AppSelection, error)
NewAppSelection creates new instance of AppSelection
func (*AppSelection) Select ¶
func (appSelection *AppSelection) Select(sessionState *State) (*ArtifactEntry, error)
Select new app
func (*AppSelection) UnmarshalJSON ¶
func (appSelection *AppSelection) UnmarshalJSON(arg []byte) error
UnmarshalJSON unmarshal AppSelection
func (*AppSelection) Validate ¶
func (appSelection *AppSelection) Validate() error
Validate AppSelection settings
type AppSelectionCore ¶
type AppSelectionCore struct { // AppMode app selection mode AppMode AppSelectionModeEnum `json:"appmode" displayname:"App selection mode" doc-key:"appselection.appmode"` // App name or GUID depending on AppMode App SyncedTemplate `json:"app,omitempty" displayname:"App" doc-key:"appselection.app"` // AppList of app names or GUID's, depending on AppMode AppList []string `json:"list,omitempty" displayname:"App selection list" doc-key:"appselection.list"` // Filename of file containing app names, one app per line Filename helpers.RowFile `json:"filename,omitempty" displayname:"App selection filename" displayelement:"file" doc-key:"appselection.filename"` }
AppSelectionCore app selection settings shared between multiple actions
type AppSelectionModeEnum ¶
type AppSelectionModeEnum int
AppSelectionModeEnum from where to get app to open, defaults to "current"
const ( AppModeCurrent AppSelectionModeEnum = iota AppModeGUID AppModeName AppModeRandom AppModeRandomNameFromList AppModeRandomGUIDFromList AppModeRandomNameFromFile AppModeRandomGUIDFromFile AppModeRound AppModeRoundNameFromList AppModeRoundGUIDFromList AppModeRoundNameFromFile AppModeRoundGUIDFromFile )
AppSelectionModeEnum from where to get app to open, defaults to "current"
func (AppSelectionModeEnum) GetEnumMap ¶
func (mode AppSelectionModeEnum) GetEnumMap() *enummap.EnumMap
GetEnumMap for app selection mode
func (AppSelectionModeEnum) MarshalJSON ¶
func (mode AppSelectionModeEnum) MarshalJSON() ([]byte, error)
MarshalJSON marshal AppSelectionModeEnum
func (AppSelectionModeEnum) String ¶
func (mode AppSelectionModeEnum) String() string
String implements stringer interface
func (*AppSelectionModeEnum) UnmarshalJSON ¶
func (mode *AppSelectionModeEnum) UnmarshalJSON(arg []byte) error
UnmarshalJSON unmarshal AppSelectionModeEnum
type ArtifactEntry ¶
ArtifactEntry is a key value pair
func (*ArtifactEntry) Copy ¶
func (entry *ArtifactEntry) Copy() *ArtifactEntry
Copy of ArtifactEntry
func (*ArtifactEntry) IsEmpty ¶
func (entry *ArtifactEntry) IsEmpty() bool
IsEmpty returns true of entry is nil or has no GUID
type ArtifactListDict ¶
type ArtifactListDict []*ArtifactEntry
func (ArtifactListDict) Len ¶
func (d ArtifactListDict) Len() int
func (ArtifactListDict) Less ¶
func (d ArtifactListDict) Less(i, j int) bool
func (ArtifactListDict) Swap ¶
func (d ArtifactListDict) Swap(i, j int)
type ArtifactMap ¶
type ArtifactMap struct { AppList ArtifactListDict // contains filtered or unexported fields }
ArtifactMap is the map between app names and GUIDs
func (*ArtifactMap) AddSpace ¶
func (am *ArtifactMap) AddSpace(space elasticstructs.Space)
AddSpace to artifact map
func (*ArtifactMap) DeleteApp ¶
func (am *ArtifactMap) DeleteApp(AppGUID string)
DeleteApp deletes an app from the ArtifactMap
func (*ArtifactMap) DeleteStream ¶
func (am *ArtifactMap) DeleteStream(streamName string)
DeleteStream deletes a stream from the ArtifactMap
func (*ArtifactMap) EmptyApps ¶
func (am *ArtifactMap) EmptyApps()
EmptyApps Empty Apps from ArtifactMap
func (*ArtifactMap) FillAppsUsingDocListEntries ¶
func (am *ArtifactMap) FillAppsUsingDocListEntries(docListEntries []*enigma.DocListEntry) error
FillAppsUsingDocListEntries should be used to fillAppMap app map in QSEfW
func (*ArtifactMap) FillAppsUsingName ¶
func (am *ArtifactMap) FillAppsUsingName(appData *AppData) error
FillAppsUsingName should be used to fillAppMap app map in QCS
func (*ArtifactMap) FillAppsUsingTitle ¶
func (am *ArtifactMap) FillAppsUsingTitle(appData *AppData) error
FillAppsUsingTitle should be used to fillAppMap app map in QSCB
func (*ArtifactMap) FillSpaces ¶
func (am *ArtifactMap) FillSpaces(spaces []elasticstructs.Space)
FillSpaces fills the spaces map with the spaces from the given list
func (*ArtifactMap) FillStreams ¶
func (am *ArtifactMap) FillStreams(streamList []elasticstructs.Collection)
FillStreams fills the stream map with the streams from the given list
func (*ArtifactMap) GetAppID ¶
func (am *ArtifactMap) GetAppID(appName string) (string, error)
GetAppID returns the app ID given the app Title. When multiple apps have the same Title, this will return the ID of the last app in the order of the struct passed to the Fill function.
func (*ArtifactMap) GetItemId ¶
func (am *ArtifactMap) GetItemId(appName string) (string, error)
GetItemId returns the item ID given the app Title. When multiple apps have the same Title, this will return the ID of the last app in the order of the struct passed to the Fill function.
func (*ArtifactMap) GetRandomApp ¶
func (am *ArtifactMap) GetRandomApp(sessionState *State) (ArtifactEntry, error)
GetRandomApp returns a random app for the map, chosen by a uniform distribution
func (*ArtifactMap) GetRoundRobin ¶
func (am *ArtifactMap) GetRoundRobin(sessionState *State) (ArtifactEntry, error)
GetRoundRobin returns a app round robin for the map
func (*ArtifactMap) GetSpaceByID ¶
func (am *ArtifactMap) GetSpaceByID(spaceID string) (*elasticstructs.Space, error)
GetSpaceByID returns the space ID given space name
func (*ArtifactMap) GetSpaceByName ¶
func (am *ArtifactMap) GetSpaceByName(spaceName string) (*elasticstructs.Space, error)
GetSpaceByName returns the space ID given space name
func (*ArtifactMap) GetStreamID ¶
func (am *ArtifactMap) GetStreamID(streamName string) (string, error)
GetStreamID returns the app ID given the stream
func (*ArtifactMap) Json ¶
func (am *ArtifactMap) Json() ([]byte, error)
Json locks artifact map and marshals json
func (*ArtifactMap) LogMap ¶
func (am *ArtifactMap) LogMap(entry *logger.LogEntry) error
LogMap log entire map as debug logging
func (*ArtifactMap) LookupAppGUID ¶
func (am *ArtifactMap) LookupAppGUID(sessionState *State, guid string) (*ArtifactEntry, error)
SetCurrentAppTitle lookup app using GUID
func (*ArtifactMap) LookupAppTitle ¶
func (am *ArtifactMap) LookupAppTitle(sessionState *State, title string) (*ArtifactEntry, error)
LookupAppTitle lookup app using title
type ConnectionSettings ¶
type ConnectionSettings interface {
AllowUntrusted() bool
}
ConnectionSettings interface
type DuplicateKeyError ¶
type DuplicateKeyError string
DuplicateKeyError is returned in case of adding an already existing key id
func (DuplicateKeyError) Error ¶
func (err DuplicateKeyError) Error() string
Error id already exist in map
type Event ¶
type Event struct { // F is function to be executed on event F func(ctx context.Context, actionState *action.State) error // NoFailOnError - // False (Default) - Report error and abort action // True - Log warning instead of failing and error reporting NoFailOnError bool // Close executed on de-registering event Close func() }
Event encapsulates an event channel and a function to be executed on events
type HeaderJar ¶
type HeaderJar struct {
// contains filtered or unexported fields
}
HeaderJar map between hosts and headers
type IConnection ¶
type IConnection interface { // Disconnect connection Disconnect() error // SetSense : set current sense environment SetSense(*enigmahandlers.SenseUplink) // Sense : connection to sense environment Sense() *enigmahandlers.SenseUplink }
IConnection interface for current
type IDMap ¶
type IDMap struct {
// contains filtered or unexported fields
}
IDMap should be used as a lookup table for Id defined in the script and id of object created. We should never define the id to be sent to engine as this might cause collision errors, instead this lookup table is used with the key id connecting object together for in-script purposes.
func (*IDMap) IsDuplicateKey ¶
IsDuplicateKey returns already in case of duplicate key
type PendingHandler ¶
type PendingHandler struct {
// contains filtered or unexported fields
}
PendingHandler handles waiting for pending requests and responses
func NewPendingHandler ¶
func NewPendingHandler(size int) PendingHandler
NewPendingHandler new instance of PendingHandler
func (*PendingHandler) DecPending ¶
func (pending *PendingHandler) DecPending()
DecPending increase finished requests
func (*PendingHandler) IncPending ¶
func (pending *PendingHandler) IncPending()
IncPending increase pending requests
func (*PendingHandler) QueueRequest ¶
func (pending *PendingHandler) QueueRequest(baseCtx context.Context, timeout time.Duration, f func(ctx context.Context) error, logEntry *logger.LogEntry, onFinished func(err error))
QueueRequest Async request,
func (*PendingHandler) WaitForPending ¶
func (pending *PendingHandler) WaitForPending(ctx context.Context)
WaitForPending uses double locking of mutex to wait until mutex is unlocked by loop listening for pending req/resp
type ReqOptions ¶
type ReqOptions struct { // ExpectedStatusCode of response, empty list accepts everything (used e.g. for separate checking status) ExpectedStatusCode []int // FailOnError set to true for request to add an error to actionState, otherwise a warning is logged. FailOnError bool // ContentType defaults to application/json ContentType string }
ReqOptions options controlling handling of requests
func DefaultReqOptions ¶
func DefaultReqOptions() ReqOptions
DefaultReqOptions sets expected status code to 200 and fails on error
type RestHandler ¶
RestHandler handles waiting for pending requests and responses
func NewRestHandler ¶
func NewRestHandler(ctx context.Context, size int, trafficLogger enigma.TrafficLogger, headerjar *HeaderJar, virtualProxy string, timeout time.Duration) *RestHandler
NewRestHandler new instance of RestHandler
func (*RestHandler) DecPending ¶
func (handler *RestHandler) DecPending(request *RestRequest)
DecPending increase finished requests
func (*RestHandler) FireOffGet ¶
func (handler *RestHandler) FireOffGet(url string, actionState *action.State, failOnError bool) *RestRequest
FireOffGet request Deprecated: Replace with GetAsync or QueueRequest
func (*RestHandler) FireOffGetWithCallback ¶
func (handler *RestHandler) FireOffGetWithCallback(url string, actionState *action.State, failOnError bool, callback func(err error, req *RestRequest)) *RestRequest
FireOffGet request with callback Deprecated: Replace with GetAsyncWithCallback or QueueRequestWithCallback
func (*RestHandler) GetAsync ¶
func (handler *RestHandler) GetAsync(url string, actionState *action.State, logEntry *logger.LogEntry, options *ReqOptions) *RestRequest
GetAsync send async GET request with options, using options=nil default options are used
func (*RestHandler) GetAsyncWithCallback ¶
func (handler *RestHandler) GetAsyncWithCallback(url string, actionState *action.State, logEntry *logger.LogEntry, options *ReqOptions, callback func(err error, req *RestRequest)) *RestRequest
GetAsync send async GET request with options and callback, with options=nil default options are used
func (*RestHandler) GetSync ¶
func (handler *RestHandler) GetSync(url string, actionState *action.State, logEntry *logger.LogEntry, options *ReqOptions) (*RestRequest, error)
GetSync sends synchronous GET request with options, using options=nil default options are used
func (*RestHandler) GetSyncWithCallback ¶
func (handler *RestHandler) GetSyncWithCallback(url string, actionState *action.State, logEntry *logger.LogEntry, options *ReqOptions, callback func(err error, req *RestRequest)) (*RestRequest, error)
GetSyncWithCallback sends synchronous GET request with options and callback, using options=nil default options are used
func (*RestHandler) IncPending ¶
func (handler *RestHandler) IncPending()
IncPending increase pending requests
func (*RestHandler) PostAsync ¶
func (handler *RestHandler) PostAsync(url string, actionState *action.State, logEntry *logger.LogEntry, content []byte, options *ReqOptions) *RestRequest
PostAsync send async POST request with options, using options=nil default options are used
func (*RestHandler) PostAsyncWithCallback ¶
func (handler *RestHandler) PostAsyncWithCallback(url string, actionState *action.State, logEntry *logger.LogEntry, content []byte, options *ReqOptions, callback func(err error, req *RestRequest)) *RestRequest
PostAsync send async POST request with options and callback, using options=nil default options are used
func (*RestHandler) QueueRequest ¶
func (handler *RestHandler) QueueRequest(actionState *action.State, failOnError bool, request *RestRequest, logEntry *logger.LogEntry)
QueueRequest Async request
func (*RestHandler) QueueRequestWithCallback ¶
func (handler *RestHandler) QueueRequestWithCallback(actionState *action.State, failOnError bool, request *RestRequest, logEntry *logger.LogEntry, callback func(err error, req *RestRequest))
QueueRequest Async request with callback, set warnOnError to log warning instead of registering error for request
func (*RestHandler) SetClient ¶
func (handler *RestHandler) SetClient(client *http.Client)
SetClient set HTTP client for this RestHandler
func (*RestHandler) WaitForPending ¶
func (handler *RestHandler) WaitForPending()
WaitForPending uses double locking of mutex to wait until mutex is unlocked by loop listening for pending req/resp
type RestMethod ¶
type RestMethod int
RestMethod method with which to execute request
const ( // GET RestMethod GET RestMethod = iota // POST RestMethod POST // DELETE RestMethod DELETE // PUT RestMethod PUT )
RestMethod values
func (RestMethod) MarshalJSON ¶
func (method RestMethod) MarshalJSON() ([]byte, error)
MarshalJSON marshal RestMethod
func (RestMethod) String ¶
func (method RestMethod) String() string
String implements fmt.Stringer interface
func (*RestMethod) UnmarshalJSON ¶
func (method *RestMethod) UnmarshalJSON(arg []byte) error
UnmarshalJSON unmarshal RestMethod
type RestRequest ¶
type RestRequest struct { Method RestMethod ContentType string Content []byte ContentReader io.Reader Destination string ResponseBody []byte ResponseStatus string ResponseStatusCode int ResponseHeaders http.Header ExtraHeaders map[string]string // contains filtered or unexported fields }
RestRequest represents a REST request and its response
type SessionVariables ¶
SessionVariables is used as a data carrier for session variables.
type SpaceNotFoundError ¶
type SpaceNotFoundError string
func (SpaceNotFoundError) Error ¶
func (err SpaceNotFoundError) Error() string
Error implements error interface
type State ¶
type State struct { Cookies http.CookieJar VirtualProxy string Connection IConnection ArtifactMap *ArtifactMap IDMap IDMap HeaderJar *HeaderJar LoggedIn bool Timeout time.Duration User *users.User OutputsDir string CurrentApp *ArtifactEntry CurrentUser *elasticstructs.User // CurrentActionState will contain the state of the latest action to be started CurrentActionState *action.State LogEntry *logger.LogEntry EW statistics.ErrWarn Pending PendingHandler Rest *RestHandler RequestMetrics *requestmetrics.RequestMetrics // contains filtered or unexported fields }
State for user
func New ¶
func New(ctx context.Context, outputsDir string, timeout time.Duration, user *users.User, session, instance uint64, virtualProxy string) *State
New instance of session state
func (*State) BaseContext ¶
BaseContext for state. Normally shouldn't be used. Use ReqContext for for context on Sense actions, or methods handling the context such as QueueRequest and SendRequest
func (*State) ContextChangeList ¶
func (state *State) ContextChangeList() (context.Context, *enigma.ChangeLists)
ContextChangeList create changeList object and context to be used for synchronizing changes
func (*State) ContextWithTimeout ¶
ContextWithTimeout new context based on ctx with default timeout
func (*State) DeRegisterEvent ¶
DeRegisterEvent for handle
func (*State) DeRegisterEvents ¶
DeRegisterEvents for handles in list
func (*State) DeregisterAllEvents ¶
func (state *State) DeregisterAllEvents()
DeregisterAllEvents for session
func (*State) Disconnect ¶
func (state *State) Disconnect()
Disconnect de-registers all events and disconnects current connection
func (*State) GetSessionVariable ¶
func (state *State) GetSessionVariable(localData interface{}) SessionVariables
GetSessionVariable populates and returns session variables struct
func (*State) IsAbortTriggered ¶
IsAbortTriggered check if abort has been flagged
func (*State) QueueRequest ¶
func (state *State) QueueRequest(f func(ctx context.Context) error, actionState *action.State, failOnError bool, errMsg string)
QueueRequest Async request, add error to action state or log as warning depending on failOnError flag. This method adds timeout and ChangeList to ctx context and auto triggers changes. Thus ctx should not be used when having multiple request in a QueueRequest function, instead use SendRequest and SendRequestRaw internally in f. Changes can also be handled "manually" with the help of TriggerContextChanges.
func (*State) QueueRequestWithCallback ¶
func (state *State) QueueRequestWithCallback(f func(ctx context.Context) error, actionState *action.State, failOnError bool, errMsg string, callback func(err error))
QueueRequestWithCallback Async request, add error to action state or log as warning depending on failOnError flag. This method adds timeout and ChangeList to ctx context and auto triggers changes. Thus ctx should not be used when having multiple request in a QueueRequest function, instead use SendRequest and SendRequestRaw internally in f. Changes can also be handled "manually" with the help of TriggerContextChanges.
func (*State) Randomizer ¶
func (state *State) Randomizer() *randomizer.Randomizer
Randomizer get randomizer for session
func (*State) RegisterEvent ¶
func (state *State) RegisterEvent(handle int, event func(ctx context.Context, actionState *action.State) error, onClose func(), failOnError bool)
RegisterEvent register function to be executed on object change
func (*State) ReplaceSessionVariables ¶
func (state *State) ReplaceSessionVariables(input *SyncedTemplate) (string, error)
ReplaceSessionVariables execute template and replace session variables, e.g. "my app ({{.UserName}})" -> "my app (user_1)"
func (*State) ReplaceSessionVariablesWithLocalData ¶
func (state *State) ReplaceSessionVariablesWithLocalData(input *SyncedTemplate, localData interface{}) (string, error)
ReplaceSessionVariablesWithLocalData execute template and replace session variables, e.g. "my app ({{.UserName}})" -> "my app (user_1)", extra "local" data can be added in addition to the session variables
func (*State) ReqContext ¶
func (state *State) ReqContext() (context.Context, *enigma.ChangeLists, context.CancelFunc)
ReqContext context to be used on request, includes timeout and changeList to be used for synchronizing changes. A request context is automatically added when using QueueRequest functions.
func (*State) Reset ¶
Reset session, to be used when an existing session state enters a new "sequence"
func (*State) SendRequest ¶
SendRequest and trigger any object changes synchronously
func (*State) SendRequestRaw ¶
func (state *State) SendRequestRaw(actionState *action.State, f func(ctx context.Context) (json.RawMessage, error)) (json.RawMessage, error)
SendRequestRaw send request, trigger any object changes synchronously and return raw json response.
func (*State) SetLogEntry ¶
SetLogEntry set the log entry
func (*State) SetRandomizer ¶
func (state *State) SetRandomizer(rnd *randomizer.Randomizer, force bool)
SetRandomizer set randomizer for session, will not be set if already has a randomizer on concurrent sets, first instance to acquire lock will "win". When setting to nil, it will be automatically forced. Set force flag to have randomizer set even when a randomizer exists.
func (*State) TrafficLogger ¶
func (state *State) TrafficLogger() enigmahandlers.ITrafficLogger
TrafficLogger returns the current trafficLogger
func (*State) TriggerContextChanges ¶
TriggerContextChanges gets ChangeList from context and triggers changes
func (*State) TriggerEvents ¶
TriggerEvents from change and close lists
type SyncedTemplate ¶
type SyncedTemplate struct {
// contains filtered or unexported fields
}
Synced Template used for creating templates parsed once
func NewSyncedTemplate ¶
func NewSyncedTemplate(t string) (*SyncedTemplate, error)
NewSyncedTemplate parses string and creates new instance of SyncedTemplate
func (*SyncedTemplate) Execute ¶
func (syn *SyncedTemplate) Execute(writer io.Writer, data interface{}) error
Execute template
func (SyncedTemplate) MarshalJSON ¶
func (syn SyncedTemplate) MarshalJSON() ([]byte, error)
MarshalJSON marshal template to json string
func (*SyncedTemplate) ReplaceWithoutSessionVariables ¶
func (input *SyncedTemplate) ReplaceWithoutSessionVariables(data interface{}) (string, error)
ReplaceWithoutSessionVariables execute template without session variables - only use if we do not have a session
func (*SyncedTemplate) String ¶
func (syn *SyncedTemplate) String() string
String return text pattern
func (SyncedTemplate) TreatAs ¶
func (syn SyncedTemplate) TreatAs() string
func (*SyncedTemplate) UnmarshalJSON ¶
func (syn *SyncedTemplate) UnmarshalJSON(arg []byte) error
UnmarshalJSON un-marshal from json string