http

package
v0.1.54 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const NO_CONTENT_TYPE string = ""

NO_CONTENT_TYPE -

Variables

View Source
var LargeMultiPartUpload = func(conn ConnAuth, paramName, filename string, fileSize int64, fileRef io.Reader, params map[string]string) (res *http.Response, err error) {
	var req *http.Request
	ms := multipartstreamer.New()

	if params != nil {
		lo.G.Debug("adding params for request: ", params)

		if err = ms.WriteFields(params); err != nil {
			lo.G.Error("writefields error: ", err)
		}
	}

	if fileSize == int64(-1) {
		fileSize = GetFileSize(filename)
	}

	ms.WriteReader(paramName, filename, fileSize, fileRef)
	if req, err = http.NewRequest("POST", conn.Url, nil); err == nil {

		if conn.BearerToken != "" {
			req.Header.Add("Authorization", "Bearer "+conn.BearerToken)

		} else if conn.Username != "" && conn.Password != "" {
			req.SetBasicAuth(conn.Username, conn.Password)
		}
		ms.SetupRequest(req)
		tr := &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		}
		client := &http.Client{Transport: tr}
		res, err = client.Do(req)
	}
	return
}
View Source
var MultiPartUpload = func(conn ConnAuth, paramName, filename string, fileSize int64, fileRef io.Reader, params map[string]string) (res *http.Response, err error) {
	var contentType string
	var rbody io.Reader

	if rbody, contentType, err = MultiPartBody(paramName, filename, fileRef, params); err == nil {
		var req *http.Request

		if req, err = http.NewRequest("POST", conn.Url, rbody); err == nil {

			if conn.BearerToken != "" {
				req.Header.Add("Authorization", "Bearer "+conn.BearerToken)

			} else if conn.Username != "" && conn.Password != "" {
				req.SetBasicAuth(conn.Username, conn.Password)
			}
			req.Header.Set("Content-Type", contentType)
			client := NewTransportClient()
			res, err = client.Do(req)
		}
	}
	return
}

MultiPartUpload -

View Source
var NewHttpGateway = func() HttpGateway {
	return &DefaultHttpGateway{}
}

NewHttpGateway -

View Source
var NewRoundTripper = func() http.RoundTripper {
	return &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
}

NewRoundTripper -

View Source
var NewTransportClient = func() (client interface {
	Do(*http.Request) (*http.Response, error)
}) {
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	client = &http.Client{Transport: tr}
	return
}

NewTransportClient -

Functions

func GetFileSize added in v0.1.39

func GetFileSize(filename string) (fileSize int64)

GetFileSize - gets the filesize of a given path

func MultiPartBody

func MultiPartBody(paramName, filename string, fileRef io.Reader, params map[string]string) (body io.ReadWriter, contentType string, err error)

MultiPartBody -

func Request

func Request(entity HttpRequestEntity, method string, body io.Reader) (response *http.Response, err error)

Request -

Types

type ConnAuth

type ConnAuth struct {
	Url         string
	Username    string
	Password    string
	BearerToken string
}

ConnAuth -

type DefaultHttpGateway

type DefaultHttpGateway struct{}

DefaultHttpGateway -

func (*DefaultHttpGateway) Get

Get -

func (*DefaultHttpGateway) Post

func (gateway *DefaultHttpGateway) Post(entity HttpRequestEntity, body io.Reader) RequestAdaptor

Post -

func (*DefaultHttpGateway) Put

func (gateway *DefaultHttpGateway) Put(entity HttpRequestEntity, body io.Reader) RequestAdaptor

Put -

type HttpRequestEntity

type HttpRequestEntity struct {
	Url           string
	Username      string
	Password      string
	ContentType   string
	Authorization string
}

HttpRequestEntity -

type MultiPartBodyFunc

type MultiPartBodyFunc func(string, string, io.Reader, map[string]string) (io.ReadWriter, string, error)

MultiPartBodyFunc -

type MultiPartUploadFunc

type MultiPartUploadFunc func(conn ConnAuth, paramName, filename string, fileSize int64, fileRef io.Reader, params map[string]string) (res *http.Response, err error)

MultiPartUploadFunc -

type RequestAdaptor

type RequestAdaptor func() (*http.Response, error)

RequestAdaptor -

type RequestFunc

type RequestFunc func(HttpRequestEntity, string, io.Reader) (*http.Response, error)

RequestFunc -

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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