dict

package
v0.0.0-...-50ff0a0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2020 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package dict has the implementation of the dictionary api for the platform

Index

Constants

View Source
const DatasetClearCheckInterval = time.Minute * 20

DatasetClearCheckInterval is the interval after which the datatset removal check has to run

View Source
const DatasetExpiry = time.Hour * 4

DatasetExpiry is the expiry time after which the datatset expiries without any active usage

Variables

View Source
var DatasetInputChannel chan DatasetRequest

DatasetInputChannel is the input channel to communicate with the cache

Functions

func Datasets

func Datasets(in chan DatasetRequest)

Datasets is the cache providing the datatsets. When a dataset is updated, coresponding users who all have access to that dataset get their DICTs updated automatically

func SendDatasetToChannel

func SendDatasetToChannel(ch chan DatasetRequest, req DatasetRequest)

SendDatasetToChannel sends a dataset request to the channel. This function is to be used with go routines so that datasets isn't blocked by the requests

func SetDefaultDatasetAggregator

func SetDefaultDatasetAggregator(agg DatasetAggregator)

SetDefaultDatasetAggregator sets the default aggregator as the passed param

func SystemDICT

func SystemDICT() interpreter.DICT

SystemDICT returns the system dictionary available for all the users

Types

type DAgg

type DAgg struct {
	// contains filtered or unexported fields
}

DAgg is the dict aggregator for getting the dict from the database

func NewDAgg

func NewDAgg(db *gorm.DB, l log.Log) *DAgg

NewDAgg returns an instance of DAgg dict aggregator

func (DAgg) Get

func (d DAgg) Get(ID string, update bool) (interpreter.DICT, error)

Get returns the user dictionary from the database

func (DAgg) GetDataset

func (d DAgg) GetDataset(ID string) (Dataset, error)

GetDataset will get the dataset required for the given id

type Dataset

type Dataset struct {
	D        map[string]interpreter.Token
	LastUsed time.Time
}

Dataset is the dataset instance having the node tokens

type DatasetAggregator

type DatasetAggregator interface {
	GetDataset(ID string) (Dataset, error)
}

DatasetAggregator is the aggregator to get the dict from a service or database

type DatasetRequest

type DatasetRequest struct {
	//ID of the dataset
	ID string
	//SubscribeID is the id which subscribes to the dataset
	SubscribeID string
	//Type is the type of the dictionary request. It can have Add, Get, Remove
	Type DatasetRequestType
	//Dataset has the tokens mapped to the token string for the dataset
	Dataset Dataset
	//Valid indicates that the dict is valid. During get requests, if valid is false then cache couldn't find the dict
	Valid bool
	//Out channel for sending response to the requester
	Out chan DatasetRequest
}

DatasetRequest can be used to make a request to get the dataset cache

type DatasetRequestType

type DatasetRequestType uint

DatasetRequestType is the type of the request for the dataset

const (
	//DatasetUpdate comes to update and datatset and update corresponding subscribed ids
	DatasetUpdate DatasetRequestType = 1
	//DatasetGet returns the dataset of a given id
	DatasetGet DatasetRequestType = 2
	//DatasetRemove to remove the dataset from the cache
	DatasetRemove DatasetRequestType = 3
)

Jump to

Keyboard shortcuts

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