Skip to content

Commit

Permalink
Merge pull request #3 from lance-e/feat/client
Browse files Browse the repository at this point in the history
feat:improve request
  • Loading branch information
ViolaPioggia authored May 17, 2024
2 parents 7f12c8e + 4fa2fce commit 59839bc
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,70 @@ type Request struct {
Result interface{}
Error interface{}
}

const (
// MethodGet HTTP method
MethodGet = "GET"

// MethodPost HTTP method
MethodPost = "POST"

// MethodPut HTTP method
MethodPut = "PUT"

// MethodDelete HTTP method
MethodDelete = "DELETE"

// MethodPatch HTTP method
MethodPatch = "PATCH"

// MethodHead HTTP method
MethodHead = "HEAD"

// MethodOptions HTTP method
MethodOptions = "OPTIONS"
)


func (r *Request) Get(url string) (*Response, error) {
return r.Execute(MethodGet, url)
}

func (r *Request) Head(url string) (*Response, error) {
return r.Execute(MethodHead, url)
}

func (r *Request) Post(url string) (*Response, error) {
return r.Execute(MethodPost, url)
}

func (r *Request) Put(url string) (*Response, error) {
return r.Execute(MethodPut, url)
}

func (r *Request) Delete(url string) (*Response, error) {
return r.Execute(MethodDelete, url)
}

func (r *Request) Options(url string) (*Response, error) {
return r.Execute(MethodOptions, url)
}

func (r *Request) Patch(url string) (*Response, error) {
return r.Execute(MethodPatch, url)
}

func (r *Request) Send() (*Response, error) {
return r.Execute(r.Method, r.Url)
}

func (r *Request) Execute(method, url string) (*Response, error) {
r.Method = method
r.Url = url
res := &Response{
Request: r,
RawResponse: &protocol.Response{},
}
err :=r.client.client.Do(context.Background(),r.RawRequest,res.RawResponse)
return res,err
}

0 comments on commit 59839bc

Please sign in to comment.