base

package
v0.0.0-...-8f9ce2e Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PubSubListenContinue = 1
	PubSubListenStop     = 0

	ProcessStatusInit   = 0  // default value, nothing to do
	ProcessStatusReady  = 1  // process is ready to be handled
	ProcessStatusUpdate = 2  // update in progress
	ProcessStatusDone   = 3  // done, can also be set to init. Done also mean the related task cannot be restarted
	ProcessStatusError  = -1 // an error occurs
)

Variables

View Source
var (
	ErrValidation             = errors.New("unable to validate data")
	ErrRevision               = errors.New("wrong revision while saving")
	ErrNotFound               = errors.New("unable to find the node")
	ErrInvalidReferenceFormat = errors.New("unable to parse the reference")
	ErrAlreadyDeleted         = errors.New("unable to find the node")
	ErrNoStreamHandler        = errors.New("no stream handler defined")
	ErrAccessForbidden        = errors.New("access forbidden")
	ErrInvalidVersion         = errors.New("wrong node version")
	ErrInvalidUuidLength      = errors.New("invalid UUID length")
)
View Source
var (
	StatusNew       = 0
	StatusDraft     = 1
	StatusCompleted = 2
	StatusValidated = 3
)

Functions

func Configure

func Configure(l *goapp.Lifecycle, conf *config.Config)

func DefaultHandlerStoreStream

func DefaultHandlerStoreStream(node *Node, r io.Reader) (int64, error)

func Deserialize

func Deserialize(r io.Reader, data interface{}) error

func DumpNode

func DumpNode(node *Node)

func GetSecurityAttributes

func GetSecurityAttributes(access []string) security.Attributes

func GetValue

func GetValue(source interface{}, field string) interface{}

func GetVaultMetadata

func GetVaultMetadata(node *Node) (meta vault.VaultMetadata)

func HandleError

func HandleError(req *http.Request, res http.ResponseWriter, err error)

func HandlerLoad

func HandlerLoad(handler Handler, data []byte, meta []byte, node *Node) error

func InterfaceToJsonMessage

func InterfaceToJsonMessage(ntype string, data interface{}) json.RawMessage

func NewRevisionError

func NewRevisionError(message string) error

func Serialize

func Serialize(w io.Writer, data interface{}) error

Types

type AccessOptions

type AccessOptions struct {
	Token security.SecurityToken
	Roles security.Attributes
}

func NewAccessOptions

func NewAccessOptions(token security.SecurityToken, roles security.Attributes) *AccessOptions

func NewAccessOptionsFromToken

func NewAccessOptionsFromToken(token security.SecurityToken) *AccessOptions

type AccessVoter

type AccessVoter struct {
}

func (*AccessVoter) Support

func (a *AccessVoter) Support(v interface{}) bool

func (*AccessVoter) Vote

func (a *AccessVoter) Vote(t security.SecurityToken, o interface{}, attrs security.Attributes) (result security.VoterResult, err error)

type DatabaseNodeHandler

type DatabaseNodeHandler interface {
	PreUpdate(node *Node, m NodeManager) error
	PostUpdate(node *Node, m NodeManager) error
	PreInsert(node *Node, m NodeManager) error
	PostInsert(node *Node, m NodeManager) error
}

type DownloadData

type DownloadData struct {
	ContentType  string
	Filename     string
	CacheControl string
	Pragma       string
	Expires      string
	Stream       func(node *Node, w io.Writer)
}

func GetDownloadData

func GetDownloadData() *DownloadData

type DownloadNodeHandler

type DownloadNodeHandler interface {
	GetDownloadData(node *Node) *DownloadData
}

type Errors

type Errors map[string][]string

func NewErrors

func NewErrors() Errors

use for model validation

func (Errors) AddError

func (es Errors) AddError(field string, message string)

func (Errors) GetError

func (es Errors) GetError(field string) []string

func (Errors) HasError

