5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 16:20:26 +00:00
matterbridge/vendor/github.com/monaco-io/request
Wim 4dd8bae5c9
Update dependencies (#1610)
* Update dependencies

* Update module to go 1.17
2021-10-17 00:47:22 +02:00
..
.gitignore Add Nextcloud Talk support (#1167) 2020-07-18 16:08:25 +02:00
build.go Update go-nc-talk (nctalk) (#1333) 2020-12-10 00:06:27 +01:00
CODE_OF_CONDUCT.md Add Nextcloud Talk support (#1167) 2020-07-18 16:08:25 +02:00
const.go Add TLSConfig to nctalk (#1195) 2020-08-30 13:49:26 +02:00
CONTRIBUTING.md Add Nextcloud Talk support (#1167) 2020-07-18 16:08:25 +02:00
doc.go Add Nextcloud Talk support (#1167) 2020-07-18 16:08:25 +02:00
LICENSE Add Nextcloud Talk support (#1167) 2020-07-18 16:08:25 +02:00
model.go Update go-nc-talk (nctalk) (#1333) 2020-12-10 00:06:27 +01:00
README.md Add TLSConfig to nctalk (#1195) 2020-08-30 13:49:26 +02:00
request.go Add TLSConfig to nctalk (#1195) 2020-08-30 13:49:26 +02:00
resp.go Add Nextcloud Talk support (#1167) 2020-07-18 16:08:25 +02:00
url.go Add TLSConfig to nctalk (#1195) 2020-08-30 13:49:26 +02:00

Request Mentioned in Awesome Go Go Report Card Go

GoDoc codecov Release TODOs License

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() {
    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

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

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

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

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

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

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