示例#1
0
文件: bang.go 项目: crufter/nocrud
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
文件: bang.go 项目: Laller/nocrud
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
}