func (es Errors) HasError(field string) bool

func (Errors) HasErrors

func (es Errors) HasErrors() bool

type Handler

type Handler interface {
	GetStruct() (NodeData, NodeMeta) // Data, Meta
}

type HandlerCollection

type HandlerCollection map[string]Handler

func (HandlerCollection) Add

func (c HandlerCollection) Add(code string, h Handler)

func (HandlerCollection) Get

func (c HandlerCollection) Get(node *Node) Handler

func (HandlerCollection) GetByType

func (c HandlerCollection) GetByType(code string) Handler

func (HandlerCollection) GetTypes

func (c HandlerCollection) GetTypes() []string

func (HandlerCollection) HasType

func (c HandlerCollection) HasType(code string) bool

func (HandlerCollection) NewNode

func (c HandlerCollection) NewNode(t string) *Node

type HandlerMetadata

type HandlerMetadata struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Icon        string   `json:"icon"`
	Code        string   `json:"code"`
	Require     []string `json:"require"`
	Authors     []string `json:"authors"`
}

func NewHandlerMetadata

func NewHandlerMetadata() *HandlerMetadata

type HandlerViewMetadata

type HandlerViewMetadata struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Icon        string   `json:"icon"`
	Code        string   `json:"code"`
	Require     []string `json:"require"`
	Authors     []string `json:"authors"`
}

func NewViewHandlerMetadata

func NewViewHandlerMetadata() *HandlerViewMetadata

type Handlers

type Handlers interface {
	NewNode(t string) *Node
	Get(node *Node) Handler
	GetByType(code string) Handler
	GetTypes() []string
	HasType(code string) bool
}

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (resp *http.Response, err error)
	Get(url string) (resp *http.Response, err error)
	Head(url string) (resp *http.Response, err error)
	Post(url string, bodyType string, body io.Reader) (resp *http.Response, err error)
	PostForm(url string, data url.Values) (resp *http.Response, err error)
}

type Listener

type Listener interface {
	Handle(notification *pq.Notification, manager NodeManager) (int, error)
}

type LoadNodeHandler

type LoadNodeHandler interface {
	Load(data []byte, meta []byte, node *Node) error
}

type MetadataHandler

type MetadataHandler interface {
	GetMetadata() *HandlerMetadata
}

type MockedManager

type MockedManager struct {
	mock.Mock
}

func (*MockedManager) Find

func (m *MockedManager) Find(uuid Reference) *Node

func (*MockedManager) FindBy

func (m *MockedManager) FindBy(query sq.SelectBuilder, offset uint64, limit uint64) *list.List

func (*MockedManager) FindOneBy

func (m *MockedManager) FindOneBy(query sq.SelectBuilder) *Node

func (*MockedManager) Move

func (m *MockedManager) Move(uuid, parentUuid Reference) (int64, error)

func (*MockedManager) NewNode

func (m *MockedManager) NewNode(t string) *Node

func (*MockedManager) Notify

func (m *MockedManager) Notify(channel string, payload string)

func (*MockedManager) Remove

func (m *MockedManager) Remove(query sq.SelectBuilder) error

func (*MockedManager) RemoveOne

func (m *MockedManager) RemoveOne(node *Node) (*Node, error)

func (*MockedManager) Save

func (m *MockedManager) Save(node *Node, revision bool) (*Node, error)

func (*MockedManager) SelectBuilder

func (m *MockedManager) SelectBuilder(options *SelectOptions) sq.SelectBuilder

func (*MockedManager) Validate

func (m *MockedManager) Validate(node *Node) (bool, Errors)

type ModelEvent

type ModelEvent struct {
	Subject     string    `json:"subject"`
	Action      string    `json:"action"`
	Type        string    `json:"type"`
	Revision    int       `json:"revision"`
	Date        time.Time `json:"date"`
	Extra       string    `json:"extra"`
	Name        string    `json:"name"`
	NewRevision bool      `json:"new_revision"`
}

