diff options
Diffstat (limited to 'teleirc/matterbridge/vendor/github.com/monaco-io')
12 files changed, 698 insertions, 0 deletions
diff --git a/teleirc/matterbridge/vendor/github.com/monaco-io/request/.gitignore b/teleirc/matterbridge/vendor/github.com/monaco-io/request/.gitignore new file mode 100644 index 0000000..da62cf0 --- /dev/null +++ b/teleirc/matterbridge/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/teleirc/matterbridge/vendor/github.com/monaco-io/request/CODE_OF_CONDUCT.md b/teleirc/matterbridge/vendor/github.com/monaco-io/request/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..91ec07c --- /dev/null +++ b/teleirc/matterbridge/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/teleirc/matterbridge/vendor/github.com/monaco-io/request/CONTRIBUTING.md b/teleirc/matterbridge/vendor/github.com/monaco-io/request/CONTRIBUTING.md new file mode 100644 index 0000000..dbaedf3 --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/monaco-io/request/CONTRIBUTING.md @@ -0,0 +1 @@ +# CONTRIBUTING
diff --git a/teleirc/matterbridge/vendor/github.com/monaco-io/request/LICENSE b/teleirc/matterbridge/vendor/github.com/monaco-io/request/LICENSE new file mode 100644 index 0000000..55b76f6 --- /dev/null +++ b/teleirc/matterbridge/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/teleirc/matterbridge/vendor/github.com/monaco-io/request/README.md b/teleirc/matterbridge/vendor/github.com/monaco-io/request/README.md new file mode 100644 index 0000000..153dbea --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/monaco-io/request/README.md @@ -0,0 +1,221 @@ +# Request [](https://github.com/avelino/awesome-go) [](https://goreportcard.com/report/github.com/monaco-io/request)  + +<img align="right" width="159px" src="https://raw.githubusercontent.com/gin-gonic/logo/master/color.png"> + +[](https://pkg.go.dev/github.com/monaco-io/request?tab=doc) +[](https://codecov.io/gh/monaco-io/request) +[](https://github.com/monaco-io/request/releases) +[](https://www.tickgit.com/browse?repo=github.com/monaco-io/request) +[](https://github.com/monaco-io/request/blob/master/LICENSE) +<!-- [](https://sourcegraph.com/github.com/monaco-io/request?badge) --> +<!-- [](https://www.codetriage.com/monaco-io/request) --> +<!-- [](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) +} +``` + + +### TLS + +```go +package main + +import ( + "log" + "crypto/tls" + + "github.com/monaco-io/request" +) + +func main() { + client := request.Client{ + URL: "https://google.com", + TLSConfig: &tls.Config{InsecureSkipVerify: true}, + } + + resp, err := client.Do() + + log.Println(resp.Code, string(resp.Data), err) +} +``` + +## License + +[MIT](LICENSE) diff --git a/teleirc/matterbridge/vendor/github.com/monaco-io/request/build.go b/teleirc/matterbridge/vendor/github.com/monaco-io/request/build.go new file mode 100644 index 0000000..56323d1 --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/monaco-io/request/build.go @@ -0,0 +1,104 @@ +package request + +import ( + "bytes" + "net/http" + "net/http/cookiejar" + "net/url" + "time" +) + +// TODO: func unit test coverage +func (c *Client) buildRequest() (err error) { + if err = c.applyRequest(); err != nil { + return + } + + c.applyHTTPHeader() + c.applyBasicAuth() + c.applyClient() + c.applyTimeout() + c.applyCookies() + // Apply transport needs to be called before TLSConfig as TLSConfig modifies + // the http transport + c.applyTransport() + c.applyTLSConfig() + err = c.applyProxy() + + c.client.Transport = c.Transport + return +} + +func (c *Client) applyRequest() (err error) { + // encode requestURL.httpURL like https://google.com?hello=world&package=request + c.requestURL = requestURL{ + urlString: c.URL, + parameters: c.Params, + } + if err = c.requestURL.EncodeURL(); err != nil { + return + } + c.req, err = http.NewRequest(c.Method, c.requestURL.string(), bytes.NewReader(c.Body)) + return +} + +func (c *Client) applyHTTPHeader() { + if c.Method == POST { + if c.ContentType == emptyString { + c.ContentType = ApplicationJSON + } + c.req.Header.Set(contentType, string(c.ContentType)) + } + for k, v := range c.Header { + c.req.Header.Add(k, v) + } +} + +func (c *Client) applyBasicAuth() { + if c.BasicAuth.Username != emptyString && c.BasicAuth.Password != emptyString { + c.req.SetBasicAuth(c.BasicAuth.Username, c.BasicAuth.Password) + } +} + +func (c *Client) applyClient() { + c.client = &http.Client{} +} + +func (c *Client) applyTimeout() { + if c.Timeout > 0 { + c.client.Timeout = c.Timeout * time.Second + } +} + +func (c *Client) applyCookies() { + if c.Cookies != nil { + jar, _ := cookiejar.New(nil) + jar.SetCookies(&url.URL{Scheme: c.requestURL.scheme(), Host: c.requestURL.host()}, c.Cookies) + c.client.Jar = jar + } +} + +// TODO: test case +func (c *Client) applyProxy() (err error) { + if c.ProxyURL != emptyString { + var proxy *url.URL + if proxy, err = url.Parse(c.ProxyURL); err != nil { + return + } else if proxy != nil { + c.Transport.Proxy = http.ProxyURL(proxy) + } + } + return +} + +func (c *Client) applyTLSConfig() { + if c.TLSConfig != nil { + c.Transport.TLSClientConfig = c.TLSConfig + } +} + +func (c *Client) applyTransport() { + if c.Transport == nil { + c.Transport = &http.Transport{} + } +} diff --git a/teleirc/matterbridge/vendor/github.com/monaco-io/request/const.go b/teleirc/matterbridge/vendor/github.com/monaco-io/request/const.go new file mode 100644 index 0000000..d7b108f --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/monaco-io/request/const.go @@ -0,0 +1,46 @@ +package request + +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" +) + +const ( + // OPTIONS http options + OPTIONS = "OPTIONS" + + // GET http get + GET = "GET" + + // HEAD http head + HEAD = "HEAD" + + // POST http post + POST = "POST" + + // PUT http put + PUT = "PUT" + + // DELETE http delete + DELETE = "DELETE" + + // TRACE http trace + TRACE = "TRACE" + + // CONNECT http connect + CONNECT = "CONNECT" + + // PATCH http patch + PATCH = "PATCH" +) + +const ( + emptyString = "" + contentType = "Content-Type" +) diff --git a/teleirc/matterbridge/vendor/github.com/monaco-io/request/doc.go b/teleirc/matterbridge/vendor/github.com/monaco-io/request/doc.go new file mode 100644 index 0000000..d225913 --- /dev/null +++ b/teleirc/matterbridge/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/teleirc/matterbridge/vendor/github.com/monaco-io/request/model.go b/teleirc/matterbridge/vendor/github.com/monaco-io/request/model.go new file mode 100644 index 0000000..2a3041e --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/monaco-io/request/model.go @@ -0,0 +1,63 @@ +package request + +import ( + "crypto/tls" + "net/http" + "time" +) + +// ContentType Content-Type +type ContentType string + +// Method http method +// TODO: +type Method 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 + TLSConfig *tls.Config + Transport *http.Transport + + // private + client *http.Client + requestURL requestURL + 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/teleirc/matterbridge/vendor/github.com/monaco-io/request/request.go b/teleirc/matterbridge/vendor/github.com/monaco-io/request/request.go new file mode 100644 index 0000000..6eb45ac --- /dev/null +++ b/teleirc/matterbridge/vendor/github.com/monaco-io/request/request.go @@ -0,0 +1,33 @@ +package request + +import ( + "io/ioutil" + "net/http" +) + +// Do send http request +func (c *Client) Do() (resp SugaredResp, err error) { + defer resp.Close() + + if err = c.buildRequest(); err != nil { + return + } + + // send request and close on func call end + if resp.resp, err = c.client.Do(c.req); err != nil { + return + } + + // read response data form resp + resp.Data, err = ioutil.ReadAll(resp.resp.Body) + resp.Code = resp.resp.StatusCode + return +} + +// 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 + } + return c.client.Do(c.req) +} diff --git a/teleirc/matterbridge/vendor/github.com/monaco-io/request/resp.go b/teleirc/matterbridge/vendor/github.com/monaco-io/request/resp.go new file mode 100644 index 0000000..fb47dd1 --- /dev/null +++ b/teleirc/matterbridge/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/teleirc/matterbridge/vendor/github.com/monaco-io/request/url.go b/teleirc/matterbridge/vendor/github.com/monaco-io/request/url.go new file mode 100644 index 0000000..b49b713 --- /dev/null +++ b/teleirc/matterbridge/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 + } + query := ru.httpURL.Query() + for k := range ru.parameters { + query.Set(k, ru.parameters[k]) + } + ru.httpURL.RawQuery = query.Encode() + return +} + +// 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 +} |
