filters

package
v0.0.0-...-bd94320 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DateFilter

type DateFilter struct {
	// contains filtered or unexported fields
}

DateFilter used to filter documents by date. Must be initialized with NewDateFilter function.

Value formats:

  • "<date>" : after date.
  • "<date>" : before date.
  • "=<date>" : equal (exact date).
  • "<date>~<date>" : between dates.

Date format is "2006-01-02 15:04:05".

func (*DateFilter) Apply

func (f *DateFilter) Apply(data models.Metadata) bool

Apply checks if given metadata date matches filter value.

Returns true if filter matches, false otherwise.

If metadata date is invalid, returns false.

type FileFilter

type FileFilter struct {
	// contains filtered or unexported fields
}

FileFilter used to filter metadata by file flag.

func NewFileFilter

func NewFileFilter(value string) (*FileFilter, error)

NewFileFilter creates new FileFilter instance.

value must be 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False..

Returns ErrInvalidFilterValue if value is invalid.

func (*FileFilter) Apply

func (f *FileFilter) Apply(data models.Metadata) bool

Apply filter to given metadata.

Return true if metadata is valid for given filter, false otherwise.

type Filter

type Filter interface {
	Apply(data models.Metadata) bool
}

Filter used to filter metadata.

func NewDateFilter

func NewDateFilter(value string) (Filter, error)

NewDateFilter creates new DateFilter instance.

value format:

  • "<date>" : after date.
  • "<date>" : before date.
  • "=<date>" : equal (exact date).
  • "<date>~<date>" : between dates.

Date format is "2006-01-02 15:04:05".

Returns ErrInvalidFilterValue if value is invalid.

func QuerryFilter

func QuerryFilter(key, value string) (Filter, error)

QuerryFilter creates new Filter instance based on given key and value.

key:

  • "owner" : filter by owner id.
  • "file" : filter by file status.
  • "name" : filter by name.
  • "mime" : filter by mime type.
  • "public" : filter by public status.
  • "created" : filter by creation date.
  • "grant" : filter by user login.
  • "id" : filter by document id.

value format depends on filter type.

Returns ErrUnknownFilter if key is unknown.

type FilterKey

type FilterKey string
const (
	FilterKeyOwner  FilterKey = "owner"
	FilterKeyFile   FilterKey = "file"
	FilterKeyName   FilterKey = "name"
	FilterKeyMime   FilterKey = "mime"
	FilterKeyPublic FilterKey = "public"
	FilterKeyDate   FilterKey = "created"
	FilterKeyGrant  FilterKey = "grant"
	FilterKeyID     FilterKey = "id"
)

type GrantFilter

type GrantFilter struct {
	// contains filtered or unexported fields
}

GrantFilter used to filter metadata by grant.

func NewGrantFilter

func NewGrantFilter(login string) (*GrantFilter, error)

NewGrantFilter creates new GrantFilter instance.

login must be login of user with grant access.

Returns ErrInvalidFilterValue if login is empty or invalid.

func (*GrantFilter) Apply

func (f *GrantFilter) Apply(data models.Metadata) bool

Apply implements Filter interface.

Returns true if data has grant access to user with login f.login.

type IDFilter

type IDFilter struct {
	// contains filtered or unexported fields
}

IDFilter used to filter metadata by id.

func NewIDFilter

func NewIDFilter(id string) (IDFilter, error)

NewIDFilter creates new IDFilter instance.

id must be valid uuid.

Returns ErrInvalidFilterValue if id is invalid.

func (IDFilter) Apply

func (f IDFilter) Apply(meta models.Metadata) bool

Apply implements filters.Filter interface.

It checks if given metadata id equals to filter id.

type MimeFilter

type MimeFilter struct {
	// contains filtered or unexported fields
}

MimeFilter used to filter metadata by mime type.

func NewMimeFilter

func NewMimeFilter(value string) (*MimeFilter, error)

NewMimeFilter creates new MimeFilter instance.

value must be mime type to filter by.

Returns ErrInvalidFilterValue if value is invalid.

func (*MimeFilter) Apply

func (f *MimeFilter) Apply(meta models.Metadata) bool

Apply checks if the mime type in the given metadata contains the mime type specified in the MimeFilter. Returns true if it contains the mime type, otherwise false.

type NameFilter

type NameFilter struct {
	// contains filtered or unexported fields
}

NameFilter used to filter metadata by name.

func NewNameFilter

func NewNameFilter(value string) (*NameFilter, error)

NewNameFilter creates a new NameFilter instance with the given name value. The value can have a wildcard prefix or suffix, indicated by '*', to match the start or end of a name, respectively.

func (*NameFilter) Apply

func (f *NameFilter) Apply(data models.Metadata) bool

Apply implements the Filter interface and returns true if the given metadata's name matches the given name value, either directly or with wildcard prefix or suffix.

type OwnerFilter

type OwnerFilter struct {
	// contains filtered or unexported fields
}

OwnerFilter used to filter metadata by owner id.

func NewOwnerFilter

func NewOwnerFilter(value string) (*OwnerFilter, error)

NewOwnerFilter creates a new OwnerFilter instance with the given owner ID value. The value should be a valid UUID string. If the value is invalid, it returns ErrInvalidFilterValue.

func (*OwnerFilter) Apply

func (f *OwnerFilter) Apply(meta models.Metadata) bool

Apply checks if the owner ID in the given metadata matches the owner ID specified in the OwnerFilter. Returns true if they match, otherwise false.

type PublicFilter

type PublicFilter struct {
	// contains filtered or unexported fields
}

PublicFilter used to filter metadata by public flag.

func NewPublicFilter

func NewPublicFilter(isPublic string) (*PublicFilter, error)

NewPublicFilter creates new PublicFilter instance.

value must be 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.

Returns ErrInvalidFilterValue if value is invalid.

func (*PublicFilter) Apply

func (f *PublicFilter) Apply(data models.Metadata) bool

Apply implements filters.Filter interface.

It returns true if the document is public according to filter and false otherwise.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL