networking

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const PrefixFieldNotFound = "could not find field in map"

PrefixFieldNotFound is what is returned in the error when we cannot find a field in the map

Variables

This section is empty.

Functions

func DownloadFile added in v1.8.0

func DownloadFile(url string, filepath string) error

DownloadFile downloads a URL to a file on the local disk as it downloads it.

func JSONRequest

func JSONRequest(
	httpClient *http.Client,
	method string,
	reqURL string,
	data string,
	headers map[string]string,
	responseData interface{},
	errorKey string,
) error

JSONRequest submits an HTTP web request and parses the response into the responseData object as JSON

func JSONRequestDynamicHeaders added in v1.8.0

func JSONRequestDynamicHeaders(
	httpClient *http.Client,
	method string,
	reqURL string,
	data string,
	headers map[string]HeaderFn,
	responseData interface{},
	errorKey string,
) error

JSONRequestDynamicHeaders submits an HTTP web request and parses the response into the responseData object as JSON

func ParseBool

func ParseBool(m map[string]interface{}, key string, methodAPI string) (bool, error)

ParseBool helps to parse a bool value out of the map

func ParseNumber

func ParseNumber(m map[string]interface{}, key string, methodAPI string) (*model.Number, error)

ParseNumber helps to parse a model.Number value out of the map

func ParseString

func ParseString(m map[string]interface{}, key string, methodAPI string) (string, error)

ParseString helps to parse a string value out of the map

Types

type AuthLevel

type AuthLevel int

AuthLevel specifies the level of authentication needed for an endpoint.

const (
	// NoAuth means that no authentication is required.
	NoAuth AuthLevel = iota
	// GoogleAuth means that a valid Google email is needed to access the endpoint.
	GoogleAuth
)

type Config

type Config struct {
	// PermittedEmails is a map of emails that are allowed access to the endpoints protected by Google authentication
	PermittedEmails map[string]bool
	// GoogleClientID - client ID of the Google application. It should only be left empty if no endpoints require
	// Google authentication
	GoogleClientID string
	// GoogleClientSecret - client secret of the Google application. It should only be left empty if no endpoints require
	// Google authentication
	GoogleClientSecret string
}

Config is a struct storing configuration parameters for the monitoring server.

type Endpoint

type Endpoint interface {
	GetHandlerFunc() http.HandlerFunc
	GetAuthLevel() AuthLevel
	GetPath() string
}

Endpoint represents an API endpoint that implements GetHandlerFunc which returns a http.HandlerFunc specifying the behavior when this endpoint is hit. It's also required to implement GetAuthLevel, which returns the level of authentication that's required to access this endpoint. Currently, the values can be NoAuth or GoogleAuth. Lastly, GetPath returns the path that routes to this endpoint.

type HeaderFn added in v1.8.0

type HeaderFn func(string, string, string) string // (string httpMethod, string requestPath, string body)

HeaderFn represents a function that transforms headers

func MakeHeaderFn added in v1.8.0

func MakeHeaderFn(value string, primaryMappings map[string]HeaderFnFactory) (HeaderFn, error)

MakeHeaderFn is a factory method that makes a HeaderFn

type HeaderFnFactory added in v1.8.0

type HeaderFnFactory func(string) (HeaderFn, error)

HeaderFnFactory is a factory method for the HeaderFn

type WebServer

type WebServer interface {
	StartServer(port uint16, certFile string, keyFile string) error
}

WebServer defines an interface for a generic HTTP/S server with a StartServer function. If certFile and certKey are specified, then the server will serve through HTTPS. StartServer will run synchronously and return a non-nil error.

func MakeServer

func MakeServer(cfg *Config, endpoints []Endpoint) (WebServer, error)

MakeServer creates a WebServer that's responsible for serving all the endpoints passed into it.

Jump to

Keyboard shortcuts

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