Skip to content

Commit

Permalink
set request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed May 9, 2024
1 parent 9b44343 commit a2bdf1f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions impl_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func (r *Lark) parseRawHttpRequest(ctx context.Context, req *RawRequestReq) (*ra
if req.MethodOption.timeout > 0 {
rawHttpReq.Timeout = req.MethodOption.timeout
}
if len(req.MethodOption.headers) > 0 {
for k, v := range req.MethodOption.headers {
rawHttpReq.Headers[k] = v
}
}

// 1 headers
if err := rawHttpReq.parseHeader(ctx, r, req); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions lark.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,18 @@ func WithRequestTimeout(timeout time.Duration) MethodOptionFunc {
}
}

// WithRequestHeaders set request headers
func WithRequestHeaders(headers map[string]string) MethodOptionFunc {
return func(option *MethodOption) {
option.headers = headers
}
}

// MethodOption method option
type MethodOption struct {
userAccessToken string
timeout time.Duration
headers map[string]string
}

func newMethodOption(options []MethodOptionFunc) *MethodOption {
Expand Down

0 comments on commit a2bdf1f

Please sign in to comment.