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