增加 buf

This commit is contained in:
Twilight 2024-07-15 16:31:17 +08:00
parent 65af28d367
commit 8b1a7d0b5e
14 changed files with 819 additions and 1 deletions

View File

@ -9,7 +9,12 @@ 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"
buf dep update
swag:
swag init -g internal/routes/router.go --parseDependency
hash-migration:
atlas migrate hash --dir "file://internal/migrations"
proto:
echo "please run buf dep update if you first use buf"
buf generate

208
api/greeting/greeting.pb.go Normal file
View File

@ -0,0 +1,208 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc (unknown)
// source: api/greeting/greeting.proto
package greeting
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 HelloRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *HelloRequest) Reset() {
*x = HelloRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_api_greeting_greeting_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HelloRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HelloRequest) ProtoMessage() {}
func (x *HelloRequest) ProtoReflect() protoreflect.Message {
mi := &file_api_greeting_greeting_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 HelloRequest.ProtoReflect.Descriptor instead.
func (*HelloRequest) Descriptor() ([]byte, []int) {
return file_api_greeting_greeting_proto_rawDescGZIP(), []int{0}
}
type HelloResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Hello string `protobuf:"bytes,1,opt,name=hello,proto3" json:"hello,omitempty"`
}
func (x *HelloResponse) Reset() {
*x = HelloResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_api_greeting_greeting_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *HelloResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*HelloResponse) ProtoMessage() {}
func (x *HelloResponse) ProtoReflect() protoreflect.Message {
mi := &file_api_greeting_greeting_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 HelloResponse.ProtoReflect.Descriptor instead.
func (*HelloResponse) Descriptor() ([]byte, []int) {
return file_api_greeting_greeting_proto_rawDescGZIP(), []int{1}
}
func (x *HelloResponse) GetHello() string {
if x != nil {
return x.Hello
}
return ""
}
var File_api_greeting_greeting_proto protoreflect.FileDescriptor
var file_api_greeting_greeting_proto_rawDesc = []byte{
0x0a, 0x1b, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x72, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x2f, 0x67,
0x72, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x47,
0x72, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 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, 0x0e, 0x0a, 0x0c,
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x25, 0x0a, 0x0d,
0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a,
0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x68, 0x65,
0x6c, 0x6c, 0x6f, 0x32, 0x59, 0x0a, 0x0f, 0x47, 0x72, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x53,
0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x46, 0x0a, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12,
0x1d, 0x2e, 0x47, 0x72, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e,
0x2e, 0x47, 0x72, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65,
0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x2c,
0x5a, 0x2a, 0x6c, 0x65, 0x61, 0x66, 0x64, 0x65, 0x76, 0x2e, 0x74, 0x6f, 0x70, 0x2f, 0x47, 0x72,
0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x72, 0x65, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x33,
}
var (
file_api_greeting_greeting_proto_rawDescOnce sync.Once
file_api_greeting_greeting_proto_rawDescData = file_api_greeting_greeting_proto_rawDesc
)
func file_api_greeting_greeting_proto_rawDescGZIP() []byte {
file_api_greeting_greeting_proto_rawDescOnce.Do(func() {
file_api_greeting_greeting_proto_rawDescData = protoimpl.X.CompressGZIP(file_api_greeting_greeting_proto_rawDescData)
})
return file_api_greeting_greeting_proto_rawDescData
}
var file_api_greeting_greeting_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_api_greeting_greeting_proto_goTypes = []interface{}{
(*HelloRequest)(nil), // 0: GreetingService.HelloRequest
(*HelloResponse)(nil), // 1: GreetingService.HelloResponse
}
var file_api_greeting_greeting_proto_depIdxs = []int32{
0, // 0: GreetingService.GreetingService.Hello:input_type -> GreetingService.HelloRequest
1, // 1: GreetingService.GreetingService.Hello:output_type -> GreetingService.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
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_greeting_greeting_proto_init() }
func file_api_greeting_greeting_proto_init() {
if File_api_greeting_greeting_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_api_greeting_greeting_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HelloRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_api_greeting_greeting_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*HelloResponse); 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_greeting_greeting_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_api_greeting_greeting_proto_goTypes,
DependencyIndexes: file_api_greeting_greeting_proto_depIdxs,
MessageInfos: file_api_greeting_greeting_proto_msgTypes,
}.Build()
File_api_greeting_greeting_proto = out.File
file_api_greeting_greeting_proto_rawDesc = nil
file_api_greeting_greeting_proto_goTypes = nil
file_api_greeting_greeting_proto_depIdxs = nil
}

