remote

package module
v1.0.2-0...-81b6043 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2021 License: MIT Imports: 6 Imported by: 0

README

Remote Go Reference

Remote is a Golang http request package to make request like POST GET PUT ... on a domain or an API

Installation

To install remote package, you need to install Go and set your Go workspace first.

  1. The first need Go installed (version 1.12+ is required), then you can use the below Go command to install Gin.
$ go get -u github.com/201RichK/remote
  1. Import it in your code:
import "github.com/201R/remote"
  1. Quick start
# assume the following codes in example.go file
$ cat example.go
package main

import (
    "github.com/201R/remote"
    "fmt"
)

func main() {
    //Create new config 
    client := remote.NewRemote(remote.Config{})

    res, err := client.GET(remote.Options{
        URL: "https://google.com",
    })

    if err != nil {
        fmt.Println(err)
    }

    if err := json.NewDecoder(os.Stdout).Decode(res.Body); err != nil {
        fmt.Println(err)
    }
    
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	//add cookie jar on avery request
	Jar http.CookieJar

	//Request time out
	Timeout time.Duration

	//check if there are a script to redirect the request on another URL
	CheckRedirect func(req *http.Request, via []*http.Request) error
}

Config is to set up the client option

type Options

type Options struct {
	//URL to visit
	URL string

	//data(map) to query on a domain
	Query map[string][]string

	//Request header
	Header map[string]string

	//Request body
	Body interface{}
}

Options is to set up the request.

type Remote

type Remote struct {
	// contains filtered or unexported fields
}

Remote Client

func NewRemote

func NewRemote(config Config) *Remote

NewRemote create a client to do a request to a specifique URL

func (*Remote) DELETE

func (remote *Remote) DELETE(config Options) (*http.Response, error)

DELETE Makes DELETE requests on a specific url with the configurations defined in RequestConfig

func (*Remote) GET

func (remote *Remote) GET(config Options) (*http.Response, error)

GET Makes GET requests on a specific url with the configurations defined in RequestConfig

func (*Remote) HEAD

func (remote *Remote) HEAD(config Options) (*http.Response, error)

HEAD Makes HEAD requests on a specific url with the configurations defined in RequestConfig

func (*Remote) PATCH

func (remote *Remote) PATCH(config Options) (*http.Response, error)

PATCH Makes PATCH requests on a specific url with the configurations defined in RequestConfig

func (*Remote) POST

func (remote *Remote) POST(config Options) (*http.Response, error)

POST Makes POST requests on a specific url with the configurations defined in RequestConfig

func (*Remote) PUT

func (remote *Remote) PUT(config Options) (*http.Response, error)

PUT Makes PUT requests on a specific url with the configurations defined in RequestConfig

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL