service

package
v0.0.0-...-76a3325 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2014 License: AGPL-3.0-or-later, AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

The service library allows to access other modules' services over RPC using a UNIX domain socket connection.

The session pool allows to conveniently reuse RPC connections. A connection is represented by a session object. After creating a session pool, you can retrieve a session object with the New method. Don't forget to return the session with the Free method.

Index

Constants

View Source
const (
	GetRequest = iota
	PostRequest
)
View Source
const (
	ViewAction = iota
	EditAction
	LoginAction
	LogoutAction
	AddAction
	RemoveAction
	RequestPasswordTokenAction
	ChangePasswordAction
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action uint

type Client

type Client struct {
	RPCClient *rpc.Client
	// Error holds the last error if any.
	Error error
	// Id is a unique identifier for this client.
	Id string
}

Client represents the rpc connection to a service.

func (*Client) Close

func (s *Client) Close() error

Close closes the client's RPC connection.

func (*Client) Connect

func (s *Client) Connect(path string) error

Connect establishes a new RPC connection to the given service.

path is the unix domain socket path to the service.

type DateTimeField

type DateTimeField struct {
	time.Time
}

func (DateTimeField) Dump

func (t DateTimeField) Dump() interface{}

func (*DateTimeField) FromFormField

func (t *DateTimeField) FromFormField(data util.NestedMap, field *NodeField)

func (*DateTimeField) Load

func (t *DateTimeField) Load(in interface{}) error

func (DateTimeField) RenderHTML

func (t DateTimeField) RenderHTML() interface{}

func (DateTimeField) ToFormField

func (t DateTimeField) ToFormField(form *htmlwidgets.Form, data util.NestedMap,
	field *NodeField, locale string)

type EmbedNode

type EmbedNode struct {
	Id  string
	URI string
}

type Field

type Field interface {
	// RenderHTML returns a string or template.HTML to be used in a html
	// template.
	RenderHTML() interface{}
	// String returns a raw string representation of the field.
	String() string
	// Load loads the field data (also see Dump).
	Load(interface{}) error
	// Dump dumps the field data.
	//
	// The dumped value must be something that can be marshalled into
	// JSON by encoding/json.
	Dump() interface{}
	// Adds a form field to the node edit form.
	ToFormField(*htmlwidgets.Form, util.NestedMap, *NodeField, string)
	// Load values from the form submission
	FromFormField(util.NestedMap, *NodeField)
}

type FileField

type FileField string

func (FileField) Dump

func (t FileField) Dump() interface{}

func (*FileField) FromFormField

func (t *FileField) FromFormField(data util.NestedMap, field *NodeField)

func (*FileField) Load

func (t *FileField) Load(in interface{}) error

func (FileField) RenderHTML

func (t FileField) RenderHTML() interface{}

func (FileField) String

func (t FileField) String() string

func (FileField) ToFormField

func (t FileField) ToFormField(form *htmlwidgets.Form, data util.NestedMap,
	field *NodeField, locale string)

type HTMLField

type HTMLField string

HTMLField is a text area containing HTML code

func (HTMLField) Dump

func (t HTMLField) Dump() interface{}

func (*HTMLField) FromFormField

func (t *HTMLField) FromFormField(data util.NestedMap, field *NodeField)

func (*HTMLField) Load

func (t *HTMLField) Load(in interface{}) error

func (HTMLField) RenderHTML

func (t HTMLField) RenderHTML() interface{}

func (HTMLField) String

func (t HTMLField) String() string

func (HTMLField) ToFormField

func (t HTMLField) ToFormField(form *htmlwidgets.Form, data util.NestedMap,
	field *NodeField, locale string)

type MonstiClient

type MonstiClient struct {
	Client
	SignalHandlers map[string]func(interface{}) (interface{}, error)
}

MonstiClient represents the RPC connection to the Monsti service.

func NewMonstiConnection

func NewMonstiConnection(path string) (*MonstiClient, error)

NewMonstiConnection establishes a new RPC connection to a Monsti service.

path is the unix domain socket path to the service.

func (*MonstiClient) AddSignalHandler

func (s *MonstiClient) AddSignalHandler(handler SignalHandler) error

AddSignalHandler connects to a signal with the given signal handler.

func (*MonstiClient) EmitSignal

func (s *MonstiClient) EmitSignal(name string, args interface{},
	retarg interface{}) error

EmitSignal emits the named signal with given arguments and return value.

func (*MonstiClient) GetAddableNodeTypes

func (s *MonstiClient) GetAddableNodeTypes(site, nodeType string) (types []string,
	err error)

GetAddableNodeTypes returns the node types that may be added as child nodes to the given node type at the given website.

func (*MonstiClient) GetChildren

func (s *MonstiClient) GetChildren(site, path string) ([]*Node, error)

GetChildren returns the children of the given node.

func (*MonstiClient) GetConfig

func (s *MonstiClient) GetConfig(site, module, name string,
	out interface{}) error

GetConfig puts the named configuration into the variable out.

func (*MonstiClient) GetNode

func (s *MonstiClient) GetNode(site, path string) (*Node, error)

GetNode reads the given node.

If the node does not exist, it returns nil, nil.

func (*MonstiClient) GetNodeData

func (s *MonstiClient) GetNodeData(site, path, file string) ([]byte, error)

GetNodeData requests data from some node.

Returns a nil slice and nil error if the data does not exist.

func (*MonstiClient) GetNodeType

func (s *MonstiClient) GetNodeType(nodeTypeID string) (*NodeType,
	error)

GetNodeType requests information about the given node type.

func (*MonstiClient) GetNodeTypes

func (s *MonstiClient) GetNodeTypes() ([]string, error)

GetNodeType returns all supported node types.

func (*MonstiClient) GetRequest

func (s *MonstiClient) GetRequest(id uint) (*Request, error)

GetRequest returns the request with the given id.

If there is no request with the given id, it returns nil.

func (*MonstiClient) ModuleInitDone

func (s *MonstiClient) ModuleInitDone(module string) error

ModuleInitDone tells Monsti that the given module has finished its initialization. Monsti won't finish its startup until all modules called this method.

func (*MonstiClient) PublishService

func (s *MonstiClient) PublishService(service, path string) error

PublishService informs the INFO service about a new service.

service is the identifier of the service path is the path to the unix domain socket of the service

If the data does not exist, return null length []byte.

func (*MonstiClient) RegisterNodeType

func (s *MonstiClient) RegisterNodeType(nodeType *NodeType) error

RegisterNodeType registers a new node type.

Known field types will be reused. Just specify the id. All other // attributes of the field type will be ignored in this case.

func (*MonstiClient) RemoveNode

func (s *MonstiClient) RemoveNode(site string, node string) error

RemoveNode recursively removes the given site's node.

func (*MonstiClient) RenameNode

func (s *MonstiClient) RenameNode(site, source, target string) error

RenameNode renames (moves) the given site's node.

Source and target path must be absolute

func (*MonstiClient) SendMail

func (s *MonstiClient) SendMail(m *mimemail.Mail) error

Send given Monsti.

func (*MonstiClient) WaitSignal

func (s *MonstiClient) WaitSignal() error

WaitSignal waits for the next emitted signal.

You have to connect to some signals before. See ConnectSignal. This method must not be called in parallel by the same client instance.

func (*MonstiClient) WriteNode

func (s *MonstiClient) WriteNode(site, path string, node *Node) error

WriteNode writes the given node.

func (*MonstiClient) WriteNodeData

func (s *MonstiClient) WriteNodeData(site, path, file string,
	content []byte) error

WriteNodeData writes data for some node.

type Node

type Node struct {
	Path string `json:",omitempty"`
	// Content type of the node.
	Type  *NodeType `json:"-"`
	Order int
	// Don't show the node in navigations if Hide is true.
	Hide               bool
	Fields             map[string]Field `json:"-"`
	TemplateOverwrites map[string]TemplateOverwrite
	Embed              []EmbedNode
	LocalFields        []*NodeField
	// Public controls wether the node or its content may be viewed by
	// unauthenticated users.
	Public bool
	// PublishTime holds the time the node has been or should be
	// published.
	PublishTime time.Time
	// Changed is updated with the current time on every write to the
	// database.
	Changed time.Time
}

func (Node) GetField

func (n Node) GetField(id string) Field

func (Node) GetValue

func (n Node) GetValue(id string) interface{}

func (*Node) InitFields

func (n *Node) InitFields()

func (Node) Name

func (n Node) Name() string

Name returns the name of the node.

func (Node) PathToID

func (n Node) PathToID() string

PathToID returns an ID for the given node based on it's path.

The ID is simply the path of the node with all slashes replaced by two underscores and the result prefixed with "node-".

PathToID will panic if the path is not set.

For example, a node with path "/foo/bar" will get the ID "node-__foo__bar".

func (Node) TypeToID

func (n Node) TypeToID() string

TypeToID returns an ID for the given node type.

The ID is simply the type of the node with the namespace dot replaced by a hyphen and the result prefixed with "node-type-".

type NodeField

type NodeField struct {
	// The Id of the field including a namespace,
	// e.g. "namespace.somefieldype".
	Id string
	// The name of the field as shown in the web interface,
	// specified as a translation map (language -> msg).
	Name     map[string]string
	Required bool
	Type     string
}

type NodeQuery

type NodeQuery struct {
	Id string
}

type NodeType

type NodeType struct {
	// The Id of the node type including a namespace,
	// e.g. "namespace.somenodetype".
	Id string
	// Per default, nodes may be added to any other node. This behaviour
	// can be overwritten for one node type with this option. Nodes of
	// this type may only be added to nodes of the specified types. You
	// may specify individual node types with their full id
	// `namespace.id` or all node types of a namespace using
	// `namespace.` (i.e. the namespace followed by a single dot). To
	// specify all available node types, use the single dot,
	// i.e.`[.]`. To specify that the node may not be added to any other
	// node, use a non existing namespace like `[null.]` (it's currently
	// not possible to specify an empty array). It's still possible
	// to add nodes to any other node by directly manipulating the node
	// data on the file system. This option merely affects the web
	// interface.
	AddableTo []string
	// The name of the node type as shown in the web interface,
	// specified as a translation map (language -> msg).
	Name   map[string]string
	Fields []*NodeField
	Embed  []EmbedNode
	// If true, never show nodes of this type in the navigation.
	Hide bool
}

func (NodeType) GetLocalName

func (n NodeType) GetLocalName(locale string) string

GetLocalName returns the name of the node type in the given language.

Fall backs to to the "en" locale or the id of the node type.

type Provider

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

func NewProvider

func NewProvider(service string, rcvr interface{}) (p *Provider)

NewProvider returns a new Provider for the given service and using rcvr as RPC receiver.

func (*Provider) Accept

func (p *Provider) Accept() error

Accept starts accepting incoming connection and setting up RPC for the client.

func (*Provider) Listen

func (p *Provider) Listen(path string) error

Listen starts listening on the given unix domain socket path for incoming rpc connections. Be sure to call Accept after that.

type Request

type Request struct {
	Id uint
	// Site name
	Site string
	// The query values of the request URL.
	Query url.Values
	// Method of the request (GET,POST,...).
	Method RequestMethod
	// User session
	Session *UserSession
	// Action to perform (e.g. "edit").
	Action Action
	// FormData stores the requests form data.
	FormData url.Values
}

A request to be processed by a nodes service.

type RequestMethod

type RequestMethod uint

type Session

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

Session holds connections to the services.

func (*Session) Monsti

func (s *Session) Monsti() *MonstiClient

Info returns an InfoClient.

type SessionPool

type SessionPool struct {
	// Size is the maximum number of sessions to cache.
	Size int
	// MonstiPath is the path to the Monsti service to be used.
	MonstiPath string
	// contains filtered or unexported fields
}

SessionPool holds sessions to be used to access services.

func NewSessionPool

func NewSessionPool(size int, monstiPath string) *SessionPool

NewSessionPool returns a new session pool.

func (*SessionPool) Free

func (s *SessionPool) Free(session *Session)

Free puts a session back to the pool.

func (*SessionPool) New

func (s *SessionPool) New() (*Session, error)

New returns a session from the pool.

type SignalHandler

type SignalHandler interface {
	// Name returns the name of the signal to handle.
	Name() string
	// Handle handles a signal with given arguments.
	Handle(args interface{}) (interface{}, error)
}

SignalHandler wraps a handler for a specific signal.

func NewNodeContextHandler

func NewNodeContextHandler(
	cb func(Request uint, NodeType string) map[string]string) SignalHandler

NewNodeContextHandler consructs a signal handler that adds some template context for rendering a node.

type TemplateOverwrite

type TemplateOverwrite struct {
	// The template to be used instead.
	Template string
}

TemplateOverwrite specifies a template that should be used instead of another.

type TextField

type TextField string

TextField is a basic unicode text field

func (TextField) Dump

func (t TextField) Dump() interface{}

func (*TextField) FromFormField

func (t *TextField) FromFormField(data util.NestedMap, field *NodeField)

func (*TextField) Load

func (t *TextField) Load(in interface{}) error

func (TextField) RenderHTML

func (t TextField) RenderHTML() interface{}

func (TextField) String

func (t TextField) String() string

func (TextField) ToFormField

func (t TextField) ToFormField(form *htmlwidgets.Form, data util.NestedMap,
	field *NodeField, locale string)

type Type

type Type uint
const (
	MonstiService Type = iota
)

Monsti service types.

func (Type) String

func (t Type) String() string

type User

type User struct {
	Login string
	Name  string
	Email string
	// Hashed password.
	Password string
	// PasswordChanged keeps the time of the last password change.
	PasswordChanged time.Time
}

User represents a registered user of the site.

type UserSession

type UserSession struct {
	// Authenticaded user or nil
	User *User
	// Locale used for this session.
	Locale string
}

UserSession is a session of an authenticated or anonymous user.

Jump to

Keyboard shortcuts

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