tagfilter

package module
v0.0.0-...-a274b92 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 2 Imported by: 0

README

TagFilter

A simple Go library to filter items by tags.

Usage

package main

import (
	"fmt"

	"github.com/vcokltfre/tagfilter"
)

func main() {
	tags := []string{"tag1", "tag2", "tag3"}
	tagsExtended := []string{"tag1", "tag2", "tag3", "tag4", "tag5", "tag6"}

	// Any of tags 'tag1', 'tag2', 'tag3'
	fmt.Println(tagfilter.Match(tags, "tag1 tag2 tag3"))

	// All of tags 'tag1', 'tag2', 'tag3'
	fmt.Println(tagfilter.Match(tags, "+tag1 +tag2 +tag3"))

	// Any of tags 'tag1', 'tag2', 'tag3' and none of tags 'tag4', 'tag5', 'tag6'
	fmt.Println(tagfilter.Match(tags, "tag1 tag2 tag3 -tag4 -tag5 -tag6"))         // Matches
	fmt.Println(tagfilter.Match(tagsExtended, "tag1 tag2 tag3 -tag4 -tag5 -tag6")) // Doesn't match

	// All of tags 'tag1', 'tag2' and none of tags 'tag4', 'tag5', 'tag6'
	fmt.Println(tagfilter.Match(tags, "+tag1 +tag2 -tag4 -tag5 -tag6"))         // Matches
	fmt.Println(tagfilter.Match(tagsExtended, "+tag1 +tag2 -tag4 -tag5 -tag6")) // Doesn't match
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(tags []string, filter string) (bool, error)

func MatchSeparator

func MatchSeparator(tags []string, filter string, separator string) (bool, error)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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