Documentation
¶
Index ¶
- Variables
- func CreateKVStoreKey(key string, sep string) string
- func GCPDownload(bucket, object string) error
- func GetEnv(variable, deflt string) string
- func NewHTTPClient() *http.Client
- func StartServer(dr DataResource, serverName string, port int) error
- type DataOutput
- type DataResource
- type DataResourceImplementorTemplate
- type Meta
- type SimpleData
- type VersionManager
Constants ¶
This section is empty.
Variables ¶
var ( //ResourceServiceName is the name of this service as visible to other services. // //Passing value through to StartServers function overrides this by hard coding. // To avoid this pass an empty string into StartServers // function or repass this value as sdsshared.ResourceServiceName. ResourceServiceName string //Whether verbose logging and test data should be used. // Never set true for production DebugMode bool //DBURI is the path -URL or local path- to the database resource. // If it doesn't exist one will be created at this resource for // some connector implementations. For local dbs this may be pre/suf-fixed // to allow for dataset updates with minimised downtime DBURI string //DBURI is the path (URL or local path) to the archive file for //the dataset used to rebuild the database DatasetURI string //PublicPort is the port from which this API can be accessed for data retrieval PublicPort string //LocalDownloadDir is the local relative or absolute path to a downloads folder to use LocalDownloadDir string //DatasetBucketName is the cloud bucket from which to find the dataset archive DatasetBucketName = "simple-data-service" //DatasetObjectName is the cloud object name found in DatasetBucketName that // identifies the dataset archive for download DatasetObjectName string )
Functions ¶
func CreateKVStoreKey ¶
CreateKVStoreKey creates a standard key for use in kv storage dbs. Appends a Unix timestamp so that duplicate entries can be stored seperately, sorted easily, and deduped using proper protocols without requiring calls to meta
Using a Unix timestamp means just sorted the keys in place will give time sorted list
func GCPDownload ¶
GCPDownload downloads assets from Google Cloud Storage with the given
Object name and within the given Bucket
func GetEnv ¶
GetEnvar get an environment variable and if it is black sets the given default.
The value may be set as default string purposefully rather than omitted. In this case an empty string will be returned instead of the default string.
func NewHTTPClient ¶
NewHTTPClient is the default client to be used instead of default client. Ammended timeouts. See //https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/
func StartServer ¶
func StartServer(dr DataResource, serverName string, port int) error
StartServer runs the server to interface with the system using the api methods of DataResource.
If port is set to 0 a default setting or the setting given using environment variable `publicport` will be used
Similarly if serverName is not set the default will be used or the value in environment variable `name` suffixed with the word 'server'
Types ¶
type DataOutput ¶
type DataOutput struct {
//... Requested data schema...
Values interface{} `json:"values"`
}
DataOutputis the SimpleData componant with the requested data payload
type DataResource ¶
type DataResource interface { Startup() error UpdateDataset() (VersionManager, error) //Retrieve takes query token and map[string]string group of query args // received in the GET request. // Returned []byte is JSON representation of SimpleData Retrieve(string, map[string]string) (SimpleData, error) Shutdown() error }
DataResource is the interface each Resource service uses and is a central library unit used for a centralised server facility that handles JWT checking centrally.
type DataResourceImplementorTemplate ¶
type DataResourceImplementorTemplate struct { DatabaseHandle interface{} // contains filtered or unexported fields }
DataResourceImplementorTemplate is a simple outline of the basic structure that can implement the full DataResource interface. See `badgerdb` for best practise
type Meta ¶
type Meta struct { Resource string `json:"resource"` LastUpdated string `json:"dataset_updated,omitempty"` //time.RFC3339 DataSources []string `json:"data_sources,omitempty"` }
Meta is the SimpleData componant with meta data on the datasource being queried
type SimpleData ¶
type SimpleData struct { ResultCount int `json:"result_count"` RequestOptions map[string]string `json:"request_options,omitempty"` Meta Meta `json:"meta"` Data DataOutput `json:"data"` Errors map[string]string `json:"errors,omitempty"` }
SimpleData is the standard response interface to the end user. Data resources should return
type VersionManager ¶
type VersionManager struct { CurrentVersion string `json:"version,omitempty"` //Repo is where to get the dataset archive from (URL) Repo string `json:"repo,omitempty"` //LastUpdated is when the Repo was last updated from latest version (time.RFC3339) LastUpdated string `json:"dataset_updated"` //List of initial data sources gained from last update from repo DataSources []string `json:"data_sources"` }
VersionManager is the struct that allows the instance to check its current used dataset version and compare it against the latest available to judge update need
func (*VersionManager) UpdateDataset ¶
func (vt *VersionManager) UpdateDataset(dr DataResource) error