Grpc hello service implementation
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user