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

Dev #1

Merged
merged 18 commits into from
Feb 5, 2024
Merged

Dev #1

merged 18 commits into from
Feb 5, 2024

Conversation

OlegVankov
Copy link
Owner

No description provided.


}

<-time.After(time.Second * time.Duration(5))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BLOCKER] здесь будет утечка памяти. Лучше использовать time.Ticker и написать как-то так:

	t := time.NewTicker(time.Second * time.Duration(5))
	defer t.Stop()

	for {
		select {
		case <-t.C:
			// logic
		}
	}

eclipse-paho/paho.mqtt.golang#518

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавил функцию sleep
коммит 60838f1

func (h *Handler) Balance(w http.ResponseWriter, r *http.Request) {
username := r.Header.Get("username")

user, err := h.Repository.GetBalance(context.Background(), username)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BLOCKER] context нужно брать из Request. Если по какой-то причине клиент отклонит запрос, контекст завершится и запрос в БД выполняться не будет.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix в коммите 56800de


func sleep(ctx context.Context, interval time.Duration) error {
timer := time.NewTimer(interval)
select {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BLOCKER] Здесь так же стоит добавить defer timer.Stop(). Чтобы после завершения выполнения функции, все ресурсы timer освободились.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

удалил функцию
коммит 2f5f087


}

if err := sleep(ctx, time.Duration(5)*time.Second); err != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LINT] выглядит чуть-чуть не красиво. Можно оставить как есть, но обычно так не пишут. Если не хочешь видеть select не обязательно делать для этого отдельную функцию. Можно просто написать:

func SendAccrual() {
	ticker := time.NewTicker(time.Duration(5)*time.Second)
	defer ticker.Stop()

	for _ = range ticker.C {
		// do something
	}
}

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переписал цикл с использованием ticker
коммит 2f5f087

return
}

tkn, _ := util.CreateToken(user.Login, user.ID)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LINT] если CreateToken вернет ошибку, то лучше ее обработать и вернуть пользователю ошибку

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

обработал ошибку
коммит 2f5f087

internal/util/hash.go Outdated Show resolved Hide resolved
@OlegVankov OlegVankov merged commit dc0408c into master Feb 5, 2024
2 checks passed
@OlegVankov OlegVankov deleted the dev branch February 5, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants