Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

microservices added #45

Merged
merged 41 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4d58183
added grpc to delivery for trips
mevain Nov 17, 2024
631b890
microservices added
timurIsaevIY Nov 21, 2024
bc14748
changed main
mevain Nov 21, 2024
b9aeab2
added trips grpc
mevain Nov 21, 2024
d9bab01
attractions service fixed
timurIsaevIY Nov 22, 2024
fbcdfee
userService
AnnHarvard Nov 21, 2024
fb666d0
gRPC for users
AnnHarvard Nov 22, 2024
bb09bd4
fixing
AnnHarvard Nov 22, 2024
72eb9d9
added auth routes
AnnHarvard Nov 22, 2024
d17c765
services fixed
timurIsaevIY Nov 22, 2024
e5d363b
returned token in cookie
AnnHarvard Nov 22, 2024
87bc563
fixed login and search
mevain Nov 23, 2024
e3a29c8
scheme changed
timurIsaevIY Nov 23, 2024
b00809d
made structure for survey's microservice
AnnHarvard Nov 23, 2024
6414574
fixed names
AnnHarvard Nov 23, 2024
7e7470f
added image path to searh response
mevain Nov 23, 2024
c24a329
fix
AnnHarvard Nov 23, 2024
132e421
fixed getPlace
mevain Nov 23, 2024
1e92184
proto added
timurIsaevIY Nov 23, 2024
38f4472
Merge remote-tracking branch 'origin/gRPC_places' into gRPC_places
timurIsaevIY Nov 23, 2024
1d5087e
http handler for surveys
AnnHarvard Nov 23, 2024
aad18ca
made http handlers for surveys
AnnHarvard Nov 23, 2024
a2de459
grpc server added
timurIsaevIY Nov 23, 2024
e2426ae
started repo
mevain Nov 23, 2024
076fbb6
started usecase for surveys
AnnHarvard Nov 23, 2024
755403e
finished repo
mevain Nov 23, 2024
99c07c0
made usecase for surveys
AnnHarvard Nov 23, 2024
6e0349e
grpc server added
timurIsaevIY Nov 23, 2024
dc98722
SCHEME BD CHANGE
timurIsaevIY Nov 23, 2024
b799ac4
SCHEME BD CHANGE
timurIsaevIY Nov 23, 2024
58d7b39
SCHEME BD CHANGE
timurIsaevIY Nov 23, 2024
19b6ebd
fixed mistakes with error handling
AnnHarvard Nov 23, 2024
5bb15b3
ne znay
timurIsaevIY Nov 23, 2024
2db430f
ne znay
timurIsaevIY Nov 23, 2024
6c09e5d
ne znay
timurIsaevIY Nov 23, 2024
58704d5
ne znay
timurIsaevIY Nov 23, 2024
300f54d
fixed authorization
mevain Nov 24, 2024
b3d2e89
fixed trip queries
mevain Nov 24, 2024
d30eaf8
added field description to db
AnnHarvard Nov 23, 2024
0481bc5
added global search to microservices
AnnHarvard Nov 24, 2024
f819b4b
fixed deleting review
AnnHarvard Nov 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions build/attraction.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.23.1-alpine AS builder
COPY . /github.com/go-park-mail-ru/2024_2_ThereWillBeName/attractions
WORKDIR /github.com/go-park-mail-ru/2024_2_ThereWillBeName/attractions
RUN go mod download
RUN go clean --modcache
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o ./.bin ./cmd/attractions/main.go
FROM scratch AS runner
WORKDIR /build
COPY --from=builder /github.com/go-park-mail-ru/2024_2_ThereWillBeName/attractions/.bin .
EXPOSE 8081
ENTRYPOINT ["./.bin"]
11 changes: 11 additions & 0 deletions build/gateway.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.23.1-alpine AS builder
COPY . /github.com/go-park-mail-ru/2024_2_ThereWillBeName/gateway
WORKDIR /github.com/go-park-mail-ru/2024_2_ThereWillBeName/gateway
RUN go mod download
RUN go clean --modcache
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o ./.bin ./cmd/gateway/main.go
FROM scratch AS runner
WORKDIR /build
COPY --from=builder /github.com/go-park-mail-ru/2024_2_ThereWillBeName/gateway/.bin .
EXPOSE 8080
ENTRYPOINT ["./.bin"]
11 changes: 11 additions & 0 deletions build/survey.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.23.1-alpine AS builder
COPY . /github.com/go-park-mail-ru/2024_2_ThereWillBeName/survey
WORKDIR /github.com/go-park-mail-ru/2024_2_ThereWillBeName/survey
RUN go mod download
RUN go clean --modcache
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o ./.bin ./cmd/survey/main.go
FROM scratch AS runner
WORKDIR /build
COPY --from=builder /github.com/go-park-mail-ru/2024_2_ThereWillBeName/survey/.bin .
EXPOSE 50054
ENTRYPOINT ["./.bin"]
11 changes: 11 additions & 0 deletions build/trips.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.23.1-alpine AS builder
COPY . /github.com/go-park-mail-ru/2024_2_ThereWillBeName/trips
WORKDIR /github.com/go-park-mail-ru/2024_2_ThereWillBeName/trips
RUN go mod download
RUN go clean --modcache
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o ./.bin ./cmd/trips/main.go
FROM scratch AS runner
WORKDIR /build
COPY --from=builder /github.com/go-park-mail-ru/2024_2_ThereWillBeName/trips/.bin .
EXPOSE 50053
ENTRYPOINT ["./.bin"]
11 changes: 11 additions & 0 deletions build/users.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.23.1-alpine AS builder
COPY . /github.com/go-park-mail-ru/2024_2_ThereWillBeName/users
WORKDIR /github.com/go-park-mail-ru/2024_2_ThereWillBeName/users
RUN go mod download
RUN go clean --modcache
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -o ./.bin ./cmd/users/main.go
FROM scratch AS runner
WORKDIR /build
COPY --from=builder /github.com/go-park-mail-ru/2024_2_ThereWillBeName/users/.bin .
EXPOSE 50052
ENTRYPOINT ["./.bin"]
122 changes: 122 additions & 0 deletions cmd/attractions/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package main

