This commit is contained in:
2026-03-11 20:21:22 +08:00
8 changed files with 691 additions and 386 deletions

View File

@@ -25,6 +25,33 @@
"application/json"
],
"paths": {
"/qgdzs/auth/custom_answer": {
"post": {
"summary": "自定义问答",
"operationId": "Qgdzs_CustomAnswerQuestion",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/CustomAnswerQuestionResp"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/CustomAnswerQuestionReq"
}
}
],
"tags": [
"Qgdzs"
]
}
},
"/qgdzs/auth/generate_question": {
"post": {
"summary": "生成题目",
@@ -454,6 +481,25 @@
}
}
},
"CustomAnswerQuestionReq": {
"type": "object",
"properties": {
"question": {
"type": "string",
"title": "问题"
}
},
"title": "---------- CustomAnswerQuestion ----------"
},
"CustomAnswerQuestionResp": {
"type": "object",
"properties": {
"answer": {
"type": "string",
"title": "答案"
}
}
},
"EnterResp": {
"type": "object",
"properties": {

View File

@@ -59,6 +59,30 @@ func local_request_Qgdzs_GenerateQuestion_0(ctx context.Context, marshaler runti
return msg, metadata, err
}
func request_Qgdzs_CustomAnswerQuestion_0(ctx context.Context, marshaler runtime.Marshaler, client QgdzsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq CustomAnswerQuestionReq
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.CustomAnswerQuestion(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Qgdzs_CustomAnswerQuestion_0(ctx context.Context, marshaler runtime.Marshaler, server QgdzsServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq CustomAnswerQuestionReq
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.CustomAnswerQuestion(ctx, &protoReq)
return msg, metadata, err
}
func request_Qgdzs_RandomGetQuestion_0(ctx context.Context, marshaler runtime.Marshaler, client QgdzsClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq RandomGetQuestionReq
@@ -349,6 +373,26 @@ func RegisterQgdzsHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv
}
forward_Qgdzs_GenerateQuestion_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Qgdzs_CustomAnswerQuestion_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, "/.Qgdzs/CustomAnswerQuestion", runtime.WithHTTPPathPattern("/qgdzs/auth/custom_answer"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Qgdzs_CustomAnswerQuestion_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_Qgdzs_CustomAnswerQuestion_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Qgdzs_RandomGetQuestion_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@@ -626,6 +670,23 @@ func RegisterQgdzsHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
}
forward_Qgdzs_GenerateQuestion_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Qgdzs_CustomAnswerQuestion_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, "/.Qgdzs/CustomAnswerQuestion", runtime.WithHTTPPathPattern("/qgdzs/auth/custom_answer"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Qgdzs_CustomAnswerQuestion_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_Qgdzs_CustomAnswerQuestion_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPost, pattern_Qgdzs_RandomGetQuestion_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@@ -818,6 +879,7 @@ func RegisterQgdzsHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie
var (
pattern_Qgdzs_GenerateQuestion_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"qgdzs", "auth", "generate_question"}, ""))
pattern_Qgdzs_CustomAnswerQuestion_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"qgdzs", "auth", "custom_answer"}, ""))
pattern_Qgdzs_RandomGetQuestion_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"qgdzs", "open", "random", "question"}, ""))
pattern_Qgdzs_RandomAnswerQuestion_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"qgdzs", "open", "random", "answer"}, ""))
pattern_Qgdzs_GetAllCategory_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"qgdzs", "open", "category", "get_category"}, ""))
@@ -833,6 +895,7 @@ var (
var (
forward_Qgdzs_GenerateQuestion_0 = runtime.ForwardResponseMessage
forward_Qgdzs_CustomAnswerQuestion_0 = runtime.ForwardResponseMessage
forward_Qgdzs_RandomGetQuestion_0 = runtime.ForwardResponseMessage
forward_Qgdzs_RandomAnswerQuestion_0 = runtime.ForwardResponseMessage
forward_Qgdzs_GetAllCategory_0 = runtime.ForwardResponseMessage

View File

@@ -24,6 +24,8 @@ const _ = grpc.SupportPackageIsVersion7
type QgdzsClient interface {
// 生成题目
GenerateQuestion(ctx context.Context, in *GenerateQuestionReq, opts ...grpc.CallOption) (*GenerateQuestionResp, error)
// 自定义问答
CustomAnswerQuestion(ctx context.Context, in *CustomAnswerQuestionReq, opts ...grpc.CallOption) (*CustomAnswerQuestionResp, error)
// ---------- 随机答题 ----------
// 获取题目
RandomGetQuestion(ctx context.Context, in *RandomGetQuestionReq, opts ...grpc.CallOption) (*RandomGetQuestionResp, error)
@@ -70,6 +72,15 @@ func (c *qgdzsClient) GenerateQuestion(ctx context.Context, in *GenerateQuestion
return out, nil
}
func (c *qgdzsClient) CustomAnswerQuestion(ctx context.Context, in *CustomAnswerQuestionReq, opts ...grpc.CallOption) (*CustomAnswerQuestionResp, error) {
out := new(CustomAnswerQuestionResp)
err := c.cc.Invoke(ctx, "/Qgdzs/CustomAnswerQuestion", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *qgdzsClient) RandomGetQuestion(ctx context.Context, in *RandomGetQuestionReq, opts ...grpc.CallOption) (*RandomGetQuestionResp, error) {
out := new(RandomGetQuestionResp)
err := c.cc.Invoke(ctx, "/Qgdzs/RandomGetQuestion", in, out, opts...)
@@ -175,6 +186,8 @@ func (c *qgdzsClient) GetPoint(ctx context.Context, in *GetPointReq, opts ...grp
type QgdzsServer interface {
// 生成题目
GenerateQuestion(context.Context, *GenerateQuestionReq) (*GenerateQuestionResp, error)
// 自定义问答
CustomAnswerQuestion(context.Context, *CustomAnswerQuestionReq) (*CustomAnswerQuestionResp, error)
// ---------- 随机答题 ----------
// 获取题目
RandomGetQuestion(context.Context, *RandomGetQuestionReq) (*RandomGetQuestionResp, error)
@@ -212,6 +225,9 @@ type UnimplementedQgdzsServer struct {
func (UnimplementedQgdzsServer) GenerateQuestion(context.Context, *GenerateQuestionReq) (*GenerateQuestionResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GenerateQuestion not implemented")
}
func (UnimplementedQgdzsServer) CustomAnswerQuestion(context.Context, *CustomAnswerQuestionReq) (*CustomAnswerQuestionResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method CustomAnswerQuestion not implemented")
}
func (UnimplementedQgdzsServer) RandomGetQuestion(context.Context, *RandomGetQuestionReq) (*RandomGetQuestionResp, error) {
return nil, status.Errorf(codes.Unimplemented, "method RandomGetQuestion not implemented")
}
@@ -276,6 +292,24 @@ func _Qgdzs_GenerateQuestion_Handler(srv interface{}, ctx context.Context, dec f
return interceptor(ctx, in, info, handler)
}
func _Qgdzs_CustomAnswerQuestion_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CustomAnswerQuestionReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(QgdzsServer).CustomAnswerQuestion(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/Qgdzs/CustomAnswerQuestion",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(QgdzsServer).CustomAnswerQuestion(ctx, req.(*CustomAnswerQuestionReq))
}
return interceptor(ctx, in, info, handler)
}
func _Qgdzs_RandomGetQuestion_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RandomGetQuestionReq)
if err := dec(in); err != nil {
@@ -485,6 +519,10 @@ var Qgdzs_ServiceDesc = grpc.ServiceDesc{
MethodName: "GenerateQuestion",
Handler: _Qgdzs_GenerateQuestion_Handler,
},
{
MethodName: "CustomAnswerQuestion",
Handler: _Qgdzs_CustomAnswerQuestion_Handler,
},
{
MethodName: "RandomGetQuestion",
Handler: _Qgdzs_RandomGetQuestion_Handler,