Skip to content

Commit

Permalink
Merge pull request #42 from go-park-mail-ru/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bqback authored Nov 27, 2024
2 parents 8f0c073 + fde166d commit 17f7af1
Show file tree
Hide file tree
Showing 81 changed files with 9,596 additions and 665 deletions.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
*.tmp

# Dependency directories (remove the comment below to include it)
# vendor/
Expand Down Expand Up @@ -42,5 +43,13 @@ api/docs.go
configs/conf.yaml
configs/conf.yml
db/migrations/tern.conf
configs/redis.windows.conf
configs/redis.conf

# redis stuff
*.rdb
*redis.log


# html
index.html
*.html
42 changes: 35 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
# define executable
EXECUTABLE=uArt.exe
EXECUTABLE=uArt

# source dir
SRC_DIR=./cmd/app

# flags for compilation
BUILD_FLAGS=

.PHONY: api
# domain dirs in internal/pkg
DOMAINS=applicant cvs employer portfolio session vacancies file_loading

all: build



.PHONY: mock-gen api

all: install build

build:
go build $(BUILD_FLAGS) -o $(EXECUTABLE) $(SRC_DIR)

install:
go mod tidy

tests:
go test ./... -coverprofile cover.out && go tool cover -func cover.out
go tool cover -html cover.out -o index.html
go test ./... -coverprofile=coverage.out.tmp
cat coverage.out.tmp | grep -v -E 'mock|pb.go' > coverage.out
go tool cover -func=coverage.out
go tool cover -html=coverage.out -o index.html

clean:
go clean
Expand All @@ -25,8 +36,25 @@ lint:
revive -config reviveconfig.toml -formatter friendly ./...

api:
swag init --generalInfo ./cmd/app/main.go --output api/
swag init --parseInternal --pd --dir cmd/myapp/,delivery/handler/ --output api/
node ./api/server.js

mock-gen:
@echo "Generating mocks..."
@for domain in $(DOMAINS); do \
echo "Generating mocks for domain: $$domain"; \
rm -rf internal/pkg/$$domain/mock; \
mockgen -source=internal/pkg/$$domain/$$domain.go \
-destination=internal/pkg/$$domain/mock/$$domain.go \
-package=mock; \
done
@echo "OK!"

redis-start:
redis-server .\configs\redis.conf

auth-microservice:
go run ./cmd/auth/main.go

run:
go run $(SRC_DIR)/main.go
go run $(SRC_DIR)/main.go
59 changes: 45 additions & 14 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,41 @@
package main

import (
"log"
"net/http"

"github.com/go-park-mail-ru/2024_2_VKatuny/internal"
"github.com/go-park-mail-ru/2024_2_VKatuny/internal/configs"
"github.com/go-park-mail-ru/2024_2_VKatuny/internal/logger"
"github.com/go-park-mail-ru/2024_2_VKatuny/internal/middleware"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

applicant_repository "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/applicant/repository"
applicantUsecase "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/applicant/usecase"
cvRepository "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/cvs/repository"
cvUsecase "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/cvs/usecase"
"github.com/go-park-mail-ru/2024_2_VKatuny/internal/utils"

//"github.com/go-park-mail-ru/2024_2_VKatuny/internal/mux"
employer_repository "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/employer/repository"
employerUsecase "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/employer/usecase"
file_loading_repository "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/file_loading/repository"
file_loading_usecase "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/file_loading/usecase"
portfolioRepository "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/portfolio/repository"
portfolioUsecase "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/portfolio/usecase"
session_repository "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/session/repository"
session_usecase "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/session/usecase"

vacanciesUsecase "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/vacancies/usecase"

grpc_auth "github.com/go-park-mail-ru/2024_2_VKatuny/microservices/auth/gen"

"github.com/go-park-mail-ru/2024_2_VKatuny/internal/mux"

_ "github.com/jackc/pgx/v5/stdlib"

cvUsecase "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/cvs/usecase"
vacancies_repository "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/vacancies/repository"
compressmicroservice "github.com/go-park-mail-ru/2024_2_VKatuny/microservices/compress/generated"

employerUsecase "github.com/go-park-mail-ru/2024_2_VKatuny/internal/pkg/employer/usecase"
)

