add signup method

This commit is contained in:
2026-06-29 00:46:57 +07:00
parent 3ec2853df6
commit bb2cb3a540
6 changed files with 300 additions and 19 deletions
+118 -12
View File
@@ -182,6 +182,102 @@ func (x *EchoRsp) GetText() string {
return ""
}
type SignupReq struct {
state protoimpl.MessageState `protogen:"open.v1"`
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SignupReq) Reset() {
*x = SignupReq{}
mi := &file_main_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SignupReq) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SignupReq) ProtoMessage() {}
func (x *SignupReq) ProtoReflect() protoreflect.Message {
mi := &file_main_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SignupReq.ProtoReflect.Descriptor instead.
func (*SignupReq) Descriptor() ([]byte, []int) {
return file_main_proto_rawDescGZIP(), []int{4}
}
func (x *SignupReq) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *SignupReq) GetEmail() string {
if x != nil {
return x.Email
}
return ""
}
type SignupRsp struct {
state protoimpl.MessageState `protogen:"open.v1"`
Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SignupRsp) Reset() {
*x = SignupRsp{}
mi := &file_main_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SignupRsp) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SignupRsp) ProtoMessage() {}
func (x *SignupRsp) ProtoReflect() protoreflect.Message {
mi := &file_main_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SignupRsp.ProtoReflect.Descriptor instead.
func (*SignupRsp) Descriptor() ([]byte, []int) {
return file_main_proto_rawDescGZIP(), []int{5}
}
func (x *SignupRsp) GetError() string {
if x != nil {
return x.Error
}
return ""
}
var File_main_proto protoreflect.FileDescriptor
const file_main_proto_rawDesc = "" +
@@ -193,10 +289,16 @@ const file_main_proto_rawDesc = "" +
"\aEchoReq\x12\x12\n" +
"\x04text\x18\x01 \x01(\tR\x04text\"\x1d\n" +
"\aEchoRsp\x12\x12\n" +
"\x04text\x18\x01 \x01(\tR\x04text2\xf2\x01\n" +
"\x04text\x18\x01 \x01(\tR\x04text\"5\n" +
"\tSignupReq\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" +
"\x05email\x18\x02 \x01(\tR\x05email\"!\n" +
"\tSignupRsp\x12\x14\n" +
"\x05error\x18\x01 \x01(\tR\x05error2\xe7\x02\n" +
"\x16EveningDetectiveServer\x12k\n" +
"\x04Ping\x12'.crabs.evening_detective_server.PingReq\x1a'.crabs.evening_detective_server.PingRsp\"\x11\x82\xd3\xe4\x93\x02\v\x12\t/api/ping\x12k\n" +
"\x04Echo\x12'.crabs.evening_detective_server.EchoReq\x1a'.crabs.evening_detective_server.EchoRsp\"\x11\x82\xd3\xe4\x93\x02\v\"\t/api/echoB\vZ\tpkg/protob\x06proto3"
"\x04Echo\x12'.crabs.evening_detective_server.EchoReq\x1a'.crabs.evening_detective_server.EchoRsp\"\x11\x82\xd3\xe4\x93\x02\v\"\t/api/echo\x12s\n" +
"\x06Signup\x12).crabs.evening_detective_server.SignupReq\x1a).crabs.evening_detective_server.SignupRsp\"\x13\x82\xd3\xe4\x93\x02\r\"\v/api/signupB\vZ\tpkg/protob\x06proto3"
var (
file_main_proto_rawDescOnce sync.Once
@@ -210,20 +312,24 @@ func file_main_proto_rawDescGZIP() []byte {
return file_main_proto_rawDescData
}
var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
var file_main_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_main_proto_goTypes = []any{
(*PingReq)(nil), // 0: crabs.evening_detective_server.PingReq
(*PingRsp)(nil), // 1: crabs.evening_detective_server.PingRsp
(*EchoReq)(nil), // 2: crabs.evening_detective_server.EchoReq
(*EchoRsp)(nil), // 3: crabs.evening_detective_server.EchoRsp
(*PingReq)(nil), // 0: crabs.evening_detective_server.PingReq
(*PingRsp)(nil), // 1: crabs.evening_detective_server.PingRsp
(*EchoReq)(nil), // 2: crabs.evening_detective_server.EchoReq
(*EchoRsp)(nil), // 3: crabs.evening_detective_server.EchoRsp
(*SignupReq)(nil), // 4: crabs.evening_detective_server.SignupReq
(*SignupRsp)(nil), // 5: crabs.evening_detective_server.SignupRsp
}
var file_main_proto_depIdxs = []int32{
0, // 0: crabs.evening_detective_server.EveningDetectiveServer.Ping:input_type -> crabs.evening_detective_server.PingReq
2, // 1: crabs.evening_detective_server.EveningDetectiveServer.Echo:input_type -> crabs.evening_detective_server.EchoReq
1, // 2: crabs.evening_detective_server.EveningDetectiveServer.Ping:output_type -> crabs.evening_detective_server.PingRsp
3, // 3: crabs.evening_detective_server.EveningDetectiveServer.Echo:output_type -> crabs.evening_detective_server.EchoRsp
2, // [2:4] is the sub-list for method output_type
0, // [0:2] is the sub-list for method input_type
4, // 2: crabs.evening_detective_server.EveningDetectiveServer.Signup:input_type -> crabs.evening_detective_server.SignupReq
1, // 3: crabs.evening_detective_server.EveningDetectiveServer.Ping:output_type -> crabs.evening_detective_server.PingRsp
3, // 4: crabs.evening_detective_server.EveningDetectiveServer.Echo:output_type -> crabs.evening_detective_server.EchoRsp
5, // 5: crabs.evening_detective_server.EveningDetectiveServer.Signup:output_type -> crabs.evening_detective_server.SignupRsp
3, // [3:6] is the sub-list for method output_type
0, // [0:3] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
@@ -240,7 +346,7 @@ func file_main_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_main_proto_rawDesc), len(file_main_proto_rawDesc)),
NumEnums: 0,
NumMessages: 4,
NumMessages: 6,
NumExtensions: 0,
NumServices: 1,
},
+78 -4
View File
@@ -91,6 +91,41 @@ func local_request_EveningDetectiveServer_Echo_0(ctx context.Context, marshaler
return msg, metadata, err
}
var filter_EveningDetectiveServer_Signup_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
func request_EveningDetectiveServer_Signup_0(ctx context.Context, marshaler runtime.Marshaler, client EveningDetectiveServerClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq SignupReq
metadata runtime.ServerMetadata
)
if req.Body != nil {
_, _ = io.Copy(io.Discard, req.Body)
}
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_EveningDetectiveServer_Signup_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Signup(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_EveningDetectiveServer_Signup_0(ctx context.Context, marshaler runtime.Marshaler, server EveningDetectiveServerServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq SignupReq
metadata runtime.ServerMetadata
)
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_EveningDetectiveServer_Signup_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Signup(ctx, &protoReq)
return msg, metadata, err
}
// RegisterEveningDetectiveServerHandlerServer registers the http handlers for service EveningDetectiveServer to "mux".
// UnaryRPC :call EveningDetectiveServerServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@@ -137,6 +172,26 @@ func RegisterEveningDetectiveServerHandlerServer(ctx context.Context, mux *runti
}
forward_EveningDetectiveServer_Echo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_EveningDetectiveServer_Signup_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)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/Signup", runtime.WithHTTPPathPattern("/api/signup"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_EveningDetectiveServer_Signup_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_EveningDetectiveServer_Signup_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -211,15 +266,34 @@ func RegisterEveningDetectiveServerHandlerClient(ctx context.Context, mux *runti
}
forward_EveningDetectiveServer_Echo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_EveningDetectiveServer_Signup_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)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/crabs.evening_detective_server.EveningDetectiveServer/Signup", runtime.WithHTTPPathPattern("/api/signup"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_EveningDetectiveServer_Signup_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_EveningDetectiveServer_Signup_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_EveningDetectiveServer_Ping_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"api", "ping"}, ""))
pattern_EveningDetectiveServer_Echo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"api", "echo"}, ""))
pattern_EveningDetectiveServer_Ping_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"api", "ping"}, ""))
pattern_EveningDetectiveServer_Echo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"api", "echo"}, ""))
pattern_EveningDetectiveServer_Signup_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"api", "signup"}, ""))
)
var (
forward_EveningDetectiveServer_Ping_0 = runtime.ForwardResponseMessage
forward_EveningDetectiveServer_Echo_0 = runtime.ForwardResponseMessage
forward_EveningDetectiveServer_Ping_0 = runtime.ForwardResponseMessage
forward_EveningDetectiveServer_Echo_0 = runtime.ForwardResponseMessage
forward_EveningDetectiveServer_Signup_0 = runtime.ForwardResponseMessage
)
+40 -2
View File
@@ -19,8 +19,9 @@ import (
const _ = grpc.SupportPackageIsVersion9
const (
EveningDetectiveServer_Ping_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/Ping"
EveningDetectiveServer_Echo_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/Echo"
EveningDetectiveServer_Ping_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/Ping"
EveningDetectiveServer_Echo_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/Echo"
EveningDetectiveServer_Signup_FullMethodName = "/crabs.evening_detective_server.EveningDetectiveServer/Signup"
)
// EveningDetectiveServerClient is the client API for EveningDetectiveServer service.
@@ -29,6 +30,7 @@ const (
type EveningDetectiveServerClient interface {
Ping(ctx context.Context, in *PingReq, opts ...grpc.CallOption) (*PingRsp, error)
Echo(ctx context.Context, in *EchoReq, opts ...grpc.CallOption) (*EchoRsp, error)
Signup(ctx context.Context, in *SignupReq, opts ...grpc.CallOption) (*SignupRsp, error)
}
type eveningDetectiveServerClient struct {
@@ -59,12 +61,23 @@ func (c *eveningDetectiveServerClient) Echo(ctx context.Context, in *EchoReq, op
return out, nil
}
func (c *eveningDetectiveServerClient) Signup(ctx context.Context, in *SignupReq, opts ...grpc.CallOption) (*SignupRsp, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(SignupRsp)
err := c.cc.Invoke(ctx, EveningDetectiveServer_Signup_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// EveningDetectiveServerServer is the server API for EveningDetectiveServer service.
// All implementations must embed UnimplementedEveningDetectiveServerServer
// for forward compatibility.
type EveningDetectiveServerServer interface {
Ping(context.Context, *PingReq) (*PingRsp, error)
Echo(context.Context, *EchoReq) (*EchoRsp, error)
Signup(context.Context, *SignupReq) (*SignupRsp, error)
mustEmbedUnimplementedEveningDetectiveServerServer()
}
@@ -81,6 +94,9 @@ func (UnimplementedEveningDetectiveServerServer) Ping(context.Context, *PingReq)
func (UnimplementedEveningDetectiveServerServer) Echo(context.Context, *EchoReq) (*EchoRsp, error) {
return nil, status.Error(codes.Unimplemented, "method Echo not implemented")
}
func (UnimplementedEveningDetectiveServerServer) Signup(context.Context, *SignupReq) (*SignupRsp, error) {
return nil, status.Error(codes.Unimplemented, "method Signup not implemented")
}
func (UnimplementedEveningDetectiveServerServer) mustEmbedUnimplementedEveningDetectiveServerServer() {
}
func (UnimplementedEveningDetectiveServerServer) testEmbeddedByValue() {}
@@ -139,6 +155,24 @@ func _EveningDetectiveServer_Echo_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler)
}
func _EveningDetectiveServer_Signup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SignupReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(EveningDetectiveServerServer).Signup(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: EveningDetectiveServer_Signup_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(EveningDetectiveServerServer).Signup(ctx, req.(*SignupReq))
}
return interceptor(ctx, in, info, handler)
}
// EveningDetectiveServer_ServiceDesc is the grpc.ServiceDesc for EveningDetectiveServer service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@@ -154,6 +188,10 @@ var EveningDetectiveServer_ServiceDesc = grpc.ServiceDesc{
MethodName: "Echo",
Handler: _EveningDetectiveServer_Echo_Handler,
},
{
MethodName: "Signup",
Handler: _EveningDetectiveServer_Signup_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "main.proto",