import (
"2024_2_ThereWillBeName/internal/models"
grpcAttractions "2024_2_ThereWillBeName/internal/pkg/attractions/delivery/grpc"
genPlaces "2024_2_ThereWillBeName/internal/pkg/attractions/delivery/grpc/gen"
placeRepo "2024_2_ThereWillBeName/internal/pkg/attractions/repo"
placeUsecase "2024_2_ThereWillBeName/internal/pkg/attractions/usecase"
grpcCategories "2024_2_ThereWillBeName/internal/pkg/categories/delivery/grpc"
genCategories "2024_2_ThereWillBeName/internal/pkg/categories/delivery/grpc/gen"
categoriesRepo "2024_2_ThereWillBeName/internal/pkg/categories/repo"
categoriesUsecase "2024_2_ThereWillBeName/internal/pkg/categories/usecase"
grpcCities "2024_2_ThereWillBeName/internal/pkg/cities/delivery/grpc"
genCities "2024_2_ThereWillBeName/internal/pkg/cities/delivery/grpc/gen"
citiesRepo "2024_2_ThereWillBeName/internal/pkg/cities/repo"
citiesUsecase "2024_2_ThereWillBeName/internal/pkg/cities/usecase"
"2024_2_ThereWillBeName/internal/pkg/logger"
grpcReviews "2024_2_ThereWillBeName/internal/pkg/reviews/delivery/grpc"
genReviews "2024_2_ThereWillBeName/internal/pkg/reviews/delivery/grpc/gen"
reviewRepo "2024_2_ThereWillBeName/internal/pkg/reviews/repo"
reviewUsecase "2024_2_ThereWillBeName/internal/pkg/reviews/usecase"
grpcSearch "2024_2_ThereWillBeName/internal/pkg/search/delivery/grpc"
genSearch "2024_2_ThereWillBeName/internal/pkg/search/delivery/grpc/gen"
searchRepo "2024_2_ThereWillBeName/internal/pkg/search/repo"
searchUsecase "2024_2_ThereWillBeName/internal/pkg/search/usecase"
"database/sql"
"flag"
"log"
"log/slog"
"net"
"os"
"os/signal"
"strconv"
"syscall"

_ "github.com/lib/pq"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)

