httpparser

package module
v0.0.2 Latest Latest
Warning

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

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

README

httpwrapper (work in progress)

remote http get wrapper

Build Status - Master
Build Status - Development

Go Report Card

TODO

two timeouts context timeout (http call should be canned if parent context is cancelled) http timeout (session call)
POST/PUT/OPTION

  • implement transport timeout (http.Client.transport)
  • implenent POST, PUT, and multi-part upload
  • implement OPTION
  • implement better JSON validation
  • custom header

Install

Supports Go 1.13 - 1.14.1

Using go modules (aka. go mod)

In your go files, simply use:

import "github.com/Greyeye/httpparser"

Then next go mod tidy or go test invocation will automatically populate your go.mod with the last httpparser release.

Using $GOPATH
go get github.com/Greyeye/httpparser

automatically downloads to $GOPATH/src. Then in your go files use:

import "github.com/Greyeye/httpparser"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPParser

type HTTPParser struct {
	Do func(req *http.Request) (*http.Response, error)
	// contains filtered or unexported fields
}

HTTPParser struct initialiser must define CtxClient...

parser := &httpparser.HttpParser{
			Client: httpClient,
			CtxClient: ctxhttp.Do,
}

overriding ctxhttp package's Do call with "CtxClient" https://github.com/golang/net/blob/master/context/ctxhttp/ctxhttp.go#L23 Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {

func NewHTTPParser

func NewHTTPParser(client *http.Client, timeout time.Duration) *HTTPParser

NewHTTPParser initialise the client. If parameters are not given, it will initialise with the default values.

func (*HTTPParser) HTTPGet

func (h *HTTPParser) HTTPGet(ctx context.Context, req *http.Request) (result []byte, err error)

HTTPGet returns raw HTTP GET body from results.

func (*HTTPParser) JSONParse

func (h *HTTPParser) JSONParse(ctx context.Context, req *http.Request) (*map[string]interface{}, error)

JSONParse returns JSON payload

type HTTPParseriface

type HTTPParseriface interface {
	JSONParse(ctx context.Context, req *http.Request) (*map[string]interface{}, error)
	HTTPGet(ctx context.Context, req *http.Request) (result []byte, err error)
}

HTTPParseriface is used to generate mock interface file under ./mock/

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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