Skip to content

Commit

Permalink
Merge pull request #611 from wuxu92/sdk/client
Browse files Browse the repository at this point in the history
`sdk/client`: req marshal with `[]byte` instead of `*[]byte`
  • Loading branch information
manicminer authored Aug 14, 2023
2 parents 09f0e75 + f47722d commit 3229ebf
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sdk/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ func (r *Request) Marshal(payload interface{}) error {
}

if strings.Contains(contentType, "application/octet-stream") || strings.Contains(contentType, "text/powershell") {
v, ok := payload.(*[]byte)
if !ok {
return fmt.Errorf("internal-error: `payload` must be *[]byte but got %+v", payload)
switch v := payload.(type) {
case *[]byte:
r.ContentLength = int64(len(*v))
r.Body = io.NopCloser(bytes.NewReader(*v))
case []byte:
r.ContentLength = int64(len(v))
r.Body = io.NopCloser(bytes.NewReader(v))
default:
return fmt.Errorf("internal-error: `payload` must be []byte or *[]byte but got type %T", payload)
}

r.ContentLength = int64(len(*v))
r.Body = io.NopCloser(bytes.NewReader(*v))
return nil
}

Expand Down

0 comments on commit 3229ebf

Please sign in to comment.