apilogic.tpl 669 B

1234567891011121314151617181920212223242526272829303132333435
  1. package logic
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/logx"
  5. "greet/api/internal/svc"
  6. "greet/api/internal/types"{{if .callRPC}}
  7. "greet/rpc/greet"{{end}}
  8. )
  9. type PingLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
  15. return &PingLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx,
  19. }
  20. }
  21. func (l *PingLogic) Ping() (resp *types.Resp, err error) {
  22. {{if .callRPC}}if _, err = l.svcCtx.GreetRpc.Ping(l.ctx, new(greet.Placeholder)); err != nil {
  23. return
  24. }
  25. {{end}}resp = new(types.Resp)
  26. resp.Msg = "pong"
  27. return
  28. }