Grpc hello service implementation

This commit is contained in:
Alexander
2026-05-04 14:56:05 +02:00
parent 6baa895c6c
commit 268ee57913
14 changed files with 186 additions and 5 deletions
+23
View File
@@ -2,15 +2,19 @@ package main
import (
"flag"
"net"
"os"
"github.com/gin-gonic/gin"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"google.golang.org/grpc"
"gopkg.in/yaml.v2"
pb "homelab.lan/music-agregator/gen/music_agregator/hello/v1"
// My modules
"homelab.lan/music-agregator/internal/config"
"homelab.lan/music-agregator/internal/hello"
appRouter "homelab.lan/music-agregator/internal/router"
)
@@ -27,6 +31,14 @@ func main() {
}
log.Info().Interface("config", cfg).Msg("Loaded config")
// start the grpc in another thread to not block the next http start
go serveGrpc()
serveHttp()
}
func serveHttp() {
router := gin.Default()
appRouter.SetupRoutes(router)
router.GET("/ping", func(c *gin.Context) {
@@ -35,7 +47,18 @@ func main() {
})
})
router.Run()
}
func serveGrpc() {
var opts []grpc.ServerOption
server := grpc.NewServer(opts...)
helloServiceHandler := hello.NewHelloServer()
pb.RegisterHelloServiceServer(server, helloServiceHandler)
listener, err := net.Listen("tcp", "localhost:8081")
if err != nil {
log.Fatal().Err(err).Msg("Failed to listen on localhost:8081")
}
server.Serve(listener)
}
func parseConfig(path *string) (config.Config, error) {