mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-15 00:19:24 +01:00
4dd8bae5c9
* Update dependencies * Update module to go 1.17 |
||
---|---|---|
.. | ||
.gitignore | ||
build.go | ||
CODE_OF_CONDUCT.md | ||
const.go | ||
CONTRIBUTING.md | ||
doc.go | ||
LICENSE | ||
model.go | ||
README.md | ||
request.go | ||
resp.go | ||
url.go |
Request
HTTP client for golang, Inspired by Javascript-axios Python-request. If you have experience about axios or requests, you will love it. No 3rd dependency.
Features
- Make http requests from Golang
- Intercept request and response
- Transform request and response data
Installing
go mod:
go get github.com/monaco-io/request
Methods
- OPTIONS
- GET
- HEAD
- POST
- PUT
- DELETE
- TRACE
- CONNECT
Example
GET
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "GET",
Method: map[string]string{"hello": "world"},
Params}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
POST
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "POST",
Method: map[string]string{"hello": "world"},
Params: []byte(`{"hello": "world"}`),
Body}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
Content-Type
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "POST",
Method: request.ApplicationXWwwFormURLEncoded, // default is "application/json"
ContentType}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
Authorization
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "POST",
Method: request.BasicAuth{
BasicAuth:"user_xxx",
Username:"pwd_xxx",
Password}, // xxx:xxx
}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
Timeout
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "POST",
Method: 10, // seconds
Timeout}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
Cookies
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL:[]*http.Cookie{
Cookies{
: "cookie_name",
Name: "cookie_value",
Value},
},
}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
TLS
package main
import (
"log"
"crypto/tls"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: &tls.Config{InsecureSkipVerify: true},
TLSConfig}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}