From c6e2b4a43a5e3145fad0ce930cb2c2c14aad7d24 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Fri, 13 May 2022 23:10:55 +0800 Subject: [PATCH] chore: coding style for quickstart (#1902) --- tools/goctl/api/gogen/main.tpl | 2 +- tools/goctl/quickstart/idl/apilogic.tpl | 40 ++++++++++++------------- tools/goctl/quickstart/idl/svc.tpl | 24 +++++++-------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/tools/goctl/api/gogen/main.tpl b/tools/goctl/api/gogen/main.tpl index a4ab692a..ad1a46d0 100644 --- a/tools/goctl/api/gogen/main.tpl +++ b/tools/goctl/api/gogen/main.tpl @@ -15,10 +15,10 @@ func main() { var c config.Config conf.MustLoad(*configFile, &c) - ctx := svc.NewServiceContext(c) server := rest.MustNewServer(c.RestConf) defer server.Stop() + ctx := svc.NewServiceContext(c) handler.RegisterHandlers(server, ctx) fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port) diff --git a/tools/goctl/quickstart/idl/apilogic.tpl b/tools/goctl/quickstart/idl/apilogic.tpl index d0363257..6cc01fbf 100644 --- a/tools/goctl/quickstart/idl/apilogic.tpl +++ b/tools/goctl/quickstart/idl/apilogic.tpl @@ -1,35 +1,35 @@ package logic import ( - "context" + "context" - "github.com/zeromicro/go-zero/core/logx" - "greet/api/internal/svc" - "greet/api/internal/types" - {{if .callRPC}}"greet/rpc/greet" -{{end}} + "github.com/zeromicro/go-zero/core/logx" + "greet/api/internal/svc" + "greet/api/internal/types"{{if .callRPC}} + "greet/rpc/greet"{{end}} ) type PingLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext } func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic { - return &PingLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } + return &PingLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } } func (l *PingLogic) Ping() (resp *types.Resp, err error) { - {{if .callRPC}}if _, err = l.svcCtx.GreetRpc.Ping(l.ctx, &greet.Placeholder{});err !=nil { - return - }{{end}} - resp = new(types.Resp) - resp.Msg = "pong" + {{if .callRPC}}if _, err = l.svcCtx.GreetRpc.Ping(l.ctx, new(greet.Placeholder)); err != nil { + return + } - return + {{end}}resp = new(types.Resp) + resp.Msg = "pong" + + return } diff --git a/tools/goctl/quickstart/idl/svc.tpl b/tools/goctl/quickstart/idl/svc.tpl index e8c14ade..36cac723 100644 --- a/tools/goctl/quickstart/idl/svc.tpl +++ b/tools/goctl/quickstart/idl/svc.tpl @@ -1,22 +1,22 @@ package svc import ( - "github.com/zeromicro/go-zero/zrpc" - "greet/api/internal/config" - "greet/rpc/greet" + "github.com/zeromicro/go-zero/zrpc" + "greet/api/internal/config" + "greet/rpc/greet" ) type ServiceContext struct { - Config config.Config - GreetRpc greet.Greet + Config config.Config + GreetRpc greet.Greet } func NewServiceContext(c config.Config) *ServiceContext { - client := zrpc.MustNewClient(zrpc.RpcClientConf{ - Target: "127.0.0.1:8080", - }) - return &ServiceContext{ - Config: c, - GreetRpc: greet.NewGreet(client), - } + client := zrpc.MustNewClient(zrpc.RpcClientConf{ + Target: "127.0.0.1:8080", + }) + return &ServiceContext{ + Config: c, + GreetRpc: greet.NewGreet(client), + } }