From e6a2d9b3ea91ca8c7f2961aedc323b260f6c3bcc Mon Sep 17 00:00:00 2001 From: Denis Korovin Date: Thu, 21 Dec 2023 15:51:53 +0300 Subject: [PATCH 1/2] pprof --- .gitignore | 4 +++- internal/port/http/server/server.go | 5 +++-- profiles/base.pprof | Bin 0 -> 16154 bytes profiles/pprof diff.log | 25 +++++++++++++++++++++++++ profiles/result.pprof | Bin 0 -> 16154 bytes 5 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 profiles/base.pprof create mode 100644 profiles/pprof diff.log create mode 100644 profiles/result.pprof diff --git a/.gitignore b/.gitignore index eaf10bc..6494a0b 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,6 @@ # Go workspace file go.work -.vscode \ No newline at end of file +.vscode + +heap \ No newline at end of file diff --git a/internal/port/http/server/server.go b/internal/port/http/server/server.go index e967e52..6ca0fd9 100644 --- a/internal/port/http/server/server.go +++ b/internal/port/http/server/server.go @@ -10,7 +10,8 @@ import ( "github.com/gin-contrib/gzip" "github.com/gin-gonic/gin" - //"github.com/gin-contrib/pprof" + + "github.com/gin-contrib/pprof" ) type handler interface { @@ -75,7 +76,7 @@ func Run(ctx context.Context, config config, handler handler, middleware middlew } // add pprof - //pprof.Register(router) + pprof.Register(router) // server settings srv := &http.Server{ diff --git a/profiles/base.pprof b/profiles/base.pprof new file mode 100644 index 0000000000000000000000000000000000000000..a7461cd6ee96df3bbba4fc569ca7f38784afefac GIT binary patch literal 16154 zcmb_i33yc1_4kHs1PGU5d+d+>CCHmMZ?a6{1|%#20x^q-L~t_ml8j7d#+gYVcKOG( zE@;7htys}2pvA3FMU8viH*DQaD^{(xmAWCV_5VBf%_Q$lhNYkKeaxHlyXT&B?z!il zbMBkuW#%%Tk(Ze}fM?<}OMK7fnU0}(IV@v9W>$8NBl9TybBxN%&mEXIXz-Byp+osF z$M6veT*~9QBS)nhnUObQv@~YyxbYJvPO{F+&iHPRa@0{{vvV`0t}gDFo;N%<9UFV& zK2MUZTX9Uw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zhnN-*qmK**Vy(-(ZH7KbVBV&tsL`R16a@7-;;#tEA@!$J>G^h8A0F!r`EUr9hkWQp z{o%S`c%43~&jmE>#H)0%$e}i7B+(HR`$T9tvMOMcMHQe_)n)}k)RCY~Y6==j z6DL@XjBS$I5J78J^CN0(kC0Es9YUc#{-A@k?IFGHM>NKCGVH0hs668Gg4<)%+k(~| zty>F{-Wfp^8LK+b5*1BoOrLXPRi?ij+}Q)7pIGuE*;Pe%je+8ibm&7bOlO&|joy3U z4?qyocvB#_;hVvUG>im+nPd85yf-~Z!#>*7iAZL~`UrAdDDGX4*rh;2i!SauXo@Wb z!N!RyDfkW}1L_QYvTdeKM?#7|(#}$03fJ>Zm|hQ&QPvERn2=z=N|L^AQKB~)Zf6j~sbCE$){|~UZK?6bsKf5Gw&)2t7>!_*bSJhpxrfWmd8wV`A-6(5 z`N!P|VWjDQ*}ibP8PRztQ0oG1kzk;?({>HFc{i5ephenVm>nXp+Po1nxLo?`A9qdS zj|iikYbd~k-)$|Gw<#Jhg0nlkF&rbj>}xaPoe`t&HDjB%CEyd5{V#ThU<^G%T%+tEMb%7 literal 0 HcmV?d00001 diff --git a/profiles/pprof diff.log b/profiles/pprof diff.log new file mode 100644 index 0000000..d9b1925 --- /dev/null +++ b/profiles/pprof diff.log @@ -0,0 +1,25 @@ +go tool pprof -top -diff_base=.\profiles\base.pprof .\profiles\result.pprof + +File: main.exe +Type: inuse_space +Time: Dec 21, 2023 at 1:46pm (MSK) +Showing nodes accounting for 4.02MB, 100% of 4.02MB total + flat flat% sum% cum cum% + 1.01MB 25.13% 25.13% 1.01MB 25.13% github.com/go-playground/validator/v10.map.init.1 + 1.01MB 25.13% 50.26% 1.01MB 25.13% regexp/syntax.(*compiler).inst (inline) + 1MB 24.87% 75.13% 1MB 24.87% regexp/syntax.(*parser).newRegexp (inline) + 1MB 24.87% 100% 1MB 24.87% github.com/gabriel-vasile/mimetype/internal/magic.init + 0 0% 100% 2.02MB 50.26% github.com/go-playground/validator/v10.init + 0 0% 100% 1MB 24.87% github.com/go-playground/validator/v10.init.0 + 0 0% 100% 2.01MB 50.00% regexp.Compile (inline) + 0 0% 100% 2.01MB 50.00% regexp.MustCompile + 0 0% 100% 2.01MB 50.00% regexp.compile + 0 0% 100% 1.01MB 25.13% regexp/syntax.(*compiler).compile + 0 0% 100% 1.01MB 25.13% regexp/syntax.(*compiler).rune + 0 0% 100% 1MB 24.87% regexp/syntax.(*parser).literal + 0 0% 100% 1.01MB 25.13% regexp/syntax.Compile + 0 0% 100% 1MB 24.87% regexp/syntax.Parse (inline) + 0 0% 100% 1MB 24.87% regexp/syntax.parse + 0 0% 100% 4.02MB 100% runtime.doInit (inline) + 0 0% 100% 4.02MB 100% runtime.doInit1 + 0 0% 100% 4.02MB 100% runtime.main \ No newline at end of file diff --git a/profiles/result.pprof b/profiles/result.pprof new file mode 100644 index 0000000000000000000000000000000000000000..a7461cd6ee96df3bbba4fc569ca7f38784afefac GIT binary patch literal 16154 zcmb_i33yc1_4kHs1PGU5d+d+>CCHmMZ?a6{1|%#20x^q-L~t_ml8j7d#+gYVcKOG( zE@;7htys}2pvA3FMU8viH*DQaD^{(xmAWCV_5VBf%_Q$lhNYkKeaxHlyXT&B?z!il zbMBkuW#%%Tk(Ze}fM?<}OMK7fnU0}(IV@v9W>$8NBl9TybBxN%&mEXIXz-Byp+osF z$M6veT*~9QBS)nhnUObQv@~YyxbYJvPO{F+&iHPRa@0{{vvV`0t}gDFo;N%<9UFV& zK2MUZTX9Uw8!k_t(qEc;C0Lg^2 zj&o$EIA>(ufLwx8oB=ZsH)#eY<_$jnggJd-md&m?dvULsbKvX|bLUl5&R?)_QPtul zORJYHuQ{={u0GYs@p*X-C#^Vn)7;X!DnKH|l!RL&jtQjibkesLgSpzP zTV?uh#$^M%o*8UQH!vn|KnVEY*SE3_U9$Np?2yJfa5lTTZXY0Z_3Rm>7bHg;5Q z2C#Rw|MB}tI6QCNiKjA9%L6_Dc=wG0-~3N{DucAaz%zkAe~rM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joy3U z4?qyocvB#_;hVvUG>im+nPd85yf-~Z!#>*7iAZL~`UrAdDDGX4*rh;2i!SauXo@Wb z!N!RyDfkW}1L_QYvTdeKM?#7|(#}$03fJ>Zm|hQ&QPvERn2=z=N|L^AQKB~)Zf6j~sbCE$){|~UZK?6bsKf5Gw&)2t7>!_*bSJhpxrfWmd8wV`A-6(5 z`N!P|VWjDQ*}ibP8PRztQ0oG1kzk;?({>HFc{i5ephenVm>nXp+Po1nxLo?`A9qdS zj|iikYbd~k-)$|Gw<#Jhg0nlkF&rbj>}xaPoe`t&HDjB%CEyd5{V#ThU<^G%T%+tEMb%7 literal 0 HcmV?d00001 From 137393ceb3fde9d58e32714b2e353c9f44fa8864 Mon Sep 17 00:00:00 2001 From: korovindenis Date: Sat, 23 Dec 2023 13:45:41 +0300 Subject: [PATCH 2/2] godoc --- .gitignore | 4 +++- Makefile | 2 +- cmd/gophermart/main.go | 6 ++++++ internal/adapters/accrual/accrual.go | 5 +++++ internal/adapters/auth/auth.go | 1 + internal/adapters/config/config.go | 1 + internal/adapters/ctxinfo/ctxinfo.go | 1 + internal/adapters/logger/logger.go | 1 + internal/adapters/storage/postgresql/init.go | 1 + internal/domain/entity/balance.go | 2 ++ internal/domain/entity/doc.go | 2 ++ internal/domain/entity/errors.go | 19 +++++++------------ internal/domain/entity/order.go | 2 ++ internal/domain/entity/user.go | 1 + internal/domain/usecases/doc.go | 2 ++ internal/port/http/handler/auth.go | 2 ++ internal/port/http/handler/balance.go | 1 + internal/port/http/handler/doc.go | 2 ++ .../handler/{auth_test.go => example_test.go} | 8 ++++++++ internal/port/http/handler/order.go | 2 ++ internal/port/http/handler/withdrawals.go | 1 + internal/port/http/server/server.go | 5 +++++ 22 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 internal/domain/entity/doc.go create mode 100644 internal/domain/usecases/doc.go create mode 100644 internal/port/http/handler/doc.go rename internal/port/http/handler/{auth_test.go => example_test.go} (96%) diff --git a/.gitignore b/.gitignore index 6494a0b..12e62ab 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ go.work .vscode -heap \ No newline at end of file +heap + +pgadmindata \ No newline at end of file diff --git a/Makefile b/Makefile index 855bffb..c3f0642 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ gotest: go test `go list ./... | grep -v test` -count 1 gotestcover: - go test -covermode=count -coverprofile=coverage.out $(shell go list ./... | egrep -v '(/test|/test/mock)$$') + go test -covermode=count -coverprofile=coverage.out $(shell go list ./... | egrep -v '(/test|/test/mock)$$') && go tool cover -func cover.out get: @echo " > Checking dependencies" diff --git a/cmd/gophermart/main.go b/cmd/gophermart/main.go index bf63213..f21286a 100644 --- a/cmd/gophermart/main.go +++ b/cmd/gophermart/main.go @@ -1,3 +1,5 @@ +// Main module +// Dependencies are initialized, and the HTTP server is started. package main import ( @@ -17,8 +19,12 @@ import ( "go.uber.org/zap" ) +// Return code for const ( + // a successful exit from the application ExitSucces = iota + + // an unsuccessful exit from the application ExitWithError ) diff --git a/internal/adapters/accrual/accrual.go b/internal/adapters/accrual/accrual.go index bad1378..7e85faa 100644 --- a/internal/adapters/accrual/accrual.go +++ b/internal/adapters/accrual/accrual.go @@ -11,13 +11,17 @@ import ( "github.com/korovindenis/go-market/internal/domain/entity" ) +// max goroutine const maxWorker = 10 +// get/set for BD type storage interface { GetAllNotProcessedOrders(ctx context.Context) ([]entity.Order, error) SetOrderStatusAndAccrual(ctx context.Context, order entity.Order) error } + +// configuration type config interface { GetAccrualAddress() string } @@ -27,6 +31,7 @@ type Accrual struct { config } +// response data type accrualRespose struct { Number string `json:"order"` Status string `json:"status"` diff --git a/internal/adapters/auth/auth.go b/internal/adapters/auth/auth.go index ee787b4..8c5b729 100644 --- a/internal/adapters/auth/auth.go +++ b/internal/adapters/auth/auth.go @@ -19,6 +19,7 @@ type Auth struct { config } +// info in jwt token type claims struct { entity.User jwt.RegisteredClaims diff --git a/internal/adapters/config/config.go b/internal/adapters/config/config.go index a056772..aa1bb41 100644 --- a/internal/adapters/config/config.go +++ b/internal/adapters/config/config.go @@ -15,6 +15,7 @@ import ( const configDefaultPath = "./configs/config.dev.yaml" +// data in configDefaultPath type config struct { App `koanf:"app"` Httpserver `koanf:"http_server"` diff --git a/internal/adapters/ctxinfo/ctxinfo.go b/internal/adapters/ctxinfo/ctxinfo.go index 75f5e49..579aa05 100644 --- a/internal/adapters/ctxinfo/ctxinfo.go +++ b/internal/adapters/ctxinfo/ctxinfo.go @@ -1,3 +1,4 @@ +// Work with context package ctxinfo import ( diff --git a/internal/adapters/logger/logger.go b/internal/adapters/logger/logger.go index a7d2fbc..e1e7fd0 100644 --- a/internal/adapters/logger/logger.go +++ b/internal/adapters/logger/logger.go @@ -1,3 +1,4 @@ +// log data package logger import ( diff --git a/internal/adapters/storage/postgresql/init.go b/internal/adapters/storage/postgresql/init.go index 8bb94b7..a3c47cc 100644 --- a/internal/adapters/storage/postgresql/init.go +++ b/internal/adapters/storage/postgresql/init.go @@ -1,3 +1,4 @@ +// work with db package postgresql import ( diff --git a/internal/domain/entity/balance.go b/internal/domain/entity/balance.go index 77fe556..fe26b93 100644 --- a/internal/domain/entity/balance.go +++ b/internal/domain/entity/balance.go @@ -6,11 +6,13 @@ import ( "github.com/ShiraazMoollatjie/goluhn" ) +// struct for user Balance type Balance struct { Current float64 `json:"current"` Withdrawn float64 `json:"withdrawn"` } +// struct for update user Balance type BalanceUpdate struct { Order string `json:"order"` Sum float64 `json:"sum"` diff --git a/internal/domain/entity/doc.go b/internal/domain/entity/doc.go new file mode 100644 index 0000000..429d1a6 --- /dev/null +++ b/internal/domain/entity/doc.go @@ -0,0 +1,2 @@ +// Domain entities +package entity diff --git a/internal/domain/entity/errors.go b/internal/domain/entity/errors.go index 74c3d5e..1c1a120 100644 --- a/internal/domain/entity/errors.go +++ b/internal/domain/entity/errors.go @@ -2,23 +2,18 @@ package entity import "errors" +// define errors var ( - // ErrMetricNotFound = errors.New("metric not set") - ErrEnvVarNotFound = errors.New("env var not set") - // ErrInvalidURLFormat = errors.New("invalid URL format") - ErrMethodNotAllowed = errors.New("method not allowed") - ErrUnsupportedMediaType = errors.New("unsupported media type") - ErrInternalServerError = errors.New("internal server error") - // ErrInputVarIsWrongType = errors.New("metric value is wrong type") + ErrEnvVarNotFound = errors.New("env var not set") + ErrMethodNotAllowed = errors.New("method not allowed") + ErrUnsupportedMediaType = errors.New("unsupported media type") + ErrInternalServerError = errors.New("internal server error") ErrStatusBadRequest = errors.New("bad request") ErrUserLoginNotUnique = errors.New("login not unique") ErrUserLoginUnauthorized = errors.New("user unauthorized") ErrUnprocessableEntity = errors.New("unprocessable entity") ErrOrderAlreadyUploadedAnotherUser = errors.New("order already uploaded another user") ErrOrderAlreadyUploaded = errors.New("order already uploaded") - // ErrInvalidGzipData = errors.New("invalid gzip data") - // ErrReadingRequestBody = errors.New("error reading request body") - ErrNoContent = errors.New("no content") - // ErrNotImplementedServerError = errors.New("not implemented server error") - ErrInsufficientBalance = errors.New("insufficient balance") + ErrNoContent = errors.New("no content") + ErrInsufficientBalance = errors.New("insufficient balance") ) diff --git a/internal/domain/entity/order.go b/internal/domain/entity/order.go index ce39a81..3b0f639 100644 --- a/internal/domain/entity/order.go +++ b/internal/domain/entity/order.go @@ -6,6 +6,7 @@ import ( "github.com/ShiraazMoollatjie/goluhn" ) +// order status const ( StatusNew = "NEW" StatusRegistered = "REGISTERED" @@ -14,6 +15,7 @@ const ( StatusProcessing = "PROCESSING" ) +// struct for user Order type Order struct { Number string `json:"number"` Status string `json:"Status"` diff --git a/internal/domain/entity/user.go b/internal/domain/entity/user.go index f7567f3..9cf539b 100644 --- a/internal/domain/entity/user.go +++ b/internal/domain/entity/user.go @@ -1,5 +1,6 @@ package entity +// struct for User type User struct { Login string `json:"login" binding:"required"` Password string `json:"password" binding:"required"` diff --git a/internal/domain/usecases/doc.go b/internal/domain/usecases/doc.go new file mode 100644 index 0000000..38724e5 --- /dev/null +++ b/internal/domain/usecases/doc.go @@ -0,0 +1,2 @@ +// Domain usecases +package usecases diff --git a/internal/port/http/handler/auth.go b/internal/port/http/handler/auth.go index 54f24d4..80e9a8f 100644 --- a/internal/port/http/handler/auth.go +++ b/internal/port/http/handler/auth.go @@ -10,6 +10,7 @@ import ( "github.com/korovindenis/go-market/internal/domain/entity" ) +// Used during user registration func (h *Handler) Register(c *gin.Context) { ctx := c.Request.Context() var user entity.User @@ -118,6 +119,7 @@ func (h *Handler) Login(c *gin.Context) { c.Status(http.StatusOK) } +// Used during user authentication func (h *Handler) createCookie(token string) (*http.Cookie, error) { return &http.Cookie{ Name: h.GetTokenName(), diff --git a/internal/port/http/handler/balance.go b/internal/port/http/handler/balance.go index 83ffd9d..309b39b 100644 --- a/internal/port/http/handler/balance.go +++ b/internal/port/http/handler/balance.go @@ -9,6 +9,7 @@ import ( "github.com/korovindenis/go-market/internal/domain/entity" ) +// Displays the user's balance, returned as entity.Balance func (h *Handler) GetBalance(c *gin.Context) { userID, err := h.GetUserIDFromCtx(c) if err != nil { diff --git a/internal/port/http/handler/doc.go b/internal/port/http/handler/doc.go new file mode 100644 index 0000000..cb9a879 --- /dev/null +++ b/internal/port/http/handler/doc.go @@ -0,0 +1,2 @@ +// Module with handlers +package handler diff --git a/internal/port/http/handler/auth_test.go b/internal/port/http/handler/example_test.go similarity index 96% rename from internal/port/http/handler/auth_test.go rename to internal/port/http/handler/example_test.go index ce34335..1c97944 100644 --- a/internal/port/http/handler/auth_test.go +++ b/internal/port/http/handler/example_test.go @@ -22,6 +22,14 @@ type callTimes struct { getUser int } +func Example() { + t := &testing.T{} + + // run test with testify + TestHandler_AuthRegister(t) + TestHandler_AuthLogin(t) +} + func TestHandler_AuthRegister(t *testing.T) { config := mocks.NewConfig(t) usecase := mocks.NewUsecase(t) diff --git a/internal/port/http/handler/order.go b/internal/port/http/handler/order.go index 5dfa17f..b84342a 100644 --- a/internal/port/http/handler/order.go +++ b/internal/port/http/handler/order.go @@ -10,6 +10,7 @@ import ( "github.com/korovindenis/go-market/internal/domain/entity" ) +// Used to add a new order func (h *Handler) SetOrder(c *gin.Context) { ctx := c.Request.Context() @@ -61,6 +62,7 @@ func (h *Handler) SetOrder(c *gin.Context) { c.Status(http.StatusAccepted) } +// Returns a list of all purchases func (h *Handler) GetAllOrders(c *gin.Context) { ctx := c.Request.Context() userID, err := h.GetUserIDFromCtx(c) diff --git a/internal/port/http/handler/withdrawals.go b/internal/port/http/handler/withdrawals.go index fa4dcd3..9a86de9 100644 --- a/internal/port/http/handler/withdrawals.go +++ b/internal/port/http/handler/withdrawals.go @@ -9,6 +9,7 @@ import ( "github.com/korovindenis/go-market/internal/domain/entity" ) +// handler for get Withdrawals func (h *Handler) Withdrawals(c *gin.Context) { ctx := c.Request.Context() userID, err := h.GetUserIDFromCtx(c) diff --git a/internal/port/http/server/server.go b/internal/port/http/server/server.go index 6ca0fd9..c87842f 100644 --- a/internal/port/http/server/server.go +++ b/internal/port/http/server/server.go @@ -1,3 +1,4 @@ +// init api (http server) package server import ( @@ -14,6 +15,7 @@ import ( "github.com/gin-contrib/pprof" ) +// handler for http server type handler interface { Register(c *gin.Context) Login(c *gin.Context) @@ -27,6 +29,7 @@ type handler interface { Withdrawals(c *gin.Context) } +// middleware for http server type middleware interface { CheckMethod() gin.HandlerFunc @@ -37,6 +40,7 @@ type middleware interface { AddUserInfoToCtx() gin.HandlerFunc } +// configuration type config interface { GetServerAddress() string GetServerMode() string @@ -46,6 +50,7 @@ type config interface { GetServerMaxHeaderBytes() int } +// run http server func Run(ctx context.Context, config config, handler handler, middleware middleware) error { // init http gin.SetMode(config.GetServerMode())