httpdrv

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2020 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package httpdrv defines two http based drivers.

Both drivers send notification to endpoint

Index

Constants

View Source
const GET = "HTTPGET"

GET is driver type of HTTPGet()

View Source
const POST = "HTTPPOST"

POST is driver type of HTTPPost()

Variables

This section is empty.

Functions

func DefaultValidator

func DefaultValidator(code int, headers http.Header, body []byte) (err error)

DefaultValidator determines http status code is 2xx, or error is returned

func HTTPGet

func HTTPGet(cl *http.Client, v Validator) (ret types.Driver)

HTTPGet creates a driver that delivers notification via HTTP GET

func HTTPPost

func HTTPPost(cl *http.Client, v Validator) (ret types.Driver)

HTTPPost creates a driver that delivers notification via HTTP POST

Types

type GetMsg

type GetMsg struct {
	// additional headers to send
	Headers http.Header `json:"headers,omitempty"`
	// url query string to send. the value is encoded and appended to endpoint
	Values url.Values `json:"values,omitempty"`
}

GetMsg defines driver specific parameters for HTTPGet()

type PostMsg

type PostMsg struct {
	// additional header to send
	Headers http.Header `json:"headers"`
	// post body
	Body []byte `json:"body"`
}

PostMsg defines driver specific parameters for HTTPPost()

func FormPostMsg

func FormPostMsg(val url.Values) (ret *PostMsg)

func JSONPostMsg

func JSONPostMsg(i interface{}) (ret *PostMsg, err error)

type Validator

type Validator func(code int, headers http.Header, body []byte) (err error)

Validator defines user-provided function to determine if response is success or failed.

func StringValidator

func StringValidator(str string) (ret Validator)

StringValidator creates a Validator which determines response body begins with specified string, or error is returned

Jump to

Keyboard shortcuts

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