go_dreamfactory/sys/cache/optionAttr.go
2022-06-17 16:34:09 +08:00

62 lines
1.0 KiB
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"
"time"
)
const (
ATTR_EXPIRE = "expire"
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 WithExpire(t time.Duration) *OperationAttr {
return &OperationAttr{
Name: ATTR_EXPIRE,
Value: t,
}
}
//禁用Mgolog操作
func WithDisabledMgoLog() *OperationAttr {
return &OperationAttr{
Name: ATTR_MGOLOG,
Value: empty{},
}
}
//新记录插入操作
func WithND() *OperationAttr {
return &OperationAttr{
Name: ATTR_INSERT,
Value: empty{},
}
}