indexfileconfig.go 759 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package dircompile
  2. import (
  3. "github.com/SongZihuan/huan-proxy/src/config/rules/action/dir"
  4. "regexp"
  5. )
  6. type IndexFileCompileConfig struct {
  7. IsRegex bool
  8. File string
  9. Regex *regexp.Regexp
  10. }
  11. func NewIndexFileCompileConfig(i *dir.IndexFileConfig) (*IndexFileCompileConfig, error) {
  12. if i.Regex.IsEnable(true) {
  13. reg, err := regexp.Compile(i.File)
  14. if err != nil {
  15. return nil, err
  16. }
  17. return &IndexFileCompileConfig{
  18. IsRegex: true,
  19. File: "",
  20. Regex: reg,
  21. }, nil
  22. } else {
  23. return &IndexFileCompileConfig{
  24. IsRegex: false,
  25. File: i.File,
  26. Regex: nil,
  27. }, nil
  28. }
  29. }
  30. func (i *IndexFileCompileConfig) CheckName(name string) bool {
  31. if i.IsRegex {
  32. return i.Regex.MatchString(name)
  33. } else {
  34. return name == i.File
  35. }
  36. }