n3context

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: Apache-2.0 Imports: 17 Imported by: 2

README

n3-context

context management for n3, wraps db/crdt to create data-sharing environment

N3Context creates an environemnt for sharing data, links deep6 db, crdt manager to manage data sharing.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrContextFileNotFound = errors.New("no previous contexts file found: " + contextsFile)

Functions

func AddTempContextConfigFromCSV added in v0.1.2

func AddTempContextConfigFromCSV(csvName, csvStr string) (string, error)

func ClearTempContextConfig added in v0.1.3

func ClearTempContextConfig()

func MergeErrors

func MergeErrors(cs ...<-chan error) <-chan error

MergeErrors merges multiple channels of errors. Based on https://blog.golang.org/pipelines.

func WaitForPipeline

func WaitForPipeline(errs ...<-chan error) error

WaitForPipeline waits for results from all error channels. It returns early on the first error.

Types

type N3Context

type N3Context struct {
	Name   string
	UserId string
	// contains filtered or unexported fields
}

func NewN3Context

func NewN3Context(userId string, contextName string) (*N3Context, error)

func (*N3Context) Activate

func (n3c *N3Context) Activate() error

connects the crdtm to the streaming service and pipes received data into the d6 db, and gql schema builder

func (*N3Context) Close

func (n3c *N3Context) Close()

shut down the context cleanly

func (*N3Context) GQLQuery

func (n3c *N3Context) GQLQuery(query string, vars map[string]interface{}) (map[string]interface{}, error)

passes the received query into the gql manager for resolution

func (*N3Context) Publish

func (n3c *N3Context) Publish(r io.Reader) error

send data into the context, passes through the crdt layer and into storage if the context is activated, any reader can be used but expects content to be array of json objects.

func (*N3Context) PublishFromFile

func (n3c *N3Context) PublishFromFile(fname string) error

send data into context via crdt manager from a file expects payload to be array of json objects.

func (*N3Context) PublishFromHTTPRequest

func (n3c *N3Context) PublishFromHTTPRequest(r *http.Request) error

send data into context via crdt manager from an http request expects payload to be array of json objects.

func (*N3Context) Query

func (n3c *N3Context) Query(startid string,
	traversal deep6.Traversal,
	filter deep6.FilterSpec) (map[string][]map[string]interface{}, error)

simplified version of query engine for demo

TODO: remove in favour of GQLQuery

type N3ContextKey

type N3ContextKey struct {
	Name, UserId string
}

type N3ContextManager

type N3ContextManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewN3ContextManager

func NewN3ContextManager() *N3ContextManager

Creates a new manager to which n3contexts can be added/removed.

func (*N3ContextManager) ActivateAll

func (n3cm *N3ContextManager) ActivateAll() error

ActivateAll runs through all loaded contexts and activates them so they are listening for updates

func (*N3ContextManager) AddContext

func (n3cm *N3ContextManager) AddContext(userId string, contextName string) (*N3Context, error)

Creates a new context and adds it to the manager. If successful the new context is returned, otherwise error.

Contexts require a name, and an owning userid. If the context matching that name/userid already exists it is returned.

func (*N3ContextManager) Close

func (n3cm *N3ContextManager) Close(persist bool) error

shuts down all active contexts

will save context info to file for use with Restore() if persist is true

func (*N3ContextManager) GetContext

func (n3cm *N3ContextManager) GetContext(userId string, contextName string) (*N3Context, error)

retrieve a context from the manager

func (*N3ContextManager) Restore

func (n3cm *N3ContextManager) Restore() error

Loads details of contexts from file, and activates the specified contexts

returns ErrContextFileNotFound if state has not previously been saved

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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