http

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthTypeCookie = "Cookie"
	AuthTypeOAuth2 = "OAuth 2.0"
)

Variables

View Source
var (
	// ErrHTTPRequest is returned when failed to make a request by http client
	ErrHTTPRequest = errors.New("failed to create a http request")
	// ErrHTTPResponse is returned when failed to receive a response by http client
	ErrHTTPResponse = errors.New("failed to receive a http response")
	// ErrHTTPRespBody is returned when failed to read a http response body
	ErrHTTPRespBody = errors.New("failed to read a http response body")
	// ErrUndefinedAPI is returned when the target API is undefined
	ErrUndefinedAPI = errors.New("target API is undefined")
)

Functions

func NewClient

func NewClient() *http.Client

Types

type AuthData

type AuthData map[string]string

AuthData is data for authentication

type AuthDataset

type AuthDataset map[string]AuthData

AuthDataset is a dataset to store AuthData

func (AuthDataset) NewAuthInfo added in v0.6.0

func (set AuthDataset) NewAuthInfo() []AuthInfo

func (AuthDataset) Select

func (set AuthDataset) Select(auth []string) AuthDataset

type AuthInfo

type AuthInfo interface {
	// contains filtered or unexported methods
}

type Endpoint

type Endpoint struct {
	URL     string            `json:"url"`
	Method  string            `json:"method"`
	Headers map[string]string `json:"headers"`
	Body    json.RawMessage   `json:"body"`
}

Endpoint is for information of a single API endpoint

type Endpoints

type Endpoints map[string]Endpoint

Endpoints is a store for API endpoints

func (Endpoints) GetEndpoint

func (store Endpoints) GetEndpoint(target string) Endpoint

type Request

type Request struct {
	URL     string
	Method  string
	Headers http.Header
	Cookies []*http.Cookie
	Body    string
}

func NewRequest

func NewRequest(ept Endpoint, info []AuthInfo, vbs Variables, ua string) *Request

func (*Request) HTTPRequest

func (req *Request) HTTPRequest() (*http.Request, error)

type Response

type Response struct {
	Body   string
	Status string
}

Response constains status and body of a HTTP Response

func DefaultResponse

func DefaultResponse() *Response

DefaultResponse creates a response with default values

func Send

func Send(req *http.Request, client *http.Client) (*Response, error)

type Variables

type Variables map[string]string

Jump to

Keyboard shortcuts

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