View File

@ -0,0 +1,163 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: api/greeting/greeting.proto
/*
Package greeting is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package greeting
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_GreetingService_Hello_0(ctx context.Context, marshaler runtime.Marshaler, client GreetingServiceClient, 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 {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Hello(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_GreetingService_Hello_0(ctx context.Context, marshaler runtime.Marshaler, server GreetingServiceServer, 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 {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Hello(ctx, &protoReq)
return msg, metadata, err
}
// RegisterGreetingServiceHandlerServer registers the http handlers for service GreetingService to "mux".
// UnaryRPC :call GreetingServiceServer 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 RegisterGreetingServiceHandlerFromEndpoint instead.
func RegisterGreetingServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server GreetingServiceServer) error {
mux.Handle("POST", pattern_GreetingService_Hello_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, "/GreetingService.GreetingService/Hello", runtime.WithHTTPPathPattern("/GreetingService.GreetingService/Hello"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_GreetingService_Hello_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_GreetingService_Hello_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterGreetingServiceHandlerFromEndpoint is same as RegisterGreetingServiceHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterGreetingServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.DialContext(ctx, endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterGreetingServiceHandler(ctx, mux, conn)
}
// RegisterGreetingServiceHandler registers the http handlers for service GreetingService to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterGreetingServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterGreetingServiceHandlerClient(ctx, mux, NewGreetingServiceClient(conn))
}
// RegisterGreetingServiceHandlerClient registers the http handlers for service GreetingService
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "GreetingServiceClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "GreetingServiceClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "GreetingServiceClient" to call the correct interceptors.
func RegisterGreetingServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client GreetingServiceClient) error {
mux.Handle("POST", pattern_GreetingService_Hello_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, "/GreetingService.GreetingService/Hello", runtime.WithHTTPPathPattern("/GreetingService.GreetingService/Hello"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_GreetingService_Hello_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_GreetingService_Hello_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_GreetingService_Hello_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"GreetingService.GreetingService", "Hello"}, ""))
)
var (
forward_GreetingService_Hello_0 = runtime.ForwardResponseMessage
)

View File

@ -0,0 +1,19 @@
syntax = "proto3";
package GreetingService;
option go_package = "leafdev.top/GreetingService/proto/greeting";
import "google/api/annotations.proto";
service GreetingService {
rpc Hello(HelloRequest) returns (HelloResponse);
}
message HelloRequest {
}
message HelloResponse {
string hello = 1;
}

View 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/greeting/greeting.proto
package greeting
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
// GreetingServiceClient is the client API for GreetingService 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 GreetingServiceClient interface {
Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error)
}
type greetingServiceClient struct {
cc grpc.ClientConnInterface
}
func NewGreetingServiceClient(cc grpc.ClientConnInterface) GreetingServiceClient {
return &greetingServiceClient{cc}
}
func (c *greetingServiceClient) Hello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloResponse, error) {
out := new(HelloResponse)
err := c.cc.Invoke(ctx, "/GreetingService.GreetingService/Hello", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// GreetingServiceServer is the server API for GreetingService service.
// All implementations must embed UnimplementedGreetingServiceServer
// for forward compatibility
type GreetingServiceServer interface {
Hello(context.Context, *HelloRequest) (*HelloResponse, error)
mustEmbedUnimplementedGreetingServiceServer()
}
// UnimplementedGreetingServiceServer must be embedded to have forward compatible implementations.
type UnimplementedGreetingServiceServer struct {
}
func (UnimplementedGreetingServiceServer) Hello(context.Context, *HelloRequest) (*HelloResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Hello not implemented")
}
func (UnimplementedGreetingServiceServer) mustEmbedUnimplementedGreetingServiceServer() {}
// UnsafeGreetingServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to GreetingServiceServer will
// result in compilation errors.
type UnsafeGreetingServiceServer interface {
mustEmbedUnimplementedGreetingServiceServer()
}
func RegisterGreetingServiceServer(s grpc.ServiceRegistrar, srv GreetingServiceServer) {
s.RegisterService(&GreetingService_ServiceDesc, srv)
}
func _GreetingService_Hello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(HelloRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(GreetingServiceServer).Hello(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/GreetingService.GreetingService/Hello",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GreetingServiceServer).Hello(ctx, req.(*HelloRequest))
}
return interceptor(ctx, in, info, handler)
}
// GreetingService_ServiceDesc is the grpc.ServiceDesc for GreetingService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var GreetingService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "GreetingService.GreetingService",
HandlerType: (*GreetingServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Hello",
Handler: _GreetingService_Hello_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "api/greeting/greeting.proto",
}

31
api/greeting/greeting_grpc_web_pb.d.ts vendored Normal file
View File

@ -0,0 +1,31 @@
import * as grpcWeb from 'grpc-web';
import * as api_greeting_greeting_pb from '../../api/greeting/greeting_pb'; // proto import: "api/greeting/greeting.proto"
export class GreetingServiceClient {
constructor (hostname: string,
credentials?: null | { [index: string]: string; },
options?: null | { [index: string]: any; });
hello(
request: api_greeting_greeting_pb.HelloRequest,
metadata: grpcWeb.Metadata | undefined,
callback: (err: grpcWeb.RpcError,
response: api_greeting_greeting_pb.HelloResponse) => void
): grpcWeb.ClientReadableStream<api_greeting_greeting_pb.HelloResponse>;
}
export class GreetingServicePromiseClient {
constructor (hostname: string,
credentials?: null | { [index: string]: string; },
options?: null | { [index: string]: any; });
hello(
request: api_greeting_greeting_pb.HelloRequest,
metadata?: grpcWeb.Metadata
): Promise<api_greeting_greeting_pb.HelloResponse>;
}

View File

@ -0,0 +1,141 @@
/**
* @fileoverview gRPC-Web generated client stub for GreetingService
* @enhanceable
* @public
*/
// Code generated by protoc-gen-grpc-web. DO NOT EDIT.
// versions:
// protoc-gen-grpc-web v1.5.0
// protoc v0.0.0
// source: api/greeting/greeting.proto
/* eslint-disable */
// @ts-nocheck
const grpc = {};
grpc.web = require('grpc-web');
var google_api_annotations_pb = require('../../google/api/annotations_pb.js')
const proto = {};
proto.GreetingService = require('./greeting_pb.js');
/**
* @param {string} hostname
* @param {?Object} credentials
* @param {?grpc.web.ClientOptions} options
* @constructor
* @struct
* @final
*/
proto.GreetingService.GreetingServiceClient =
function(hostname, credentials, options) {
if (!options) options = {};
options.format = 'binary';
/**
* @private @const {!grpc.web.GrpcWebClientBase} The client
*/
this.client_ = new grpc.web.GrpcWebClientBase(options);
/**
* @private @const {string} The hostname
*/
this.hostname_ = hostname.replace(/\/+$/, '');
};
/**
* @param {string} hostname
* @param {?Object} credentials
* @param {?grpc.web.ClientOptions} options
* @constructor
* @struct
* @final
*/
proto.GreetingService.GreetingServicePromiseClient =
function(hostname, credentials, options) {
if (!options) options = {};
options.format = 'binary';
/**
* @private @const {!grpc.web.GrpcWebClientBase} The client
*/
this.client_ = new grpc.web.GrpcWebClientBase(options);
/**
* @private @const {string} The hostname
*/
this.hostname_ = hostname.replace(/\/+$/, '');
};
/**
* @const
* @type {!grpc.web.MethodDescriptor<
* !proto.GreetingService.HelloRequest,
* !proto.GreetingService.HelloResponse>}
*/
const methodDescriptor_GreetingService_Hello = new grpc.web.MethodDescriptor(
'/GreetingService.GreetingService/Hello',
grpc.web.MethodType.UNARY,
proto.GreetingService.HelloRequest,
proto.GreetingService.HelloResponse,
/**
* @param {!proto.GreetingService.HelloRequest} request
* @return {!Uint8Array}
*/
function(request) {
return request.serializeBinary();
},
proto.GreetingService.HelloResponse.deserializeBinary
);
/**
* @param {!proto.GreetingService.HelloRequest} request The
* request proto
* @param {?Object<string, string>} metadata User defined
* call metadata
* @param {function(?grpc.web.RpcError, ?proto.GreetingService.HelloResponse)}
* callback The callback function(error, response)
* @return {!grpc.web.ClientReadableStream<!proto.GreetingService.HelloResponse>|undefined}
* The XHR Node Readable Stream
*/
proto.GreetingService.GreetingServiceClient.prototype.hello =
function(request, metadata, callback) {
return this.client_.rpcCall(this.hostname_ +
'/GreetingService.GreetingService/Hello',
request,
metadata || {},
methodDescriptor_GreetingService_Hello,
callback);
};
/**
* @param {!proto.GreetingService.HelloRequest} request The
* request proto
* @param {?Object<string, string>=} metadata User defined
* call metadata
* @return {!Promise<!proto.GreetingService.HelloResponse>}
* Promise that resolves to the response
*/
proto.GreetingService.GreetingServicePromiseClient.prototype.hello =
function(request, metadata) {
return this.client_.unaryCall(this.hostname_ +
'/GreetingService.GreetingService/Hello',
request,
metadata || {},
methodDescriptor_GreetingService_Hello);
};
module.exports = proto.GreetingService;

