Skip to content

openprovider/tags

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5024cf6 · Nov 8, 2014

History

12 Commits
Nov 8, 2014
Nov 8, 2014
Nov 8, 2014
Nov 8, 2014
Nov 8, 2014
Nov 8, 2014
Nov 8, 2014

Repository files navigation

Go Tags

A tags package for use with Go (golang) services

Build Status GoDoc

Definitions

  • Tags - a strings which used for tag any object
  • Non-strict Tags - a strings which match to strings in data ("new" -> "new")
  • Strict Tags - all strict tags have prefix "+" for strict match ("+new") and "-" for strict mismatch ("-old")

Rules

  • All strict Tags applied with logical operator "AND" between each other
  • All non-strict Tags applied with logical operator "OR" between all tags

Queries

{"a","b"} this mean that we ask "a" OR "b" tag

{"a","+b","+c"} this mean that we ask "a" OR ("b" AND "c") tag

{"a","+b", "c", "-d"} this mean that we ask "a" OR "c" OR ("b" AND NOT "d") tag

Example

package main

import (
	"fmt"

	"github.com/takama/tags"
)

// Product is struct with tags
type Product struct {
	Name        string
	Description string
	Tags        tags.Tags
}

func main() {
	product := Product{
		Name:        "the tee",
		Description: "the boutle of ice black tee with sugar",
		Tags:        tags.Tags{"ice", "black", "sugar"},
	}

	fmt.Println("Product:", product.Description)

	// We ask for any tee "black" or "green"
	fmt.Println("Is this tee black or green?")
	query := tags.Tags{"black", "green"}

	if product.Tags.IsTagged(query) {
		fmt.Println("Yes, the tee is black.")
	} else {
		fmt.Println("No, the tee has not black or green options.")
	}

	// We ask fot strict match "green" and "sugar"
	fmt.Println("Is this tee green with sugar?")
	query = tags.Tags{"+green", "+sugar"}

	if product.Tags.IsTagged(query) {
		fmt.Println("Yes, the tee is green with sugar.")
	} else {
		fmt.Println("No, the tee with sugar, but is not green.")
	}

	// We ask for strict mismatch, not "ice"
	fmt.Println("Is this tee hot?")
	query = tags.Tags{"-ice"}

	if product.Tags.IsTagged(query) {
		fmt.Println("Yes, the tee is hot.")
	} else {
		fmt.Println("No, it is ice tee.")
	}
}

Author

Igor Dolzhikov

Contributors

All the contributors are welcome. If you would like to be the contributor please accept some rules.

  • The pull requests will be accepted only in "develop" branch
  • All modifications or additions should be tested
  • Sorry, I'll not accept code with any dependency, only standard library

Thank you for your understanding!

License

MIT Public License

About

Openprovider: tags package for use with Go (golang) services

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages