Documentation
¶
Index ¶
- Variables
- func FactoryHTTPClient() *http.Client
- func ProxyFactoryHTTPClient(key string) *http.Client
- type Conf
- type Connector
- func (c *Connector) DoWithHeader(method, path string, header *http.Header, body io.Reader, ...) ([]byte, error)
- func (c *Connector) DoWithStatusCheck(req *http.Request, exceptedStatusCode StatusCodeRange) ([]byte, error)
- func (c *Connector) Ping(t int) error
- func (c *Connector) SimpleDelete(path string, body io.Reader) ([]byte, error)
- func (c *Connector) SimpleDo(method, path string, body io.Reader) ([]byte, error)
- func (c *Connector) SimpleGet(path string) ([]byte, error)
- func (c *Connector) SimplePost(path string, body io.Reader) ([]byte, error)
- func (c *Connector) SimplePut(path string, body io.Reader) ([]byte, error)
- type FailRequestError
- type StatusCodeRange
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultStatusRange that encompass most of all success HTTP status code cases. DefaultStatusRange = StatusCodeRange{ Min: http.StatusOK, Max: http.StatusBadRequest, } )
Functions ¶
func FactoryHTTPClient ¶
FactoryHTTPClient returns a fresh new http.Client instance.
func ProxyFactoryHTTPClient ¶
ProxyFactoryHTTPClient creates a new client if it does not exists in `instanciatedClient` map. If the client key is already defined, the function returns the associated client.
Types ¶
type Conf ¶
type Conf struct {
URL string `yaml:"url"` // Base url of the target HTTP server such as https://myserver.com
PingEndpoint string `yaml:"ping_endpoint"` // Path of the ping endpoint of the target HTTP server
}
Conf for the connector. All parameters are required.
type Connector ¶
type Connector struct {
*http.Client // Native http client
URL string // Base url of the target HTTP server such as https://myserver.com
// contains filtered or unexported fields
}
Connector is a supercharged HTTP client. It embeds a native http.Client so it can be used as native client.
func FactoryConnector ¶
FactoryConnector instantiates and returns a *Connector. Call *Connector.Ping() to ensure that the target API is available.
func (*Connector) DoWithHeader ¶
func (c *Connector) DoWithHeader(method, path string, header *http.Header, body io.Reader, exceptedStatusCode StatusCodeRange) ([]byte, error)
DoWithHeader eases the Connector.DoWithStatusCheck use. You have to specify the method, the path, the header, the body, the excepted status range. The excepted status range Min will be included and Max will be excluded.
func (*Connector) DoWithStatusCheck ¶
func (c *Connector) DoWithStatusCheck(req *http.Request, exceptedStatusCode StatusCodeRange) ([]byte, error)
DoWithStatusCheck a HTTP request with the given request. The caller should use Connector.URL as base URL when building the request. You have to provide a status code range to validate if the request was succesfull.
func (*Connector) Ping ¶
Ping sends one ping every 50ms with timeout of t second, it ends if the ping is a success or timeout.
func (*Connector) SimpleDelete ¶
SimpleDelete eases the Connector.SimpleDo use. You have to specify the path and the request body as an io.Reader. The StatusCodeRange use in Connector.DoWithStatusCheck will be DefautStatusRange [200,400[.
func (*Connector) SimpleDo ¶
SimpleDo eases the Connector.SimpleDo use. You have to specify the method, the path and the body as an io.Reader. The StatusCodeRange use in Connector.DoWithStatusCheck will be DefautStatusRange [200,400[.
func (*Connector) SimpleGet ¶
SimpleGet eases the Connector.SimpleDo use. You have to specify the path. The StatusCodeRange use in Connector.DoWithStatusCheck will be DefautStatusRange [200,400[.
func (*Connector) SimplePost ¶
SimplePost eases the Connector.SimpleDo use. You have to specify the path and the request body as an io.Reader. The StatusCodeRange use in Connector.DoWithStatusCheck will be DefautStatusRange [200,400[.
type FailRequestError ¶
func (*FailRequestError) Error ¶
func (e *FailRequestError) Error() string
type StatusCodeRange ¶
StatusCodeRange defines the range of valid status codes. Status codes within the range will be considered as expected codes when received from the target API.