go_dreamfactory/sys/cache/optionAttr.go
2022-06-16 20:26:20 +08:00

48 lines
846 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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{},
}
}