ua

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: MIT Imports: 6 Imported by: 1

README

Simple http client

Summary

  • Use tiny Go
  • Require Go version >= 1.10
  • Minimum external dependencies
  • Simple in usage

Install

go get github.com/wmentor/ua

Usage

package main

import (
  "fmt"
  "strings"
  "time"

  "github.com/wmentor/ua"
)

func main() {

  agent := ua.New()

  agent.Timeout = time.Second * 5
  agent.UserAgent = "Mozilla"
  agent.Decode = true // deconde to utf-8

  headers := map[string]string{"X-Request-Id": "12313"}
  data := strings.NewReader("content body")

  resp, err := agent.Request( "POST", "https://someurl.ru", headers, data)

  if err != nil || resp == nil {
    panic("request failed")
  }

  if resp.StatusCode != 200 {
    panic("invalid status code")
  }

  fmt.Println(string(resp.Content))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Timeout   time.Duration
	UserAgent string
	Decode    bool
}

func New

func New() *Client

func (*Client) Request

func (c *Client) Request(method string, url string, headers map[string]string, rd io.Reader) (*Response, error)

type Response

type Response struct {
	StatusCode int
	Content    []byte
	Header     http.Header
}

Jump to

Keyboard shortcuts

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