{"modulePath":"github.com/JacobMoxham/PartIIProjectImplementation","version":"v0.0.0-20190516140124-028b8ad327b1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package middleware\n\n## Functions\n\n```go\nfunc PolicyAwareHandler(policy ComputationPolicy) http.HandlerFunc\n```\nPolicyAwareHandler returns a http.Handler based on the passed ComputationPolicy. It also performs some basic logging of requests received.\n\n## Types\n\n```go\ntype ColumnTransform func(interface{}) (transformedValue interface{}, excludeRow bool, err error)\n```\n\n```go\ntype ComputationLevel int\n```\nComputationLevel specifies whether a handler for a http request can compute no globalResult, just provide the raw data or compute a full globalResult\n\n```go\nconst (\n\tNoComputation ComputationLevel = iota\n\tRawData       ComputationLevel = iota\n\tCanCompute    ComputationLevel = iota\n)\n```\n\n```go\nfunc ComputationLevelFromString(level string) (ComputationLevel, error)\n```\nComputationLevelFromString converts a string to the relevant ComputationLevel\n\n```go\nfunc (c ComputationLevel) ToString() string\n```\nToString converts from a ComputationLevel to the relevant string\n\n```go\ntype ComputationPolicy interface {\n\tRegister(string, ComputationLevel, http.Handler)\n\tUnregisterAll(string)\n\tUnregisterOne(string, ComputationLevel)\n\tResolve(string, ProcessingLocation) (ComputationLevel, http.Handler)\n}\n```\nComputationPolicy stores the computation capabilities of a node\n\n```go\ntype DataPolicy interface {\n\t// resolve takes an identifier for an entity and returns the TableOperatoinsg for the entity\n\tResolve(string) (*TableOperations, error)\n\tLastUpdated() time.Time\n}\n```\nDataPolicy allow us to get a function which must be applied to data before returning for a given identifier\n\n```go\ntype DataTransforms map[*PrivacyGroup]*TableOperations\n```\ntransforms is a map from privacyGroups to TableOperations\n\n```go\ntype DynamicComputationPolicy struct {\n\t// contains filtered or unexported fields\n}\n```\nDynamicComputationPolicy holds a set of computation capabilities for paths, these must be set manually\n\n```go\nfunc NewDynamicComputationPolicy() *DynamicComputationPolicy\n```\nNewDynamicComputationPolicy returns a pointer to a DynamicComputationPolicy with an empty, initialised internal map\n\n```go\nfunc (p *DynamicComputationPolicy) Activate(path string, level ComputationLevel) error\n```\nActivate marks a handler for a specific request path and computation level as active and hence it will appear as registered\n\n```go\nfunc (p *DynamicComputationPolicy) Deactivate(path string, level ComputationLevel) error\n```\nDeactivate marks the handler for a specific request path and computation level as deactivated which means it will appear not be registered but can easily be re-activated with a call to Activate\n\n```go\nfunc (p *DynamicComputationPolicy) Register(path string, level ComputationLevel, handler http.Handler)\n```\nRegister adds a capability for a path at a specific ComputationLevel\n\n```go\nfunc (p *DynamicComputationPolicy) Resolve(path string, preferredLocation ProcessingLocation) (ComputationLevel, http.Handler)\n```\nResolve takes a path and preferred processing location and returns a handler and the computation level which that handler provides. It does this based on the capabilities for this path registered with the StaticComputationPolicy. The preferred processing location is used to break ties when we can offer full computation and raw data.\n\n```go\nfunc (p *DynamicComputationPolicy) UnregisterAll(path string)\n```\nUnregisterAll removes all capabilities for a path\n\n```go\nfunc (p *DynamicComputationPolicy) UnregisterOne(path string, level ComputationLevel)\n```\nUnregisterOne removes a capability for a path at a specific computation level\n\n```go\ntype MySQLPrivateDatabase struct {\n\tDataPolicy  DataPolicy\n\tCacheTables bool\n\t// contains filtered or unexported fields\n}\n```\nMySQLPrivateDatabase is a wrapper around a MySQL database which implements the PrivateRelationalDatabase interface, it supports DataPolicies which specify transforms for columns and excluded columns on a per PrivacyGroup basis\n\n```go\nfunc (mspd *MySQLPrivateDatabase) Close() error\n```\nClose closes the connection to the MySQL database\n\n```go\nfunc (mspd *MySQLPrivateDatabase) Connect(user, password, databaseName, uri string, port int) error\n```\nConnect opens the connection to the MySQL database\n\n```go\nfunc (mspd *MySQLPrivateDatabase) Exec(query string, requestPolicy *RequestPolicy, args ...interface{}) (sql.Result, error)\n```\nExec takes a query string and a RequestPolicy and resolves the DataPolicy from the MySQLPrivateDatabase with the request policy to give a globalResult to the query on transformed versions of the actual database tables\n\n```go\nfunc (mspd *MySQLPrivateDatabase) ExecContext(ctx context.Context, query string, requestPolicy *RequestPolicy, args ...interface{}) (sql.Result, error)\n```\nExecContext takes a query string and a RequestPolicy and resolves the DataPolicy from the MySQLPrivateDatabase with the request policy to give a globalResult to the query on transformed versions of the actual database tables\n\n```go\nfunc (mspd *MySQLPrivateDatabase) Ping() error\n```\nPing verifies a connection to the database is still alive, establishing a connection if necessary.\n\n```go\nfunc (mspd *MySQLPrivateDatabase) PingContext(ctx context.Context) error\n```\nPingContext verifies a connection to the database is still alive, establishing a connection if necessary.\n\n```go\nfunc (mspd *MySQLPrivateDatabase) Query(query string, requestPolicy *RequestPolicy, args ...interface{}) (*sql.Rows, error)\n```\nQuery takes a query string and a RequestPolicy and resolves the DataPolicy from the MySQLPrivateDatabase with the request policy to give a globalResult to the query on transformed versions of the actual database tables\n\n```go\nfunc (mspd *MySQLPrivateDatabase) QueryContext(ctx context.Context, query string, requestPolicy *RequestPolicy, args ...interface{}) (*sql.Rows, error)\n```\nQueryContext takes a query string and a RequestPolicy and resolves the DataPolicy from the MySQLPrivateDatabase with the request policy to give a globalResult to the query on transformed versions of the actual database tables\n\n```go\nfunc (mspd *MySQLPrivateDatabase) QueryRow(query string, requestPolicy *RequestPolicy, args ...interface{}) (*sql.Row, error)\n```\nQueryRow takes a query string and a RequestPolicy and resolves the DataPolicy from the MySQLPrivateDatabase with the // request policy to give a globalResult to the query on transformed versions of the actual database tables\n\n```go\nfunc (mspd *MySQLPrivateDatabase) QueryRowContext(ctx context.Context, query string, requestPolicy *RequestPolicy, args ...interface{}) (*sql.Row, error)\n```\nQueryRowContext takes a query string and a RequestPolicy and resolves the DataPolicy from the MySQLPrivateDatabase with the request policy to give a globalResult to the query on transformed versions of the actual database tables\n\n```go\nfunc (mspd *MySQLPrivateDatabase) SetConnMaxLifetime(d time.Duration)\n```\nSetConnMaxLifetime sets the maximum amount of time a connection may be reused.\n\nExpired connections may be closed lazily before reuse.\n\nIf d \\\u003c= 0, connections are reused forever.\n\n```go\nfunc (mspd *MySQLPrivateDatabase) SetMaxIdleConns(n int)\n```\nSetMaxIdleConns sets the maximum number of connections in the idle connection pool.\n\nIf MaxOpenConns is greater than 0 but less than the new MaxIdleConns, then the new MaxIdleConns will be reduced to match the MaxOpenConns limit.\n\nIf n \\\u003c= 0, no idle connections are retained.\n\nThe default max idle connections is currently 2. This may change in a future release.\n\n```go\nfunc (mspd *MySQLPrivateDatabase) SetMaxOpenConns(n int)\n```\nSetMaxOpenConns sets the maximum number of open connections to the database.\n\nIf MaxIdleConns is greater than 0 and the new MaxOpenConns is less than MaxIdleConns, then MaxIdleConns will be reduced to match the new MaxOpenConns limit.\n\nIf n \\\u003c= 0, then there is no limit on the number of open connections. The default is 0 (unlimited).\n\n```go\nfunc (mspd *MySQLPrivateDatabase) Stats() sql.DBStats\n```\nStats returns database statistics\n\n```go\ntype PamRequest struct {\n\tPolicy      *RequestPolicy\n\tHttpRequest *http.Request\n}\n```\nPamRequest contains a RequestPolicy and a http request\n\n```go\nfunc BuildPamRequest(req *http.Request) (PamRequest, error)\n```\nBuildPamRequest takes a pointer to a http request and returns a PamRequest with policy values taken from the parameters of the passed request\n\n```go\nfunc (r *PamRequest) AddParam(key, value string)\n```\nAddParam adds a parameter to the contained http request with the same semantics as adding to the URL.Values of the http request\n\n```go\nfunc (r *PamRequest) DelParam(key string)\n```\nAddParam deletes a parameter from the contained http request with the same semantics as adding to the URL.Values of the http request\n\n```go\nfunc (r *PamRequest) GetParam(key string) string\n```\nAddParam gets a parameter from the contained http request with the same semantics as adding to the URL.Values of the http request\n\n```go\nfunc (r *PamRequest) SetParam(key, value string)\n```\nAddParam sets a parameter on the contained http request with the same semantics as adding to the URL.Values of the http request\n\n```go\ntype PamResponse struct {\n\tComputationLevel ComputationLevel\n\tHttpResponse     *http.Response\n}\n```\nPamResponse contains a http response and its associated computation level\n\n```go\nfunc BuildPamResponse(resp *http.Response) (PamResponse, error)\n```\nBuildPamResponse takes a pointer to a http response and returns a PamResponse with the ComputationLevel taken from the response header\n\n```go\ntype PolicyAwareClient struct {\n\t// contains filtered or unexported fields\n}\n```\nPolicyAwareClient wraps a http client with a ComputationPolicy\n\n```go\nfunc MakePolicyAwareClient(policy ComputationPolicy) PolicyAwareClient\n```\nMakePolicyAwareClient returns an PolicyAwareClient with initialised fields\n\n```go\nfunc (c PolicyAwareClient) Send(req PamRequest) (PamResponse, error)\n```\nSend takes a PamRequest and martials the RequestPolicy into the http request parameters before sending it using the contained http client. If the ComputationPolicy has a local handler for the requested path, and the preferred location is local, and all of the data required for a globalResult is contained within the request then the request will instead be handled locally.\n\n```go\ntype PrivacyGroup struct {\n\t// contains filtered or unexported fields\n}\n```\nPrivacyGroup a struct which contain a data structure of RequesterID's which we can Add to and Remove from\n\n```go\nfunc NewPrivacyGroup(name string) *PrivacyGroup\n```\n\n```go\nfunc (pg *PrivacyGroup) Add(id string)\n```\n\n```go\nfunc (pg *PrivacyGroup) AddMany(ids []string)\n```\n\n```go\nfunc (pg *PrivacyGroup) Name() string\n```\n\n```go\nfunc (pg *PrivacyGroup) Remove(id string) error\n```\n\n```go\ntype PrivateRelationalDatabase interface {\n\tConnect(user, password, databaseName, uri string, port int) error\n\tClose() error\n\tQuery(query string, requestPolicy *RequestPolicy, args ...interface{}) (*sql.Rows, error)\n\tQueryContext(ctx context.Context, query string, requestPolicy *RequestPolicy, args ...interface{}) (*sql.Rows, error)\n\tQueryRow(query string, requestPolicy *RequestPolicy, args ...interface{}) (*sql.Row, error)\n\tQueryRowContext(ctx context.Context, query string, requestPolicy *RequestPolicy, args ...interface{}) (*sql.Row, error)\n\tExec(ctx context.Context, query string, requestPolicy *RequestPolicy, args ...interface{}) (sql.Result, error)\n\tExecContext(ctx context.Context, query string, requestPolicy *RequestPolicy, args ...interface{}) (sql.Result, error)\n\tStats() sql.DBStats\n\tSetConnMaxLifetime(d time.Duration)\n\tSetMaxOpenConns(n int)\n\tSetMaxIdleConns(n int)\n\tPing() error\n\tPingContext(ctx context.Context) error\n}\n```\nPrivateRelationalDatabase wraps an SQL database and edits queries so that they operate over tables adjusted to match privacy policies\n\n```go\ntype ProcessingLocation string\n```\nProcessingLocation refers to either local or remote computation over data\n\n```go\nconst (\n\t// Specified if the request should ideally be executed locally and never leave the device\n\tLocal ProcessingLocation = \"local\"\n\t// Specified if the returned data would ideally be unprocessed\n\tRemote ProcessingLocation = \"remote\"\n)\n```\n\n```go\nfunc ProcessingLocationFromString(loc string) (ProcessingLocation, error)\n```\nProcessingLocationFromString converts from a string to the relevant ProcessingLocation\n\n```go\nfunc (p ProcessingLocation) ToString() string\n```\nToString coverts from a ProcessingLocation to the relevant string\n\n```go\ntype RequestPolicy struct {\n\tRequesterID                 string\n\tPreferredProcessingLocation ProcessingLocation\n\tHasAllRequiredData          bool\n}\n```\nRequestPolicy stores the preferred location for processing of a request (and the identity of the requester?)\n\n```go\nfunc BuildRequestPolicy(req *http.Request) (*RequestPolicy, error)\n```\nBuildRequestPolicy takes a http request and extracts the values for a RequestPolicy from its parameters\n\n```go\nfunc (p *RequestPolicy) AddToParams(params *url.Values)\n```\nAddToParams adds each of its fields as a parameter in the passed Values struct\n\n```go\ntype StaticComputationPolicy struct {\n\t// contains filtered or unexported fields\n}\n```\nStaticComputationPolicy holds a map from http request paths to computation capabilities which dictate which handlers can be used for the request. A handler can be specified for returning a full globalResult (CanCompute) or just the raw data (RawData)\n\n```go\nfunc NewStaticComputationPolicy() *StaticComputationPolicy\n```\nNewStaticComputationPolicy returns a pointer to an initialised StaticComputationPolicy\n\n```go\nfunc (p *StaticComputationPolicy) Register(path string, level ComputationLevel, handler http.Handler)\n```\nRegister adds a capability for a path at a specific ComputationLevel\n\n```go\nfunc (p *StaticComputationPolicy) Resolve(path string, preferredLocation ProcessingLocation) (ComputationLevel, http.Handler)\n```\nResolve takes a path and preferred processing location and returns a handler and the computation level which that handler provides. It does this based on the capabilities for this path registered with the StaticComputationPolicy. The preferred processing location is used to break ties when we can offer full computation and raw data.\n\n```go\nfunc (p *StaticComputationPolicy) UnregisterAll(path string)\n```\nUnregisterAll removes all capabilities for a path\n\n```go\nfunc (p *StaticComputationPolicy) UnregisterOne(path string, level ComputationLevel)\n```\nUnregisterOne removes a capability for a path at a specific computation level\n\n```go\ntype StaticDataPolicy struct {\n\t// contains filtered or unexported fields\n}\n```\nStaticDataPolicy implements the DataPolicy interface and contains a list of privacyGroups and DataTransforms for them\n\n```go\nfunc NewStaticDataPolicy(privacyGroups []*PrivacyGroup, transforms DataTransforms) *StaticDataPolicy\n```\nNewStaticDataPolicy returns a pointer to a StaticDataPolicy with initialised fields\n\n```go\nfunc (sdp StaticDataPolicy) LastUpdated() time.Time\n```\n\n```go\nfunc (sdp *StaticDataPolicy) Resolve(entityID string) (*TableOperations, error)\n```\nResolve takes an entity ID and returns a pointer to the relevant TableOperations struct based on the privacyGroups that the entity ID is in and the associated transforms stored in the StaticDataPolicy\n\n```go\ntype TableOperations struct {\n\tTableTransforms map[string]TableTransform\n\tExcludedCols    map[string][]string\n}\n```\nTableOperations contains functions to apply to tables before sending to an entity and columns to exclude\n\n```go\nfunc NewTableOperations() *TableOperations\n```\nNewTableOperations returns a pointer to a TableOperations struct with initialised fields\n\n```go\ntype TableTransform map[string]ColumnTransform\n```\n\n","path":"github.com/JacobMoxham/PartIIProjectImplementation/middleware","name":"middleware","synopsis":"","isRedistributable":true}
