feat: Add goctl quickstart (#1889)
* Add goctl quickstart * Format code * Format code
This commit is contained in:
3
tools/goctl/quickstart/idl/api.yaml
Normal file
3
tools/goctl/quickstart/idl/api.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
Name: ping
|
||||
Host: 127.0.0.1
|
||||
Port: 8888
|
||||
35
tools/goctl/quickstart/idl/apilogic.tpl
Normal file
35
tools/goctl/quickstart/idl/apilogic.tpl
Normal file
@@ -0,0 +1,35 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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
|
||||
}
|
||||
|
||||
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
|
||||
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"
|
||||
|
||||
return
|
||||
}
|
||||
10
tools/goctl/quickstart/idl/greet.api
Normal file
10
tools/goctl/quickstart/idl/greet.api
Normal file
@@ -0,0 +1,10 @@
|
||||
syntax = "v1"
|
||||
|
||||
type resp {
|
||||
msg string `json:"msg"`
|
||||
}
|
||||
|
||||
service greet {
|
||||
@handler ping
|
||||
post /ping returns (resp)
|
||||
}
|
||||
10
tools/goctl/quickstart/idl/greet.proto
Normal file
10
tools/goctl/quickstart/idl/greet.proto
Normal file
@@ -0,0 +1,10 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ping;
|
||||
option go_package = "./pb";
|
||||
|
||||
message Placeholder{}
|
||||
|
||||
service Greet {
|
||||
rpc ping (Placeholder) returns (Placeholder);
|
||||
}
|
||||
22
tools/goctl/quickstart/idl/svc.tpl
Normal file
22
tools/goctl/quickstart/idl/svc.tpl
Normal file
@@ -0,0 +1,22 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"greet/api/internal/config"
|
||||
"greet/rpc/greet"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
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),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user