Exemplo n.º 1
0
// NewInstance creates *Instance
func NewInstance() *Instance {
	instance := &Instance{
		Server: gae.NewServer(),
	}
	instance.Routes().Before(wcg.NewNamedHandler("init", func(res *wcg.Response, req *wcg.Request) {
		instance.once.Do(func() {
			req.Logger.Infof("----------- Server initialization ----------- ")
			if instance.Init != nil {
				instance.Init(req)
			}
			req.Logger.Infof("----------- Apps initialization ----------- ")
			for _, app := range instance.apps {
				if app.Init != nil {
					app.Init(req)
				}
			}
			req.Logger.Infof("----------- All init processes finished ----------- ")
		})
	}))
	auth.Prepare(instance.Routes(), func() {
		instance.Routes().GET("/cron.yaml", wcg.NewNamedHandler("cron.yaml", func(res *wcg.Response, req *wcg.Request) {
			res.Header().Add("Content-Type", "text/yaml")
			res.WriteString("cron:\n")
			for _, app := range instance.apps {
				res.WriteString(app.Cron().ToYAML())
			}
		}))
		instance.Routes().GET("/queue.yaml", wcg.NewNamedHandler("queue.yaml", func(res *wcg.Response, req *wcg.Request) {
			res.Header().Add("Content-Type", "text/yaml")
			res.WriteString("queue:\n")
			for _, app := range instance.apps {
				res.WriteString(app.Queue().ToYAML())
			}
		}))
	})

	instance.Routes().NotFound = Handler(func(req *wcg.Request) response.Response {
		return response.NotFound(req)
	})
	return instance
}
Exemplo n.º 2
0
func init() {
	server := gae.NewServer()
	server.Run()
}