tags

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2015 License: MIT Imports: 1 Imported by: 1

README

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 query tag - a string which match to string in tag ("new" -> "new")
  • Strict query tag - all strict query tags have prefix "+" for strict match ("+new") and "-" for strict mismatch ("-old")
Rules
  • All strict query tags applied with logical operator "AND" between each other
  • All non-strict query tags applied with logical operator "OR" between all tags in query
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/openprovider/tags"
)

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

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

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

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

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

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

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

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

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

Authors

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

Thank you for your understanding!

License

MIT Public License

Documentation

Overview

Package tags 0.2.0

Definitions:

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

Rules:

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

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/openprovider/tags"
)

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

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

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

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

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

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

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

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

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

Go Tags

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tags

type Tags []string

Tags is a slice of strings which used for tag any object

func (Tags) IsTagged

func (t Tags) IsTagged(query Tags) bool

IsTagged - this method checks if Tags are matched with tags in query

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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