client

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

go-http-client

Go Go Report Card PkgGoDev

HTTP Client for Go to ease interaction with web services, especially APIs

Usage example

package main

import (
	"fmt"

	"github.com/pkg/errors"
	ghc "github.com/teran/go-http-client"
)

// FIXME: Change this to your test JSON URL
const testURL = "http://........."

func main() {
	resp := map[string]string{}
	errResp := map[string]string{}
	statusCode, err := ghc.New().
		Base(testURL).
		Get("/json").
		DoJSON(s.ctx, nil, &resp, &errResp)
	if err != nil {
		panic(errors.Wrap(err, fmt.Sprintf("%#v", errResp)))
	}

	fmt.Printf("%#v", resp)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMisconfig            = errors.New("misconfiguration detected")
	ErrUnsupportedMediaType = errors.New("unsupported media type")
)

Functions

This section is empty.

Types

type Client

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

func New

func New() Client

func NewWithHTTPClient

func NewWithHTTPClient(cli *http.Client) Client

func (Client) Auth

func (c Client) Auth(kind, credential string) Client

func (Client) Base

func (c Client) Base(uri string, args ...any) Client

func (Client) BasicAuth

func (c Client) BasicAuth(username, password string) Client

func (Client) Clone

func (c Client) Clone() Client

func (Client) Delete

func (c Client) Delete(path string, args ...any) Client

func (Client) Do

func (c Client) Do(ctx context.Context, body io.Reader) (*http.Response, error)

func (Client) DoJSON

func (c Client) DoJSON(ctx context.Context, body io.Reader, model, errorModel any) (int, error)

func (Client) Get

func (c Client) Get(path string, args ...any) Client

func (Client) Head

func (c Client) Head(path string, args ...any) Client

func (Client) Header

func (c Client) Header(name, value string) Client

func (Client) Options

func (c Client) Options(path string, args ...any) Client

func (Client) Post

func (c Client) Post(path string, args ...any) Client

func (Client) Put

func (c Client) Put(path string, args ...any) Client

func (Client) QueryParam

func (c Client) QueryParam(key, value string) Client

func (Client) Request

func (c Client) Request(method, path string, args ...any) Client

func (Client) UserAgent

func (c Client) UserAgent(name string) Client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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