common

package module
v0.0.0-...-57e0f59 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: Apache-2.0 Imports: 21 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsPrintable

func AsPrintable(p *swan.Pair) string

AsPrintable gets the value of the pair as a printable string for display.

func AsString

func AsString(p *swan.Pair) string

AsString gets the value of the pair as string for display.

func AsStringFromUUID

func AsStringFromUUID(p *swan.Pair) string

func GetCleanURL

func GetCleanURL(c *Configuration, r *http.Request) *url.URL

GetCleanURL returns a URL with the SWAN data removed and no query string parameters.

func GetConfigFile

func GetConfigFile(folder string) *os.File

GetConfig returns the configuration from the folder, or nil if the configuration does not exist.

func GetCurrentPage

func GetCurrentPage(c *Configuration, r *http.Request) *url.URL

GetCurrentPage returns the current request URL.

func GetReturnURL

func GetReturnURL(r *http.Request) (*url.URL, error)

GetReturnURL returns a parsed URL from the query string, or if not present from the referer HTTP header.

func GetSWANDataFromRequest

func GetSWANDataFromRequest(r *http.Request) string

GetSWANDataFromRequest returns the base 64 SWAN data from the request if present, otherwise an empty string.

func Handler

func Handler(d []*Domain) http.HandlerFunc

Handler for all HTTP requests to domains controlled by the demo.

func HandlerHTML

func HandlerHTML(d *Domain, w http.ResponseWriter, r *http.Request)

HandlerHTML returns HTML that does not require a model for the template.

func NewError

func NewError(c *Configuration, r *http.Response) *swan.Error

NewError creates an error instance that includes the details of the response returned. This is needed to pass the correct status codes and context back to the caller.

func OWIDDate

func OWIDDate(p *swan.Pair) string

OWIDDate returns the creator domain of the ID.

func OWIDDomain

func OWIDDomain(p *swan.Pair) string

OWIDDomain returns the creator domain of the ID.

func ReturnProxyError

func ReturnProxyError(c *Configuration, w http.ResponseWriter, e *swan.Error)

ReturnProxyError returns an error where the request is related to a proxy request being passed to another end point.

func ReturnServerError

func ReturnServerError(c *Configuration, w http.ResponseWriter, err error)

ReturnServerError returns an internal server error.

func ReturnStatusCodeError

func ReturnStatusCodeError(
	c *Configuration,
	w http.ResponseWriter,
	e error,
	code int)

ReturnStatusCodeError returns the HTTP status code specified.

Types

type Advert struct {
	MediaURL      string // The URL of the content of the advert provided in response
	AdvertiserURL string // The URL to direct the browser to if the advert is selected
}

Advert represents an advert to display on a publishers web page.

type Configuration

type Configuration struct {
	AccessKeys []string  `json:"accessKeys"` // Array of valid keys for SWAN access
	Scheme     string    `json:"scheme"`     // The scheme to use for requests
	Debug      bool      `json:"debug"`      // True if debug HTML output should be provided
	Domains    []*Domain // All the domains that form the demo
	// contains filtered or unexported fields
}

Configuration maps to the appsettings.json settings file.

func NewConfig

func NewConfig(settingsFile string) Configuration

NewConfig creates a new instance of configuration from the file provided.

type Domain

type Domain struct {
	Category                 string // Category of the domain
	Name                     string // Common name for the domain
	Bad                      bool   // True if this domain is a bad actor for the demo
	Host                     string // The host name for the domain
	SwanMessage              string // Message if used with SWAN
	SwanBackgroundColor      string // Background color if used with SWAN
	SwanMessageColor         string // Message text color if used with SWAN
	SwanProgressColor        string // Message progress color if used with SWAN
	SwanPostMessage          bool   // True if the publisher gets the results from SWAN as a post message
	SwanDisplayUserInterface bool   // True to display the user interface
	SwanUseHomeNode          bool   // True to use the home node if it has current data
	SwanJavaScript           bool   // True to use JavaScript responses rather than HTML documents
	SwanNodeCount            int    // The number of SWAN nodes to use for operations
	CmpNodeCount             int    // The number of nodes to visit when accessing the CMP
	Default                  bool   // True to indicate the default domain
	// The domain of the access node used with SWAN (only set for CMPs)
	SWANAccessNode string
	SWANAccessKey  string // The access key to use when communicating with SWAN.
	// The domain of the CMP that will in turn access the SWAN Network via an Operator
	CMP       string
	Suppliers []string       // Suppliers used by the domain operator
	Adverts   []Advert       // Adverts the domain can serve
	Config    *Configuration // Configuration for the server
	// contains filtered or unexported fields
}

Domain represents the information held in the domain configuration file commonly represented in the demo in config.json.

func NewDomain

func NewDomain(
	c *Configuration,
	folder string,
	configFile *os.File) (*Domain, error)

NewDomain creates a new instance of domain information from the file provided.

func (*Domain) GetOWIDCreator

func (d *Domain) GetOWIDCreator() (*owid.Creator, error)

GetOWIDCreator returns the OWID creator from the OWID store for the the domain.

func (*Domain) LookupHTML

func (d *Domain) LookupHTML(p string) *template.Template

LookupHTML based on the templates available to the domain.

func (*Domain) SWAN

func (d *Domain) SWAN() *swan.Connection

func (*Domain) SetHandler

func (d *Domain) SetHandler(fn func(
	d *Domain,
	w http.ResponseWriter,
	r *http.Request))

SetHandler adds a HTTP handler to the domain.

type PageModel

type PageModel struct {
	Domain *Domain // The domain associated with the request
	// The request that relates to the page request with the ParseForm method complete
	Request *http.Request
}

PageModel used as the base for models used with HTML templates.

func (PageModel) Config

func (m PageModel) Config() *Configuration

Config returns the domain configuration.

func (PageModel) HttpHeaders

func (m PageModel) HttpHeaders() []string

HttpHeaders available in the request.

func (PageModel) IsCrawler

func (m PageModel) IsCrawler() (bool, error)

IsCrawler returns true if the browser is a crawler, otherwise false.

func (PageModel) PreferencesDialogURL

func (m PageModel) PreferencesDialogURL() (string, error)

PreferencesDialogURL returns the URL to display the preferences dialog.

func (PageModel) SupportsHTTPS

func (m PageModel) SupportsHTTPS() bool

SupportsHTTPS returns true if the server supports HTTPS.

type SMTP

type SMTP struct {
	Sender   string
	Host     string
	Port     string
	Password string
}

func NewSMTP

func NewSMTP() *SMTP

func (*SMTP) Send

func (s *SMTP) Send(
	email string,
	subject string,
	emailTemplate *template.Template,
	data interface{}) error

Jump to

Keyboard shortcuts

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