Skip to content

Commit

Permalink
Merge pull request #170 from icey-yu/feat-gen
Browse files Browse the repository at this point in the history
feat: gen rpc
  • Loading branch information
icey-yu authored Dec 13, 2024
2 parents 3585a35 + 4d4c16a commit cc43ff1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions rpccall/caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (r RpcCaller[Req, Resp]) Invoke(ctx context.Context, in *Req, opts ...grpc.
return out, nil
}

func (r RpcCaller[Req, Resp]) Execute(ctx context.Context, req *Req) error {
_, err := r.Invoke(ctx, req)
func (r RpcCaller[Req, Resp]) Execute(ctx context.Context, req *Req, opts ...grpc.CallOption) error {
_, err := r.Invoke(ctx, req, opts...)
return err
}

Expand All @@ -43,8 +43,8 @@ func (r RpcCaller[Req, Resp]) MethodName() string {
}

// ExtractField is a generic function that extracts a field from the response of a given function.
func ExtractField[A, B, C any](ctx context.Context, fn func(ctx context.Context, req *A) (*B, error), req *A, get func(*B) C) (C, error) {
resp, err := fn(ctx, req)
func ExtractField[A, B, C any](ctx context.Context, fn func(ctx context.Context, req *A, opts ...grpc.CallOption) (*B, error), req *A, get func(*B) C, opts ...grpc.CallOption) (C, error) {
resp, err := fn(ctx, req, opts...)
if err != nil {
var c C
return c, err
Expand All @@ -56,7 +56,7 @@ type pagination interface {
GetPagination() *sdkws.RequestPagination
}

func Page[Req pagination, Resp any, Elem any](ctx context.Context, req Req, api func(ctx context.Context, req Req) (*Resp, error), fn func(*Resp) []Elem) ([]Elem, error) {
func Page[Req pagination, Resp any, Elem any](ctx context.Context, req Req, api func(ctx context.Context, req Req, opts ...grpc.CallOption) (*Resp, error), fn func(*Resp) []Elem, opts ...grpc.CallOption) ([]Elem, error) {
if req.GetPagination() == nil {
vof := reflect.ValueOf(req)
for {
Expand Down Expand Up @@ -84,7 +84,7 @@ func Page[Req pagination, Resp any, Elem any](ctx context.Context, req Req, api
var result []Elem
for i := int32(0); ; i++ {
req.GetPagination().PageNumber = i + 1
resp, err := api(ctx, req)
resp, err := api(ctx, req, opts...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit cc43ff1

Please sign in to comment.