Attribute Manager has been added.

This commit is contained in:
crusader 2017-11-27 14:53:04 +09:00
parent f1f75535be
commit b221ead4e4

68
context/attributes.go Normal file
View File

@ -0,0 +1,68 @@
package context
type AttributeManager interface {
Init()
SetAttribute(key string, value interface{})
GetAttribute(key string) (value interface{})
GetAttributeNames() []string
RemoveAttribute(key string)
Contains(key string) (exist bool)
Destroy()
}
type AttributeManagers struct {
attributes map[string]interface{}
}
func (am *AttributeManagers) Init() {
if nil == am.attributes {
am.attributes = make(map[string]interface{})
}
}
func (am *AttributeManagers) SetAttribute(key string, value interface{}) {
if nil == am.attributes {
am.attributes = make(map[string]interface{})
}
am.attributes[key] = value
}
func (am *AttributeManagers) GetAttribute(key string) (value interface{}) {
if nil == am.attributes {
return nil
}
return am.attributes[key]
}
func (am *AttributeManagers) GetAttributeNames() []string {
if nil == am.attributes {
return nil
}
keys := []string{}
for k, _ := range am.attributes {
keys = append(keys, k)
}
return keys
}
func (am *AttributeManagers) RemoveAttribute(key string) {
if nil == am.attributes {
return
}
delete(am.attributes, key)
}
func (am *AttributeManagers) Contains(key string) (exist bool) {
if nil == am.attributes {
return false
}
_, ok := am.attributes[key]
return ok
}
func (am *AttributeManagers) Destroy() {
if nil == am.attributes {
am.attributes = nil
}
}