feat(proto): add new key base

This commit is contained in:
bandl 2021-11-01 15:28:52 +08:00
parent bed3f1893a
commit 3bcd154177
1 changed files with 26 additions and 0 deletions

View File

@ -1,5 +1,9 @@
package proto package proto
import (
"google.golang.org/protobuf/types/known/timestamppb"
)
type GetKeyBaseInterface interface { type GetKeyBaseInterface interface {
GetKey() *BaseKey GetKey() *BaseKey
} }
@ -7,3 +11,25 @@ type GetKeyBaseInterface interface {
const ( const (
BaseKeyMethodKey = "basekey" BaseKeyMethodKey = "basekey"
) )
// NewBaseKey
// keyttlexpire
func NewBaseKey(key string, t ...int64) *BaseKey {
var expire *timestamppb.Timestamp
var ttl int64
if len(t) > 1 {
expire = &timestamppb.Timestamp{
Seconds: t[1],
}
ttl = t[0]
} else if len(t) == 1 {
ttl = t[0]
}
return &BaseKey{
Key: key,
Expire: expire,
Ttl: ttl,
}
}