http

package
v0.0.0-...-a53416d Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 5 Imported by: 0

README

HTTP package

Why this package exists, what problems does it solve?

TODO

Explain common utility layer for making http requests.

What are the alternatives? Maybe internal/utilities/http? I don't think so. We need http utilities only in context of adapters! Adapters is the right place, why weather and incidents are inside http? Because they build on top of this package + net/http!

Things to note:

  • closing response body is important while doing http request. Look at this code, there's only one place we do actual requests! So there's only one place to check if we do them properly!

Why Doer interface?

TODO

Explain in context of testing.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetJSON

func GetJSON(
	ctx context.Context,
	doer Doer,
	timeout time.Duration,
	url string,
	result interface{},
) error

GetJSON fetches json data using HTTP GET request. Json from response is unmarshalled to the `result` object (it usually should be a pointer!).

Types

type Doer

type Doer interface {
	Do(*http.Request) (*http.Response, error)
}

Doer is a utility interface. It's implemented by http.Client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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