37
api/greeting/greeting_pb.d.ts vendored Normal file
View File

@ -0,0 +1,37 @@
import * as jspb from 'google-protobuf'
import * as google_api_annotations_pb from '../../google/api/annotations_pb'; // proto import: "google/api/annotations.proto"
export class HelloRequest extends jspb.Message {
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): HelloRequest.AsObject;
static toObject(includeInstance: boolean, msg: HelloRequest): HelloRequest.AsObject;
static serializeBinaryToWriter(message: HelloRequest, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): HelloRequest;
static deserializeBinaryFromReader(message: HelloRequest, reader: jspb.BinaryReader): HelloRequest;
}
export namespace HelloRequest {
export type AsObject = {
}
}
export class HelloResponse extends jspb.Message {
getHello(): string;
setHello(value: string): HelloResponse;
serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): HelloResponse.AsObject;
static toObject(includeInstance: boolean, msg: HelloResponse): HelloResponse.AsObject;
static serializeBinaryToWriter(message: HelloResponse, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): HelloResponse;
static deserializeBinaryFromReader(message: HelloResponse, reader: jspb.BinaryReader): HelloResponse;
}
export namespace HelloResponse {
export type AsObject = {
hello: string,
}
}

21
buf.gen.yaml Normal file
View File

@ -0,0 +1,21 @@
version: v2
plugins:
- local: protoc-gen-go
out: .
opt: paths=source_relative
- local: protoc-gen-go-grpc
out: .
opt: paths=source_relative
- remote: buf.build/grpc/web
out: .
opt: import_style=commonjs+dts,mode=grpcweb
- remote: buf.build/grpc-ecosystem/gateway:v2.19.1
out: .
opt:
- paths=source_relative
- generate_unbound_methods=true
- remote: buf.build/grpc-ecosystem/openapiv2:v2.19.1
out: proto/spider
opt:
- allow_merge
- merge_file_name=mce-spider

