services

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LOCAL ServiceType = "LOCAL"
	FIRE  ServiceType = "FIREBASE"

	// All services into one list: including local and remote.
	Services []string = []string{
		LOCAL.ToStr(),
		FIRE.ToStr(),
	}

	// Only remote services into one list.
	RemoteServices []string = []string{FIRE.ToStr()}
)

Functions

func IsFirebaseEnabled

func IsFirebaseEnabled(s models.Settings, local *ServiceRepo) bool

IsFirebaseEnabled checks if firebase connection is enabled or not.

Types

type FirebaseService

type FirebaseService struct {
	LS      ServiceRepo // embedded local service.
	Stdargs models.StdArgs
	Config  models.Settings

	// Firebase related.
	Ctx       context.Context
	FireApp   *firebase.App
	FireAuth  *auth.Client
	FireStore *firestore.Client
}

FirebaseService is a class implementation of service repo. Which's methods are based on Firebase client. ...

func NewFirebaseService

func NewFirebaseService(stdargs models.StdArgs, ls ServiceRepo) *FirebaseService

NewFirebaseService creates new firebase service by given arguments.

func (*FirebaseService) ClearNodes

func (s *FirebaseService) ClearNodes() ([]models.Node, []error)

ClearNodes removes all nodes from collection. TODO: improve the speed of clearing

func (*FirebaseService) Copy

func (s *FirebaseService) Copy(note models.Note) error

Copy fetches note from [note.Title], and copies its body to machine's clipboard.

func (*FirebaseService) Create

func (s *FirebaseService) Create(note models.Note) (*models.Note, error)

Create, creates a new file document at note's path. If a node(file or folder) already exists at provided note's path, it will return already formatted error message.

func (*FirebaseService) Cut

func (s *FirebaseService) Cut(note models.Note) (*models.Note, error)

Cut, copies note data to machine's clipboard and removes it instantly.

func (*FirebaseService) Edit

func (s *FirebaseService) Edit(note models.Note) (*models.Note, error)

Edit, updates the already created note, with locally updated note data. If a node doesn't exists at provided note's path, it will return a already formatted error message.

func (*FirebaseService) Fetch

func (s *FirebaseService) Fetch(remote ServiceRepo) ([]models.Node, []error)

