init post-service

This commit is contained in:
2023-09-27 16:17:47 +01:00
parent e0bd8ef953
commit 0341a938fd
31 changed files with 5666 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
package main
import (
"context"
"github.com/rs/zerolog"
"github.com/hexolan/panels/post-service/internal"
"github.com/hexolan/panels/post-service/internal/postgres"
"github.com/hexolan/panels/post-service/internal/redis"
"github.com/hexolan/panels/post-service/internal/kafka"
"github.com/hexolan/panels/post-service/internal/kafka/producer"
"github.com/hexolan/panels/post-service/internal/rpc"
"github.com/hexolan/panels/post-service/internal/service"
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
// Load the configuration
cfg := internal.NewConfig()
zerolog.SetGlobalLevel(cfg.GetLogLevel())
// Create the interface dependencies
ctx := context.Background()
db := postgres.NewPostgresInterface(ctx, cfg)
rdb := redis.NewRedisInterface(ctx, cfg)
events := producer.NewPostEventProducer(cfg)
// Create the repositories and services
dbRepo := postgres.NewPostRepository(db)
cacheRepo := redis.NewPostRepository(rdb, dbRepo)
service := service.NewPostService(events, cacheRepo)
// Start the event consumers
eventConsumers := kafka.NewEventConsumers(cfg, dbRepo, events)
eventConsumers.Start()
// Create and serve RPC
rpcServer := rpc.NewRPCServer(service)
rpcServer.Serve()
}

View File

@@ -0,0 +1,12 @@
//go:build tools
package main
import (
// Protobuf Generation
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
// DB Migrations
_ "github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
)