diff options
Diffstat (limited to 'vendor/github.com/monaco-io/request')
-rw-r--r-- | vendor/github.com/monaco-io/request/.gitignore | 20 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/.travis.yml | 16 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/CODE_OF_CONDUCT.md | 76 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/CONTRIBUTING.md | 1 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/LICENSE | 21 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/README.md | 197 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/doc.go | 59 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/go.mod | 3 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/go.sum | 0 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/model.go | 66 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/request.go | 98 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/resp.go | 18 | ||||
-rw-r--r-- | vendor/github.com/monaco-io/request/url.go | 36 |
13 files changed, 611 insertions, 0 deletions
diff --git a/vendor/github.com/monaco-io/request/.gitignore b/vendor/github.com/monaco-io/request/.gitignore new file mode 100644 index 00000000..da62cf0f --- /dev/null +++ b/vendor/github.com/monaco-io/request/.gitignore @@ -0,0 +1,20 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +.idea +.vscode + +coverage.txt
\ No newline at end of file diff --git a/vendor/github.com/monaco-io/request/.travis.yml b/vendor/github.com/monaco-io/request/.travis.yml new file mode 100644 index 00000000..abc79551 --- /dev/null +++ b/vendor/github.com/monaco-io/request/.travis.yml @@ -0,0 +1,16 @@ +language: go + +go: + - 1.14.x + - tip + +sudo: false + +before_install: + - go get -t -v ./... + +script: + - go test -race -coverprofile=coverage.txt -covermode=atomic + +after_success: + - bash <(curl -s https://codecov.io/bash) -t 6cf6f7ab-26e6-429c-ac44-f0ad85c1e586 diff --git a/vendor/github.com/monaco-io/request/CODE_OF_CONDUCT.md b/vendor/github.com/monaco-io/request/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..91ec07cd --- /dev/null +++ b/vendor/github.com/monaco-io/request/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at luxuze@agora.io. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html> + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +<https://www.contributor-covenant.org/faq> diff --git a/vendor/github.com/monaco-io/request/CONTRIBUTING.md b/vendor/github.com/monaco-io/request/CONTRIBUTING.md new file mode 100644 index 00000000..dbaedf3f --- /dev/null +++ b/vendor/github.com/monaco-io/request/CONTRIBUTING.md @@ -0,0 +1 @@ +# CONTRIBUTING
diff --git a/vendor/github.com/monaco-io/request/LICENSE b/vendor/github.com/monaco-io/request/LICENSE new file mode 100644 index 00000000..55b76f67 --- /dev/null +++ b/vendor/github.com/monaco-io/request/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Monaco.HappyHacking + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/monaco-io/request/README.md b/vendor/github.com/monaco-io/request/README.md new file mode 100644 index 00000000..7ac32be0 --- /dev/null +++ b/vendor/github.com/monaco-io/request/README.md @@ -0,0 +1,197 @@ +# Request [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) [![Go Report Card](https://goreportcard.com/badge/github.com/monaco-io/request)](https://goreportcard.com/report/github.com/monaco-io/request) ![Go](https://github.com/monaco-io/request/workflows/Go/badge.svg) + +<img align="right" width="159px" src="https://raw.githubusercontent.com/gin-gonic/logo/master/color.png"> + +[![Build Status](https://travis-ci.org/monaco-io/request.svg?branch=master)](https://travis-ci.org/monaco-io/request) +[![GoDoc](https://godoc.org/github.com/monaco-io/request?status.svg)](https://pkg.go.dev/github.com/monaco-io/request?tab=doc) +[![codecov](https://codecov.io/gh/monaco-io/request/branch/master/graph/badge.svg)](https://codecov.io/gh/monaco-io/request) +[![Release](https://img.shields.io/github/release/monaco-io/request.svg?style=flat-square)](https://github.com/monaco-io/request/releases) +[![TODOs](https://badgen.net/https/api.tickgit.com/badgen/github.com/monaco-io/request)](https://www.tickgit.com/browse?repo=github.com/monaco-io/request) +[![License](https://img.shields.io/github/license/monaco-io/request?style=plastic)](https://github.com/monaco-io/request/blob/master/LICENSE) +<!-- [![Sourcegraph](https://sourcegraph.com/github.com/monaco-io/request/-/badge.svg)](https://sourcegraph.com/github.com/monaco-io/request?badge) --> +<!-- [![Open Source Helpers](https://www.codetriage.com/monaco-io/request/badges/users.svg)](https://www.codetriage.com/monaco-io/request) --> +<!-- [![Join the chat at https://gitter.im/monaco-io/request](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/monaco-io/request?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) --> + +HTTP client for golang, Inspired by [Javascript-axios](https://github.com/axios/axios) [Python-request](https://github.com/psf/requests). +If you have experience about axios or requests, you will love it. +No 3rd dependency. + +## Features + +- Make [http](https://golang.org) requests from Golang +- Intercept request and response +- Transform request and response data + +## Installing + +go mod: + +```bash +go get github.com/monaco-io/request +``` + +## Methods + +- OPTIONS +- GET +- HEAD +- POST +- PUT +- DELETE +- TRACE +- CONNECT + +## Example + +### GET + +```go +package main + +import ( + "log" + + "github.com/monaco-io/request" +) + +func main() { + client := request.Client{ + URL: "https://google.com", + Method: "GET", + Params: map[string]string{"hello": "world"}, + } + resp, err := client.Do() + + log.Println(resp.Code, string(resp.Data), err) +} +``` + +### POST + +```go +package main + +import ( + "log" + + "github.com/monaco-io/request" +) + +func main() { + client := request.Client{ + URL: "https://google.com", + Method: "POST", + Params: map[string]string{"hello": "world"}, + Body: []byte(`{"hello": "world"}`), + } + resp, err := client.Do() + + log.Println(resp.Code, string(resp.Data), err) +} +``` + +### Content-Type + +```go +package main + +import ( + "log" + + "github.com/monaco-io/request" +) + +func main() { + client := request.Client{ + URL: "https://google.com", + Method: "POST", + ContentType: request.ApplicationXWwwFormURLEncoded, // default is "application/json" + } + resp, err := client.Do() + + log.Println(resp.Code, string(resp.Data), err) +} +``` + +### Authorization + +```go +package main + +import ( + "log" + + "github.com/monaco-io/request" +) + +func main() { + client := request.Client{ + URL: "https://google.com", + Method: "POST", + BasicAuth: request.BasicAuth{ + Username:"user_xxx", + Password:"pwd_xxx", + }, // xxx:xxx + } + + resp, err := client.Do() + + log.Println(resp.Code, string(resp.Data), err) +} +``` + +### Timeout + +```go +package main + +import ( + "log" + + "github.com/monaco-io/request" +) + +func main() { + client := request.Client{ + URL: "https://google.com", + Method: "POST", + Timeout: 10, // seconds + } + + resp, err := client.Do() + + log.Println(resp.Code, string(resp.Data), err) +} +``` + +### Cookies + +```go +package main + +import ( + "log" + + "github.com/monaco-io/request" +) + +func main() { + client := request.Client{ + URL: "https://google.com", + Cookies:[]*http.Cookie{ + { + Name: "cookie_name", + Value: "cookie_value", + }, + }, + } + + resp, err := client.Do() + + log.Println(resp.Code, string(resp.Data), err) +} +``` + +## License + +[MIT](LICENSE) diff --git a/vendor/github.com/monaco-io/request/doc.go b/vendor/github.com/monaco-io/request/doc.go new file mode 100644 index 00000000..d2259131 --- /dev/null +++ b/vendor/github.com/monaco-io/request/doc.go @@ -0,0 +1,59 @@ +// Package request HTTP client for golang +// - Make http requests from Golang +// - Intercept request and response +// - Transform request and response data +// +// GET +// +// client := request.Client{ +// URL: "https://google.com", +// Method: "GET", +// Params: map[string]string{"hello": "world"}, +// } +// resp, err := client.Do() +// +// POST +// +// client := request.Client{ +// URL: "https://google.com", +// Method: "POST", +// Params: map[string]string{"hello": "world"}, +// Body: []byte(`{"hello": "world"}`), +// } +// resp, err := client.Do() +// +// Content-Type +// +// client := request.Client{ +// URL: "https://google.com", +// Method: "POST", +// ContentType: request.ApplicationXWwwFormURLEncoded, // default is "application/json" +// } +// resp, err := client.Do() +// +// Authorization +// +// client := request.Client{ +// URL: "https://google.com", +// Method: "POST", +// BasicAuth: request.BasicAuth{ +// Username:"user_xxx", +// Password:"pwd_xxx", +// }, // xxx:xxx +// } +// +// resp, err := client.Do() +// +// Cookies +// client := request.Client{ +// URL: "https://google.com", +// Cookies:[]*http.Cookie{ +// { +// Name: "cookie_name", +// Value: "cookie_value", +// }, +// }, +// } +// +// resp, err := client.Do() +package request diff --git a/vendor/github.com/monaco-io/request/go.mod b/vendor/github.com/monaco-io/request/go.mod new file mode 100644 index 00000000..4e5e14b5 --- /dev/null +++ b/vendor/github.com/monaco-io/request/go.mod @@ -0,0 +1,3 @@ +module github.com/monaco-io/request + +go 1.14 diff --git a/vendor/github.com/monaco-io/request/go.sum b/vendor/github.com/monaco-io/request/go.sum new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/vendor/github.com/monaco-io/request/go.sum diff --git a/vendor/github.com/monaco-io/request/model.go b/vendor/github.com/monaco-io/request/model.go new file mode 100644 index 00000000..6dd58bca --- /dev/null +++ b/vendor/github.com/monaco-io/request/model.go @@ -0,0 +1,66 @@ +package request + +import ( + "net/http" + "time" +) + +const ( + // ApplicationJSON application/json + ApplicationJSON ContentType = "application/json" + + // ApplicationXWwwFormURLEncoded application/x-www-form-urlencoded + ApplicationXWwwFormURLEncoded ContentType = "application/x-www-form-urlencoded" + + // MultipartFormData multipart/form-data + MultipartFormData ContentType = "multipart/form-data" +) + +// ContentType Content-Type +type ContentType string + +// Client Method +/* + Method = "OPTIONS" ; Section 9.2 + | "GET" ; Section 9.3 + | "HEAD" ; Section 9.4 + | "POST" ; Section 9.5 + | "PUT" ; Section 9.6 + | "DELETE" ; Section 9.7 + | "TRACE" ; Section 9.8 + | "CONNECT" ; Section 9.9 + | extension-method + extension-method = token + token = 1*<any CHAR except CTLs or separators> +*/ +type Client struct { + URL string + Method string + Header map[string]string + Params map[string]string + Body []byte + BasicAuth BasicAuth + Timeout time.Duration // second + ProxyURL string + ContentType ContentType + Cookies []*http.Cookie + + // private + client *http.Client + req *http.Request +} + +// BasicAuth Add Username:Password as Basic Auth +type BasicAuth struct { + Username string + Password string +} + +// SugaredResp Sugared response with status code and body data +type SugaredResp struct { + Data []byte + Code int + + // private + resp *http.Response +} diff --git a/vendor/github.com/monaco-io/request/request.go b/vendor/github.com/monaco-io/request/request.go new file mode 100644 index 00000000..0a4e7df4 --- /dev/null +++ b/vendor/github.com/monaco-io/request/request.go @@ -0,0 +1,98 @@ +package request + +import ( + "bytes" + "crypto/tls" + "io/ioutil" + "net/http" + "net/http/cookiejar" + "net/url" + "time" +) + +// Do send http request +func (c *Client) Do() (resp SugaredResp, err error) { + defer resp.Close() + + if err := c.buildRequest(); err != nil { + return resp, err + } + + // send request and close on func call end + if resp.resp, err = c.client.Do(c.req); err != nil { + return resp, err + } + + // read response data form resp + resp.Data, err = ioutil.ReadAll(resp.resp.Body) + resp.Code = resp.resp.StatusCode + return resp, err +} + +func (c *Client) buildRequest() (err error) { + + // encode requestURL.httpURL like https://google.com?hello=world&package=request + ru := requestURL{ + urlString: c.URL, + parameters: c.Params, + } + if err := ru.EncodeURL(); err != nil { + return err + } + + // build request + c.req, err = http.NewRequest(c.Method, ru.string(), bytes.NewReader(c.Body)) + if err != nil { + return err + } + + // apply Header to request + if c.Method == "POST" { + if c.ContentType == "" { + c.ContentType = ApplicationJSON + } + c.req.Header.Set("Content-Type", string(c.ContentType)) + } + for k, v := range c.Header { + c.req.Header.Add(k, v) + } + + // apply basic Auth of request header + if c.BasicAuth.Username != "" && c.BasicAuth.Password != "" { + c.req.SetBasicAuth(c.BasicAuth.Username, c.BasicAuth.Password) + } + + c.client = &http.Client{} + + // apply timeout + if c.Timeout > 0 { + c.client.Timeout = c.Timeout * time.Second + } + + // apply cookies + if c.Cookies != nil { + jar, _ := cookiejar.New(nil) + jar.SetCookies(&url.URL{Scheme: ru.scheme(), Host: ru.host()}, c.Cookies) + c.client.Jar = jar + } + + // apply proxy + if c.ProxyURL != "" { + if proxy, err := url.Parse(c.ProxyURL); err == nil && proxy != nil { + c.client.Transport = &http.Transport{ + Proxy: http.ProxyURL(proxy), + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + } + } + + return err +} + +// Resp do request and get original http response struct +func (c *Client) Resp() (resp *http.Response, err error) { + if err = c.buildRequest(); err != nil { + return resp, err + } + return c.client.Do(c.req) +} diff --git a/vendor/github.com/monaco-io/request/resp.go b/vendor/github.com/monaco-io/request/resp.go new file mode 100644 index 00000000..fb47dd1c --- /dev/null +++ b/vendor/github.com/monaco-io/request/resp.go @@ -0,0 +1,18 @@ +package request + +// StatusCode get response status code +func (s *SugaredResp) StatusCode() (code int) { + return s.resp.StatusCode +} + +// Status get response status code and text, like 200 ok +func (s *SugaredResp) Status() (status string) { + return s.resp.Status +} + +// Close close response body +func (s *SugaredResp) Close() { + if s.resp != nil { + _ = s.resp.Body.Close() + } +} diff --git a/vendor/github.com/monaco-io/request/url.go b/vendor/github.com/monaco-io/request/url.go new file mode 100644 index 00000000..98526149 --- /dev/null +++ b/vendor/github.com/monaco-io/request/url.go @@ -0,0 +1,36 @@ +package request + +import "net/url" + +type requestURL struct { + httpURL *url.URL + urlString string + parameters map[string]string +} + +// EncodeURL add and encoded parameters. +func (ru *requestURL) EncodeURL() (err error) { + ru.httpURL, err = url.Parse(ru.urlString) + if err != nil { + return err + } + query := ru.httpURL.Query() + for k := range ru.parameters { + query.Set(k, ru.parameters[k]) + } + ru.httpURL.RawQuery = query.Encode() + return err +} + +// String return example: https://www.google.com/search?a=1&b=2 +func (ru requestURL) string() string { + return ru.httpURL.String() +} + +func (ru requestURL) scheme() string { + return ru.httpURL.Scheme +} + +func (ru requestURL) host() string { + return ru.httpURL.Host +} |