chore: coding style for quickstart (#1902)
This commit is contained in:
@@ -15,10 +15,10 @@ func main() {
|
|||||||
var c config.Config
|
var c config.Config
|
||||||
conf.MustLoad(*configFile, &c)
|
conf.MustLoad(*configFile, &c)
|
||||||
|
|
||||||
ctx := svc.NewServiceContext(c)
|
|
||||||
server := rest.MustNewServer(c.RestConf)
|
server := rest.MustNewServer(c.RestConf)
|
||||||
defer server.Stop()
|
defer server.Stop()
|
||||||
|
|
||||||
|
ctx := svc.NewServiceContext(c)
|
||||||
handler.RegisterHandlers(server, ctx)
|
handler.RegisterHandlers(server, ctx)
|
||||||
|
|
||||||
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"greet/api/internal/svc"
|
"greet/api/internal/svc"
|
||||||
"greet/api/internal/types"
|
"greet/api/internal/types"{{if .callRPC}}
|
||||||
{{if .callRPC}}"greet/rpc/greet"
|
"greet/rpc/greet"{{end}}
|
||||||
{{end}}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PingLogic struct {
|
type PingLogic struct {
|
||||||
logx.Logger
|
logx.Logger
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
|
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
|
||||||
return &PingLogic{
|
return &PingLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
svcCtx: svcCtx,
|
svcCtx: svcCtx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *PingLogic) Ping() (resp *types.Resp, err error) {
|
func (l *PingLogic) Ping() (resp *types.Resp, err error) {
|
||||||
{{if .callRPC}}if _, err = l.svcCtx.GreetRpc.Ping(l.ctx, &greet.Placeholder{});err !=nil {
|
{{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
|
{{end}}resp = new(types.Resp)
|
||||||
|
resp.Msg = "pong"
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/zeromicro/go-zero/zrpc"
|
"github.com/zeromicro/go-zero/zrpc"
|
||||||
"greet/api/internal/config"
|
"greet/api/internal/config"
|
||||||
"greet/rpc/greet"
|
"greet/rpc/greet"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContext struct {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
GreetRpc greet.Greet
|
GreetRpc greet.Greet
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
client := zrpc.MustNewClient(zrpc.RpcClientConf{
|
client := zrpc.MustNewClient(zrpc.RpcClientConf{
|
||||||
Target: "127.0.0.1:8080",
|
Target: "127.0.0.1:8080",
|
||||||
})
|
})
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
GreetRpc: greet.NewGreet(client),
|
GreetRpc: greet.NewGreet(client),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user