You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
662 B
Go
36 lines
662 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"shorturl/rpc/transform/internal/svc"
|
|
transform "shorturl/rpc/transform/pb"
|
|
|
|
"github.com/tal-tech/go-zero/core/logx"
|
|
)
|
|
|
|
type ExpandLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewExpandLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ExpandLogic {
|
|
return &ExpandLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *ExpandLogic) Expand(in *transform.ExpandReq) (*transform.ExpandResp, error) {
|
|
res, err := l.svcCtx.Model.FindOne(in.Shorten)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &transform.ExpandResp{
|
|
Url: res.Url,
|
|
}, nil
|
|
}
|