server

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = 10 * time.Second

DefaultTimeout it used for almost every request to SecuritySpy. Adjust as needed.

Variables

View Source
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) Auth

func (s *Config) Auth() string

Auth returns the base64'd auth parameter.

func (*Config) BaseURL

func (s *Config) BaseURL() string

BaseURL returns the URL.

func (*Config) Get

func (s *Config) Get(apiPath string, params url.Values) (*http.Response, error)

Get is a helper function that formats the http request to SecuritySpy.

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) GetXML

func (s *Config) GetXML(apiPath string, params url.Values, v interface{}) error

GetXML returns raw http body, so it can be unmarshaled into an xml struct.

func (*Config) HTTPClient

func (s *Config) HTTPClient() *http.Client

func (*Config) Post

func (s *Config) Post(apiPath string, params url.Values, body io.ReadCloser) ([]byte, error)

Post is a helper function that formats the http request to SecuritySpy.

func (*Config) SimpleReq

func (s *Config) SimpleReq(apiURI string, params url.Values, cameraNum int) error

SimpleReq performes HTTP req, checks for OK at end of output.

func (*Config) TimeoutDur

func (s *Config) TimeoutDur() time.Duration

TimeoutDur returns the configured timeout.

type Duration

type Duration struct {
	time.Duration
}

Duration allows you to pass the server Config struct in from a json file.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) (err error)

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.

Jump to

Keyboard shortcuts

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