yats.git

ref: 34e888df1bac1f38c5783c2fa746819f2d10853f

server/grpc/yats-grpc-server.go


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
 * Yats - yats
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Paolo Lulli <kevwe.com>
 * @copyright Paolo Lulli 2024
 */

package grpc

import (
	"google.golang.org/grpc"
	"log"
	"net"
	"yats-server/proto"
)

type server struct {
	proto.UnimplementedYatsGrpcServiceServer
}

func RunYatsGrpcServer(address string) {
	lis, err := net.Listen("tcp", address)
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	s := grpc.NewServer()
	proto.RegisterYatsGrpcServiceServer(s, &server{})
	log.Printf("Server is running on port %s\n", address)
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}