-
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 #2 from korovindenis/iter3-orders
Iter3 orders
- Loading branch information
Showing
37 changed files
with
2,718 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: gophermart | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
container: golang:1.19 | ||
|
||
services: | ||
postgres: | ||
image: postgres | ||
env: | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: praktikum | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 5s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Download autotests binaries | ||
uses: robinraju/release-downloader@v1.2 | ||
with: | ||
repository: Yandex-Practicum/go-autotests-bin | ||
latest: true | ||
fileName: "*" | ||
out-file-path: .tools | ||
|
||
- name: Setup autotest binary | ||
run: | | ||
chmod -R +x $GITHUB_WORKSPACE/.tools | ||
mv $GITHUB_WORKSPACE/.tools/gophermarttest /usr/local/bin/gophermarttest | ||
mv $GITHUB_WORKSPACE/.tools/random /usr/local/bin/random | ||
- name: Prepare binaries | ||
run: | | ||
(cd cmd/gophermart && go build -buildvcs=false -o gophermart) | ||
(cd cmd/accrual && chmod +x accrual_linux_amd64) | ||
- name: Test | ||
run: | | ||
gophermarttest \ | ||
-test.v -test.run=^TestGophermart$ \ | ||
-gophermart-binary-path=cmd/gophermart/gophermart \ | ||
-gophermart-host=localhost \ | ||
-gophermart-port=8080 \ | ||
-gophermart-database-uri="postgresql://postgres:postgres@postgres/praktikum?sslmode=disable" \ | ||
-accrual-binary-path=cmd/accrual/accrual_linux_amd64 \ | ||
-accrual-host=localhost \ | ||
-accrual-port=$(random unused-port) \ | ||
-accrual-database-uri="postgresql://postgres:postgres@postgres/praktikum?sslmode=disable" |
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,35 @@ | ||
name: go vet test | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
|
||
jobs: | ||
|
||
statictest: | ||
runs-on: ubuntu-latest | ||
container: golang:1.19 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Download statictest binary | ||
uses: robinraju/release-downloader@v1 | ||
with: | ||
repository: Yandex-Practicum/go-autotests-bin | ||
latest: true | ||
fileName: statictest | ||
out-file-path: .tools | ||
|
||
- name: Setup autotest binary | ||
run: | | ||
chmod -R +x $GITHUB_WORKSPACE/.tools/statictest | ||
mv $GITHUB_WORKSPACE/.tools/statictest /usr/local/bin/statictest | ||
- name: Run statictest | ||
run: | | ||
go vet -vettool=$(which statictest) ./... |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
*.dll | ||
*.so | ||
*.dylib | ||
*.bat | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
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,27 @@ | ||
.PHONY: all | ||
|
||
OS = linux | ||
APP_BUILD_NAME = server | ||
PATH_MAIN_GO = ./cmd/app/main.go | ||
|
||
|
||
all: clean getbuild-server | ||
|
||
build-server: | ||
@echo " > Building server" | ||
@CGO_ENABLED=0 GOOS=$(OS) go build -ldflags "-w" -a -o $(APP_BUILD_NAME) $(PATH_MAIN_GO) | ||
|
||
gotest: | ||
go test `go list ./... | grep -v test` -count 1 | ||
|
||
gotestcover: | ||
go test `go list ./... | grep -v test` -count 1 -cover | ||
|
||
get: | ||
@echo " > Checking dependencies" | ||
@go mod download | ||
@go install $(PATH_MAIN_GO) | ||
|
||
clean: | ||
@echo " > Clearing folder" | ||
@rm -f ./$(APP_BUILD_NAME) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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,87 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/korovindenis/go-market/internal/adapters/accrual" | ||
"github.com/korovindenis/go-market/internal/adapters/auth" | ||
"github.com/korovindenis/go-market/internal/adapters/config" | ||
"github.com/korovindenis/go-market/internal/adapters/logger" | ||
bd "github.com/korovindenis/go-market/internal/adapters/storage/postgresql" | ||
"github.com/korovindenis/go-market/internal/domain/usecases" | ||
"github.com/korovindenis/go-market/internal/port/http/handler" | ||
"github.com/korovindenis/go-market/internal/port/http/middleware" | ||
"github.com/korovindenis/go-market/internal/port/http/server" | ||
"go.uber.org/zap" | ||
) | ||
|
||
const ( | ||
ExitSucces = iota | ||
ExitWithError | ||
) | ||
|
||
func main() { | ||
// init config | ||
config, err := config.New() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// init logger | ||
logger, err := logger.New(config) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// init bd | ||
sqlBd, err := bd.Init(config) | ||
if err != nil { | ||
logger.Fatal("init bd", zap.Error(err)) | ||
} | ||
|
||
// init storage | ||
storage, err := bd.New(sqlBd) | ||
if err != nil { | ||
logger.Fatal("init storage", zap.Error(err)) | ||
} | ||
|
||
// init usecases | ||
usecases, err := usecases.New(config, storage) | ||
if err != nil { | ||
logger.Fatal("init usecases", zap.Error(err)) | ||
} | ||
|
||
// init auth methods | ||
auth, err := auth.New(config) | ||
if err != nil { | ||
logger.Fatal("init auth", zap.Error(err)) | ||
} | ||
|
||
// init handlers | ||
handler, err := handler.New(config, usecases, auth) | ||
if err != nil { | ||
logger.Fatal("init handler", zap.Error(err)) | ||
} | ||
|
||
// init middleware | ||
middleware, err := middleware.New(config, auth) | ||
if err != nil { | ||
logger.Fatal("init middleware", zap.Error(err)) | ||
} | ||
|
||
// cancel the context when main() is terminated | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
// accrual | ||
accrual, err := accrual.New(config, storage) | ||
if err != nil { | ||
logger.Fatal("init accrual", zap.Error(err)) | ||
} | ||
go accrual.Run(ctx) | ||
|
||
if err := server.Run(ctx, config, handler, middleware); err != nil { | ||
logger.Fatal("run web server", zap.Error(err)) | ||
} | ||
} |
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,19 @@ | ||
app: | ||
logs_level: info | ||
secret_key: xxxxxxxx | ||
token_name: gomarket_auth | ||
token_lifetime: 6 | ||
http_server: | ||
mode: debug | ||
address: localhost:8080 | ||
maxHeaderBytes: 16384 | ||
timeouts: | ||
idle: 5 | ||
readHeader: 120 | ||
read: 10 | ||
write: 10 | ||
storage: | ||
connection_string: host=127.0.0.1:5432 user=go password=go dbname=go sslmode=disable | ||
salt: gomarket | ||
accrual: | ||
address: "http://localhost:8082" |
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,30 @@ | ||
-- +goose Up | ||
CREATE TABLE users ( | ||
id BIGSERIAL PRIMARY KEY, | ||
login VARCHAR(50) NOT NULL UNIQUE, | ||
password VARCHAR(255) NOT NULL | ||
); | ||
|
||
CREATE TABLE orders ( | ||
id BIGSERIAL PRIMARY KEY, | ||
number BIGINT NOT NULL UNIQUE, | ||
user_id BIGSERIAL NOT NULL, | ||
sum DECIMAL(10, 2) DEFAULT 0, | ||
accrual DECIMAL(10, 2) DEFAULT 0, | ||
uploaded_at TIMESTAMP DEFAULT current_timestamp, | ||
status VARCHAR(20) NOT NULL CHECK (status IN ('NEW', 'PROCESSING', 'INVALID', 'PROCESSED')), | ||
FOREIGN KEY (user_id) REFERENCES users(id) | ||
); | ||
|
||
CREATE TABLE balances ( | ||
id BIGSERIAL PRIMARY KEY, | ||
user_id INT NOT NULL, | ||
current DECIMAL(10, 2) DEFAULT 0, | ||
withdrawn DECIMAL(10, 2) DEFAULT 0, | ||
FOREIGN KEY (user_id) REFERENCES users(id) | ||
); | ||
|
||
-- +goose Down | ||
DROP TABLE users; | ||
DROP TABLE orders; | ||
DROP TABLE balances; |
Empty file.
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 |
---|---|---|
@@ -1,3 +1,58 @@ | ||
module github.com/korovindenis/go-market | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/knadh/koanf v1.5.0 | ||
golang.org/x/crypto v0.14.0 | ||
) | ||
|
||
require ( | ||
github.com/bytedance/sonic v1.9.1 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.14.0 // indirect | ||
github.com/goccy/go-json v0.10.2 // indirect | ||
github.com/jackc/pgpassfile v1.0.0 // indirect | ||
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect | ||
github.com/leodido/go-urn v1.2.4 // indirect | ||
github.com/mattn/go-isatty v0.0.19 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/stretchr/objx v0.5.0 // indirect | ||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.11 // indirect | ||
go.uber.org/multierr v1.10.0 // indirect | ||
golang.org/x/arch v0.3.0 // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
) | ||
|
||
require ( | ||
github.com/ShiraazMoollatjie/goluhn v0.0.0-20211017190329-0d86158c056a | ||
github.com/fsnotify/fsnotify v1.4.9 // indirect | ||
github.com/gin-contrib/gzip v0.0.6 | ||
github.com/gin-gonic/gin v1.9.1 | ||
github.com/go-resty/resty/v2 v2.10.0 | ||
github.com/golang-jwt/jwt/v5 v5.0.0 | ||
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa | ||
github.com/jackc/pgx/v5 v5.4.3 | ||
github.com/mitchellh/copystructure v1.2.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
github.com/pressly/goose v2.7.0+incompatible | ||
github.com/stretchr/testify v1.8.4 | ||
go.uber.org/zap v1.26.0 | ||
golang.org/x/sys v0.13.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.