func CreateModelEvent

func CreateModelEvent(notification *pq.Notification) *ModelEvent

type Modules

type Modules map[string]interface{}

func (Modules) Get

func (p Modules) Get(name string) (interface{}, error)

func (Modules) Has

func (p Modules) Has(name string) bool

func (Modules) Set

func (p Modules) Set(name string, v interface{})

type Node

type Node struct {
	Id         int         `json:"-"`
	Uuid       Reference   `json:"uuid"`
	Type       string      `json:"type"`
	Name       string      `json:"name"`
	Slug       string      `json:"slug"`
	Path       string      `json:"path"`
	Data       interface{} `json:"data"`
	Meta       interface{} `json:"meta"`
	Status     int         `json:"status"`
	Weight     int         `json:"weight"`
	Revision   int         `json:"revision"`
	Version    int         `json:"version"`
	CreatedAt  time.Time   `json:"created_at"`
	UpdatedAt  time.Time   `json:"updated_at"`
	Enabled    bool        `json:"enabled"`
	Deleted    bool        `json:"deleted"`
	Parents    []Reference `json:"parents"`
	UpdatedBy  Reference   `json:"updated_by"`
	CreatedBy  Reference   `json:"created_by"`
	ParentUuid Reference   `json:"parent_uuid"`
	SetUuid    Reference   `json:"set_uuid"`
	Source     Reference   `json:"source"`
	Modules    Modules     `json:"modules"`
	Access     []string    `json:"access"` // key => roles required to access the nodes
}

func NewNode

func NewNode() *Node

func (*Node) UniqueId

func (node *Node) UniqueId() string

type NodeData

type NodeData interface{}

type NodeDeserializer

type NodeDeserializer func(r io.Reader, node *Node) error

type NodeManager

type NodeManager interface {
	SelectBuilder(option *SelectOptions) sq.SelectBuilder
	FindBy(query sq.SelectBuilder, offset uint64, limit uint64) *list.List
	FindOneBy(query sq.SelectBuilder) *Node
	Find(uuid Reference) *Node
	Remove(query sq.SelectBuilder) error
	RemoveOne(node *Node) (*Node, error)
	Save(node *Node, revision bool) (*Node, error)
	Notify(channel string, payload string)
	NewNode(t string) *Node
	Validate(node *Node) (bool, Errors)
	Move(uuid, parent Reference) (int64, error)
}

type NodeMeta

type NodeMeta interface{}

type NodeSerializer

type NodeSerializer func(w io.Writer, node *Node) error

type PgNodeManager

type PgNodeManager struct {
	Logger   *log.Logger
	Handlers Handlers
	Db       *sql.DB
	ReadOnly bool
	Prefix   string
}

func (*PgNodeManager) Find

func (m *PgNodeManager) Find(uuid Reference) *Node

func (*PgNodeManager) FindBy

func (m *PgNodeManager) FindBy(query sq.SelectBuilder, offset uint64, limit uint64) *list.List

func (*PgNodeManager) FindOneBy

func (m *PgNodeManager) FindOneBy(query sq.SelectBuilder) *Node

func (*PgNodeManager) Move

func (m *PgNodeManager) Move(uuid, parentUuid Reference) (int64, error)

func (*PgNodeManager) NewNode

func (m *PgNodeManager) NewNode(t string) *Node

func (*PgNodeManager) Notify

func (m *PgNodeManager) Notify(channel string, payload string)

func (*PgNodeManager) Remove

func (m *PgNodeManager) Remove(query sq.SelectBuilder) error

func (*PgNodeManager) RemoveOne

func (m *PgNodeManager) RemoveOne(node *Node) (*Node, error)

func (*PgNodeManager) Save

func (m *PgNodeManager) Save(node *Node, newRevision bool) (*Node, error)

func (*PgNodeManager) SelectBuilder

func (m *PgNodeManager) SelectBuilder(options *SelectOptions) sq.SelectBuilder

