dominikh / go-js-xhr

MIT License
19 stars 7 forks source link

[proposal] xhr.Send() provides some opts to set the xhr header #7

Open scbizu opened 5 years ago

scbizu commented 5 years ago

Hi , issue and PR will be accepted here ?

I think I need some options to do with the xhr.Send() rather than create a new func to send request with different headers .

Maybe something like this ?


type XHRRequestOption func(*Request)*Request{}

func Send(method, url string, data []byte, opts ...XHRRequestOption) ([]byte, error) {
    xhr := NewRequest(method, url)
    xhr.ResponseType = ArrayBuffer
        for _,opt:=range opts {
            xhr = opt(xhr)
       }
    err := xhr.Send(data)
    if err != nil {
        return nil, err
    }
    return js.Global.Get("Uint8Array").New(xhr.Response).Interface().([]byte), nil
}

I can raise a pr if it is possible .