base

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: MIT Imports: 17 Imported by: 2

README

Go Report Card GoDoc GolangCI

xmodules/base for Xamboo - GO

The base package is used to control the applications and compiled xmodules for the Xamboo CMS, so each site is build on top of its base. The base contains links to databases, tables, logs, config params, supported languages and installed modules. The base package controls also the installed package on each datasource. The base package is compatible with database transactions and multithread. The base package support english, spanish and french installations.

TO DO:

  • Finish translation of messages in spanish y French
  • Add messages in container.go

Version Changes Control

v0.1.1 - 2021-01-17

  • Implementation of languages and messages

v0.1.0 - 2020-05-25

  • Renamed to base instead of context
  • Now support new xamboo standart assets.Application for Applications and XModules

v0.0.1 - 2020-03-05

  • Implemented support for multithread (Mutex) on each object of the Container and base.
  • The data is now accessible by Get/Set/Add functions

v0.0.0 - 2019-12-18

  • First release of module

Manual:

I. base

Intro


  1. Overview

Example:

import "github.com/webability-go/xmodules/base"


  1. Reference

To use the package:

import "github.com/webability-go/xmodules/xbase"

II. Modules

Intro

  1. Overview

Example:

import "github.com/webability-go/xmodules/base"

  1. Reference

To use the package:

import "github.com/webability-go/xmodules/xbase"


Documentation

Overview

package base is the controler for all the XModules of Xamboo and is required to build any other XModule in the system. It controls different datasources for different sites, installed xmodules, logs, caches, databases and tables.

package base is the controler for all the XModules of Xamboo and is required to build any other XModule in the system. It controls different datasources for different sites, installed xmodules, logs, caches, databases and tables.

Package user contains the list of administrative user for the system. All users have accesses, into a profile and even extended access based upon table records. It needs context xmodule.

Index

Constants

View Source
const (
	MODULEID = "base"
	VERSION  = "0.1.1"
)

Variables

View Source
var ContainersLock sync.RWMutex
View Source
var ModulesList = &Modules{}
View Source
var Needs = []string{}

Functions

func AddModule

func AddModule(ds applications.Datasource, id string, name string, version string) error

AddModule will insert a record in the modules table and sends back status error

func GetDatasourceStats

func GetDatasourceStats(ds *Datasource) *xcore.XDataset

Analyze a datasource and gets back the main data

func GetEntries added in v0.0.16

func GetEntries(ctx *context.Context, moduleid string) interface{}

func GetModule

func GetModule(ds applications.Datasource, id string) *xcore.XDataset

func ModuleInstalledVersion

func ModuleInstalledVersion(ds applications.Datasource, id string) string

ModuleStatus returns status of the module: "" not installed "version.number" version installed

func SynchroFiles added in v0.0.16

func SynchroFiles(origin fs.FS, destination string) (error, []string)

func SynchroTable

func SynchroTable(ds applications.Datasource, tablename string) (error, []string)

func TryDatasource

func TryDatasource(ctx *context.Context, datasourcename string) applications.Datasource

func VerifyNeeds

func VerifyNeeds(ds applications.Datasource, needs []string) (bool, []string)

Types

type Container

type Container struct {
	CoreLog *log.Logger
	// contains filtered or unexported fields
}

Container if the list of created datasources The XConfig file must have this syntax:

database.[dbid].type=[dbtype]
database.[dbid].username=[dbusername]
database.[dbid].password=[dbpassword]
database.[dbid].database=[dbname]
database.[dbid].server=[dbserver]
database.[dbid].ssl=[dbsslflag]

log.[logid].file=[pathtologfile]

every line can be repeated for each dbid or logid

func Create

func Create(configfile string) *Container

Create will scan a full config file for Containers The XConfig file must have this syntax:

datasource=[datasourceid1]
datasource=[datasourceid2]
datasource=[datasourceid3]
datasourceid1-config=[path-to-config-file]
datasourceid2-config=[path-to-config-file]
datasourceid3-config=[path-to-config-file]

func (*Container) CreateDatasource

func (cnt *Container) CreateDatasource(name string, config *xconfig.XConfig) (applications.Datasource, error)

Createdatasource will create a new datasource, link databases and logs based on XConfig data

func (*Container) GetDatasource

func (cnt *Container) GetDatasource(id string) applications.Datasource

func (*Container) GetDatasources

func (cnt *Container) GetDatasources() map[string]applications.Datasource

func (*Container) RegisterModule added in v0.0.16

func (cnt *Container) RegisterModule(mod applications.Module)

func (*Container) SetDatasource

func (cnt *Container) SetDatasource(id string, ds applications.Datasource)

func (*Container) TryDatasource

func (cnt *Container) TryDatasource(ctx *context.Context, datasourcename string) applications.Datasource

TryDatasource will create a new datasource, link databases and logs based on XConfig data

type ContainersList

type ContainersList map[string]*Container
var Containers *ContainersList

var Containers = &ContainersList{}

func (*ContainersList) AddContainer

func (cntl *ContainersList) AddContainer(id string, cnt *Container)

func (*ContainersList) GetContainer

func (cntl *ContainersList) GetContainer(id string) *Container

func (*ContainersList) RegisterModule added in v0.0.16

func (cntl *ContainersList) RegisterModule(mod applications.Module)

type Datasource