func (*PgNodeManager) Validate

func (m *PgNodeManager) Validate(node *Node) (bool, Errors)

type Reference

type Reference struct {
	uuid.UUID
}

func GetEmptyReference

func GetEmptyReference() Reference

func GetReference

func GetReference(uuid uuid.UUID) Reference

func GetReferenceFromString

func GetReferenceFromString(reference string) (Reference, error)

func GetRootReference

func GetRootReference() Reference

func (*Reference) CleanString

func (m *Reference) CleanString() string

func (*Reference) MarshalJSON

func (m *Reference) MarshalJSON() ([]byte, error)

func (*Reference) UnmarshalJSON

func (m *Reference) UnmarshalJSON(data []byte) error

type SelectOptions

type SelectOptions struct {
	TableSuffix  string
	SelectClause string
}

func NewSelectOptions

func NewSelectOptions() *SelectOptions

type Serializer

type Serializer struct {
	Handlers Handlers
	// contains filtered or unexported fields
}

func NewSerializer

func NewSerializer() *Serializer

func (*Serializer) AddDeserializer

func (s *Serializer) AddDeserializer(name string, f NodeDeserializer)

func (*Serializer) AddSerializer

func (s *Serializer) AddSerializer(name string, f NodeSerializer)

func (*Serializer) Deserialize

func (s *Serializer) Deserialize(r io.Reader, o interface{}) error

func (*Serializer) Serialize

func (s *Serializer) Serialize(w io.Writer, data interface{}) error

type StoreStreamNodeHandler

type StoreStreamNodeHandler interface {
	StoreStream(node *Node, r io.Reader) (int64, error)
}

type Subscriber

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

func NewSubscriber

func NewSubscriber(conninfo string, logger *log.Logger) *Subscriber

func (*Subscriber) ListenMessage

func (s *Subscriber) ListenMessage(name string, handler SubscriberHander)

func (*Subscriber) Register

func (s *Subscriber) Register()

func (*Subscriber) Stop

func (s *Subscriber) Stop()

type SubscriberHander

type SubscriberHander func(notification *pq.Notification) (int, error)

type ValidateNodeHandler

type ValidateNodeHandler interface {
	Validate(node *Node, m NodeManager, e Errors)
}

type ViewHandler

type ViewHandler interface {
	Support(node *Node, request *ViewRequest, response *ViewResponse) bool
	Execute(node *Node, request *ViewRequest, response *ViewResponse) error
}

type ViewHandlerCollection

type ViewHandlerCollection map[string]ViewHandler

func (ViewHandlerCollection) Add

func (c ViewHandlerCollection) Add(code string, h ViewHandler)

func (ViewHandlerCollection) Get

func (c ViewHandlerCollection) Get(node *Node) ViewHandler

func (ViewHandlerCollection) GetByType

func (c ViewHandlerCollection) GetByType(code string) ViewHandler

func (ViewHandlerCollection) GetTypes

func (c ViewHandlerCollection) GetTypes() []string

func (ViewHandlerCollection) HasType

func (c ViewHandlerCollection) HasType(code string) bool

type ViewMetadataHandler

type ViewMetadataHandler interface {
	GetViewMetadata() *HandlerViewMetadata
}

type ViewRequest

type ViewRequest struct {
	Format      string
	HttpRequest *http.Request
	Context     web.C
}

type ViewResponse

type ViewResponse struct {
	StatusCode   int
	Template     string
	Context      template.Context
	HttpResponse http.ResponseWriter
	ContentType  string
}

func NewViewResponse

func NewViewResponse(res http.ResponseWriter) *ViewResponse

func (*ViewResponse) Add

func (r *ViewResponse) Add(name string, v interface{}) *ViewResponse

func (*ViewResponse) Set

func (r *ViewResponse) Set(code int, template string) *ViewResponse

Jump to

Keyboard shortcuts

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