Skip to content

Commit

Permalink
Merge pull request #53 from go-park-mail-ru/develop
Browse files Browse the repository at this point in the history
rk4
  • Loading branch information
K0STYAa authored Dec 22, 2024
2 parents dded2de + fab72e5 commit 5a72114
Show file tree
Hide file tree
Showing 3,057 changed files with 6,749 additions and 1,041,227 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
100 changes: 100 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: BogoSort_2024_2 Deploy

on:
push:
branches: [main, develop, 'TP-*']
pull_request:
branches: [main]

jobs:
run-linters:
name: run-linters
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Check out code into directory
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: 1.23
id: go

- name: Cache Go modules
uses: actions/cache@v2
with:
path: /path/to/your/cache
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install required dependencies
run: go mod tidy

- name: Run linter
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: .
args: -c ./.golangci.yaml

run-tests:
name: run-tests
needs: run-linters
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: Cache Go modules
uses: actions/cache@v2
with:
path: /path/to/your/cache
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get Dependencies
run: go get ./...

- name: Build Application
run: go build ./...

- name: Run Tests
run: |
go test -json ./... -coverprofile coverprofile_.tmp -coverpkg=./... ; \
grep -v -e '/mocks' -e 'mock_repository.go' -e 'mock.go' -e 'docs.go' -e '_easyjson.go' -e '.pb.go' -e 'gen.go' -e '/cmd/' -e '/config/' -e '/pkg/connector/' coverprofile_.tmp > coverprofile.tmp ; \
rm coverprofile_.tmp ; \
go tool cover -html coverprofile.tmp -o ../heatmap.html; \
go tool cover -func coverprofile.tmp
deploy:
name: deploy to server
if: github.ref == 'refs/heads/main'
needs: [run-linters, run-tests]
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Deploy to Server
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
debug: true
script: |
cd /home/${{ secrets.USERNAME }}/2024_2_BogoSort
git checkout develop
git fetch && git pull
sudo docker-compose build
sudo docker-compose down
sudo docker-compose up -d --build --remove-orphans
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ go.work.sum

.DS_Store

dump.rdb
app

.idea/

.vscode/

