Skip to content

Commit

Permalink
更新脚手架
Browse files Browse the repository at this point in the history
  • Loading branch information
yiirs committed Jan 8, 2025
1 parent 83d97ee commit e0136c2
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 127 deletions.
24 changes: 24 additions & 0 deletions cmd/internal/grpc/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

.idea/
.vscode/
.DS_Store
logs/
*.log
.env
.yml
config.toml
14 changes: 7 additions & 7 deletions cmd/internal/grpc/pkg/app/api/api.swagger.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/apiHelloReply"
"$ref": "#/definitions/apiHelloResponse"
}
},
"default": {
Expand All @@ -51,23 +51,23 @@
}
},
"definitions": {
"apiHelloReply": {
"apiHelloRequest": {
"type": "object",
"properties": {
"message": {
"name": {
"type": "string"
}
},
"title": "The response message containing the greetings"
"title": "The request message containing the user's name"
},
"apiHelloRequest": {
"apiHelloResponse": {
"type": "object",
"properties": {
"name": {
"message": {
"type": "string"
}
},
"title": "The request message containing the user's name"
"title": "The response message containing the greetings"
},
"protobufAny": {
"type": "object",
Expand Down
58 changes: 24 additions & 34 deletions cmd/internal/grpc/pkg/app/api/greeter.pb.gw.yiigo
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package api

import (
"context"
"errors"
"io"
"net/http"

Expand All @@ -24,37 +25,38 @@ import (
)

// Suppress "imported and not used" errors
var _ codes.Code
var _ io.Reader
var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = metadata.Join
var (
_ codes.Code
_ io.Reader
_ status.Status
_ = errors.New
_ = runtime.String
_ = utilities.NewDoubleArray
_ = metadata.Join
)

func request_Greeter_SayHello_0(ctx context.Context, marshaler runtime.Marshaler, client GreeterClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq HelloRequest
var metadata runtime.ServerMetadata

if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
var (
protoReq HelloRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}

msg, err := client.SayHello(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err

}

func local_request_Greeter_SayHello_0(ctx context.Context, marshaler runtime.Marshaler, server GreeterServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq HelloRequest
var metadata runtime.ServerMetadata

if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF {
var (
protoReq HelloRequest
metadata runtime.ServerMetadata
)
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}

msg, err := server.SayHello(ctx, &protoReq)
return msg, metadata, err

}

// RegisterGreeterHandlerServer registers the http handlers for service Greeter to "mux".
Expand All @@ -63,16 +65,13 @@ func local_request_Greeter_SayHello_0(ctx context.Context, marshaler runtime.Mar
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterGreeterHandlerFromEndpoint instead.
// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.
func RegisterGreeterHandlerServer(ctx context.Context, mux *runtime.ServeMux, server GreeterServer) error {

mux.Handle("POST", pattern_Greeter_SayHello_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
mux.Handle(http.MethodPost, pattern_Greeter_SayHello_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/api.Greeter/SayHello", runtime.WithHTTPPathPattern("/v1/greeter"))
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/api.Greeter/SayHello", runtime.WithHTTPPathPattern("/v1/greeter"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
Expand All @@ -84,9 +83,7 @@ func RegisterGreeterHandlerServer(ctx context.Context, mux *runtime.ServeMux, se
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}

forward_Greeter_SayHello_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)

})

return nil
Expand All @@ -113,7 +110,6 @@ func RegisterGreeterHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeM
}
}()
}()

return RegisterGreeterHandler(ctx, mux, conn)
}

Expand All @@ -129,14 +125,11 @@ func RegisterGreeterHandler(ctx context.Context, mux *runtime.ServeMux, conn *gr
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "GreeterClient" to call the correct interceptors. This client ignores the HTTP middlewares.
func RegisterGreeterHandlerClient(ctx context.Context, mux *runtime.ServeMux, client GreeterClient) error {

mux.Handle("POST", pattern_Greeter_SayHello_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
mux.Handle(http.MethodPost, pattern_Greeter_SayHello_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/api.Greeter/SayHello", runtime.WithHTTPPathPattern("/v1/greeter"))
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/api.Greeter/SayHello", runtime.WithHTTPPathPattern("/v1/greeter"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
Expand All @@ -147,11 +140,8 @@ func RegisterGreeterHandlerClient(ctx context.Context, mux *runtime.ServeMux, cl
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}

forward_Greeter_SayHello_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)

})

return nil
}

Expand Down
117 changes: 43 additions & 74 deletions cmd/internal/grpc/pkg/app/api/greeter.pb.yiigo
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.34.2
// protoc-gen-go v1.36.1
// protoc (unknown)
// source: greeter.proto

Expand All @@ -25,20 +25,17 @@ const (

// The request message containing the user's name
type HelloRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
state protoimpl.MessageState `protogen:"open.v1"`
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
unknownFields protoimpl.UnknownFields

Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
sizeCache protoimpl.SizeCache
}

func (x *HelloRequest) Reset() {
*x = HelloRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_greeter_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
mi := &file_greeter_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}

func (x *HelloRequest) String() string {
Expand All @@ -49,7 +46,7 @@ func (*HelloRequest) ProtoMessage() {}

func (x *HelloRequest) ProtoReflect() protoreflect.Message {
mi := &file_greeter_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
Expand All @@ -72,32 +69,29 @@ func (x *HelloRequest) GetName() string {
}

// The response message containing the greetings
type HelloReply struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
type HelloResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
unknownFields protoimpl.UnknownFields

Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
sizeCache protoimpl.SizeCache
}

func (x *HelloReply) Reset() {
*x = HelloReply{}
if protoimpl.UnsafeEnabled {
mi := &file_greeter_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *HelloResponse) Reset() {
*x = HelloResponse{}
mi := &file_greeter_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}

func (x *HelloReply) String() string {
func (x *HelloResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}

func (*HelloReply) ProtoMessage() {}
func (*HelloResponse) ProtoMessage() {}

func (x *HelloReply) ProtoReflect() protoreflect.Message {
func (x *HelloResponse) ProtoReflect() protoreflect.Message {
mi := &file_greeter_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
Expand All @@ -107,12 +101,12 @@ func (x *HelloReply) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}

// Deprecated: Use HelloReply.ProtoReflect.Descriptor instead.
func (*HelloReply) Descriptor() ([]byte, []int) {
// Deprecated: Use HelloResponse.ProtoReflect.Descriptor instead.
func (*HelloResponse) Descriptor() ([]byte, []int) {
return file_greeter_proto_rawDescGZIP(), []int{1}
}

func (x *HelloReply) GetMessage() string {
func (x *HelloResponse) GetMessage() string {
if x != nil {
return x.Message
}
Expand All @@ -131,21 +125,22 @@ var file_greeter_proto_rawDesc = []byte{
0x2f, 0x77, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
0x2a, 0x0a, 0x0c, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12,
0x1a, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x06, 0xba,
0x48, 0x03, 0xc8, 0x01, 0x01, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x26, 0x0a, 0x0a, 0x48,
0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73,
0x61, 0x67, 0x65, 0x32, 0x51, 0x0a, 0x07, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x12, 0x46,
0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x11, 0x2e, 0x61, 0x70, 0x69,
0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0f, 0x2e,
0x61, 0x70, 0x69, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x16,
0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x01, 0x2a, 0x22, 0x0b, 0x2f, 0x76, 0x31, 0x2f, 0x67,
0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x42, 0x5c, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x70,
0x69, 0x42, 0x0c, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50,
0x01, 0x5a, 0x17, 0x78, 0x78, 0x78, 0x2e, 0x79, 0x79, 0x79, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70,
0x6b, 0x67, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x61, 0x70, 0x69, 0xa2, 0x02, 0x03, 0x41, 0x58, 0x58,
0xaa, 0x02, 0x03, 0x41, 0x70, 0x69, 0xca, 0x02, 0x03, 0x41, 0x70, 0x69, 0xe2, 0x02, 0x0f, 0x41,
0x70, 0x69, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02,
0x03, 0x41, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x48, 0x03, 0xc8, 0x01, 0x01, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x29, 0x0a, 0x0d, 0x48,
0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07,
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d,
0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x54, 0x0a, 0x07, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65,
0x72, 0x12, 0x49, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x11, 0x2e,
0x61, 0x70, 0x69, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x12, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x3a, 0x01, 0x2a, 0x22,
0x0b, 0x2f, 0x76, 0x31, 0x2f, 0x67, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x42, 0x5f, 0x0a, 0x07,
0x63, 0x6f, 0x6d, 0x2e, 0x61, 0x70, 0x69, 0x42, 0x0c, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72,
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x1a, 0x69, 0x69, 0x69, 0x6e, 0x73, 0x6f, 0x6d,
0x6e, 0x69, 0x61, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x66, 0x6f, 0x6f, 0x2f,
0x61, 0x70, 0x69, 0xa2, 0x02, 0x03, 0x41, 0x58, 0x58, 0xaa, 0x02, 0x03, 0x41, 0x70, 0x69, 0xca,
0x02, 0x03, 0x41, 0x70, 0x69, 0xe2, 0x02, 0x0f, 0x41, 0x70, 0x69, 0x5c, 0x47, 0x50, 0x42, 0x4d,
0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x03, 0x41, 0x70, 0x69, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}

var (
Expand All @@ -162,12 +157,12 @@ func file_greeter_proto_rawDescGZIP() []byte {

var file_greeter_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_greeter_proto_goTypes = []any{
(*HelloRequest)(nil), // 0: api.HelloRequest
(*HelloReply)(nil), // 1: api.HelloReply
(*HelloRequest)(nil), // 0: api.HelloRequest
(*HelloResponse)(nil), // 1: api.HelloResponse
}
var file_greeter_proto_depIdxs = []int32{
0, // 0: api.Greeter.SayHello:input_type -> api.HelloRequest
1, // 1: api.Greeter.SayHello:output_type -> api.HelloReply
1, // 1: api.Greeter.SayHello:output_type -> api.HelloResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
Expand All @@ -180,32 +175,6 @@ func file_greeter_proto_init() {
if File_greeter_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_greeter_proto_msgTypes[0].Exporter = func(v any, i int) any {
switch v := v.(*HelloRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_greeter_proto_msgTypes[1].Exporter = func(v any, i int) any {
switch v := v.(*HelloReply); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
Expand Down
Loading

0 comments on commit e0136c2

Please sign in to comment.