// @title μArt's API
Expand All @@ -43,38 +50,62 @@ import (
// @host 127.0.0.1:8080
// @BasePath /api/v1
func main() {
conf, _ := configs.ReadConfig("./configs/conf.yml")
conf := configs.ReadConfig("./configs/conf.yml")
logger := logger.NewLogrusLogger()

dbConnection, err := utils.GetDBConnection(conf.DataBase.GetDSN())
if err != nil {
logger.Fatal(err.Error())
}
defer dbConnection.Close()
sessionApplicantRepository, sessionEmployerRepository := session_repository.NewSessionStorage(dbConnection)

connAuthGRPC, err := grpc.NewClient(
conf.AuthMicroservice.Server.GetAddress(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
log.Fatalf("cant connect to grpc")
}
defer connAuthGRPC.Close()
logger.Infof("gRPC client started at %s", conf.AuthMicroservice.Server.GetAddress())

connCompressGRPC, err := grpc.NewClient(
conf.CompressMicroservice.Server.GetAddress(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
log.Fatalf("cant connect to grpc")
}
defer connAuthGRPC.Close()
logger.Infof("Compress gRPC client started at %s", conf.CompressMicroservice.Server.GetAddress())


repositories := &internal.Repositories{
ApplicantRepository: applicant_repository.NewApplicantStorage(dbConnection),
PortfolioRepository: portfolioRepository.NewPortfolioStorage(dbConnection),
CVRepository: cvRepository.NewCVStorage(dbConnection),
VacanciesRepository: vacancies_repository.NewVacanciesStorage(dbConnection),
EmployerRepository: employer_repository.NewEmployerStorage(dbConnection),
SessionApplicantRepository: sessionApplicantRepository,
SessionEmployerRepository: sessionEmployerRepository,
FileLoadingRepository: file_loading_repository.NewFileLoadingStorage(conf.Server.Front),
FileLoadingRepository: file_loading_repository.NewFileLoadingStorage(conf.Server.MediaDir),
}
microservices := &internal.Microservices{
Auth: grpc_auth.NewAuthorizationClient(connAuthGRPC),
Compress: compressmicroservice.NewCompressServiceClient(connCompressGRPC),
}
usecases := &internal.Usecases{
ApplicantUsecase: applicantUsecase.NewApplicantUsecase(logger, repositories),
PortfolioUsecase: portfolioUsecase.NewPortfolioUsecase(logger, repositories),
CVUsecase: cvUsecase.NewCVsUsecase(logger, repositories),
VacanciesUsecase: vacanciesUsecase.NewVacanciesUsecase(logger, repositories),
EmployerUsecase: employerUsecase.NewEmployerUsecase(logger, repositories),
SessionUsecase: session_usecase.NewSessionUsecase(logger, repositories),
FileLoadingUsecase: file_loading_usecase.NewFileLoadingUsecase(logger, repositories),
FileLoadingUsecase: file_loading_usecase.NewFileLoadingUsecase(logger, repositories, microservices, conf),
}

app := &internal.App{
Logger: logger,
Repositories: repositories,
Usecases: usecases,
Logger: logger,
Repositories: repositories,
Usecases: usecases,
Microservices: microservices,
}

Mux := mux.Init(app)
Expand Down
50 changes: 50 additions & 0 deletions cmd/auth/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"net"

"github.com/go-park-mail-ru/2024_2_VKatuny/internal/configs"
"github.com/go-park-mail-ru/2024_2_VKatuny/internal/logger"
"github.com/go-park-mail-ru/2024_2_VKatuny/internal/utils"
"github.com/go-park-mail-ru/2024_2_VKatuny/microservices/auth"
grpc_auth "github.com/go-park-mail-ru/2024_2_VKatuny/microservices/auth/gen"
"github.com/gomodule/redigo/redis"
"google.golang.org/grpc"

_ "github.com/jackc/pgx/v5/stdlib"
)

func main() {
conf := configs.ReadConfig("./configs/conf.yml")
logger := logger.NewLogrusLogger()

pgSQLConn, err := utils.GetDBConnection(conf.DataBase.GetDSN())
if err != nil {
logger.Fatal(err.Error())
}
logger.Info("Successfully connected to postgres")
defer pgSQLConn.Close()

redisConn, err := redis.Dial("tcp", conf.AuthMicroservice.Database.GetDSN())
if err != nil {
logger.Fatal(err.Error())
}
defer redisConn.Close()

if _, err := redisConn.Do("AUTH", conf.AuthMicroservice.Database.Password); err != nil {
logger.Fatal(err.Error())
}
logger.Info("Successfully connected to redis")

lister, err := net.Listen("tcp", conf.AuthMicroservice.Server.GetAddress())
if err != nil {
logger.Fatalf("failed to listen port: %s", err)
}

server := grpc.NewServer()

grpc_auth.RegisterAuthorizationServer(server, auth.NewAuthorization(pgSQLConn, redisConn, logger))

logger.Infof("Starting gRPC server on %s", conf.AuthMicroservice.Server.GetAddress())
server.Serve(lister)
}
32 changes: 32 additions & 0 deletions cmd/compress_microservice/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"log"
"net"

"github.com/go-park-mail-ru/2024_2_VKatuny/internal/configs"
"github.com/go-park-mail-ru/2024_2_VKatuny/internal/logger"
compressdelivery "github.com/go-park-mail-ru/2024_2_VKatuny/microservices/compress/compress/delivery"
compressrepository "github.com/go-park-mail-ru/2024_2_VKatuny/microservices/compress/compress/repository"
compressusecase "github.com/go-park-mail-ru/2024_2_VKatuny/microservices/compress/compress/usecase"
compress_api "github.com/go-park-mail-ru/2024_2_VKatuny/microservices/compress/generated"

"google.golang.org/grpc"
)

func main() {
conf := configs.ReadConfig("./configs/conf.yml")
logger := logger.NewLogrusLogger()

lis, err := net.Listen("tcp", conf.CompressMicroservice.Server.GetAddress())
if err != nil {
log.Fatalln("can't listen port", err)
}
repository := compressrepository.NewCompressRepository(conf.CompressMicroservice.CompressedMediaDir, logger)
usecase := compressusecase.NewCompressUsecase(repository, logger)
server := grpc.NewServer()
compress_api.RegisterCompressServiceServer(server, compressdelivery.NewCompressManager(usecase, logger))

logger.Infof("Compress starting server at %s", conf.CompressMicroservice.Server.GetAddress())
server.Serve(lis)
}
34 changes: 25 additions & 9 deletions configs/example-conf.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
# configurations

server:
scheme: "http"
host: "0.0.0.0"
port: 8080
frontURI: "http://172.28.166.156:8080/"
mediadir: "media/"
host: "192.168.77.130"
port: 8090
frontURI: "http://192.168.77.130:8000"
mediadir: "media/UnCompressed/"


database:
host: "127.0.0.1"
port: 8008
host: "192.168.77.130"
port: 5432
user: "postgres"
password: "most_secure_password"
password: "passIMO"
schema: "public"
db_name: "postgres"
ssl_mode: "disable"
# conn_timeout: 60s

auth_microservice:
server:
scheme: "http"
host: "192.168.77.130"
port: 8091
database:
host: "192.168.77.130"
port: 6379
password: "passIMO"

compress_microservice:
server:
scheme: "http"
host: "192.168.77.130"
port: 8071
CompressedMediaDir: "media/Compressed/"
26 changes: 26 additions & 0 deletions configs/example-redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
port 6379

# задать хост
bind 127.0.0.1

# в винде не работает
# protected-mode yes

# задать пароль
requirepass "pass"

# maxmemory 32mb

loglevel notice
logfile "redis.log"

save 900 1
save 300 10
save 60 10000

maxclients 10000

timeout 0

echo "bind 0.0.0.0" > /usr/local/etc/redis/redis.conf &&
echo "requirepass $REDIS_PASSWORD" >> /usr/local/etc/redis/redis.conf
Loading

0 comments on commit 17f7af1

Please sign in to comment.