48 lines
846 B
Go
48 lines
846 B
Go
package cache
|
||
|
||
import "fmt"
|
||
|
||
const (
|
||
ATTR_MGOLOG = "mgolog"
|
||
ATTR_INSERT = "insert"
|
||
|
||
OpenMgoLog = false //true表示不禁用Mgolog,即不传入WithDisabledMgoLog()时也表示禁用
|
||
)
|
||
|
||
type empty struct {
|
||
}
|
||
|
||
type OperationAttr struct {
|
||
Name string
|
||
Value interface{}
|
||
}
|
||
|
||
type OperationAttrs []*OperationAttr
|
||
|
||
func (this OperationAttrs) Find(name string) *InterfaceResult {
|
||
for _, v := range this {
|
||
if v.Name == name {
|
||
return NewInterfaceResult(v.Value, nil)
|
||
}
|
||
}
|
||
|
||
if OpenMgoLog {
|
||
return NewInterfaceResult(ATTR_MGOLOG, nil)
|
||
}
|
||
return NewInterfaceResult(nil, fmt.Errorf("Operationattrs not found err: %v", name))
|
||
}
|
||
|
||
func WithDisabledMgoLog() *OperationAttr {
|
||
return &OperationAttr{
|
||
Name: ATTR_MGOLOG,
|
||
Value: empty{},
|
||
}
|
||
}
|
||
|
||
func WithND() *OperationAttr {
|
||
return &OperationAttr{
|
||
Name: ATTR_INSERT,
|
||
Value: empty{},
|
||
}
|
||
}
|