-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from go-park-mail-ru/dev
РК3
- Loading branch information
Showing
134 changed files
with
83,806 additions
and
4,468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
go.mod | ||
2024-2-Zdes-budet-nazvanie-UykwHnIE.crt | ||
data/ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
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/dblogger" | ||
"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() | ||
|
||
wrappedDB := dblogger.NewDB(db, logger) | ||
|
||
reviewsRepo := reviewRepo.NewReviewRepository(wrappedDB) | ||
reviewUsecase := reviewUsecase.NewReviewsUsecase(reviewsRepo) | ||
placeRepo := placeRepo.NewPLaceRepository(wrappedDB) | ||
placeUsecase := placeUsecase.NewPlaceUsecase(placeRepo) | ||
citiesRepo := citiesRepo.NewCitiesRepository(wrappedDB) | ||
citiesUsecase := citiesUsecase.NewCitiesUsecase(citiesRepo) | ||
categoriesRepo := categoriesRepo.NewCategoriesRepo(wrappedDB) | ||
categoriesUsecase := categoriesUsecase.NewCategoriesUsecase(categoriesRepo) | ||
searchRepo := searchRepo.NewSearchRepository(wrappedDB) | ||
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) | ||
} |
Oops, something went wrong.