Skip to content

Commit

Permalink
iter8 fix Generate func
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteDSM committed Oct 30, 2023
1 parent dda4cfa commit 7e73691
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/middlewares/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (c *compressWriter) Write(p []byte) (int, error) {
}

func (c *compressWriter) WriteHeader(statusCode int) {
if statusCode < 300 {
if statusCode < 400 {
c.w.Header().Set("Content-Encoding", "gzip")
}
c.w.WriteHeader(statusCode)
Expand Down
11 changes: 9 additions & 2 deletions internal/shotenermaker/makeurl.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package shotenermaker

import "encoding/base64"
import (
"crypto/sha1"
"encoding/hex"
)

// GenerateID Функция для генерации уникального идентификатора
func GenerateID(fullURL []byte) string {
encodedStr := base64.URLEncoding.EncodeToString(fullURL)
h := sha1.New()
h.Write(fullURL)
hashBytes := h.Sum(nil)
encodedStr := hex.EncodeToString(hashBytes)

// Возвращаем первые 6 символов закодированной строки
if len(encodedStr) > 6 {
return encodedStr[:6]
Expand Down
4 changes: 2 additions & 2 deletions internal/storage/urlstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ func NewURLStorage() *URLStorage {
storage := &URLStorage{
urlMap: make(map[string]string),
}
// Adding Test Compliance
storage.AddURL("aHR0cH", "https://practicum.yandex.ru/")
// Adding Test Compliance TEST
//storage.AddURL("aHR0cH", "https://practicum.yandex.ru/")
return storage
}

Expand Down

0 comments on commit 7e73691

Please sign in to comment.