I am batman

This commit is contained in:
2026-06-20 11:07:01 -04:00
commit 013d01358c
52 changed files with 7615 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
FROM golang:1.24-alpine AS build
RUN apk add --no-cache git ca-certificates protobuf-dev
WORKDIR /app
# use repo-level go.mod so modules are resolvable
COPY go.mod go.sum ./
RUN go mod download
# install Go protoc plugins
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# copy service sources and proto files
COPY services/post-service ./services/post-service
COPY proto ./proto
# generate proto files
RUN mkdir -p proto/auth proto/user proto/post && \
export PATH=/go/bin:$PATH && \
protoc --go_out=proto --go_opt=paths=source_relative \
--go-grpc_out=proto --go-grpc_opt=paths=source_relative \
--proto_path=proto \
proto/auth.proto proto/user.proto proto/post.proto && \
ls -la proto/auth/ proto/user/ proto/post/
# build static binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/post-service ./services/post-service/cmd
FROM alpine:3.20
RUN apk add --no-cache ca-certificates
COPY --from=build /usr/local/bin/post-service /usr/local/bin/post-service
EXPOSE 50053
ENTRYPOINT ["/usr/local/bin/post-service"]

View File

@@ -0,0 +1,40 @@
package main
import (
"fmt"
pb "go-microservices/proto/post"
"go-microservices/services/post-service/internal/database"
"go-microservices/services/post-service/internal/repository"
"go-microservices/services/post-service/internal/server"
"log"
"net"
"os"
"google.golang.org/grpc"
)
func main() {
fmt.Println("Starting Post Service...")
port := os.Getenv("PORT")
if port == "" {
port = "50053"
}
lis, err := net.Listen("tcp", ":"+port)
if err != nil {
log.Fatalf("Failed to listen: %v", err)
}
db, err := database.Init()
if err != nil {
log.Fatalf("failed to init database: %v", err)
}
repo := repository.NewRepository(db)
grpcServer := grpc.NewServer()
pb.RegisterPostServiceServer(grpcServer, server.NewPostServer(repo))
log.Printf("Post Service listening on %s", port)
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("Failed to serve: %v", err)
}
}

View File

@@ -0,0 +1 @@
This is the configuration file for the Post Service microservice.

View File

@@ -0,0 +1,22 @@
package config
import (
"os"
"strconv"
)
type Env struct {
Port int
JWTSecret string
TokenDuration int
DatabaseURL string
RedisAddr string
RedisPassword string
RedisDB int
EmailHost string
EmailPort int
EmailUsername string
EmailPassword string
EmailFrom string
FrontendURL string
}

View File

@@ -0,0 +1,22 @@
package database
import (
"os"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
func Init() (*gorm.DB, error) {
dsn := os.Getenv("DATABASE_URL")
if dsn == "" {
dsn = "host=localhost user=postgres password=postgres dbname=postgres port=5432 sslmode=disable TimeZone=UTC"
}
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
return nil, err
}
return db, nil
}

View File

@@ -0,0 +1,7 @@
package models
// TODO: Add database models for post service
// Example models:
// - Post model for blog posts
// - Comment model for post comments
// - Category model for post categorization

View File

@@ -0,0 +1,7 @@
package repository
// TODO: Add database repository implementations
// Example repositories:
// - PostRepository for post data access
// - CommentRepository for comment management
// - CategoryRepository for category management

View File

@@ -0,0 +1,13 @@
package repository
import (
"gorm.io/gorm"
)
type Repository struct {
DB *gorm.DB
}
func NewRepository(db *gorm.DB) *Repository {
return &Repository{DB: db}
}

View File

@@ -0,0 +1,47 @@
package server
import (
"context"
pb "go-microservices/proto/post"
"go-microservices/services/post-service/internal/repository"
"google.golang.org/protobuf/types/known/emptypb"
)
type PostServer struct {
pb.UnimplementedPostServiceServer
repo *repository.Repository
}
func NewPostServer(repo *repository.Repository) *PostServer {
return &PostServer{repo: repo}
}
func (s *PostServer) CreatePost(ctx context.Context, req *pb.CreatePostRequest) (*pb.CreatePostResponse, error) {
// TODO: Implement create post logic
post := &pb.Post{Id: "1", AuthorId: req.AuthorId, Title: req.Title, Content: req.Content, CreatedAt: 0, UpdatedAt: 0}
return &pb.CreatePostResponse{Post: post}, nil
}
func (s *PostServer) GetPost(ctx context.Context, req *pb.GetPostRequest) (*pb.GetPostResponse, error) {
// TODO: Implement get post logic
post := &pb.Post{Id: req.Id, AuthorId: "author", Title: "title", Content: "content", CreatedAt: 0, UpdatedAt: 0}
return &pb.GetPostResponse{Post: post}, nil
}
func (s *PostServer) UpdatePost(ctx context.Context, req *pb.UpdatePostRequest) (*pb.UpdatePostResponse, error) {
// TODO: Implement update post logic
post := &pb.Post{Id: req.Id, AuthorId: "author", Title: req.Title, Content: req.Content, CreatedAt: 0, UpdatedAt: 0}
return &pb.UpdatePostResponse{Post: post}, nil
}
func (s *PostServer) DeletePost(ctx context.Context, req *pb.DeletePostRequest) (*emptypb.Empty, error) {
// TODO: Implement delete post logic
return &emptypb.Empty{}, nil
}
func (s *PostServer) ListPosts(ctx context.Context, req *pb.ListPostsRequest) (*pb.ListPostsResponse, error) {
// TODO: Implement list posts logic
posts := []*pb.Post{}
return &pb.ListPostsResponse{Posts: posts}, nil
}