// Match matches a needle with an array of regular expressions and returns true if a match was found. func Match(p Policy, haystack []string, needle string) (bool, error) { var reg *regexp.Regexp var err error for _, h := range haystack { reg, err = compiler.CompileRegex(h, p.GetStartDelimiter(), p.GetEndDelimiter()) if err != nil { return false, errors.Wrap(err, "") } if reg.MatchString(needle) { return true, nil } } return false, nil }
func createLink(tx *sql.Tx, table string, p Policy, templates []string) error { for _, template := range templates { reg, err := compiler.CompileRegex(template, p.GetStartDelimiter(), p.GetEndDelimiter()) // Execute SQL statement query := fmt.Sprintf("INSERT INTO %s (policy, template, compiled) VALUES ($1, $2, $3)", table) if _, err = tx.Exec(query, p.GetID(), template, reg.String()); err != nil { if rb := tx.Rollback(); rb != nil { return rb } return err } } return nil }
func createLinkSQL(db *sqlx.DB, tx *sql.Tx, table string, p Policy, templates []string) error { for _, template := range templates { reg, err := compiler.CompileRegex(template, p.GetStartDelimiter(), p.GetEndDelimiter()) // Execute SQL statement query := db.Rebind(fmt.Sprintf("INSERT INTO %s (policy, template, compiled) VALUES (?, ?, ?)", table)) if _, err = tx.Exec(query, p.GetID(), template, reg.String()); err != nil { if rb := tx.Rollback(); rb != nil { return errors.Wrap(rb, "") } return errors.Wrap(err, "") } } return nil }
func Matches(p policy.Policy, patterns []string, match string) (bool, error) { var reg *regexp.Regexp var err error var matches bool for _, h := range patterns { reg, err = compiler.CompileRegex(h, p.GetStartDelimiter(), p.GetEndDelimiter()) if err != nil { return false, err } matches = reg.MatchString(match) if matches { return true, nil } } return false, nil }