diff --git a/airingschedule.go b/airingschedule.go index e58f03c..a830505 100644 --- a/airingschedule.go +++ b/airingschedule.go @@ -2,7 +2,7 @@ package anilist import "context" -func (api *Api) GetAiringSchedule(ctx context.Context, vars AiringScheduleQuery, onError func(error)) Cursor[AiringSchedule] { +func (api *Api) GetAiringSchedule(ctx context.Context, vars AiringScheduleQuery, onError func(error)) *Cursor[AiringSchedule] { resp := responseObj[*page[AiringSchedule]]{} return requestPaged(api, ctx, getAiringScheduleQuery, vars.toMap(), &resp, onError) } diff --git a/api.go b/api.go index 89037b6..c0c9b2f 100644 --- a/api.go +++ b/api.go @@ -61,7 +61,7 @@ func request[T any](api *Api, query string, vars map[string]interface{}, respObj return nil } -func requestPaged[R any](api *Api, ctx context.Context, query string, vars map[string]interface{}, respObj *responseObj[*page[R]], onError func(error)) Cursor[R] { +func requestPaged[R any](api *Api, ctx context.Context, query string, vars map[string]interface{}, respObj *responseObj[*page[R]], onError func(error)) *Cursor[R] { resp := responseObj[struct { Page *page[R] `json:"Page"` }]{} @@ -105,7 +105,7 @@ func requestPaged[R any](api *Api, ctx context.Context, query string, vars map[s } }() - return Cursor[R]{ + return &Cursor[R]{ Chan: out, ctx: ctx, cancelFunc: cancelFunc, diff --git a/cursor.go b/cursor.go index 3ed6b14..494d46b 100644 --- a/cursor.go +++ b/cursor.go @@ -8,16 +8,16 @@ type Cursor[T any] struct { Chan <-chan *T } -func (c Cursor[T]) First() *T { +func (c *Cursor[T]) First() *T { defer c.cancelFunc() return <-c.Chan } -func (c Cursor[T]) Close() { +func (c *Cursor[T]) Close() { c.cancelFunc() } -func (c Cursor[T]) Next() (*T, bool) { +func (c *Cursor[T]) Next() (*T, bool) { if c.ctx.Err() == nil { value, ok := <-c.Chan return value, ok @@ -26,7 +26,7 @@ func (c Cursor[T]) Next() (*T, bool) { return nil, false } -func (c Cursor[T]) Slice() []T { +func (c *Cursor[T]) Slice() []T { s := make([]T, 0) for value, ok := c.Next(); ok; value, ok = c.Next() { s = append(s, *value) diff --git a/media.go b/media.go index e0d4911..da05015 100644 --- a/media.go +++ b/media.go @@ -2,7 +2,7 @@ package anilist import "context" -func (api *Api) GetMedia(ctx context.Context, vars MediaQuery, onError func(error)) Cursor[Media] { +func (api *Api) GetMedia(ctx context.Context, vars MediaQuery, onError func(error)) *Cursor[Media] { resp := responseObj[*page[Media]]{} return requestPaged(api, ctx, getMediaQuery, vars.toMap(), &resp, onError) } diff --git a/medialist.go b/medialist.go index e0547cb..257f1f0 100644 --- a/medialist.go +++ b/medialist.go @@ -2,7 +2,7 @@ package anilist import "context" -func (api *Api) GetMediaList(ctx context.Context, vars MediaListQuery, onError func(error)) Cursor[MediaList] { +func (api *Api) GetMediaList(ctx context.Context, vars MediaListQuery, onError func(error)) *Cursor[MediaList] { resp := responseObj[*page[MediaList]]{} return requestPaged(api, ctx, getMediaListQuery, vars.toMap(), &resp, onError) } diff --git a/user.go b/user.go index 10812cf..ef1686a 100644 --- a/user.go +++ b/user.go @@ -44,7 +44,7 @@ func (api *Api) GetUserByID(id int) (*User, error) { return resp.Data.User, nil } -func (api *Api) SearchUsers(ctx context.Context, search string, onError func(error)) Cursor[User] { +func (api *Api) SearchUsers(ctx context.Context, search string, onError func(error)) *Cursor[User] { vars := map[string]interface{}{"search": search} resp := responseObj[*page[User]]{} return requestPaged(api, ctx, searchUsersQuery, vars, &resp, onError)