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
- type Action
- type Client
- type DateTimeField
- func (t DateTimeField) Dump() interface{}
- func (t *DateTimeField) FromFormField(data util.NestedMap, field *NodeField)
- func (t *DateTimeField) Init(m *MonstiClient, site string) error
- func (t *DateTimeField) Load(f func(interface{}) error) error
- func (t DateTimeField) RenderHTML() interface{}
- func (t DateTimeField) String() string
- func (t DateTimeField) ToFormField(form *htmlwidgets.Form, data util.NestedMap, field *NodeField, locale string)
- type EmbedNode
- type Field
- type FileField
- func (t FileField) Dump() interface{}
- func (t *FileField) FromFormField(data util.NestedMap, field *NodeField)
- func (t FileField) Init(*MonstiClient, string) error
- func (t *FileField) Load(f func(interface{}) error) error
- func (t FileField) RenderHTML() interface{}
- func (t FileField) String() string
- func (t FileField) ToFormField(form *htmlwidgets.Form, data util.NestedMap, field *NodeField, locale string)
- type HTMLField
- func (t HTMLField) Dump() interface{}
- func (t *HTMLField) FromFormField(data util.NestedMap, field *NodeField)
- func (t HTMLField) Init(*MonstiClient, string) error
- func (t *HTMLField) Load(f func(interface{}) error) error
- func (t HTMLField) RenderHTML() interface{}
- func (t HTMLField) String() string
- func (t HTMLField) ToFormField(form *htmlwidgets.Form, data util.NestedMap, field *NodeField, locale string)
- type MonstiClient
- func (s *MonstiClient) AddSignalHandler(handler SignalHandler) error
- func (s *MonstiClient) EmitSignal(name string, args interface{}, retarg interface{}) error
- func (s *MonstiClient) GetAddableNodeTypes(site, nodeType string) (types []string, err error)
- func (s *MonstiClient) GetChildren(site, path string) ([]*Node, error)
- func (s *MonstiClient) GetNode(site, path string) (*Node, error)
- func (s *MonstiClient) GetNodeData(site, path, file string) ([]byte, error)
- func (s *MonstiClient) GetNodeType(nodeTypeID string) (*NodeType, error)
- func (s *MonstiClient) GetNodeTypes() ([]string, error)
- func (s *MonstiClient) GetRequest(id uint) (*Request, error)
- func (s *MonstiClient) GetSiteConfig(site, name string, out interface{}) error
- func (s *MonstiClient) ModuleInitDone(module string) error
- func (s *MonstiClient) PublishService(service, path string) error
- func (s *MonstiClient) RegisterNodeType(nodeType *NodeType) error
- func (s *MonstiClient) RemoveNode(site string, node string) error
- func (s *MonstiClient) RenameNode(site, source, target string) error
- func (s *MonstiClient) SendMail(m *mimemail.Mail) error
- func (s *MonstiClient) WaitSignal() error
- func (s *MonstiClient) WriteNode(site, path string, node *Node) error
- func (s *MonstiClient) WriteNodeData(site, path, file string, content []byte) error
- type Node
- func (n Node) GetField(id string) Field
- func (n Node) GetParentPath() string
- func (n Node) GetPathPrefix() string
- func (n Node) GetValue(id string) interface{}
- func (n *Node) InitFields(m *MonstiClient, site string) error
- func (n Node) Name() string
- func (n Node) PathToID() string
- func (n Node) TypeToID() string
- type NodeContextArgs
- type NodeField
- type NodeQuery
- type NodeType
- type Provider
- type Request
- type RequestMethod
- type Session
- type SessionPool
- type SignalHandler
- type TemplateOverwrite
- type TextField
- func (t TextField) Dump() interface{}
- func (t *TextField) FromFormField(data util.NestedMap, field *NodeField)
- func (t TextField) Init(*MonstiClient, string) error
- func (t *TextField) Load(f func(interface{}) error) error
- func (t TextField) RenderHTML() interface{}
- func (t TextField) String() string
- func (t TextField) ToFormField(form *htmlwidgets.Form, data util.NestedMap, field *NodeField, locale string)
- type Type
- type User
- type UserSession
Constants ¶
const ( GetRequest = iota PostRequest )
const ( ViewAction = iota EditAction LoginAction LogoutAction AddAction RemoveAction RequestPasswordTokenAction ChangePasswordAction )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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.
type DateTimeField ¶
func (DateTimeField) Dump ¶
func (t DateTimeField) Dump() interface{}
func (*DateTimeField) FromFormField ¶
func (t *DateTimeField) FromFormField(data util.NestedMap, field *NodeField)
func (*DateTimeField) Init ¶
func (t *DateTimeField) Init(m *MonstiClient, site string) error
func (*DateTimeField) Load ¶
func (t *DateTimeField) Load(f func(interface{}) error) error
func (DateTimeField) RenderHTML ¶
func (t DateTimeField) RenderHTML() interface{}
func (DateTimeField) String ¶
func (t DateTimeField) String() string
func (DateTimeField) ToFormField ¶
func (t DateTimeField) ToFormField(form *htmlwidgets.Form, data util.NestedMap, field *NodeField, locale string)
type Field ¶
type Field interface { // Init initializes the field. Init(*MonstiClient, string) error // 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(func(interface{}) error) 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) FromFormField ¶
func (FileField) RenderHTML ¶
func (t FileField) RenderHTML() interface{}
func (FileField) ToFormField ¶
type HTMLField ¶
type HTMLField string
HTMLField is a text area containing HTML code
func (*HTMLField) FromFormField ¶
func (HTMLField) RenderHTML ¶
func (t HTMLField) RenderHTML() interface{}
func (HTMLField) ToFormField ¶
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.
Currently, you can only set one handler per signal and MonstiClient.
Be sure to wait for incoming signals by calling WaitSignal() on this MonstiClient!
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) 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) GetSiteConfig ¶
func (s *MonstiClient) GetSiteConfig(site, name string, out interface{}) error
GetSiteConfig puts the named site local configuration into the variable out.
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 AddSignalHandler. 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) GetParentPath ¶
GetParentPath calculates the parent node's path respecting the node's path prefix.
func (Node) GetPathPrefix ¶
GetPathPrefix returns the calculated prefix path.
func (*Node) InitFields ¶
func (n *Node) InitFields(m *MonstiClient, site string) error
func (Node) PathToID ¶
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".
type NodeContextArgs ¶
type NodeType ¶
type NodeType struct { // The Id of the node type including a namespace, // e.g. "namespace.somenodetype". Id string // Per default, nodes may not be added to any other node. This // behaviour can be overwritten 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.`.`. It's always 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 // PathPrefix defines a dynamic path that will be prepended to the // node name. // // Supported values: $year, $month, $day PathPrefix string }
func (NodeType) GetLocalName ¶
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 ¶
func NewProvider ¶
NewProvider returns a new Provider for the given service and using rcvr as RPC receiver.
type Request ¶
type Request struct { Id uint NodePath string // 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.
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, embedNode *EmbedNode) 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) FromFormField ¶
func (TextField) RenderHTML ¶
func (t TextField) RenderHTML() interface{}
func (TextField) ToFormField ¶
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.