expandlogic.go 722 B

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