httpclient

package module
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 16 Imported by: 1

Documentation

Overview

Package httpclient provides http client used for SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*gclient.Client
	Handler
}

Client is a http client for SDK.

func New

func New(config Config) *Client

New creates and returns a http client for SDK.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, in, out interface{}) error

Get sends a request using GET method.

func (*Client) Request

func (c *Client) Request(ctx context.Context, req, res interface{}) error

Request sends request to service by struct object `req`, and receives response to struct object `res`.

type Config

type Config struct {
	URL     string          `v:"required"` // Service address. Eg: user.svc.local, http://user.svc.local
	Client  *gclient.Client // Custom underlying client.
	Handler Handler         // Custom response handler.
	Logger  *glog.Logger    // Custom logger.
	RawDump bool            // Whether auto dump request&response in stdout.
}

Config is the configuration struct for SDK client.

type DefaultHandler added in v2.7.1

type DefaultHandler struct {
	Logger  *glog.Logger
	RawDump bool
}

DefaultHandler handle ghttp.DefaultHandlerResponse of json format.

func NewDefaultHandler added in v2.7.1

func NewDefaultHandler(logger *glog.Logger, rawRump bool) *DefaultHandler

func (DefaultHandler) HandleResponse added in v2.7.1

func (h DefaultHandler) HandleResponse(ctx context.Context, res *gclient.Response, out interface{}) error

type Handler added in v2.7.1

type Handler interface {
	// HandleResponse handles the http response and transforms its body to the specified object.
	// The parameter `out` specifies the object that the response body is transformed to.
	HandleResponse(ctx context.Context, res *gclient.Response, out interface{}) error
}

Handler is the interface for http response handling.

Jump to

Keyboard shortcuts

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