🚚 Rename protobuf

This commit is contained in:
2024-10-21 22:07:36 +08:00
parent 80ad9399a3
commit 87a7eb8f45
31 changed files with 502 additions and 414 deletions

1
pkg/internal/auth/jwt.go Normal file
View File

@ -0,0 +1 @@
package auth

View File

@ -12,7 +12,7 @@ import (
)
type CommandRpcServer struct {
proto.UnimplementedCommandControllerServer
proto.UnimplementedCommandProviderServer
}
func (c CommandRpcServer) AddCommand(ctx context.Context, info *proto.CommandInfo) (*proto.AddCommandResponse, error) {
@ -66,7 +66,7 @@ func (c CommandRpcServer) SendCommand(ctx context.Context, argument *proto.Comma
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()
out, err := proto.NewCommandControllerClient(conn).SendCommand(ctx, argument)
out, err := proto.NewCommandProviderClient(conn).SendCommand(ctx, argument)
if err != nil {
return &proto.CommandReturn{
IsDelivered: true,
@ -99,7 +99,7 @@ func (c CommandRpcServer) SendStreamCommand(g grpc.BidiStreamingServer[proto.Com
conn, err := handler.GetGrpcConn()
ctx, cancel := context.WithTimeout(g.Context(), time.Second*10)
out, err := proto.NewCommandControllerClient(conn).SendCommand(ctx, pck)
out, err := proto.NewCommandProviderClient(conn).SendCommand(ctx, pck)
cancel()
if err != nil {

View File

@ -69,7 +69,7 @@ func BroadcastEvent(event string, data any) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, _ = proto.NewServiceDirectoryClient(conn).BroadcastEvent(ctx, &proto.EventInfo{
_, _ = proto.NewDirectoryServiceClient(conn).BroadcastEvent(ctx, &proto.EventInfo{
Event: event,
Data: nex.EncodeMap(data),
})

View File

@ -12,7 +12,7 @@ import (
)
type ServiceRpcServer struct {
proto.UnimplementedServiceDirectoryServer
proto.UnimplementedDirectoryServiceServer
}
func instantiationService(in *ServiceInstance) *proto.ServiceInfo {

View File

@ -15,8 +15,8 @@ import (
)
type Server struct {
proto.UnimplementedDatabaseControllerServer
proto.UnimplementedStreamControllerServer
proto.UnimplementedDatabaseServiceServer
proto.UnimplementedStreamServiceServer
health.UnimplementedHealthServer
srv *grpc.Server
@ -27,10 +27,10 @@ func NewServer() *Server {
srv: grpc.NewServer(),
}
proto.RegisterServiceDirectoryServer(server.srv, &directory2.ServiceRpcServer{})
proto.RegisterCommandControllerServer(server.srv, &directory2.CommandRpcServer{})
proto.RegisterDatabaseControllerServer(server.srv, server)
proto.RegisterStreamControllerServer(server.srv, server)
proto.RegisterDirectoryServiceServer(server.srv, &directory2.ServiceRpcServer{})
proto.RegisterCommandProviderServer(server.srv, &directory2.CommandRpcServer{})
proto.RegisterDatabaseServiceServer(server.srv, server)
proto.RegisterStreamServiceServer(server.srv, server)
health.RegisterHealthServer(server.srv, server)
reflection.Register(server.srv)

View File

@ -52,7 +52,7 @@ func invokeCommand(c *fiber.Ctx) error {
ctx, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()
out, err := proto.NewCommandControllerClient(conn).SendCommand(ctx, &proto.CommandArgument{
out, err := proto.NewCommandProviderClient(conn).SendCommand(ctx, &proto.CommandArgument{
Command: command,
Method: method,
Payload: c.Body(),

View File

@ -60,7 +60,7 @@ func Listen(c *websocket.Conn) {
continue
}
sc := proto.NewStreamControllerClient(pc)
sc := proto.NewStreamServiceClient(pc)
_, err = sc.EmitStreamEvent(context.Background(), &proto.StreamEventRequest{
Event: packet.Action,
UserId: uint64(user.ID),

19
pkg/internal/kv/etcd.go Normal file
View File

@ -0,0 +1,19 @@
package kv
import (
clientv3 "go.etcd.io/etcd/client/v3"
"time"
)
var Kv *clientv3.Client
func ConnectEtcd(endpoints []string) error {
conn, err := clientv3.New(clientv3.Config{
Endpoints: endpoints,
DialTimeout: 10 * time.Second,
})
if err == nil {
Kv = conn
}
return err
}