datastore

package
v0.0.0-...-02bf1be Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package datastore provides mongo implementation for store to keep and access rules

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoServer

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

MongoServer top level mongo ops

func New

func New(connectionURI, dbName string, delay time.Duration) (*MongoServer, error)

New MongoServer

func (*MongoServer) GetStores

func (m *MongoServer) GetStores() (rules RulesDAO)

GetStores initialize collections and make indexes

type Rule

type Rule struct {
	ID        primitive.ObjectID `json:"id" bson:"_id,omitempty"`
	Domain    string             `json:"domain"`
	MatchURLs []string           `json:"match_url,omitempty" bson:"match_urls,omitempty"`
	Content   string             `json:"content"`
	Author    string             `json:"author,omitempty" bson:"author,omitempty"`
	TS        string             `json:"ts,omitempty" bson:"ts,omitempty"` // ts of original article
	Excludes  []string           `json:"excludes,omitempty" bson:"excludes,omitempty"`
	TestURLs  []string           `json:"test_urls,omitempty" bson:"test_urls"`
	User      string             `json:"user"`
	Enabled   bool               `json:"enabled"`
}

Rule record, entry in mongo

func (Rule) String

func (s Rule) String() string

type RulesDAO

type RulesDAO struct {
	*mongo.Collection
}

RulesDAO data-access obj for custom parsing rules, implements Rules

func (RulesDAO) All

func (r RulesDAO) All(ctx context.Context) []Rule

All returns list of all rules, both enabled and disabled

func (RulesDAO) Disable

func (r RulesDAO) Disable(ctx context.Context, id primitive.ObjectID) error

Disable marks enabled=false, by id

func (RulesDAO) Get

func (r RulesDAO) Get(ctx context.Context, rURL string) (Rule, bool)

Get rule by url. Checks if found in mongo, matching by domain

func (RulesDAO) GetByID

func (r RulesDAO) GetByID(ctx context.Context, id primitive.ObjectID) (Rule, bool)

GetByID returns record by id

func (RulesDAO) Save

func (r RulesDAO) Save(ctx context.Context, rule Rule) (Rule, error)

Save upsert rule and returns one with ID for inserted one only

Jump to

Keyboard shortcuts

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