-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Code generated by '{{GENERATOR}}'. DO NOT EDIT. | ||
// template: {{TEMPLATE}} | ||
|
||
package clients | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"{{GRPC_INC}}" | ||
{{TYPE_PACKAGE}} "{{PROTO_INC}}" | ||
"github.com/chain4travel/camino-messenger-bot/internal/messaging/types" | ||
|
||
"google.golang.org/grpc" | ||
"google.golang.org/protobuf/reflect/protoreflect" | ||
) | ||
|
||
const ( | ||
{{SERVICE}}V{{VERSION}} = {{FQPN}} | ||
{{SERVICE}}V{{VERSION}}Request types.MessageType = types.MessageType({{SERVICE}}V{{VERSION}} + ".Request") | ||
{{SERVICE}}V{{VERSION}}Response types.MessageType = types.MessageType({{SERVICE}}V{{VERSION}} + ".Response") | ||
) | ||
|
||
var _ Client = (*{{SERVICE}}Client)(nil) | ||
|
||
func New{{SERVICE}}V{{VERSION}}(grpcCon *grpc.ClientConn) *{{SERVICE}}Client { | ||
client := {{GRPC_PACKAGE}}.New{{SERVICE}}Client(grpcCon) | ||
return &{{SERVICE}}Client{client: &client} | ||
} | ||
|
||
type {{SERVICE}}Client struct { | ||
client *{{GRPC_PACKAGE}}.{{SERVICE}}Client | ||
} | ||
|
||
func (s {{SERVICE}}Client) Call(ctx context.Context, requestIntf protoreflect.ProtoMessage, opts ...grpc.CallOption) (protoreflect.ProtoMessage, types.MessageType, error) { | ||
request, ok := requestIntf.(*{{TYPE_PACKAGE}}.{{REQUEST}})) | ||
if !ok { | ||
return nil, {{SERVICE}}V{{VERSION}}Response, fmt.Errorf("invalid request type") | ||
} | ||
response, err := (*s.client).{{METHOD}})(ctx, request, opts...) | ||
return response, {{SERVICE}}V{{VERSION}}Response, err | ||
} |
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,42 @@ | ||
// Code generated by '{{GENERATOR}}'. DO NOT EDIT. | ||
// template: {{TEMPLATE}} | ||
|
||
package server | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"{{GRPC_INC}}" | ||
{{TYPE_PACKAGE}} "{{PROTO_INC}}" | ||
|
||
"github.com/chain4travel/camino-messenger-bot/internal/messaging/clients" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
var _ {{GRPC_PACKAGE}}.{{SERVICE}}Server = (*{{TYPE_PACKAGE}}_srv1)(nil) | ||
|
||
type {{TYPE_PACKAGE}}_srv struct { | ||
reqProcessor externalRequestProcessor | ||
} | ||
|
||
func New{{SERVICE}}Server( | ||
grpcServer *grpc.Server, | ||
reqProcess externalRequestProcessor, | ||
) {{GRPC_PACKAGE}}.{{SERVICE}}Server { | ||
{{TYPE_PACKAGE}}_srv := &{{TYPE_PACKAGE}}_srv1{reqProcessor: reqProcess} | ||
{{GRPC_PACKAGE}}.Register{{SERVICE}}Server(grpcServer, {{TYPE_PACKAGE}}_srv) | ||
return {{TYPE_PACKAGE}}_srv | ||
} | ||
|
||
func (s *{{TYPE_PACKAGE}}_srv1) {{METHOD}}(ctx context.Context, request *{{TYPE_PACKAGE}}.{{REQUEST}}) (*{{TYPE_PACKAGE}}.{{RESPONSE}}, error) { | ||
response, err := s.reqProcessor.processExternalRequest(ctx, clients.{{SERVICE}}V{{VERSION}}Request, request) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to process %s request: %w", clients.{{SERVICE}}V{{VERSION}}Request, err) | ||
} | ||
resp, ok := response.(*{{TYPE_PACKAGE}}.{{RESPONSE}}) | ||
if !ok { | ||
return nil, fmt.Errorf("invalid response type: expected %s, got %T", clients.{{SERVICE}}V{{VERSION}}Response, response) | ||
} | ||
return resp, nil | ||
} |