Documentation ¶
Index ¶
- Constants
- type AbstractClient
- type Body
- type Config
- type MockAbstractClient
- func (m *MockAbstractClient) ActiveUserID() int
- func (m *MockAbstractClient) CloseWebsocketConnection() error
- func (m *MockAbstractClient) Delete(ctx context.Context, path string) (*http.Response, error)
- func (m *MockAbstractClient) DialWebsocket(endpoint string) (*websocket.Conn, *http.Response, error)
- func (m *MockAbstractClient) Get(ctx context.Context, path string) (*http.Response, error)
- func (m *MockAbstractClient) GetIPAddress() (string, error)
- func (m *MockAbstractClient) GetToken() string
- func (m *MockAbstractClient) GetURL(protocol ...string) string
- func (m *MockAbstractClient) IsAuthenticated() bool
- func (m *MockAbstractClient) Login(username, password string) error
- func (m *MockAbstractClient) NewRequest(method, path string, body io.Reader) (*http.Request, error)
- func (m *MockAbstractClient) Patch(ctx context.Context, path string, body []byte) (*http.Response, error)
- func (m *MockAbstractClient) Path() string
- func (m *MockAbstractClient) Post(ctx context.Context, path string, body []byte) (*http.Response, error)
- func (m *MockAbstractClient) Put(ctx context.Context, path string, body []byte) (*http.Response, error)
- func (m *MockAbstractClient) ReadFromWebsocket() (int, []byte, error)
- func (m *MockAbstractClient) SetAPIKey(key string)
- func (m *MockAbstractClient) SetToken(token string)
- func (m *MockAbstractClient) WriteToWebsocket(message []byte) error
- type Response
- type ServiceClient
- func (a *ServiceClient) Client() *http.Client
- func (a *ServiceClient) CloseWebsocketConnection() error
- func (a *ServiceClient) Delete(ctx context.Context, path string) (*http.Response, error)
- func (a *ServiceClient) DialWebsocket(endpoint string) (*websocket.Conn, *http.Response, error)
- func (a *ServiceClient) Get(ctx context.Context, path string) (*http.Response, error)
- func (a *ServiceClient) GetAPIKey() string
- func (a *ServiceClient) GetAuthHeader() http.Header
- func (a *ServiceClient) GetIPAddress() (string, error)
- func (a *ServiceClient) GetToken() string
- func (a *ServiceClient) GetURL(protocolInput ...string) string
- func (a *ServiceClient) GetURLWithPath(path string, protocolInput ...string) string
- func (a *ServiceClient) IsAuthenticated() bool
- func (a *ServiceClient) NewRequest(method, path string, body io.Reader) (*http.Request, error)
- func (a *ServiceClient) Patch(ctx context.Context, path string, body []byte) (*http.Response, error)
- func (a *ServiceClient) Path() string
- func (a *ServiceClient) Post(ctx context.Context, path string, body []byte) (*http.Response, error)
- func (a *ServiceClient) Put(ctx context.Context, path string, body []byte) (*http.Response, error)
- func (a *ServiceClient) ReadFromWebsocket() (int, []byte, error)
- func (a *ServiceClient) RoundTrip(req *http.Request) (*http.Response, error)
- func (a *ServiceClient) SetAPIKey(key string)
- func (a *ServiceClient) SetHeader(key string, value string)
- func (a *ServiceClient) SetToken(token string)
- func (a *ServiceClient) WriteToWebsocket(message []byte) error
Constants ¶
const ( APIKeyHeaderKey = "x-api-key" AuthorizationHeaderKey = "Authorization" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AbstractClient ¶
type AbstractClient interface { Path() string GetIPAddress() (string, error) Login(username, password string) error SetAPIKey(key string) SetToken(key string) GetToken() string GetURL(protocol ...string) string IsAuthenticated() bool NewRequest(method, path string, body io.Reader) (*http.Request, error) Get(ctx context.Context, path string) (*http.Response, error) Post(ctx context.Context, path string, body []byte) (*http.Response, error) Put(ctx context.Context, path string, body []byte) (*http.Response, error) Patch(ctx context.Context, path string, body []byte) (*http.Response, error) Delete(ctx context.Context, path string) (*http.Response, error) DialWebsocket(endpoint string) (*websocket.Conn, *http.Response, error) WriteToWebsocket(message []byte) error ReadFromWebsocket() (int, []byte, error) CloseWebsocketConnection() error }
type Config ¶
type Config struct { ServiceConfig urlfinder.ServiceConfig APIKey string Token string TimeoutSeconds int }
Config is a struct that holds the configuration for the ServiceClient
type MockAbstractClient ¶
type MockAbstractClient struct { Lock sync.Mutex NumCalledGetIPAddress int GetIPAddressError error NumCalledGetURL int NumCalledLogin int LoginError error NumCalledSetAPIKey int NumCalledSetToken int Token string NumCalledGetToken int NumCalledIsAuthenticated int NumCalledActiveUserID int NumCalledGet int GetError error NumCalledPost int PostError error NumCalledPut int PutError error NumCalledPatch int PatchError error NumCalledDelete int DeleteError error NumCalledDialWebsocket int DialWebsocketError error NumCalledWriteToWebsocketError int WriteToWebsocketError error NumCalledReadFromWebsocket int ReadFromWebsocketError error NumCalledCloseWebsocket int CloseWebsocketError error Response []byte }
MockAbstractClient is a mock implementation of the AbstractClient interface
func (*MockAbstractClient) ActiveUserID ¶
func (m *MockAbstractClient) ActiveUserID() int
ActiveUserID returns 1
func (*MockAbstractClient) CloseWebsocketConnection ¶
func (m *MockAbstractClient) CloseWebsocketConnection() error
CloseWebsocketConnection increments the number of times it was called and returns an error if provided
func (*MockAbstractClient) Delete ¶
Delete increments the number of times it was called and returns an error if provided
func (*MockAbstractClient) DialWebsocket ¶
func (m *MockAbstractClient) DialWebsocket(endpoint string) (*websocket.Conn, *http.Response, error)
DialWebsocket increments the number of times it was called and returns an error if provided
func (*MockAbstractClient) Get ¶
Get increments the number of times it was called and returns an error if provided
func (*MockAbstractClient) GetIPAddress ¶
func (m *MockAbstractClient) GetIPAddress() (string, error)
GetIPAddress returns an error if provided or localhost
func (*MockAbstractClient) GetToken ¶
func (m *MockAbstractClient) GetToken() string
GetToken returns the token
func (*MockAbstractClient) GetURL ¶
func (m *MockAbstractClient) GetURL(protocol ...string) string
GetURL returns a random URL
func (*MockAbstractClient) IsAuthenticated ¶
func (m *MockAbstractClient) IsAuthenticated() bool
IsAuthenticated returns false
func (*MockAbstractClient) Login ¶
func (m *MockAbstractClient) Login(username, password string) error
Login sets the token to a fake JWT
func (*MockAbstractClient) NewRequest ¶
NewRequest returns a new request
func (*MockAbstractClient) Patch ¶
func (m *MockAbstractClient) Patch(ctx context.Context, path string, body []byte) (*http.Response, error)
Patch increments the number of times it was called and returns an error if provided
func (*MockAbstractClient) Post ¶
func (m *MockAbstractClient) Post(ctx context.Context, path string, body []byte) (*http.Response, error)
Post increments the number of times it was called and returns an error if provided
func (*MockAbstractClient) Put ¶
func (m *MockAbstractClient) Put(ctx context.Context, path string, body []byte) (*http.Response, error)
Put increments the number of times it was called and returns an error if provided
func (*MockAbstractClient) ReadFromWebsocket ¶
func (m *MockAbstractClient) ReadFromWebsocket() (int, []byte, error)
ReadFromWebsocket increments the number of times it was called and returns an error if provided
func (*MockAbstractClient) SetAPIKey ¶
func (m *MockAbstractClient) SetAPIKey(key string)
SetAPIKey increments the number of times it was called
func (*MockAbstractClient) SetToken ¶
func (m *MockAbstractClient) SetToken(token string)
SetToken sets the token to the provided value
func (*MockAbstractClient) WriteToWebsocket ¶
func (m *MockAbstractClient) WriteToWebsocket(message []byte) error
WriteToWebsocket increments the number of times it was called and returns an error if provided
type ServiceClient ¶
type ServiceClient struct {
// contains filtered or unexported fields
}
ServiceClient is a struct that handles generic http client operations
func NewClient ¶
func NewClient(config Config) *ServiceClient
NewClient creates a new ServiceClient given a config struct
func (*ServiceClient) Client ¶
func (a *ServiceClient) Client() *http.Client
Client returns the resty client
func (*ServiceClient) CloseWebsocketConnection ¶
func (a *ServiceClient) CloseWebsocketConnection() error
CloseWebsocketConnection closes the websocket connection.
func (*ServiceClient) DialWebsocket ¶
DialWebsocket creates a new websocket connection to the given endpoint.
func (*ServiceClient) GetAPIKey ¶
func (a *ServiceClient) GetAPIKey() string
GetAPIKey returns the token of the service client
func (*ServiceClient) GetAuthHeader ¶
func (a *ServiceClient) GetAuthHeader() http.Header
GetAuthHeader gets the current auth header of the service client
func (*ServiceClient) GetIPAddress ¶
func (a *ServiceClient) GetIPAddress() (string, error)
GetIPAddress returns the IP address of the client using a get request to httpbin.org/ip
func (*ServiceClient) GetToken ¶
func (a *ServiceClient) GetToken() string
GetToken returns the token of the service client
func (*ServiceClient) GetURL ¶
func (a *ServiceClient) GetURL(protocolInput ...string) string
GetURL returns the url of the service client for the given protocol
func (*ServiceClient) GetURLWithPath ¶
func (a *ServiceClient) GetURLWithPath(path string, protocolInput ...string) string
GetURLWithPath returns the url of the service client with the given path appended
func (*ServiceClient) IsAuthenticated ¶
func (a *ServiceClient) IsAuthenticated() bool
IsAuthenticated returns true if the client is authenticated
func (*ServiceClient) NewRequest ¶
NewRequest returns a new resty request
func (*ServiceClient) Patch ¶
func (a *ServiceClient) Patch(ctx context.Context, path string, body []byte) (*http.Response, error)
Patch makes a PATCH request to the URL
func (*ServiceClient) Path ¶
func (a *ServiceClient) Path() string
Path returns the path of this service client
func (*ServiceClient) ReadFromWebsocket ¶
func (a *ServiceClient) ReadFromWebsocket() (int, []byte, error)
ReadFromWebsocket reads a message from the websocket connection.
func (*ServiceClient) SetAPIKey ¶
func (a *ServiceClient) SetAPIKey(key string)
SetAPIKey sets the token of the service client
func (*ServiceClient) SetHeader ¶
func (a *ServiceClient) SetHeader(key string, value string)
SetHeader sets a header of the service client
func (*ServiceClient) SetToken ¶
func (a *ServiceClient) SetToken(token string)
SetToken sets the token of the service client
func (*ServiceClient) WriteToWebsocket ¶
func (a *ServiceClient) WriteToWebsocket(message []byte) error
WriteToWebsocket writes a message to the websocket connection.