package cmdparser import ( "regexp" "strings" ) // CommandType - type CommandType int // CmdAction - type CmdAction struct { Key string Value string Origin string } var actRegex = regexp.MustCompile("{{(.+?)}}") // ParseCmdAction - func ParseCmdAction(value string) (acts []*CmdAction) { strs := actRegex.FindAllStringSubmatch(value, -1) if len(strs) == 0 { return nil } acts = make([]*CmdAction, 0, len(strs)) for _, key := range strs { act := &CmdAction{} act.Origin = key[1] keys := strings.Split(key[1], "=") if len(keys) == 2 { act.Key = keys[0] act.Value = keys[1] } else { act.Key = key[1] } acts = append(acts, act) } return }