(fix): finalize v2 contracts (tests): cover v2 migration (doc): prepare release guidance
This commit is contained in:
+6
-6
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.scuroneko.dev/scuroneko/laniakea/utils"
|
||||
"git.scuroneko.dev/scuroneko/laniakea/v2/utils"
|
||||
"git.scuroneko.dev/scuroneko/sneklog/v2"
|
||||
)
|
||||
|
||||
@@ -236,7 +236,7 @@ func NewRequestWithChatID[R, P any](method string, params P, chatID int64) Teleg
|
||||
return TelegramRequest[R, P]{method, params, chatID}
|
||||
}
|
||||
|
||||
func (r TelegramRequest[R, P]) doRequest(ctx context.Context, api *API) (R, error) {
|
||||
func (api *API) doRequest[R, P any](ctx context.Context, r TelegramRequest[R, P]) (R, error) {
|
||||
var zero R
|
||||
reqData, err := json.Marshal(r.params)
|
||||
if err != nil {
|
||||
@@ -336,11 +336,11 @@ func (r TelegramRequest[R, P]) doRequest(ctx context.Context, api *API) (R, erro
|
||||
|
||||
// DoWithContext executes the request asynchronously via the worker pool.
|
||||
// Returns result or error via channel. Respects context cancellation.
|
||||
func (r TelegramRequest[R, P]) DoWithContext(ctx context.Context, api *API) (R, error) {
|
||||
func (api *API) DoWithContext[R, P any](ctx context.Context, r TelegramRequest[R, P]) (R, error) {
|
||||
var zero R
|
||||
|
||||
resultChan, err := api.pool.submit(ctx, func(ctx context.Context) (any, error) {
|
||||
return r.doRequest(ctx, api)
|
||||
return api.doRequest(ctx, r)
|
||||
})
|
||||
if err != nil {
|
||||
return zero, err
|
||||
@@ -362,8 +362,8 @@ func (r TelegramRequest[R, P]) DoWithContext(ctx context.Context, api *API) (R,
|
||||
|
||||
// Do executes the request synchronously with a background context.
|
||||
// Use only for simple, non-critical calls.
|
||||
func (r TelegramRequest[R, P]) Do(api *API) (R, error) {
|
||||
return r.DoWithContext(context.Background(), api)
|
||||
func (api *API) Do[R, P any](r TelegramRequest[R, P]) (R, error) {
|
||||
return api.DoWithContext(context.Background(), r)
|
||||
}
|
||||
|
||||
func readBody(body io.ReadCloser) ([]byte, error) {
|
||||
|
||||
Reference in New Issue
Block a user