dirconfig.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package dircompile
  2. import (
  3. "github.com/SongZihuan/huan-proxy/src/config/rules/action/dir"
  4. "github.com/SongZihuan/huan-proxy/src/config/rulescompile/actioncompile/corscompile"
  5. "github.com/SongZihuan/huan-proxy/src/config/rulescompile/actioncompile/rewritecompile"
  6. )
  7. type RuleDirCompileConfig struct {
  8. BasePath string
  9. IndexFile []*IndexFileCompileConfig
  10. IgnoreFile []*IgnoreFileCompileConfig
  11. AddPath string
  12. SubPath string
  13. Rewrite *rewritecompile.RewriteCompileConfig
  14. Cors *corscompile.CorsCompileConfig
  15. }
  16. func NewRuleDirCompileConfig(r *dir.RuleDirConfig) (*RuleDirCompileConfig, error) {
  17. Index := make([]*IndexFileCompileConfig, 0, len(r.IndexFile))
  18. for _, i := range r.IndexFile {
  19. file, err := NewIndexFileCompileConfig(i)
  20. if err != nil {
  21. return nil, err
  22. }
  23. Index = append(Index, file)
  24. }
  25. Ignore := make([]*IgnoreFileCompileConfig, 0, len(r.IgnoreFile))
  26. for _, i := range r.IgnoreFile {
  27. file, err := NewIgnoreFileCompileConfig(i)
  28. if err != nil {
  29. return nil, err
  30. }
  31. Ignore = append(Ignore, file)
  32. }
  33. rewrite, err := rewritecompile.NewRewriteCompileConfig(&r.Rewrite)
  34. if err != nil {
  35. return nil, err
  36. }
  37. cors, err := corscompile.NewCorsCompileConfig(&r.Cors)
  38. if err != nil {
  39. return nil, err
  40. }
  41. return &RuleDirCompileConfig{
  42. BasePath: r.BasePath,
  43. IndexFile: Index,
  44. IgnoreFile: Ignore,
  45. AddPath: r.AddPath,
  46. SubPath: r.SubPath,
  47. Rewrite: rewrite,
  48. Cors: cors,
  49. }, nil
  50. }
  51. func (i *IgnoreFileCompileConfig) CheckName(name string) bool {
  52. if i.IsRegex {
  53. return i.Regex.MatchString(name)
  54. } else {
  55. return name == i.File
  56. }
  57. }