Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Многопоточная обработка #14

Merged
merged 25 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4c8f33d
Многопоточная обработка
StainlessSteelSnake Jan 24, 2023
ef462e9
Исправление для StaticTest
StainlessSteelSnake Jan 24, 2023
68602d4
Update handlers.go
StainlessSteelSnake Jan 24, 2023
9e0ea53
Update handlers.go
StainlessSteelSnake Jan 24, 2023
aecc053
Update handlers.go
StainlessSteelSnake Jan 24, 2023
630976a
Исправление ошибок
StainlessSteelSnake Jan 24, 2023
63dc584
Update storage.go
StainlessSteelSnake Jan 24, 2023
76faaa6
Исправление замечаний
StainlessSteelSnake Jan 27, 2023
5cac084
Правки по результатам Code Review
StainlessSteelSnake Feb 2, 2023
35747a3
Update db.go
StainlessSteelSnake Feb 2, 2023
12a49f5
Update handlers_test.go
StainlessSteelSnake Feb 2, 2023
41f559a
Часть обработчиков вынесены в middleware
StainlessSteelSnake Feb 6, 2023
72e7620
Update handlers.go
StainlessSteelSnake Feb 6, 2023
a1dff0d
Исправления замечаний
StainlessSteelSnake Feb 6, 2023
00ea34c
Update handlers_test.go
StainlessSteelSnake Feb 6, 2023
dae9bdc
Update shortenertest.yml
StainlessSteelSnake Feb 6, 2023
eae6d4d
Update shortenertest.yml
StainlessSteelSnake Feb 6, 2023
214a191
Update main.go
StainlessSteelSnake Feb 6, 2023
7cd014f
Update main.go
StainlessSteelSnake Feb 6, 2023
7cc5868
.
StainlessSteelSnake Feb 6, 2023
579ea21
polish
StainlessSteelSnake Jun 27, 2023
3f00a45
Update handlers.go
StainlessSteelSnake Jun 27, 2023
96fc8ea
undo locks
StainlessSteelSnake Jun 27, 2023
ffa2e7e
mutex
StainlessSteelSnake Jun 27, 2023
e7e2182
DUPLICATE
StainlessSteelSnake Jun 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/shortenertest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Build server binary
run: |
cd cmd/shortener
go build -o shortener
go build -buildvcs=false -o shortener

- name: "Code increment #1"
if: |
Expand Down
3 changes: 1 addition & 2 deletions cmd/shortener/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import (

func main() {
cfg := config.NewConfiguration()

ctx := context.Background()

str := storage.NewStorage(cfg.FileStoragePath, cfg.DatabaseDSN, ctx)
str := storage.NewStorage(ctx, cfg.FileStoragePath, cfg.DatabaseDSN)
if closeFunc := str.CloseFunc(); closeFunc != nil {
defer closeFunc()
}
Expand Down
19 changes: 10 additions & 9 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type authentication struct {
}

type Authenticator interface {
Authenticate(http.HandlerFunc) http.HandlerFunc
Authenticate(http.Handler) http.Handler
GetUserID() string
}

Expand Down Expand Up @@ -81,7 +81,7 @@ func (a *authentication) authExisting(cookie string) error {
}
log.Println("Cookie расшифрованы в следующие байты:", data)

if userIDLength*2 < len(cookie) {
if len(cookie) < userIDLength*2 {
return errors.New("неправильная длина cookie")
}
id := cookie[:userIDLength*2]
Expand Down Expand Up @@ -110,16 +110,17 @@ func (a *authentication) authExisting(cookie string) error {
return nil
}

func (a *authentication) Authenticate(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
func (a *authentication) Authenticate(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if a == nil {
return
}

a.userID = ""
a.cookieFull = ""

cookie, err := r.Cookie(cookieAuthentication)
if err != nil {
a.cookieFull = ""
a.userID = ""
log.Println("Cookie '" + cookieAuthentication + "' не переданы")
}

Expand All @@ -128,7 +129,7 @@ func (a *authentication) Authenticate(next http.HandlerFunc) http.HandlerFunc {
err = a.authExisting(cookie.Value)
}
if err != nil {
log.Println("Ошибка при чтении cookie:", err)
log.Println("Ошибка при аутентификации пользователя через cookie 'authentication':", err)
}

err = nil
Expand All @@ -143,8 +144,8 @@ func (a *authentication) Authenticate(next http.HandlerFunc) http.HandlerFunc {
http.SetCookie(w, &http.Cookie{Name: cookieAuthentication, Value: a.cookieFull})
}

next(w, r)
}
next.ServeHTTP(w, r)
})
}

func (a *authentication) GetUserID() string {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ func (c *Configuration) fillFromEnvironment() error {
log.Println("Environment config:", c)

return nil
}
}
Loading