options.go 777 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package gzip
  2. var (
  3. DefaultExcludedExtentions = NewExcludedExtensions([]string{
  4. ".png", ".gif", ".jpeg", ".jpg",
  5. })
  6. DefaultOptions = &Options{
  7. ExcludedExtensions: DefaultExcludedExtentions,
  8. }
  9. )
  10. type Options struct {
  11. ExcludedExtensions ExcludedExtensions
  12. }
  13. type Option func(*Options)
  14. func WithExcludedExtensions(args []string) Option {
  15. return func(o *Options) {
  16. o.ExcludedExtensions = NewExcludedExtensions(args)
  17. }
  18. }
  19. // Using map for better lookup performance
  20. type ExcludedExtensions map[string]bool
  21. func NewExcludedExtensions(extensions []string) ExcludedExtensions {
  22. res := make(ExcludedExtensions)
  23. for _, e := range extensions {
  24. res[e] = true
  25. }
  26. return res
  27. }
  28. func (e ExcludedExtensions) Contains(target string) bool {
  29. _, ok := e[target]
  30. return ok
  31. }