update
This commit is contained in:
parent
df929aa104
commit
7ed130a16e
7
Makefile
7
Makefile
@ -1,4 +1,4 @@
|
||||
.PHONY: ent
|
||||
.PHONY: *
|
||||
|
||||
setup:
|
||||
go run . setup
|
||||
@ -9,7 +9,10 @@ grpc-web:
|
||||
install-deps:
|
||||
go install github.com/swaggo/swag/cmd/swag@latest
|
||||
curl -sSf https://atlasgo.sh | sh
|
||||
echo "Buf install: https://buf.build/docs/installation"
|
||||
swag:
|
||||
swag init -g internal/routes/router.go --parseDependency
|
||||
hash-migration:
|
||||
atlas migrate hash --dir "file://internal/migrations"
|
||||
atlas migrate hash --dir "file://internal/migrations"
|
||||
proto:
|
||||
buf generate
|
199
api/library/library.pb.go
Normal file
199
api/library/library.pb.go
Normal file
@ -0,0 +1,199 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.1
|
||||
// protoc (unknown)
|
||||
// source: api/library/library.proto
|
||||
|
||||
package library
|
||||
|
||||
import (
|
||||
_ "google.golang.org/genproto/googleapis/api/annotations"
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type ListLibraryRequest struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *ListLibraryRequest) Reset() {
|
||||
*x = ListLibraryRequest{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_api_library_library_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ListLibraryRequest) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ListLibraryRequest) ProtoMessage() {}
|
||||
|
||||
func (x *ListLibraryRequest) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_api_library_library_proto_msgTypes[0]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ListLibraryRequest.ProtoReflect.Descriptor instead.
|
||||
func (*ListLibraryRequest) Descriptor() ([]byte, []int) {
|
||||
return file_api_library_library_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
type ListLibraryResponse struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *ListLibraryResponse) Reset() {
|
||||
*x = ListLibraryResponse{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_api_library_library_proto_msgTypes[1]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *ListLibraryResponse) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*ListLibraryResponse) ProtoMessage() {}
|
||||
|
||||
func (x *ListLibraryResponse) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_api_library_library_proto_msgTypes[1]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use ListLibraryResponse.ProtoReflect.Descriptor instead.
|
||||
func (*ListLibraryResponse) Descriptor() ([]byte, []int) {
|
||||
return file_api_library_library_proto_rawDescGZIP(), []int{1}
|
||||
}
|
||||
|
||||
var File_api_library_library_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_api_library_library_proto_rawDesc = []byte{
|
||||
0x0a, 0x19, 0x61, 0x70, 0x69, 0x2f, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x2f, 0x6c, 0x69,
|
||||
0x62, 0x72, 0x61, 0x72, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x4c, 0x69, 0x62,
|
||||
0x72, 0x61, 0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x1a, 0x1c, 0x67, 0x6f, 0x6f,
|
||||
0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x14, 0x0a, 0x12, 0x4c, 0x69, 0x73,
|
||||
0x74, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22,
|
||||
0x15, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, 0x65,
|
||||
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x7a, 0x0a, 0x0e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72,
|
||||
0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x68, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74,
|
||||
0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x12, 0x22, 0x2e, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72,
|
||||
0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4c, 0x69, 0x62,
|
||||
0x72, 0x61, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x4c, 0x69,
|
||||
0x62, 0x72, 0x61, 0x72, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, 0x4c, 0x69, 0x73,
|
||||
0x74, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
|
||||
0x22, 0x10, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0a, 0x12, 0x08, 0x2f, 0x6c, 0x69, 0x62, 0x72, 0x61,
|
||||
0x72, 0x79, 0x42, 0x24, 0x5a, 0x22, 0x6c, 0x65, 0x61, 0x66, 0x64, 0x65, 0x76, 0x2e, 0x74, 0x6f,
|
||||
0x70, 0x2f, 0x6c, 0x65, 0x61, 0x66, 0x2f, 0x72, 0x61, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x2f, 0x6c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_api_library_library_proto_rawDescOnce sync.Once
|
||||
file_api_library_library_proto_rawDescData = file_api_library_library_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_api_library_library_proto_rawDescGZIP() []byte {
|
||||
file_api_library_library_proto_rawDescOnce.Do(func() {
|
||||
file_api_library_library_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_library_library_proto_rawDescData)
|
||||
})
|
||||
return file_api_library_library_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_api_library_library_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
|
||||
var file_api_library_library_proto_goTypes = []interface{}{
|
||||
(*ListLibraryRequest)(nil), // 0: LibraryService.ListLibraryRequest
|
||||
(*ListLibraryResponse)(nil), // 1: LibraryService.ListLibraryResponse
|
||||
}
|
||||
var file_api_library_library_proto_depIdxs = []int32{
|
||||
0, // 0: LibraryService.LibraryService.ListLibrary:input_type -> LibraryService.ListLibraryRequest
|
||||
1, // 1: LibraryService.LibraryService.ListLibrary:output_type -> LibraryService.ListLibraryResponse
|
||||
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
|
||||
0, // [0:0] is the sub-list for extension extendee
|
||||
0, // [0:0] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_api_library_library_proto_init() }
|
||||
func file_api_library_library_proto_init() {
|
||||
if File_api_library_library_proto != nil {
|
||||
return
|
||||
}
|
||||
if !protoimpl.UnsafeEnabled {
|
||||
file_api_library_library_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ListLibraryRequest); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_api_library_library_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*ListLibraryResponse); 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{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_api_library_library_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 2,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
GoTypes: file_api_library_library_proto_goTypes,
|
||||
DependencyIndexes: file_api_library_library_proto_depIdxs,
|
||||
MessageInfos: file_api_library_library_proto_msgTypes,
|
||||
}.Build()
|
||||
File_api_library_library_proto = out.File
|
||||
file_api_library_library_proto_rawDesc = nil
|
||||
file_api_library_library_proto_goTypes = nil
|
||||
file_api_library_library_proto_depIdxs = nil
|
||||
}
|
155
api/library/library.pb.gw.go
Normal file
155
api/library/library.pb.gw.go
Normal file
@ -0,0 +1,155 @@
|
||||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: api/library/library.proto
|
||||
|
||||
/*
|
||||
Package library is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package library
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
// Suppress "imported and not used" errors
|
||||
var _ codes.Code
|
||||
var _ io.Reader
|
||||
var _ status.Status
|
||||
var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
var _ = metadata.Join
|
||||
|
||||
func request_LibraryService_ListLibrary_0(ctx context.Context, marshaler runtime.Marshaler, client LibraryServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListLibraryRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.ListLibrary(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_LibraryService_ListLibrary_0(ctx context.Context, marshaler runtime.Marshaler, server LibraryServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListLibraryRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.ListLibrary(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterLibraryServiceHandlerServer registers the http handlers for service LibraryService to "mux".
|
||||
// UnaryRPC :call LibraryServiceServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterLibraryServiceHandlerFromEndpoint instead.
|
||||
func RegisterLibraryServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server LibraryServiceServer) error {
|
||||
|
||||
mux.Handle("GET", pattern_LibraryService_ListLibrary_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, "/LibraryService.LibraryService/ListLibrary", runtime.WithHTTPPathPattern("/library"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_LibraryService_ListLibrary_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_LibraryService_ListLibrary_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterLibraryServiceHandlerFromEndpoint is same as RegisterLibraryServiceHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterLibraryServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||
conn, err := grpc.NewClient(endpoint, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
}()
|
||||
}()
|
||||
|
||||
return RegisterLibraryServiceHandler(ctx, mux, conn)
|
||||
}
|
||||
|
||||
// RegisterLibraryServiceHandler registers the http handlers for service LibraryService to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over "conn".
|
||||
func RegisterLibraryServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||
return RegisterLibraryServiceHandlerClient(ctx, mux, NewLibraryServiceClient(conn))
|
||||
}
|
||||
|
||||
// RegisterLibraryServiceHandlerClient registers the http handlers for service LibraryService
|
||||
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "LibraryServiceClient".
|
||||
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "LibraryServiceClient"
|
||||
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||
// "LibraryServiceClient" to call the correct interceptors.
|
||||
func RegisterLibraryServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client LibraryServiceClient) error {
|
||||
|
||||
mux.Handle("GET", pattern_LibraryService_ListLibrary_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, "/LibraryService.LibraryService/ListLibrary", runtime.WithHTTPPathPattern("/library"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_LibraryService_ListLibrary_0(annotatedContext, inboundMarshaler, client, req, pathParams)
|
||||
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_LibraryService_ListLibrary_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_LibraryService_ListLibrary_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"library"}, ""))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_LibraryService_ListLibrary_0 = runtime.ForwardResponseMessage
|
||||
)
|
25
api/library/library.proto
Normal file
25
api/library/library.proto
Normal file
@ -0,0 +1,25 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package LibraryService;
|
||||
|
||||
option go_package = "leafdev.top/leaf/rag/proto/library";
|
||||
|
||||
import "google/api/annotations.proto";
|
||||
import "google.golang.org/grpc/health/grpc_health_v1";
|
||||
|
||||
service LibraryService {
|
||||
rpc ListLibrary(ListLibraryRequest) returns (ListLibraryResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/library"
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
message ListLibraryRequest {
|
||||
|
||||
}
|
||||
|
||||
message ListLibraryResponse {
|
||||
|
||||
}
|
75
api/library/library.swagger.json
Normal file
75
api/library/library.swagger.json
Normal file
@ -0,0 +1,75 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "api/library/library.proto",
|
||||
"version": "version not set"
|
||||
},
|
||||
"tags": [
|
||||
{
|
||||
"name": "LibraryService"
|
||||
}
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/library": {
|
||||
"get": {
|
||||
"operationId": "LibraryService_ListLibrary",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/LibraryServiceListLibraryResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"LibraryService"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"LibraryServiceListLibraryResponse": {
|
||||
"type": "object"
|
||||
},
|
||||
"protobufAny": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"@type": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": {}
|
||||
},
|
||||
"rpcStatus": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/protobufAny"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
105
api/library/library_grpc.pb.go
Normal file
105
api/library/library_grpc.pb.go
Normal file
@ -0,0 +1,105 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc (unknown)
|
||||
// source: api/library/library.proto
|
||||
|
||||
package library
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// LibraryServiceClient is the client API for LibraryService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type LibraryServiceClient interface {
|
||||
ListLibrary(ctx context.Context, in *ListLibraryRequest, opts ...grpc.CallOption) (*ListLibraryResponse, error)
|
||||
}
|
||||
|
||||
type libraryServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewLibraryServiceClient(cc grpc.ClientConnInterface) LibraryServiceClient {
|
||||
return &libraryServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *libraryServiceClient) ListLibrary(ctx context.Context, in *ListLibraryRequest, opts ...grpc.CallOption) (*ListLibraryResponse, error) {
|
||||
out := new(ListLibraryResponse)
|
||||
err := c.cc.Invoke(ctx, "/LibraryService.LibraryService/ListLibrary", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// LibraryServiceServer is the server API for LibraryService service.
|
||||
// All implementations must embed UnimplementedLibraryServiceServer
|
||||
// for forward compatibility
|
||||
type LibraryServiceServer interface {
|
||||
ListLibrary(context.Context, *ListLibraryRequest) (*ListLibraryResponse, error)
|
||||
mustEmbedUnimplementedLibraryServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedLibraryServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedLibraryServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedLibraryServiceServer) ListLibrary(context.Context, *ListLibraryRequest) (*ListLibraryResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListLibrary not implemented")
|
||||
}
|
||||
func (UnimplementedLibraryServiceServer) mustEmbedUnimplementedLibraryServiceServer() {}
|
||||
|
||||
// UnsafeLibraryServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to LibraryServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeLibraryServiceServer interface {
|
||||
mustEmbedUnimplementedLibraryServiceServer()
|
||||
}
|
||||
|
||||
func RegisterLibraryServiceServer(s grpc.ServiceRegistrar, srv LibraryServiceServer) {
|
||||
s.RegisterService(&LibraryService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _LibraryService_ListLibrary_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListLibraryRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(LibraryServiceServer).ListLibrary(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/LibraryService.LibraryService/ListLibrary",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(LibraryServiceServer).ListLibrary(ctx, req.(*ListLibraryRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// LibraryService_ServiceDesc is the grpc.ServiceDesc for LibraryService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var LibraryService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "LibraryService.LibraryService",
|
||||
HandlerType: (*LibraryServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "ListLibrary",
|
||||
Handler: _LibraryService_ListLibrary_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "api/library/library.proto",
|
||||
}
|
21
buf.gen.yaml
Normal file
21
buf.gen.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
version: v1
|
||||
|
||||
plugins:
|
||||
- name: go
|
||||
out: .
|
||||
opt: paths=source_relative
|
||||
- name: go-grpc
|
||||
out: .
|
||||
opt: paths=source_relative
|
||||
- plugin: buf.build/grpc-ecosystem/gateway:v2.20.0
|
||||
out: .
|
||||
opt:
|
||||
- paths=source_relative
|
||||
- plugin: buf.build/grpc-ecosystem/openapiv2:v2.20.0
|
||||
out: .
|
||||
# - plugin: buf.build/grpc-ecosystem/openapiv2:v2.19.1
|
||||
# out: proto
|
||||
# opt:
|
||||
# - allow_merge
|
||||
# - merge_file_name=mce-spider
|
||||
#
|
8
buf.lock
Normal file
8
buf.lock
Normal file
@ -0,0 +1,8 @@
|
||||
# Generated by buf. DO NOT EDIT.
|
||||
version: v1
|
||||
deps:
|
||||
- remote: buf.build
|
||||
owner: googleapis
|
||||
repository: googleapis
|
||||
commit: f0e53af8f2fc4556b94f482688b57223
|
||||
digest: shake256:de26a277fc28b8b411ecf58729d78d32fcf15090ffd998a4469225b17889bfb51442eaab04bb7a8d88d203ecdf0a9febd4ffd52c18ed1c2229160c7bd353ca95
|
4
go.mod
4
go.mod
@ -9,6 +9,7 @@ require (
|
||||
github.com/gin-gonic/gin v1.10.0
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
|
||||
github.com/hibiken/asynq v0.24.1
|
||||
github.com/jackc/pgx/v5 v5.5.5
|
||||
github.com/joho/godotenv v1.5.1
|
||||
@ -23,6 +24,7 @@ require (
|
||||
github.com/swaggo/gin-swagger v1.6.0
|
||||
github.com/swaggo/swag v1.16.3
|
||||
go.uber.org/zap v1.27.0
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8
|
||||
google.golang.org/grpc v1.64.0
|
||||
)
|
||||
|
||||
@ -99,7 +101,7 @@ require (
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
golang.org/x/time v0.5.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
google.golang.org/protobuf v1.34.2
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -100,6 +100,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
|
||||
github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgCNc=
|
||||
@ -315,6 +317,8 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 h1:W5Xj/70xIA4x60O/IFyXivR5MGqblAb8R3w26pnD6No=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8/go.mod h1:vPrPUTsDCYxXWjP7clS81mZ6/803D8K4iM9Ma27VKas=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e h1:Elxv5MwEkCI9f5SkoL6afed6NTdxaGoAo39eANBwHL8=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240521202816-d264139d666e/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
|
||||
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
|
||||
|
@ -1,14 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth"
|
||||
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"leafdev.top/leaf/rag/api/library"
|
||||
libraryGw "leafdev.top/leaf/rag/api/library"
|
||||
grpc2 "leafdev.top/leaf/rag/internal/middleware/grpc"
|
||||
"leafdev.top/leaf/rag/internal/providers/jwks"
|
||||
|
||||
"leafdev.top/leaf/rag/internal/services/libraryService"
|
||||
"net"
|
||||
)
|
||||
|
||||
@ -17,11 +22,11 @@ var rpcCommand = &cobra.Command{
|
||||
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
jwks.InitJwksRefresh()
|
||||
StartSpiderService()
|
||||
StartGRPC()
|
||||
},
|
||||
}
|
||||
|
||||
func StartSpiderService() {
|
||||
func StartGRPC() {
|
||||
if config.ListenAddr.GRPC == "" {
|
||||
config.ListenAddr.GRPC = "0.0.0.0:8081"
|
||||
}
|
||||
@ -46,9 +51,7 @@ func StartSpiderService() {
|
||||
|
||||
reflection.Register(grpcServer)
|
||||
|
||||
// 如需实现,需要手动实现这里
|
||||
//library.RegisterLibraryServiceServer(grpcServer, &services.LibraryService{})
|
||||
//document.RegisterDocumentServiceServer(grpcServer, &services.DocumentService{})
|
||||
library.RegisterLibraryServiceServer(grpcServer, libraryService.LibraryService{})
|
||||
|
||||
err = grpcServer.Serve(lis)
|
||||
if err != nil {
|
||||
@ -56,4 +59,18 @@ func StartSpiderService() {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
mux := runtime.NewServeMux()
|
||||
clientOpts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())}
|
||||
err := gw.RegisterYourServiceHandlerFromEndpoint(ctx, mux, config.ListenAddr.GRPC, clientOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Start HTTP server (and proxy calls to gRPC server endpoint)
|
||||
return http.ListenAndServe(":8081", mux)
|
||||
|
||||
}
|
||||
|
14
internal/services/libraryService/libraryservice.go
Normal file
14
internal/services/libraryService/libraryservice.go
Normal file
@ -0,0 +1,14 @@
|
||||
package libraryService
|
||||
|
||||
import (
|
||||
"context"
|
||||
"leafdev.top/leaf/rag/api/library"
|
||||
)
|
||||
|
||||
type LibraryService struct {
|
||||
library.UnimplementedLibraryServiceServer
|
||||
}
|
||||
|
||||
func (LibraryService) ListLibrary(ctx context.Context, req *library.ListLibraryRequest) (*library.ListLibraryResponse, error) {
|
||||
return &library.ListLibraryResponse{}, nil
|
||||
}
|
44
proto/mce-spider.swagger.json
Normal file
44
proto/mce-spider.swagger.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "api/library/library.proto",
|
||||
"version": "version not set"
|
||||
},
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {},
|
||||
"definitions": {
|
||||
"protobufAny": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"@type": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"additionalProperties": {}
|
||||
},
|
||||
"rpcStatus": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/protobufAny"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user