http

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 25, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

http_client

package main

import (
    "github.com/joshqu1985/fireman/transport/http"
)

var (
    xclient *http.Client
)

func init() {
    xclient = http.NewClient()
}

func main() {
    r, err := http.NewRequester("GET", url, []byte{})
    if err != nil {
        fmt.Println(err)
    }

    bytes, err := r.Do(ctx, xclient, 500*time.Millisecond)
    if err != nil {
        fmt.Println(err)
    }

    response := &Response{}
    if err = json.Unmarshal(bytes, response); err != nil {
        fmt.Println(err)
    }

    if response.ErrCode != 0 {
        fmt.Println(response.ErrMsg)
    }
    return nil
}

Documentation

Index

Constants

View Source
const (
	DefaultMaxConns            = 1024
	DefaultMaxConnsPerHost     = 256
	DefaultMaxIdleConnDuration = time.Duration(10) * time.Second
	DefaultTimeout             = time.Duration(10) * time.Second
)

Variables

This section is empty.

Functions

func StartHttpSpan

func StartHttpSpan(ctx context.Context, req *http.Request) opentracing.Span

func Trace

func Trace(tracer opentracing.Tracer) gin.HandlerFunc

Trace gin middleware

Types

type Client

type Client = http.Client

func NewClient

func NewClient() *Client

type Requester

type Requester struct {
	*http.Request
}

func NewRequester

func NewRequester(method, host string, data []byte) (*Requester, error)

func (*Requester) Do

func (r *Requester) Do(ctx context.Context, client *http.Client, tm time.Duration) ([]byte, error)

func (*Requester) SetHeaders

func (r *Requester) SetHeaders(headers map[string]string)

Jump to

Keyboard shortcuts

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