Skip to content

Commit a2909ce

Browse files
committed
fix: bad reference of example code
1 parent 5273281 commit a2909ce

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

go-zero.dev/cn/micro-service.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $ go mod init go-zero-demo
5252
```shell
5353
$ vim mall/user/rpc/user.proto
5454
```
55-
55+
5656
增加如下代码:
5757

5858
```protobuf
@@ -220,20 +220,20 @@ $ go mod init go-zero-demo
220220

221221
import (
222222
"go-zero-demo/mall/order/api/internal/config"
223-
"go-zero-demo/mall/user/rpc/user"
223+
"go-zero-demo/mall/user/rpc/userclient"
224224

225225
"github.com/zeromicro/go-zero/zrpc"
226226
)
227227

228228
type ServiceContext struct {
229229
Config config.Config
230-
UserRpc user.User
230+
UserRpc userclient.User
231231
}
232232

233233
func NewServiceContext(c config.Config) *ServiceContext {
234234
return &ServiceContext{
235235
Config: c,
236-
UserRpc: user.NewUser(zrpc.MustNewClient(c.UserRpc)),
236+
UserRpc: userclient.NewUser(zrpc.MustNewClient(c.UserRpc)),
237237
}
238238
}
239239
```
@@ -248,44 +248,44 @@ $ go mod init go-zero-demo
248248

249249
```go
250250
package logic
251-
251+
252252
import (
253253
"context"
254254
"errors"
255-
255+
256256
"go-zero-demo/mall/order/api/internal/svc"
257257
"go-zero-demo/mall/order/api/internal/types"
258258
"go-zero-demo/mall/user/rpc/types/user"
259-
259+
260260
"github.com/zeromicro/go-zero/core/logx"
261261
)
262-
262+
263263
type GetOrderLogic struct {
264264
logx.Logger
265265
ctx context.Context
266266
svcCtx *svc.ServiceContext
267267
}
268-
268+
269269
func NewGetOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetOrderLogic {
270270
return GetOrderLogic{
271271
Logger: logx.WithContext(ctx),
272272
ctx: ctx,
273273
svcCtx: svcCtx,
274274
}
275275
}
276-
276+
277277
func (l *GetOrderLogic) GetOrder(req *types.OrderReq) (*types.OrderReply, error) {
278278
user, err := l.svcCtx.UserRpc.GetUser(l.ctx, &user.IdRequest{
279279
Id: "1",
280280
})
281281
if err != nil {
282282
return nil, err
283283
}
284-
284+
285285
if user.Name != "test" {
286286
return nil, errors.New("用户不存在")
287287
}
288-
288+
289289
return &types.OrderReply{
290290
Id: req.Id,
291291
Name: "test order",
@@ -324,7 +324,7 @@ $ go mod init go-zero-demo
324324
Content-Type: application/json
325325
Date: Sun, 07 Feb 2021 03:45:05 GMT
326326
Content-Length: 30
327-
327+
328328
{"id":"1","name":"test order"}
329329
```
330330

go-zero.dev/en/micro-service.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,15 @@ $ go mod init go-zero-demo
170170
```shell
171171
$ goctl api go -api order.api -dir .
172172
Done.
173-
```
173+
```
174174
* Add user rpc configuration
175175

176176
```shell
177177
$ vim internal/config/config.go
178178
```
179179
```go
180180
package config
181-
181+
182182
import (
183183
"github.com/zeromicro/go-zero/zrpc"
184184
"github.com/zeromicro/go-zero/rest"
@@ -214,20 +214,20 @@ $ go mod init go-zero-demo
214214
215215
import (
216216
"go-zero-demo/mall/order/api/internal/config"
217-
"go-zero-demo/mall/user/rpc/user"
217+
"go-zero-demo/mall/user/rpc/userclient"
218218
219219
"github.com/zeromicro/go-zero/zrpc"
220220
)
221221
222222
type ServiceContext struct {
223223
Config config.Config
224-
UserRpc user.User
224+
UserRpc userclient.User
225225
}
226226
227227
func NewServiceContext(c config.Config) *ServiceContext {
228228
return &ServiceContext{
229229
Config: c,
230-
UserRpc: user.NewUser(zrpc.MustNewClient(c.UserRpc)),
230+
UserRpc: userclient.NewUser(zrpc.MustNewClient(c.UserRpc)),
231231
}
232232
}
233233
```
@@ -241,44 +241,44 @@ $ go mod init go-zero-demo
241241

242242
```go
243243
package logic
244-
244+
245245
import (
246246
"context"
247247
"errors"
248-
248+
249249
"go-zero-demo/mall/order/api/internal/svc"
250250
"go-zero-demo/mall/order/api/internal/types"
251251
"go-zero-demo/mall/user/rpc/types/user"
252-
252+
253253
"github.com/zeromicro/go-zero/core/logx"
254254
)
255-
255+
256256
type GetOrderLogic struct {
257257
logx.Logger
258258
ctx context.Context
259259
svcCtx *svc.ServiceContext
260260
}
261-
261+
262262
func NewGetOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetOrderLogic {
263263
return GetOrderLogic{
264264
Logger: logx.WithContext(ctx),
265265
ctx: ctx,
266266
svcCtx: svcCtx,
267267
}
268268
}
269-
269+
270270
func (l *GetOrderLogic) GetOrder(req types.OrderReq) (*types.OrderReply, error) {
271271
user, err := l.svcCtx.UserRpc.GetUser(l.ctx, &user.IdRequest{
272272
Id: "1",
273273
})
274274
if err != nil {
275275
return nil, err
276276
}
277-
277+
278278
if user.Name != "test" {
279279
return nil, errors.New("用户不存在")
280280
}
281-
281+
282282
return &types.OrderReply{
283283
Id: req.Id,
284284
Name: "test order",
@@ -317,7 +317,7 @@ $ go mod init go-zero-demo
317317
Content-Type: application/json
318318
Date: Sun, 07 Feb 2021 03:45:05 GMT
319319
Content-Length: 30
320-
320+
321321
{"id": "1", "name": "test order"}
322322
```
323323

0 commit comments

Comments
 (0)