# SSL certificates
db/certs/*.crt
db/certs/*.key
110 changes: 8 additions & 102 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,114 +1,20 @@
linters:
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- cyclop
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forcetypeassert
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godox
- goerr113
- goheader
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosimple
- gosmopolitan
- govet
- grouper
- importas
- ineffassign
- interfacebloat
- ireturn
- lll
- loggercheck
- maintidx
- makezero
- mirror
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- nolintlint
- nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- testableexamples
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
- wsl
- zerologlint

disable:
- varcheck
- exhaustivestruct
- exhaustruct
- maligned
- scopelint
- interfacer
- structcheck
- nosnakecase
- golint
- deadcode
- ifshort
- depguard
- wrapcheck
- varnamelen
- testpackage
- tagliatelle
- noctx
- gochecknoglobals
- gofmt
- gci
- paralleltest
- gocyclo
- goconst
- gofumpt
- gosec
- goimports
- funlen


- misspell

linters-settings:
cyclop:
max-complexity: 12
run:
build-tags:
- wireinject
tests: false
timeout: 5m
31 changes: 0 additions & 31 deletions .vscode/launch.json

This file was deleted.

Binary file removed app
Binary file not shown.
38 changes: 32 additions & 6 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ func main() {
if err != nil {
panic(err)
}
defer logger.Sync()
defer func() {
if err := logger.Sync(); err != nil {
logger.Error("Error syncing logger", zap.Error(err))
}
}()

zap.ReplaceGlobals(logger)

Expand Down Expand Up @@ -70,6 +74,8 @@ func main() {
AllowedOrigins: []string{
"http://5.188.141.136:8008",
"http://localhost:8008",
"http://emporium-bs.ru",
"http://bs-emporium.ru",
},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
AllowedHeaders: []string{"Content-Type", "Authorization", "X-CSRF-Token"},
Expand Down Expand Up @@ -109,7 +115,7 @@ func main() {
}

func Init(cfg config.Config) (*mux.Router, error) {
var logger = zap.L()
logger := zap.L()

router := mux.NewRouter()
router.Use(recoveryMiddleware)
Expand All @@ -125,7 +131,7 @@ func Init(cfg config.Config) (*mux.Router, error) {

authRouter := router.PathPrefix("").Subrouter()

dbPool, err := connector.GetPostgresConnector(cfg.GetConnectURL())
dbPool, err := connector.GetPostgresConnector(cfg.GetConnectURL(), int32(cfg.GetPGMaxConns()))
if err != nil {
zap.L().Error("Failed to connect to Postgres", zap.Error(err))
return nil, errors.Wrap(err, "failed to connect to Postgres")
Expand Down Expand Up @@ -158,15 +164,26 @@ func Init(cfg config.Config) (*mux.Router, error) {
if err != nil {
return nil, handleRepoError(err, "unable to create seller repository")
}
historyRepo, err := postgres.NewHistoryRepository(dbPool, ctx, cfg.PGTimeout)
if err != nil {
return nil, handleRepoError(err, "unable to create history repository")
}
csrfToken, err := utils.NewAesCryptHashToken(zap.L())
if err != nil {
return nil, handleRepoError(err, "unable to create csrf token")
}
paymentRepo, err := postgres.NewPaymentRepository(dbPool, ctx, cfg.PGTimeout)
if err != nil {
return nil, handleRepoError(err, "unable to create payment repository")
}
promotionRepo, err := postgres.NewPromotionRepository(dbPool, ctx, cfg.PGTimeout)
if err != nil {
return nil, handleRepoError(err, "unable to create promotion repository")
}
authGrpcClient, err := auth.NewGrpcClient(config.GetAuthAddress())
if err != nil {
return nil, handleRepoError(err, "unable to create grpc client")
}

cartPurchaseClient, err := cart_purchase.NewCartPurchaseClient(config.GetCartPurchaseAddress())
if err != nil {
return nil, handleRepoError(err, "unable to create cart purchase client")
Expand All @@ -176,10 +193,12 @@ func Init(cfg config.Config) (*mux.Router, error) {
return nil, handleRepoError(err, "unable to create static client")
}

advertsUseCase := service.NewAdvertService(advertsRepo, sellerRepo, userRepo)
advertsUseCase := service.NewAdvertService(advertsRepo, sellerRepo, userRepo, historyRepo)
paymentUC := service.NewPaymentService(cfg.PaymentShopID, cfg.PaymentSecret, paymentRepo, advertsRepo, promotionRepo)
categoryUseCase := service.NewCategoryService(categoryRepo)
userUC := service.NewUserService(userRepo, sellerRepo)
sessionUC := service.NewAuthService(sessionRepo)
promotionUC := service.NewPromotionService(promotionRepo)
sessionManager := utils.NewSessionManager(authGrpcClient, int(cfg.Session.ExpirationTime.Seconds()), cfg.Session.SecureCookie, logger)
router.Use(middleware.NewAuthMiddleware(sessionManager).AuthMiddleware)

Expand All @@ -191,7 +210,9 @@ func Init(cfg config.Config) (*mux.Router, error) {
cartHandler := http3.NewCartEndpoint(cartPurchaseClient)
categoryHandler := http3.NewCategoryEndpoint(categoryUseCase)
staticHandler := http3.NewStaticEndpoint(*staticClient)

historyHandler := http3.NewHistoryEndpoint(historyRepo)
paymentHandler := http3.NewPaymentEndpoint(paymentUC, sessionManager)
promotionHandler := http3.NewPromotionEndpoint(promotionUC)
csrfEndpoints := http3.NewCSRFEndpoint(csrfToken, sessionManager)
csrfEndpoints.Configure(router)
userHandler.ConfigureUnprotectedRoutes(router)
Expand All @@ -201,15 +222,20 @@ func Init(cfg config.Config) (*mux.Router, error) {

advertsHandler.ConfigureProtectedRoutes(authRouter)
categoryHandler.ConfigureRoutes(authRouter)
paymentHandler.ConfigureProtectedRoutes(authRouter)
promotionHandler.ConfigureRoutes(authRouter)
authHandler.Configure(authRouter)
userHandler.ConfigureProtectedRoutes(authRouter)
sellerHandler.Configure(authRouter)
cartHandler.Configure(authRouter)
purchaseHandler.ConfigureRoutes(authRouter)
staticHandler.ConfigureRoutes(router)
historyHandler.ConfigureRoutes(authRouter)
router.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
router.PathPrefix("/api/v1/metrics").Handler(promhttp.Handler())

go paymentUC.PaymentProcessor(ctx)

return router, nil
}

Expand Down
Loading

0 comments on commit 5a72114

Please sign in to comment.