gottp

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: MIT Imports: 13 Imported by: 0

README

Gottp Http Client

Gottp is a wrapper over the base http's client functionality written in go, providing additional features like tracing and resilience

Note: This version is built with the github.com/mailru/easyjson package or similar packages in mind and requires for the request and response bodies to implement the IRequest and IResponse interfaces respectively, visit the versions/base branch to see a version that does not rely on this and uses the encoding/* packages instead

Installation

  1. Install module
go get github.com/betalixt/gottp
  1. Import
import "github.com/betalixt/gottp" 

TODO

  • Handle Form Data with files
  • Benchmarking and optimizations
  • Further Documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientOptions added in v0.2.1

type ClientOptions struct {
	Retry RetryPolicy
}

func DefaultOptions added in v0.2.1

func DefaultOptions() *ClientOptions

type HttpClient

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

func NewHttpClientProvider

func NewHttpClientProvider(
	tracer ITracer,
	headers map[string]string,
) *HttpClient

- "Constructors"

func NewHttpClientWithClientProvider added in v0.2.1

func NewHttpClientWithClientProvider(
	client IInternalClient,
	tracer ITracer,
	headers map[string]string,
	tid string,
	pid string,
	flg string,
) *HttpClient

func (*HttpClient) Delete

func (HttpClient *HttpClient) Delete(
	ctx context.Context,
	headers map[string]string,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) DeleteBody

func (HttpClient *HttpClient) DeleteBody(
	ctx context.Context,
	headers map[string]string,
	body IJsonDTO,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) DeleteForm

func (HttpClient *HttpClient) DeleteForm(
	ctx context.Context,
	headers map[string]string,
	form url.Values,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) DeleteXml added in v0.2.2

func (HttpClient *HttpClient) DeleteXml(
	ctx context.Context,
	headers map[string]string,
	body interface{},
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) Get

func (HttpClient *HttpClient) Get(
	ctx context.Context,
	headers map[string]string,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) Patch

func (HttpClient *HttpClient) Patch(
	ctx context.Context,
	headers map[string]string,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) PatchBody

func (HttpClient *HttpClient) PatchBody(
	ctx context.Context,
	headers map[string]string,
	body IJsonDTO,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) PatchForm

func (HttpClient *HttpClient) PatchForm(
	ctx context.Context,
	headers map[string]string,
	form url.Values,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) PatchXml added in v0.2.2

func (HttpClient *HttpClient) PatchXml(
	ctx context.Context,
	headers map[string]string,
	body interface{},
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) Post

func (HttpClient *HttpClient) Post(
	ctx context.Context,
	headers map[string]string,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) PostBody

func (HttpClient *HttpClient) PostBody(
	ctx context.Context,
	headers map[string]string,
	body IJsonDTO,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) PostForm

func (HttpClient *HttpClient) PostForm(
	ctx context.Context,
	headers map[string]string,
	form url.Values,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) PostXml added in v0.2.2

func (HttpClient *HttpClient) PostXml(
	ctx context.Context,
	headers map[string]string,
	body interface{},
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) Put

func (HttpClient *HttpClient) Put(
	ctx context.Context,
	headers map[string]string,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) PutBody

func (HttpClient *HttpClient) PutBody(
	ctx context.Context,
	headers map[string]string,
	body IJsonDTO,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) PutForm

func (HttpClient *HttpClient) PutForm(
	ctx context.Context,
	headers map[string]string,
	form url.Values,
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) PutXml added in v0.2.2

func (HttpClient *HttpClient) PutXml(
	ctx context.Context,
	headers map[string]string,
	body interface{},
	endpoint string,
	qParam map[string][]string,
	params ...string,
) (*Response, error)

func (*HttpClient) WithOptions added in v0.2.1

func (client *HttpClient) WithOptions(
	optn *ClientOptions,
) *HttpClient

type IInternalClient added in v0.2.1

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

type IJsonDTO added in v0.4.1

type IJsonDTO interface {
	MarshalJSON() ([]byte, error)
	UnmarshalJSON([]byte) error
}

type ITracer

type ITracer interface {
	ExtractTraceInfo(
		ctx context.Context,
	) (ver, tid, pid, rid, flg string)
	TraceDependency(
		ctx context.Context,
		spanId string,
		dependencyType string,
		serviceName string,
		commandName string,
		success bool,
		startTimestamp time.Time,
		eventTimestamp time.Time,
		fields map[string]string,
	)
}

type Response

type Response http.Response

func (*Response) Unmarshal

func (resp *Response) Unmarshal(data IJsonDTO) error

func (*Response) UnmarshalXml added in v0.2.2

func (resp *Response) UnmarshalXml(data interface{}) error

type RetryPolicy added in v0.2.1

type RetryPolicy struct {
	Enabled        bool
	RetriableCodes []int
	RetryCount     int
	InitialBackoff time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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