Documentation ¶
Index ¶
- Constants
- Variables
- func BuildReq(body *[]byte, url string, method string, auth bool) (*http.Request, error)
- func CheckToken() (bool, error)
- func GetToken() (string, error)
- func GetURL(uri string, params ...Parameters) (string, error)
- func ParseReq(resp *http.Response) ([]byte, error)
- type Client
- type Decorator
- type Func
- type Parameters
Constants ¶
const ( LOGDEBUG = iota LOGINFO LOGERROR )
Constants for the request log level. Currently ignored if not LOGINFO.
Variables ¶
var ( LhAddress string // LhAddress: The address of Lighthouse instance (FQDN or IP) LhUsername string // LhUsername: The username for auth. LhPassword string // LhPassword: The password for auth. LhToken string // LhToken: The auth token. LogLevel int // LogLevel: The loglevel, for request logging. )
All variables are retrieved from the config file and set in main routine.
Functions ¶
func BuildReq ¶
BuildReq is a wrapper around the http.NewRequest function that ensures authenticated requests have the expected auth headers, and any http client has the fault tolerance etc added to it.
func CheckToken ¶ added in v0.1.3
CheckToken checks if a token is still valid with the lighthouse instance. Returns true if it's invalid.
func GetToken ¶ added in v0.1.3
GetToken logs into the lighthouse instance and creates an Auth token for subsequent requests.
Types ¶
type Client ¶
Client is an interface with the idea of wrapping an http.Client with extra functionality.
func HTTPClient ¶ added in v0.1.3
func HTTPClient() Client
HTTPClient returns a decorated http client.
type Decorator ¶
Decorator wraps a Client with extra behaviour. Inspired by Tomas Senart (https://www.youtube.com/watch?v=xyDkyFjzFVc)
func IgnoreTLSErr ¶ added in v0.1.3
func IgnoreTLSErr() Decorator
IgnoreTLSErr is a that will prevent http client certificate errors when making an http request with a self-signed cert.
type Parameters ¶
Parameters can be passed to the getURL function if query params are needed. These will be added and the percent-encoded URL will be returned.