Skip to content

Commit

Permalink
<Refactor gRPC address handling in main.go>
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunSu1768 committed Aug 28, 2024
1 parent c6b7063 commit bd1b423
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"fmt"
"google.golang.org/grpc"
"log"
"net"
"otel-trace-reciever/internal/config"

"otel-trace-reciever/internal/repository"
"otel-trace-reciever/internal/server"
"google.golang.org/grpc/reflection"
Expand All @@ -15,7 +15,15 @@ import (
)

func main() {
grpcHost := "0.0.0.0"
grpcPort := 4317
grpcAddress := fmt.Sprintf("%s:%d", grpcHost, grpcPort)

cfg, err := config.Load()
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}

repo, err := repository.NewMongoRepository(cfg.MongoURI)
if err != nil {
log.Fatalf("Failed to create repository: %v", err)
Expand All @@ -29,13 +37,13 @@ func main() {

reflection.Register(grpcServer)

lis, err := net.Listen("tcp", "0.0.0.0:4317")
lis, err := net.Listen("tcp", grpcAddress)
if err != nil {
log.Fatalf("Failed to listen: %v", err)
}

log.Println("gRPC server listening on 0.0.0.0:4317")
log.Printf("gRPC server listening on %s", grpcAddress)
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("Failed to serve: %v", err)
}
}
}

0 comments on commit bd1b423

Please sign in to comment.