context

package
v0.0.0-...-076d96f Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2012 License: BSD-2-Clause-Views Imports: 8 Imported by: 0

Documentation

Overview

Context contains the type Uni. An instance of this type is passed to the modules when routing the control to them.

Index

Constants

This section is empty.

Variables

View Source
var Convert = basic.Convert

Functions

This section is empty.

Types

type Ev

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

With the help of this type it's possible for the model to not have direct access to everything (*context.Uni), but still trigger events, which in turn will result in hooks (which may need access to everything) being called. Ev is an implementation of the interface Event fround in "github.com/opesun/hypecms/interfaces"

func NewEv

func NewEv(uni *Uni) *Ev

func (*Ev) Iterate

func (e *Ev) Iterate(eventname string, stopfunc interface{}, params ...interface{})

Calls all hooks subscribed to eventname, with params, feeding the output of every hook into stopfunc. Stopfunc's argument signature must match the signatures of return values of the called hooks. Stopfunc must return a boolean value. A boolean value of true stops the iteration. Iterate allows to mimic the semantics of calling all hooks one by one, with *Uni if the need it, without having access to *Uni.

func (*Ev) Trigger

func (e *Ev) Trigger(eventname string, params ...interface{})

Trigger calls hooks subscribed to eventname, passes *Uni as a first parameter if the given hook needs it (eg *context.Uni is defined as its first parameter), and params... if they are given.

Example eventname: "content.insert" Note that, different subscriptions should not be created for subsets of functionality, eg: "content.blog.insert" (where blog is a content type) should not be used, because we build the hook function name from the access path, eg: content.insert => ContentInsert may be a static, valid hookname, but ContentBlogInsert not (a module author can't know that the type will be blog or cats ahead of time).

Filtering can be done inside ContentInsert if one module wants to act only on certain information (in the example case on certain content types).

type Uni

type Uni struct {
	Session *mgo.Session
	Db      *mgo.Database
	W       http.ResponseWriter
	Req     *http.Request

	P     string   // Path string
	Paths []string // Path slice, contains the url (after the domain) splitted by "/"

	Opt    map[string]interface{} // Freshest options from database.
	Dat    map[string]interface{} // General communication channel.
	Put    func(...interface{})   // Just a convenience function to allow fast output to http response.
	Root   string                 // Absolute path of the application.
	Ev     *Ev
	Caller interfaces.Caller
	// contains filtered or unexported fields
}

General context for the application.

func (*Uni) OriginalOpt

func (u *Uni) OriginalOpt() string

func (*Uni) Secret

func (u *Uni) Secret() string

Maybe we should not even return the secret, because a badly written module can make publish it. Or, we could serve different values to different packages. That makes the encrypted values noncompatible across packages though.

func (*Uni) SetOriginalOpt

func (u *Uni) SetOriginalOpt(s string)

Set only once.

func (*Uni) SetSecret

func (u *Uni) SetSecret(s string)

Set only once.

Jump to

Keyboard shortcuts

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