MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / FindActionInstance

Function FindActionInstance

internal/waf/action_utils.go:13–42  ·  view source on GitHub ↗
(action ActionString, options maps.Map)

Source from the content-addressed store, hash-verified

11var seedActionId int64 = 1
12
13func FindActionInstance(action ActionString, options maps.Map) ActionInterface {
14 for _, def := range AllActions {
15 if def.Code == action {
16 if def.Type != nil {
17 // create new instance
18 var ptrValue = reflect.New(def.Type)
19 var instance = ptrValue.Interface().(ActionInterface)
20 instance.SetActionId(atomic.AddInt64(&seedActionId, 1))
21
22 if len(options) > 0 {
23 optionsJSON, err := json.Marshal(options)
24 if err != nil {
25 remotelogs.Error("WAF_FindActionInstance", "encode options to json failed: "+err.Error())
26 } else {
27 err = json.Unmarshal(optionsJSON, instance)
28 if err != nil {
29 remotelogs.Error("WAF_FindActionInstance", "decode options from json failed: "+err.Error())
30 }
31 }
32 }
33
34 return instance
35 }
36
37 // return shared instance
38 return def.Instance
39 }
40 }
41 return nil
42}
43
44func FindActionName(action ActionString) string {
45 for _, def := range AllActions {

Callers 4

TestFindActionInstanceFunction · 0.92
InitMethod · 0.85

Calls 3

ErrorFunction · 0.92
SetActionIdMethod · 0.65
ErrorMethod · 0.45

Tested by 3

TestFindActionInstanceFunction · 0.74