Пример #1
0
func NewWS(conn *gt.Connection, session *mgo.Session, dbConn *mgo.Database, w http.ResponseWriter, req *http.Request, config *config.Config, ws io.Writer) (iface.Context, error) {
	opts, _, err := queryOptions(dbConn, false)
	if err != nil {
		return nil, err
	}
	cli := client.New(w, req, req.Header, config.Secret)
	hookz, has := opts["Hooks"].(map[string]interface{})
	if !has {
		hookz = map[string]interface{}{}
	}
	hoo := hooks.New(hookz, mod.NewModule)
	datab := db.New(session, dbConn, opts, hoo)
	usr := user.New(datab, cli)
	err = req.ParseMultipartForm(1000000)
	if err != nil {
		return nil, err
	}
	var tempFiles map[string][]*multipart.FileHeader
	if req.MultipartForm != nil {
		tempFiles = req.MultipartForm.File
	}
	temp := temporaries.New(tempFiles)
	fs := filesys.New(config.AbsPath, scut.CanonicalHost(req.Host, opts), opts, temp)
	mods := modifiers(req.Form)
	np := nonportable.New(req.URL.Path, convert.Mapify(req.Form), req, w)
	vctx := viewcontext.New()
	dsp := ws_display.New(ws, config.AbsPath)
	ch := channels.New()
	o := options.New(opts, mods)
	ev := events.New(conn)
	cond := conducting.New(hoo, ev)
	ctx := context.New(cond, fs, usr, cli, datab, ch, vctx, np, dsp, o)
	hoo.Initer(moduleIniter(ctx))
	return ctx, err
}
Пример #2
0
// Should not handle dot notation.
func TestNonDot(t *testing.T) {
	vctx := viewcontext.New()
	vctx.Publish("whatever.whatever", "asdasd")
	m := vctx.Get()
	_, ok := m["whatever"]
	if ok {
		t.Fatal()
	}
}
Пример #3
0
func TestBasic(t *testing.T) {
	vctx := viewcontext.New()
	vctx.Publish("str", "x")
	vctx.Publish("int", 12)
	m := vctx.Get()
	if m["str"] != "x" {
		t.Fatal()
	}
	if m["int"] != 12 {
		t.Fatal()
	}
}
Пример #4
0
func New(conn *gt.Connection, session *mgo.Session, dbConn *mgo.Database, w http.ResponseWriter, req *http.Request, config *config.Config) (iface.Context, error) {
	opts, _, err := queryOptions(dbConn, false)
	if err != nil {
		return nil, err
	}
	paths := strings.Split(req.URL.Path, "/")
	if strings.Index(paths[len(paths)-1], ".") != -1 {
		serveFile(opts, w, req, config.AbsPath, scut.CanonicalHost(req.Host, opts), req.URL.Path)
		return nil, nil
	}
	cli := client.New(w, req, req.Header, config.Secret)
	hookz, has := opts["Hooks"].(map[string]interface{})
	if !has {
		hookz = map[string]interface{}{}
	}
	hoo := hooks.New(hookz, mod.NewModule)
	datab := db.New(dbConn, opts, hoo)
	usrFilter, err := filter.NewSimple(set.New(dbConn, "users"), nil)
	if err != nil {
		return nil, err
	}
	usr := user.New(datab, usrFilter, hoo, cli)
	err = req.ParseMultipartForm(1000000)
	if err != nil {
		return nil, err
	}
	var tempFiles map[string][]*multipart.FileHeader
	if req.MultipartForm != nil {
		tempFiles = req.MultipartForm.File
	}
	temp := temporaries.New(tempFiles)
	fs := filesys.New(config.AbsPath, scut.CanonicalHost(req.Host, opts), opts, temp)
	mods := modifiers(req.Form)
	np := nonportable.New(req.URL.Path, convert.Mapify(req.Form), req, w)
	vctx := viewcontext.New()
	dsp := http_display.New(w, config.AbsPath)
	ch := channels.New()
	o := options.New(opts, mods)
	ev := events.New(conn)
	cond := conducting.New(hoo, ev)
	ctx := context.New(cond, fs, usr, cli, datab, ch, vctx, np, dsp, o)
	initer := func(inst iface.Instance) error {
		if inst.HasMethod("Init") {
			inst.Method("Init").Call(nil, ctx)
		}
		return nil
	}
	hoo.Initer(initer)
	return ctx, err
}
Пример #5
0
// Existing map under a given key + another map published with same key = two maps merged
func TestMerge(t *testing.T) {
	vctx := viewcontext.New()
	tm := map[string]interface{}{
		"x": 1,
	}
	tm1 := map[string]interface{}{
		"y": 2,
	}
	mname := "mapname"
	vctx.Publish(mname, tm)
	vctx.Publish(mname, tm1)
	m := vctx.Get()
	if len(m) != 1 {
		t.Fatal(m)
	}
	if m[mname].(map[string]interface{})["x"] != 1 || m[mname].(map[string]interface{})["y"] != 2 {
		t.Fatal(m)
	}
}