http

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 9 Imported by: 0

README

go-utils Http

The go-utils Http package provides handy methods to use api end points using http protocol.

Installation

To use the log package you must import the package.

import "github.com/eliona-smart-building-assistant/go-utils/http"

Usage

After installation, you can read payload from http end points.

import "github.com/eliona-smart-building-assistant/go-utils/http"

For example, you can make a request and read current weather conditions from this endpoint.

payload, err := http.Read(http.NewRequest("https://weatherdbi.herokuapp.com/data/weather/winterthur"), 10, true)
var result map[string]interface{}
_ = json.Unmarshal(payload, &result)
fmt.Printf(result["currentConditions"].(map[string]interface{})["comment"].(string))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(request *http.Request, timeout time.Duration, checkCertificate bool) ([]byte, error)

Do return the payload returned from the request

func NewPostRequest

func NewPostRequest(url string, body any) (*http.Request, error)

NewPostRequest creates a new request for the given url and the body as payload. The url have to provide free access without any authentication. For authentication use other functions like NewPostRequestWithBearer.

func NewPostRequestWithBearer

func NewPostRequestWithBearer(url string, body any, token string) (*http.Request, error)

NewPostRequestWithBearer creates a new request for the given url. The url have is authenticated with a barrier token.

func NewPutRequest

func NewPutRequest(url string, body any) (*http.Request, error)

NewPutRequest creates a new request for the given url and the body as payload. The url have to provide free access without any authentication. For authentication use other functions like NewPutRequestWithBearer.

func NewPutRequestWithBearer

func NewPutRequestWithBearer(url string, body any, token string) (*http.Request, error)

NewPutRequestWithBearer creates a new request for the given url. The url have is authenticated with a barrier token.

func NewRequest

func NewRequest(url string) (*http.Request, error)

NewRequest creates a new request for the given url. The url have to provide free access without any authentication. For authentication use other functions like NewGetRequestWithBarrier.

func NewRequestWithBearer

func NewRequestWithBearer(url string, token string) (*http.Request, error)

NewRequestWithBearer creates a new request for the given url. The url have is authenticated with a barrier token.

func Read

func Read[T any](request *http.Request, timeout time.Duration, checkCertificate bool) (T, error)

Read returns the response data converted to a corresponding structure

Types

This section is empty.

Jump to

Keyboard shortcuts

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