-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from zhoushuguang/article-four
Article four
- Loading branch information
Showing
50 changed files
with
1,427 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/zeromicro/go-zero/rest/httpx" | ||
"github.com/zhoushuguang/lebron/apps/app/api/internal/logic" | ||
"github.com/zhoushuguang/lebron/apps/app/api/internal/svc" | ||
"github.com/zhoushuguang/lebron/apps/app/api/internal/types" | ||
) | ||
|
||
func ProductDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
var req types.ProductDetailRequest | ||
if err := httpx.Parse(r, &req); err != nil { | ||
httpx.Error(w, err) | ||
return | ||
} | ||
|
||
l := logic.NewProductDetailLogic(r.Context(), svcCtx) | ||
resp, err := l.ProductDetail(&req) | ||
if err != nil { | ||
httpx.Error(w, err) | ||
} else { | ||
httpx.OkJson(w, resp) | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package logic | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/zeromicro/go-zero/core/mr" | ||
"github.com/zhoushuguang/lebron/apps/app/api/internal/svc" | ||
"github.com/zhoushuguang/lebron/apps/app/api/internal/types" | ||
"github.com/zhoushuguang/lebron/apps/product/rpc/product" | ||
"github.com/zhoushuguang/lebron/apps/reply/rpc/reply" | ||
|
||
"github.com/zeromicro/go-zero/core/logx" | ||
) | ||
|
||
type ProductDetailLogic struct { | ||
logx.Logger | ||
ctx context.Context | ||
svcCtx *svc.ServiceContext | ||
} | ||
|
||
func NewProductDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductDetailLogic { | ||
return &ProductDetailLogic{ | ||
Logger: logx.WithContext(ctx), | ||
ctx: ctx, | ||
svcCtx: svcCtx, | ||
} | ||
} | ||
|
||
func (l *ProductDetailLogic) ProductDetail(req *types.ProductDetailRequest) (resp *types.ProductDetailResponse, err error) { | ||
var ( | ||
p *product.ProductItem | ||
cs *reply.CommentsResponse | ||
) | ||
if err := mr.Finish(func() error { | ||
var err error | ||
if p, err = l.svcCtx.ProductRPC.Product(l.ctx, &product.ProductItemRequest{ProductId: req.ProductID}); err != nil { | ||
return err | ||
} | ||
return nil | ||
}, func() error { | ||
var err error | ||
if cs, err = l.svcCtx.ReplyRPC.Comments(l.ctx, &reply.CommentsRequest{TargetId: req.ProductID}); err != nil { | ||
logx.Errorf("get comments error: %v", err) | ||
} | ||
return nil | ||
}); err != nil { | ||
return nil, err | ||
} | ||
var comments []*types.Comment | ||
for _, c := range cs.Comments { | ||
comments = append(comments, &types.Comment{ | ||
ID: c.Id, | ||
Content: c.Content, | ||
}) | ||
} | ||
return &types.ProductDetailResponse{ | ||
Product: &types.Product{ | ||
ID: p.ProductId, | ||
Name: p.Name, | ||
}, | ||
Comments: comments, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
type Request { | ||
Name string `path:"name,options=you|me"` | ||
} | ||
syntax = "v1" | ||
|
||
type Response { | ||
Message string `json:"message"` | ||
} | ||
type ( | ||
UploadImageResponse { | ||
Success bool `json:"success"` | ||
} | ||
) | ||
|
||
service admin-api { | ||
@handler AdminHandler | ||
get /from/:name(Request) returns (Response) | ||
@handler UploadImageHandler | ||
post /v1/upload/image() returns (UploadImageResponse) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
Name: admin-api | ||
Host: 0.0.0.0 | ||
Port: 8888 | ||
OSSEndpoint: https://oss-cn-hangzhou.aliyuncs.com | ||
AccessKeyID: xxxxxxxxxxxx | ||
AccessKeySecret: xxxxxxxxxxxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.