Beispiel #1
0
func (vh *VirtualHost) Load() error {
	store := object.NewBoltStore(vh.root, "vhost.dat", object.BoltCoder{})
	if err := store.Load(); err != nil {
		return err
	}
	vh.store = store
	return nil
}
Beispiel #2
0
func (app *Application) Init() error {
	httpAddr, err := net.ResolveTCPAddr("tcp", app.Options.HTTPAddress)
	if err != nil {
		return err
	}
	app.httpAddr = httpAddr

	httpListener, err := net.Listen("tcp", app.httpAddr.String())
	if err != nil {
		return err
	}
	app.httpListener = httpListener

	app.Configs.SetSection("h2object")

	if app.Options.AppID != "" {
		app.Configs.SetOption("appid", app.Options.AppID)
	}
	if app.Options.AppSecret != "" {
		app.Configs.SetOption("secret", app.Options.AppSecret)
	}

	cache_expire := app.Configs.StringDefault("cache.expire", "10m")
	duration_expire, err := time.ParseDuration(cache_expire)
	if err != nil {
		return err
	}

	cache_flush := app.Configs.StringDefault("cache.flush", "10s")
	duration_flush, err := time.ParseDuration(cache_flush)
	if err != nil {
		return err
	}
	// cache init
	app.cache = object.NewMutexCache(duration_expire, duration_flush)

	// index init
	app.pageIndexes = object.NewBleveIndexes(app.Options.IndexesRoot, "pages.idx")
	app.objectIndexes = object.NewBleveIndexes(app.Options.IndexesRoot, "objects.idx")

	// store init
	systems := object.NewBoltStore(app.Options.StorageRoot, "systems.dat", object.BoltCoder{})
	if err := systems.Load(); err != nil {
		return err
	}
	app.systems = systems

	objects := object.NewBoltStore(app.Options.StorageRoot, "objects.dat", object.BoltCoder{})
	if err := objects.Load(); err != nil {
		return err
	}
	app.objects = objects

	pages := object.NewBoltStore(app.Options.StorageRoot, "pages.dat", object.BoltCoder{})
	if err := pages.Load(); err != nil {
		return err
	}
	app.pages = pages

	clicks := object.NewBoltStore(app.Options.StorageRoot, "clicks.dat", object.BoltCoder{})
	if err := clicks.Load(); err != nil {
		return err
	}
	app.clicks = clicks
	// template
	paths := []string{app.Options.TemplateRoot}
	delimiters := app.Configs.StringDefault("template.delimiters", "{{ }}")
	app.templates = template.NewTemplateLoader(delimiters, paths, app.Logger)

	// template load
	if err := app.templates.Load(); err != nil {
		return err
	}

	// context init
	ctx := new_context(app)
	if err := ctx.init(); err != nil {
		return err
	}
	set_context(ctx)
	app.Info("application signature (%s)", ctx.signature)

	// service
	serv := new_service(ctx)
	if err := serv.init(); err != nil {
		return err
	}

	// stats
	stats_enable := app.Configs.BoolDefault("stats.enable", true)
	if stats_enable {
		app.statistics = stats.New()
		app.service = app.statistics.Handler(serv)
	} else {
		app.service = serv
	}

	if err := app.Configs.Save(""); err != nil {
		return err
	}
	// init succeed
	return nil
}