Documentation
¶
Overview ¶
Package tlsclient with a TLS client helper supporting certificate, JWT or Basic authentication
Index ¶
- Constants
- func ConnectTLS(serverURL string, clientCert *tls.Certificate, caCert *x509.Certificate) (*tls.Conn, error)
- func NewHttp2TLSClient(caCert *x509.Certificate, clientCert *tls.Certificate, timeout time.Duration) *http.Client
- func NewRequest(method string, fullURL string, bearerToken string, body []byte) (*http.Request, error)
- type TLSClient
- func (cl *TLSClient) Certificate() *tls.Certificate
- func (cl *TLSClient) Close()
- func (cl *TLSClient) Delete(path string) (resp []byte, httpStatus int, err error)
- func (cl *TLSClient) Get(path string) (resp []byte, httpStatus int, err error)
- func (cl *TLSClient) GetHttpClient() *http.Client
- func (cl *TLSClient) Patch(path string, body []byte) (resp []byte, statusCode int, err error)
- func (cl *TLSClient) Post(path string, body []byte) (resp []byte, statusCode int, err error)
- func (cl *TLSClient) PostForm(path string, formData map[string]string) (resp []byte, statusCode int, err error)
- func (cl *TLSClient) Put(path string, body []byte) (resp []byte, statusCode int, err error)
- func (cl *TLSClient) Send(method string, requrl string, body []byte, contentType string, ...) (resp []byte, httpStatus int, headers http.Header, err error)
- func (cl *TLSClient) SetAuthToken(token string)
- func (cl *TLSClient) SetHeader(name string, val string)
Constants ¶
const DefaultClientTimeout = time.Second * 30
Variables ¶
This section is empty.
Functions ¶
func ConnectTLS ¶
func ConnectTLS(serverURL string, clientCert *tls.Certificate, caCert *x509.Certificate) ( *tls.Conn, error)
ConnectTLS creates a TLS connection to a server, optionally using a client certificate.
serverURL full URL: tls/tcp/tcps://host:8883, wss://host:9001 clientCert to login with. Nil to not use client certs caCert of the server to setup to (recommended). Nil to not verify the server connection.
func NewHttp2TLSClient ¶
func NewHttp2TLSClient(caCert *x509.Certificate, clientCert *tls.Certificate, timeout time.Duration) *http.Client
NewHttp2TLSClient creates a http client setup for http/2
Types ¶
type TLSClient ¶
type TLSClient struct {
// contains filtered or unexported fields
}
TLSClient is a simple TLS Client with authentication using certificates or JWT authentication with login/pw
func NewTLSClient ¶
func NewTLSClient(hostPort string, clientCert *tls.Certificate, caCert *x509.Certificate, timeout time.Duration) *TLSClient
NewTLSClient creates a new TLS Client instance. Use setup/Remove to open and close connections
hostPort is the server hostname or IP address and port to setup to clientCert is an option client certificate used to connect caCert with the x509 CA certificate, nil if not available timeout duration of the request or 0 for default
returns TLS client for submitting requests
func (*TLSClient) Certificate ¶
func (cl *TLSClient) Certificate() *tls.Certificate
Certificate returns the client auth certificate or nil if none is used
func (*TLSClient) Delete ¶
Delete sends a delete message Note that delete methods do not allow a body, or a 405 is returned.
path to invoke
func (*TLSClient) Get ¶
Get is a convenience function to send a request This returns the response data, the http status code and an error of delivery failed
path to invoke
func (*TLSClient) GetHttpClient ¶
GetHttpClient returns the underlying HTTP client
func (*TLSClient) Patch ¶
Patch sends a patch message with json payload If msg is a string then it is considered to be already serialized. If msg is not a string then it will be json encoded.
path to invoke body contains the serialized body
func (*TLSClient) Post ¶
Post a message. If msg is a string then it is considered to be already serialized. If msg is not a string then it will be json encoded.
path to invoke body contains the serialized request body
func (*TLSClient) PostForm ¶
func (cl *TLSClient) PostForm(path string, formData map[string]string) ( resp []byte, statusCode int, err error)
PostForm posts a form message.
func (*TLSClient) Put ¶
Put a message with json payload If msg is a string then it is considered to be already serialized. If msg is not a string then it will be json encoded.
path to invoke body contains the serialized request body correlationID optional field to link async requests and responses
func (*TLSClient) Send ¶
func (cl *TLSClient) Send( method string, requrl string, body []byte, contentType string, qParams map[string]string) ( resp []byte, httpStatus int, headers http.Header, err error)
Send a HTTPS method and read response.
If a JWT authentication is enabled then add the bearer token to the header If msg is a string then it is considered to be already serialized. If msg is not a string then it will be json encoded.
method: GET, PUT, POST, ... url: full URL to invoke body contains the serialized request body contentType: default is "application/json" qParams: optional map with query parameters
This returns the serialized response data, a response message ID, return status code or an error
func (*TLSClient) SetAuthToken ¶
SetAuthToken Sets login ID and secret for bearer token authentication using a token obtained at login or elsewhere.
No error is returned as this just sets up the token for future use. No messages are send yet.