Documentation ¶
Index ¶
- Constants
- Variables
- type API
- type Config
- func (s *Config) Auth() string
- func (s *Config) BaseURL() string
- func (s *Config) Get(apiPath string, params url.Values) (*http.Response, error)
- func (s *Config) GetClient(apiPath string, params url.Values, client *http.Client) (*http.Response, error)
- func (s *Config) GetContext(ctx context.Context, apiPath string, params url.Values) (*http.Response, error)
- func (s *Config) GetContextClient(ctx context.Context, api string, params url.Values, client *http.Client) (*http.Response, error)
- func (s *Config) GetXML(apiPath string, params url.Values, v interface{}) error
- func (s *Config) HTTPClient() *http.Client
- func (s *Config) Post(apiPath string, params url.Values, body io.ReadCloser) ([]byte, error)
- func (s *Config) SimpleReq(apiURI string, params url.Values, cameraNum int) error
- func (s *Config) TimeoutDur() time.Duration
- type Duration
Constants ¶
const DefaultTimeout = 10 * time.Second
DefaultTimeout it used for almost every request to SecuritySpy. Adjust as needed.
Variables ¶
var ErrorCmdNotOK = fmt.Errorf("command unsuccessful")
ErrorCmdNotOK is returned for any command that has a successful web request, but the reply does not end with the word OK.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface { Get(apiPath string, params url.Values) (resp *http.Response, err error) GetContext(ctx context.Context, apiPath string, params url.Values) (resp *http.Response, err error) GetContextClient(context.Context, string, url.Values, *http.Client) (resp *http.Response, err error) GetClient(string, url.Values, *http.Client) (resp *http.Response, err error) Post(apiPath string, params url.Values, post io.ReadCloser) (body []byte, err error) GetXML(apiPath string, params url.Values, v interface{}) (err error) SimpleReq(apiURI string, params url.Values, cameraNum int) error TimeoutDur() time.Duration BaseURL() string Auth() string HTTPClient() *http.Client }
API interface is provided only to allow overriding local methods during local testing. The methods in this interface connect to SecuritySpy so they become blockers when testing without a SecuritySpy server available. Overriding them with fakes makes testing (for most methods in this library) possible.
type Config ¶
type Config struct { URL string Password string Username string Client *http.Client // Provide an HTTP client, or: Timeout Duration // Only used if you do not provide an HTTP client. VerifySSL bool // Also only used if you do not provide an HTTP client. }
Config is the input data for this library. Only set VerifySSL to true if your server has a valid SSL certificate. The password is auto-repalced with a base64 encoded string.
func (*Config) GetClient ¶
func (s *Config) GetClient(apiPath string, params url.Values, client *http.Client) (*http.Response, error)
GetClient is the same as Get except you can pass in your own http Client.
func (*Config) GetContext ¶
func (s *Config) GetContext(ctx context.Context, apiPath string, params url.Values) (*http.Response, error)
GetContext is the same as Get except you can pass in your own context.
func (*Config) GetContextClient ¶
func (s *Config) GetContextClient(ctx context.Context, api string, params url.Values, client *http.Client) (*http.Response, error)
GetContextClient is the same as Get except you can pass in your own context and http Client.
func (*Config) HTTPClient ¶
func (*Config) TimeoutDur ¶
TimeoutDur returns the configured timeout.
type Duration ¶
Duration allows you to pass the server Config struct in from a json file.
func (*Duration) UnmarshalText ¶
UnmarshalText parses a duration type from a config file. This method works with the Duration type to allow unmarshaling of durations from files and env variables in the same struct. You won't generally call this directly.