func main() {
var cfg models.ConfigGrpc
flag.IntVar(&cfg.Port, "grpc-port", 50051, "gRPC server port")
flag.StringVar(&cfg.ConnStr, "connStr", "host=tripdb port=5432 user=service password=test dbname=trip sslmode=disable", "PostgreSQL connection string")
flag.Parse()

logger := setupLogger()

db, err := sql.Open("postgres", cfg.ConnStr)
if err != nil {
log.Fatalf("failed to connect to database: %v", err)
}
defer db.Close()

reviewsRepo := reviewRepo.NewReviewRepository(db)
reviewUsecase := reviewUsecase.NewReviewsUsecase(reviewsRepo)
placeRepo := placeRepo.NewPLaceRepository(db)
placeUsecase := placeUsecase.NewPlaceUsecase(placeRepo)
citiesRepo := citiesRepo.NewCitiesRepository(db)
citiesUsecase := citiesUsecase.NewCitiesUsecase(citiesRepo)
categoriesRepo := categoriesRepo.NewCategoriesRepo(db)
categoriesUsecase := categoriesUsecase.NewCategoriesUsecase(categoriesRepo)
searchRepo := searchRepo.NewSearchRepository(db)
searchUsecase := searchUsecase.NewSearchUsecase(searchRepo)

grpcAttractionsServer := grpc.NewServer()

attractionsHandler := grpcAttractions.NewGrpcAttractionsHandler(placeUsecase)
genPlaces.RegisterAttractionsServer(grpcAttractionsServer, attractionsHandler)

citiesHandler := grpcCities.NewGrpcCitiesHandler(citiesUsecase)
genCities.RegisterCitiesServer(grpcAttractionsServer, citiesHandler)

reviewsHandler := grpcReviews.NewGrpcReviewsHandler(reviewUsecase)
genReviews.RegisterReviewsServer(grpcAttractionsServer, reviewsHandler)

categoriesHandler := grpcCategories.NewGrpcCategoriesHandler(categoriesUsecase)
genCategories.RegisterCategoriesServer(grpcAttractionsServer, categoriesHandler)

searchHandler := grpcSearch.NewGrpcSearchHandler(searchUsecase, logger)
genSearch.RegisterSearchServer(grpcAttractionsServer, searchHandler)

reflection.Register(grpcAttractionsServer)

go func() {
listener, err := net.Listen("tcp", ":8081")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
log.Printf("gRPC server listening on :%d", cfg.Port)
if err := grpcAttractionsServer.Serve(listener); err != nil {
log.Fatalf("failed to serve gRPC: %v", err)
}
}()

stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-stop

log.Println("Shutting down gRPC server...")
grpcAttractionsServer.GracefulStop()
log.Println("gRPC server gracefully stopped")
}

func setupLogger() *slog.Logger {

levelEnv := os.Getenv("LOG_LEVEL")
logLevel := slog.LevelDebug
if level, err := strconv.Atoi(levelEnv); err == nil {
logLevel = slog.Level(level)
}

opts := logger.PrettyHandlerOptions{
SlogOpts: slog.HandlerOptions{
Level: logLevel,
},
}

handler := logger.NewPrettyHandler(os.Stdout, opts)

return slog.New(handler)
}
Loading
Loading