6
buf.lock Normal file
View File

@ -0,0 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v2
deps:
- name: buf.build/googleapis/googleapis
commit: f0e53af8f2fc4556b94f482688b57223
digest: b5:24e758f963ee1bb3b5218eb452e0bdfb7a5449d9a77d174b8284b6368ccc1884213689381cdcd79e4231796c281c128ac1ae50825237b1774deb542bdc704b32

12
buf.yaml Normal file
View File

@ -0,0 +1,12 @@
version: v2
deps:
- buf.build/googleapis/googleapis
lint:
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT

View File

@ -0,0 +1,11 @@
-- +goose Up
-- create "users" table
CREATE TABLE "users" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "name" character varying NOT NULL, "created_at" timestamptz NOT NULL, "updated_at" timestamptz NOT NULL, PRIMARY KEY ("id"));
-- create index "user_name" to table: "users"
CREATE INDEX "user_name" ON "users" ("name");
-- +goose Down
-- reverse: create index "user_name" to table: "users"
DROP INDEX "user_name";
-- reverse: create "users" table
DROP TABLE "users";

View File

@ -0,0 +1,2 @@
h1:YlnxO6ydgS11asUeu8kbF9g5KzRdpwb7SKaTU7GNM4E=
20240714103412_init.sql h1:RFiLRFHMFEtEBzjW5z9aHC3s26Jee2gkdGg4YVh7Rh8=

View File

@ -0,0 +1,57 @@
{
"swagger": "2.0",
"info": {
"title": "api/greeting/greeting.proto",
"version": "version not set"
},
"tags": [
{
"name": "GreetingService"
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {},
"definitions": {
"GreetingServiceHelloResponse": {
"type": "object",
"properties": {
"hello": {
"type": "string"
}
}
},
"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"
}
}
}
}
}
}