Fetch creates a clone of nodes(that doesn't exists on [s](firebase-service)) from given [remote] service.

func (*FirebaseService) GenerateDoc

GenerateDoc is firebase.DocumentRef generator, that used to generate concrete document reference by a string path.

So, the: `<base-collection>/<document>/<sub-collection>/<sub-document>` string will be converted to: `Collection("<base-collection>").Doc("<document>").Collection("<sub-collection>").Doc("<sub-document>")`

In case of being node [Folder] type. The collection reference return will be the "sub" collection of generated document. But for the [File] type, it'd return nil.

func (*FirebaseService) GeneratePath

GeneratePath generates a string valid path from provided "custom" base of collection reference and models.Node model. first returned value would be the full-valid path of provided node in collection, and second returned value would be the valid "base" collection of that path.

func (*FirebaseService) GetAll

func (s *FirebaseService) GetAll(additional, typ string, ignore []string) ([]models.Node, []string, error)

GetAll fetches all documents and their sub documents (if they exist) from a database and returns them as an array of models.Node

@param additional path, [typ] that is allowed to fetch, and ignore list. @returns an array of all nodes, titles of nodes and error if something went wrong.

func (*FirebaseService) GetDoc

func (s *FirebaseService) GetDoc(n models.Node) (*models.Node, error)

GetDoc is a function that used to get document reference as models.Node.

func (*FirebaseService) Init

func (s *FirebaseService) Init(settings *models.Settings) error

Init creates notya working directory into current machine.

func (*FirebaseService) InitFirebase

func (s *FirebaseService) InitFirebase() error

Initializes firebase services as [s.FireApp], [s.FireAuth], and [s.FireStore].

func (*FirebaseService) IsNodeExists

func (s *FirebaseService) IsNodeExists(node models.Node) (bool, error)

IsNodeExists checks if an element(given node) exists at notya collection or not.

func (*FirebaseService) ListDir

func (s *FirebaseService) ListDir(path *firestore.CollectionRef, typ string, ignore []string, level int) ([]models.Node, []string, error)

ListDir retrieves the documents and sub-collections from a specified Firebase CollectionRef.

@param {firestore.CollectionRef} path - The Firebase CollectionRef to retrieve documents and sub-collections from. @param {string} typ - The type of documents to retrieve. @param {[]string} ignore - An array of sub-collection names to ignore. @param {int} level - The number of levels deep to retrieve sub-collections.

@returns {[]models.Node, []string, error} A tuple containing an array of retrieved documents and sub-collections (models.Node), an array of ignored sub-collection names, and an error if one occurred.

func (*FirebaseService) Migrate

func (s *FirebaseService) Migrate(remote ServiceRepo) ([]models.Node, []error)

Migrate overwrites all notes of given [remote] service with [s](firebase-service).

func (*FirebaseService) Mkdir

func (s *FirebaseService) Mkdir(dir models.Folder) (*models.Folder, error)

Mkdir creates a document in provided folder path(from dir.Path) and plus that, creates a sub collection of current folder document. that sub collection gonna represent the files/folders that current directory includes.

func (*FirebaseService) MoveNotes

func (s *FirebaseService) MoveNotes(settings models.Settings) error

MoveNote moves all notes from "CURRENT" firebase collection to new collection(given by settings parameter).

func (*FirebaseService) NotyaCollection

func (s *FirebaseService) NotyaCollection() firestore.CollectionRef

notyaCollection generates the main firestore collection reference.

func (*FirebaseService) Open

func (s *FirebaseService) Open(node models.Node) error

Open, opens a remote note in local machine. clones it on local, makes able to modify, after modifying, overwrites on it db.

func (*FirebaseService) OpenSettings

func (s *FirebaseService) OpenSettings(settings models.Settings) error

OpenSettigns, opens note remotely from firebase. caches it on local, makes able to modify after modifying overwrites on db.

func (*FirebaseService) Path

func (s *FirebaseService) Path() (string, string)

Path returns current service base working directory and name of working collection.

func (*FirebaseService) Push

func (s *FirebaseService) Push(remote ServiceRepo) ([]models.Node, []error)

Push uploads nodes(that doesn't exists on given remote) from [s](current) to given [remote].

func (*FirebaseService) Remove

func (s *FirebaseService) Remove(node models.Node) error

Remove deletes given node from [node.Path]. If a node doesn't exists at provided note's path, it will return a already formatted error message.

func (*FirebaseService) Rename

func (s *FirebaseService) Rename(editNode models.EditNode) error

Rename changes reference ID of document.

func (*FirebaseService) Settings

func (s *FirebaseService) Settings(p *string) (*models.Settings, error)

Settings gets and returns current settings state data.

func (*FirebaseService) StateConfig

func (s *FirebaseService) StateConfig() models.Settings

StateConfig returns current configuration of state i.e [s.Config].

func (*FirebaseService) Type

func (s *FirebaseService) Type() string

Type returns type of FirebaseService - FIRE.

func (*FirebaseService) View

func (s *FirebaseService) View(note models.Note) (*models.Note, error)

View, gets the note document from note's path. If a node doesn't exists at provided note's path, it will return a already formatted error message.

func (*FirebaseService) WriteSettings

func (s *FirebaseService) WriteSettings(settings models.Settings) error

WriteSettings overwrites settings data by given settings model.

type LocalService

type LocalService struct {
	Stdargs   models.StdArgs
	NotyaPath string
	Config    models.Settings
}

LocalService is a class implementation of service repo. Which is connected to local storage of users machine. Uses ~notya/ as main root folder for notes and configuration files.

func NewLocalService

func NewLocalService(stdargs models.StdArgs) *LocalService

NewLocalService creates new local service by given arguments.

func (*LocalService) ClearNodes

func (l *LocalService) ClearNodes() ([]models.Node, []error)

ClearNodes removes all nodes from local (including folders).

func (*LocalService) Copy

func (l *LocalService) Copy(note models.Note) error

Copy writes given notes' body, to machines main clipboard.

func (*LocalService) Create

func (l *LocalService) Create(note models.Note) (*models.Note, error)

Create creates new note file. and fills it's data by given note model.

func (*LocalService) Cut

func (l *LocalService) Cut(note models.Note) (*models.Note, error)

Cut, copies note data to machine's clipboard and removes it instantly.

func (*LocalService) Edit

func (l *LocalService) Edit(note models.Note) (*models.Note, error)

Edit overwrites exiting file's content-body.

func (*LocalService) Fetch

func (l *LocalService) Fetch(remote ServiceRepo) ([]models.Node, []error)

Fetch creates a clone of nodes(that doesn't exists on [l](local-service)) from given [remote] service.

func (*LocalService) GeneratePath

func (l *LocalService) GeneratePath(base string, n models.Node) (string, error)

GeneratePath returns non-zero-valuable string path from given additional sub-path(title of node).

func (*LocalService) GetAll

func (l *LocalService) GetAll(additional, typ string, ignore []string) ([]models.Node, []string, error)

GetAll fetches all nodes(files and folders) from current active local directory.

func (*LocalService) Init

func (l *LocalService) Init(settings *models.Settings) error

Init creates notya working directory into current machine.

func (*LocalService) IsNodeExists

func (l *LocalService) IsNodeExists(node models.Node) (bool, error)

IsNodeExists checks for a file or folder at [node.Path] or at generated path from [node.Title]. Note: rather than remote services, error checking is not required.

func (*LocalService) Migrate

func (l *LocalService) Migrate(remote ServiceRepo) ([]models.Node, []error)

Migrate overwrites all notes of given [remote] service with [l](current-service).

func (*LocalService) Mkdir

func (l *LocalService) Mkdir(dir models.Folder) (*models.Folder, error)

Mkdir creates a new working directory.

func (*LocalService) MoveNotes

func (l *LocalService) MoveNotes(settings models.Settings) error

MoveNotes moves all notes from "CURRENT" path to new path(given by settings parameter).

func (*LocalService) Open

func (l *LocalService) Open(node models.Node) error

Open opens given node(file or folder) via editor.

func (*LocalService) OpenSettings

func (l *LocalService) OpenSettings(settings models.Settings) error

OpenSettings opens given settings via editor.

func (*LocalService) Path

func (l *LocalService) Path() (string, string)

Path returns current service's base working directory.

func (*LocalService) Push

func (l *LocalService) Push(remote ServiceRepo) ([]models.Node, []error)

Push uploads nodes(that doesn't exists on given remote) from [l](current) to given [remote].

func (*LocalService) Remove

func (l *LocalService) Remove(node models.Node) error

Remove deletes given node.

func (*LocalService) Rename

func (l *LocalService) Rename(editNode models.EditNode) error

Rename changes given file's or folder's name.

func (*LocalService) Settings

func (l *LocalService) Settings(p *string) (*models.Settings, error)

Settings gets and returns current settings state data.

func (*LocalService) StateConfig

func (l *LocalService) StateConfig() models.Settings

StateConfig returns current configuration of state i.e [l.Config].

func (*LocalService) Type

func (l *LocalService) Type() string

Type returns type of LocalService - LOCAL

func (*LocalService) View

func (l *LocalService) View(note models.Note) (*models.Note, error)

View opens note-file from given [note.Name], then takes it body, and returns new fully-filled note.

func (*LocalService) WriteSettings

func (l *LocalService) WriteSettings(settings models.Settings) error

WriteSettings overwrites settings data by given settings model.

type ServiceRepo

type ServiceRepo interface {
	// Type returns the current implementation's type.
	// - LOCAL, if it's local service implementation.
	// - FIRE, if it's firebase service implementation.
	// and etc ...
	Type() string

	// Path returns the path of current base service. And base service's notes path.
	// ...   main | notes
	Path() (string, string)

	// Current config data of service implementation.
	StateConfig() models.Settings

	// Init setups all kinda minimal services for application.
	Init(settings *models.Settings) error

	// Settings reads and parses current configuration file and returns
	// it as settings model pointer. In case of a error, setting model will be
	// [nil] and [error] will be provided.
	Settings(p *string) (*models.Settings, error)

	// WriteSettings overwrites current configuration data,
	// with provided [settings] model.
	WriteSettings(settings models.Settings) error

	// OpenSettings opens provided settings with [current] editor
	// that we take it from provided settings.
	OpenSettings(settings models.Settings) error

	// General functions that used for both [Note]s and [Folder]s
	IsNodeExists(node models.Node) (bool, error)
	Open(node models.Node) error
	Remove(node models.Node) error
	Rename(editNode models.EditNode) error
	ClearNodes() ([]models.Node, []error)

	// GetAll gets the all notes from current service.
	//
	// [additional] provides a way of entering to sub-folders of main folder.
	// [ignore] provides a way of ignoring files. Default ignorable files: [models.NotyaIgnoreFiles].
	// [typ] provides a way to get only specific type of file-nodes.
	GetAll(additional, typ string, ignore []string) ([]models.Node, []string, error)

	Create(note models.Note) (*models.Note, error)
	View(note models.Note) (*models.Note, error)
	Edit(note models.Note) (*models.Note, error)
	Copy(note models.Note) error
	Cut(note models.Note) (*models.Note, error)

	// Folder(directory) related functions.
	Mkdir(dir models.Folder) (*models.Folder, error)

	// MoveNotes moves all exiting notes from CURRENT directory
	// to new one, appropriate by settings which comes from arguments.
	MoveNotes(settings models.Settings) error

	// Fetch fetches nodes(that doesn't exists
	// on current service) from remote service to local service.
	Fetch(remote ServiceRepo) ([]models.Node, []error)

	// Push uploads all notes from local service to provided remote.
	Push(remote ServiceRepo) ([]models.Node, []error)

	// Migrate clones current service data to [remote] service data.
	// [remote] service data would be cleared and replaced with current service data.
	Migrate(remote ServiceRepo) ([]models.Node, []error)
}

ServiceRepo is a abstract class for all service implementations.

╭──────╮     ╭────────────────────╮
│ User │ ──▶ │ Interface Commands │
╰──────╯     ╰────────────────────╯
                       │
           ╭───────────────────────╮
           ▼                       ▼
   ╭───────────────╮       ╭────────────────╮
   │ Local Service │       │ Remote Service │
   ╰───────────────╯       ╰────────────────╯
   Connected to local       Connected to user defined
   storage, and uses        key-store remote database, and uses
   ~notya/ as main root     notya/ as base root key map.
   folder for notes.

type ServiceType

type ServiceType string

Custom string struct to define type of services

func (*ServiceType) ToStr

func (s *ServiceType) ToStr() string

ToStr returns exact key value of ServiceType.

Jump to

Keyboard shortcuts

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