Obey supplied expiration time ShortenReq.ExpiresAfter
This commit is contained in:
parent
0e8dccb9d0
commit
131cc2640a
@ -18,8 +18,8 @@ type (
|
||||
|
||||
type (
|
||||
ShortenReq {
|
||||
LongUrl string `json:"longUrl"`
|
||||
ExpiresIn int64 `json:"expiresIn,optional"`
|
||||
LongUrl string `json:"longUrl"`
|
||||
ExpiresAfter int64 `json:"expiresAfter,optional"`
|
||||
}
|
||||
|
||||
ShortenResp {
|
||||
|
@ -27,8 +27,14 @@ func NewShortenUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Shorte
|
||||
|
||||
func (l *ShortenUrlLogic) ShortenUrl(req *types.ShortenReq) (resp *types.ShortenResp, err error) {
|
||||
id := l.svcCtx.Snowflake.Generate().Base58()
|
||||
insertBuilder := db.UrlTable.InsertBuilder()
|
||||
|
||||
insertUrl := db.UrlTable.InsertBuilder().TTL(30 * time.Second).Query(l.svcCtx.DB)
|
||||
logx.Info(req.ExpiresAfter)
|
||||
if req.ExpiresAfter != 0 {
|
||||
insertBuilder.TTL(time.Second * time.Duration(req.ExpiresAfter))
|
||||
}
|
||||
|
||||
insertUrl := insertBuilder.Query(l.svcCtx.DB)
|
||||
insertUrl.BindStruct(db.UrlModel{
|
||||
ID: id,
|
||||
LongUrl: req.LongUrl,
|
||||
|
@ -10,8 +10,8 @@ type ExpandResp struct {
|
||||
}
|
||||
|
||||
type ShortenReq struct {
|
||||
LongUrl string `json:"longUrl"`
|
||||
ExpiresIn int64 `json:"expiresIn,optional"`
|
||||
LongUrl string `json:"longUrl"`
|
||||
ExpiresAfter int64 `json:"expiresAfter,optional"`
|
||||
}
|
||||
|
||||
type ShortenResp struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user