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.
go-zero/example/bookstore/api/internal/logic/addlogic.go

38 lines
679 B
Go

package logic
import (
"bookstore/api/internal/svc"
"bookstore/api/internal/types"
"bookstore/rpc/add/adder"
"context"
"github.com/tal-tech/go-zero/core/logx"
)
type AddLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) AddLogic {
return AddLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AddLogic) Add(req types.AddReq) (*types.AddResp, error) {
resp, err := l.svcCtx.Adder.Add(l.ctx, &adder.AddReq{
Book: req.Book,
Price: req.Price,
})
if err != nil {
return nil, err
}
return &types.AddResp{
Ok: resp.Ok,
}, nil
}