Skip to content

Instantly share code, notes, and snippets.

@kyleterry
Created May 12, 2020 19:01

Revisions

  1. kyleterry created this gist May 12, 2020.
    11 changes: 11 additions & 0 deletions request.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    // SetJSONBody is used to set a request body that is a JSON-encoded value.
    func (r *Request) SetJSONBody(val interface{}) error {
    buf, err := json.Marshal(val)
    if err != nil {
    return err
    }

    r.Obj = val
    r.BodyBytes = buf
    return nil
    }