From 3bcd154177da6a178f19234737379c2b4dc7fade Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Mon, 1 Nov 2021 15:28:52 +0800 Subject: [PATCH] feat(proto): add new key base --- pkg/proto/define.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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, + } +}