diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef3b6eb --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +# Проверка наличия golangci-lint +GO_LINT := $(shell command -v golangci-lint 2>/dev/null) + +# Цель: запуск всех проверок кода +check: + @echo "🔍 Running code checks..." + @go mod tidy -v + @go vet ./... + @if [ -n "$(GO_LINT)" ]; then \ + echo "✅ golangci-lint found, running..." && \ + golangci-lint run --timeout=5m --verbose; \ + else \ + echo "⚠️ golangci-lint not installed. Install with: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2"; \ + fi + @go test -race -v ./... 2>/dev/null || echo "⚠️ Tests skipped or failed (run manually with 'go test -race ./...')" diff --git a/cmd_generator.go b/cmd_generator.go index 45da59d..8723e51 100644 --- a/cmd_generator.go +++ b/cmd_generator.go @@ -16,7 +16,7 @@ func generateBotCommand[T any](cmd Command[T]) tgapi.BotCommand { var descArgs []string for _, a := range cmd.args { if a.required { - descArgs = append(descArgs, fmt.Sprintf("%s", a.text)) + descArgs = append(descArgs, a.text) } else { descArgs = append(descArgs, fmt.Sprintf("[%s]", a.text)) } diff --git a/plugins.go b/plugins.go index a30514b..daf6f7f 100644 --- a/plugins.go +++ b/plugins.go @@ -15,7 +15,7 @@ const ( ) var ( - CommandRegexInt = regexp.MustCompile("\\d+") + CommandRegexInt = regexp.MustCompile(`\d+`) CommandRegexString = regexp.MustCompile(".+") ) diff --git a/tgapi/chat_methods.go b/tgapi/chat_methods.go index ad1fc33..a95f2c6 100644 --- a/tgapi/chat_methods.go +++ b/tgapi/chat_methods.go @@ -209,7 +209,9 @@ func (api *API) DeclineChatJoinRequest(params DeclineChatJoinRequestP) (bool, er func (api *API) SetChatPhoto() { uploader := NewUploader(api) - defer uploader.Close() + defer func() { + _ = uploader.Close() + }() } type DeleteChatPhotoP struct { diff --git a/tgapi/methods.go b/tgapi/methods.go index 95956d8..3be5f8e 100644 --- a/tgapi/methods.go +++ b/tgapi/methods.go @@ -57,6 +57,8 @@ func (api *API) GetFileByLink(link string) ([]byte, error) { if err != nil { return nil, err } - defer res.Body.Close() + defer func() { + _ = res.Body.Close() + }() return io.ReadAll(res.Body) } diff --git a/tgapi/types.go b/tgapi/types.go index 6143a63..4fcf7fb 100644 --- a/tgapi/types.go +++ b/tgapi/types.go @@ -261,20 +261,20 @@ type Gifts struct { Gifts []Gift `json:"gifts"` } +type OwnedGiftType string + const ( OwnedGiftRegularType OwnedGiftType = "regular" OwnedGiftUniqueType OwnedGiftType = "unique" ) -type OwnedGiftType string -type BaseOwnedGift struct { +type OwnedGift struct { Type OwnedGiftType `json:"type"` OwnerGiftID *string `json:"owner_gift_id,omitempty"` SendDate *int `json:"send_date,omitempty"` IsSaved *bool `json:"is_saved,omitempty"` -} -type OwnedGiftRegular struct { - BaseOwnedGift + + // Поля, характерные для "regular" Gift Gift `json:"gift"` SenderUser User `json:"sender_user,omitempty"` Text string `json:"text,omitempty"` @@ -286,18 +286,15 @@ type OwnedGiftRegular struct { PrepaidUpgradeStarCount *int `json:"prepaid_upgrade_star_count,omitempty"` IsUpgradeSeparate *bool `json:"is_upgrade_separate,omitempty"` UniqueGiftNumber *int `json:"unique_gift_number,omitempty"` -} -type OwnedGiftUnique struct { - BaseOwnedGift + + // Поля, характерные для "unique" CanBeTransferred *bool `json:"can_be_transferred,omitempty"` TransferStarCount *int `json:"transfer_star_count,omitempty"` NextTransferDate *int `json:"next_transfer_date,omitempty"` } + type OwnedGifts struct { - TotalCount int `json:"total_count"` - Gifts []struct { - OwnedGiftRegular - OwnedGiftUnique - } `json:"gifts"` - NextOffset string `json:"next_offset"` + TotalCount int `json:"total_count"` + Gifts []OwnedGift `json:"gifts"` + NextOffset string `json:"next_offset"` } diff --git a/tgapi/uploader_api.go b/tgapi/uploader_api.go index e7184ff..3d0a60f 100644 --- a/tgapi/uploader_api.go +++ b/tgapi/uploader_api.go @@ -113,6 +113,9 @@ func (r UploaderRequest[R, P]) doRequest(ctx context.Context, up *Uploader) (R, body, err := readBody(resp.Body) _ = resp.Body.Close() + if err != nil { + return zero, err + } up.logger.Debugln("UPLOADER RES", r.method, string(body)) response, err := parseBody[R](body) @@ -145,7 +148,7 @@ func (r UploaderRequest[R, P]) doRequest(ctx context.Context, up *Uploader) (R, func (r UploaderRequest[R, P]) DoWithContext(ctx context.Context, up *Uploader) (R, error) { var zero R - result, err := up.api.pool.Submit(ctx, func(ctx context.Context) (any, error) { + result, err := up.api.pool.submit(ctx, func(ctx context.Context) (any, error) { return r.doRequest(ctx, up) }) if err != nil { @@ -156,10 +159,10 @@ func (r UploaderRequest[R, P]) DoWithContext(ctx context.Context, up *Uploader) case <-ctx.Done(): return zero, ctx.Err() case res := <-result: - if res.Err != nil { - return zero, res.Err + if res.err != nil { + return zero, res.err } - if val, ok := res.Value.(R); ok { + if val, ok := res.value.(R); ok { return val, nil } return zero, ErrPoolUnexpected diff --git a/utils/version.go b/utils/version.go index 5ad969a..da80125 100644 --- a/utils/version.go +++ b/utils/version.go @@ -1,9 +1,9 @@ package utils const ( - VersionString = "1.0.0-beta.9" + VersionString = "1.0.0-beta.10" VersionMajor = 1 VersionMinor = 0 VersionPatch = 0 - Beta = 9 + Beta = 10 )