xhttp

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

README

const Timeout = 6 * time.Second const ApiFindUserById = Root + "/twirp/user.v1.User/FindUserById"

params := struct {
	Id int64 `json:"id"`
}{
	Id: id,
}
b, _ := json.Marshal(params)

req, _ := http.NewRequest(http.MethodPost, frame.ApiFindUserById, bytes.NewReader(b))

resp, err := httpD.NewClient(frame.Timeout).Do(ctx, req)
fmt.Println(resp)
if err != nil {
	return
}
if resp.StatusCode != 200 {
	return u, errors.New("请求失败")
}

respBody, _ := ioutil.ReadAll(resp.Body)
_ = json.Unmarshal(respBody, &u)

Documentation

Overview

Package xhttp 提供基础 http 客户端组件 内置以下功能: - logging - opentracing - prometheus

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	// Do 发送单个 http 请求
	Do(ctx context.Context, req *http.Request) (*http.Response, error)
}

Client http 客户端接口

func NewClient

func NewClient(timeout time.Duration) Client

NewClient 创建 Client 实例

Jump to

Keyboard shortcuts

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