type Datasource struct {
	// The name of the datasource (informative only)
	Name string
	// A configuration for the datasource: (does not need lock to be accessed since it's a pointer) lock yourself for now (next XConfig version will be TS)
	Config *xconfig.XConfig
	// contains filtered or unexported fields
}

Datasource is a portable structure containing pointer to usefull structures used in any datasource of sites. It must be compilant with assets.Datasource interface Since it's thread safe and based on maps and slices, it must be accessed through Get/Set functions with mutexes to avoid race conditions The is only ONE database by datasource, with a set of modules and tables into this database.

func (*Datasource) AddLanguage

func (ds *Datasource) AddLanguage(lang language.Tag)

func (*Datasource) CloneShell

func (ds *Datasource) CloneShell() applications.Datasource

func (*Datasource) Commit

func (ds *Datasource) Commit() error

func (*Datasource) GetCache

func (ds *Datasource) GetCache(id string) *xcore.XCache

func (*Datasource) GetCaches

func (ds *Datasource) GetCaches() map[string]*xcore.XCache

func (*Datasource) GetDatabase

func (ds *Datasource) GetDatabase() *xdominion.XBase

func (*Datasource) GetLanguages

func (ds *Datasource) GetLanguages() []language.Tag

func (*Datasource) GetLog

func (ds *Datasource) GetLog(id string) *log.Logger

func (*Datasource) GetLogs

func (ds *Datasource) GetLogs() map[string]*log.Logger

func (*Datasource) GetModule

func (ds *Datasource) GetModule(moduleid string) string

func (*Datasource) GetModules

func (ds *Datasource) GetModules() map[string]string

func (*Datasource) GetName

func (ds *Datasource) GetName() string

func (*Datasource) GetTable

func (ds *Datasource) GetTable(id string) *xdominion.XTable

func (*Datasource) GetTables

func (ds *Datasource) GetTables() map[string]*xdominion.XTable

func (*Datasource) GetTransaction

func (ds *Datasource) GetTransaction() *xdominion.XTransaction

func (*Datasource) IsModuleAuthorized

func (ds *Datasource) IsModuleAuthorized(id string) bool

func (*Datasource) Log

func (ds *Datasource) Log(id string, messages ...interface{})

func (*Datasource) RegisterModule added in v0.0.16

func (ds *Datasource) RegisterModule(mod applications.Module)

func (*Datasource) Rollback

func (ds *Datasource) Rollback() error

func (*Datasource) SetCache

func (ds *Datasource) SetCache(id string, cache *xcore.XCache)

func (*Datasource) SetDatabase

func (ds *Datasource) SetDatabase(db *xdominion.XBase)

func (*Datasource) SetLog

func (ds *Datasource) SetLog(id string, logger *log.Logger)

func (*Datasource) SetModule

func (ds *Datasource) SetModule(moduleid string, moduleversion string)

func (*Datasource) SetTable

func (ds *Datasource) SetTable(id string, table *xdominion.XTable)

func (*Datasource) StartTransaction

func (ds *Datasource) StartTransaction() (*xdominion.XTransaction, error)

type Hook added in v0.0.16

type Hook func(ds *Datasource, data ...interface{})

type Hooks added in v0.0.16

type Hooks struct {
	Hooks map[string]Hook
}

func NewHooks added in v0.0.16

func NewHooks() *Hooks

func (*Hooks) Call added in v0.0.16

func (h *Hooks) Call(ds *Datasource, data ...interface{})

func (*Hooks) Register added in v0.0.16

func (h *Hooks) Register(id string, f Hook)

type Module

type Module struct {
	ID      string
	Version string

	Languages map[language.Tag]string
	Needs     []string

	FSetup        func(applications.Datasource, string) ([]string, error)
	FSynchronize  func(applications.Datasource, string) ([]string, error)
	FStartContext func(applications.Datasource, *context.Context) error

	Entries interface{}
}

func (*Module) GetID

func (m *Module) GetID() string

func (*Module) GetInstalledVersion

func (m *Module) GetInstalledVersion(ds applications.Datasource) string

func (*Module) GetLanguages

func (m *Module) GetLanguages() map[language.Tag]string

func (*Module) GetNeeds

func (m *Module) GetNeeds() []string

func (*Module) GetVersion

func (m *Module) GetVersion() string

func (*Module) Setup

func (m *Module) Setup(ds applications.Datasource, prefix string) ([]string, error)

func (*Module) StartContext

func (m *Module) StartContext(ds applications.Datasource, ctx *context.Context) error

func (*Module) Synchronize

func (m *Module) Synchronize(ds applications.Datasource, prefix string) ([]string, error)

type Modules

type Modules map[string]applications.Module

func (*Modules) Get

func (ml *Modules) Get(id string) applications.Module

func (*Modules) Register

func (ml *Modules) Register(m applications.Module)

type Structure

type Structure interface {

	// ComplementData adds all the needed data from other objects /duplicable in the thread since the object will be destroyed at the end
	ComplementData(ds applications.Datasource)

	// IsAuthorized returns true if the structure can be used on this site/language/device
	IsAuthorized(ds applications.Datasource, site string, language string, device string) bool

	// GetData Returns the raw data
	GetData() *xdominion.XRecord

	// Clone will clone the whole structure
	Clone() Structure
}

Structure interface is made to implement a standarized object to use cross modules, graph, memory caches etc.

Jump to

Keyboard shortcuts

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