expandlogic.go 662 B

1234567891011121314151617181920212223242526272829303132333435
  1. package logic
  2. import (
  3. "context"
  4. "shorturl/rpc/transform/internal/svc"
  5. transform "shorturl/rpc/transform/pb"
  6. "github.com/tal-tech/go-zero/core/logx"
  7. )
  8. type ExpandLogic struct {
  9. logx.Logger
  10. ctx context.Context
  11. svcCtx *svc.ServiceContext
  12. }
  13. func NewExpandLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ExpandLogic {
  14. return &ExpandLogic{
  15. Logger: logx.WithContext(ctx),
  16. ctx: ctx,
  17. svcCtx: svcCtx,
  18. }
  19. }
  20. func (l *ExpandLogic) Expand(in *transform.ExpandReq) (*transform.ExpandResp, error) {
  21. res, err := l.svcCtx.Model.FindOne(in.Shorten)
  22. if err != nil {
  23. return nil, err
  24. }
  25. return &transform.ExpandResp{
  26. Url: res.Url,
  27. }, nil
  28. }