/* Attributes */ type Attributes map[string]string /* SetTag */ func (attrs Attributes) SetTag(tag string) { if tags,exists := attrs["tags"]; !exists { attrs["tags"] = tag } else { attrs["tags"] = strings.Join([]string{tags,tag}," ") } } /* Tag */ func (attrs Attributes) Tag(tag string) bool { if tags,exists := attrs["tags"]; exists { for _,t := range strings.Split(tags," ") { if t == tag { return true } } } return false } /* SetKeyValue */ func (attrs Attributes) SetKeyValue(key,value string) { attrs[key] = value } /* KeyValue */ func (attrs Attributes) KeyValue(key, def string) string { if value,exists := attrs[key]; exists { return value } return def } type Ternary string const ( True = Ternary("ternary'true") Unknown = Ternary("ternary'unknown") False = Ternary("ternary'false") ) /* SetTernary */ func (attrs Attributes) SetTernary(key string, value Ternary) { attrs[key] = string(ternary) } /* Ternary */ func (attrs Attributes) Ternary(key string) Ternary { if value,exists := attrs[key]; exists { switch Ternary(value) { case True,Unknown,False: return Ternary(value) break default: return True break } } return Unknown } /* Form */ func (attrs Attributes) Form(key string) string { if value,exists := attrs[key]; exists { switch Ternary(value) { case True,Unknown,False: return "ternary" break default: return "keyvalue" break } } for _,tag := range strings.Split(attrs["tags"]," ") { if tag == key { return "tag" } } return "unknown" }