| 11 | var seedActionId int64 = 1 |
| 12 | |
| 13 | func 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 | |
| 44 | func FindActionName(action ActionString) string { |
| 45 | for _, def := range AllActions { |