示例#1
0
文件: app.go 项目: speedland/apps
func init() {
	server := gae.NewServer()
	server.Routes().Get("/", func(res *wcg.Response, req *wcg.Request) {
		res.WriteString("static")
	})
	server.Run()
}
示例#2
0
文件: hello.go 项目: speedland/wcg
func init() {
	app := gae.NewServer()
	routes := app.Routes()
	routes.Get("/", func(res *Response, req *Request) {
		res.WriteString("Hello World!")
	})
	app.Run()
}
示例#3
0
func startServer() {
	app := gae.NewServer()
	routes := app.Routes()

	dir, _ := os.Getwd()
	wcg.ViewConfig.BaseDir = filepath.Join(dir, "app/templates")

	routes.Before(func(res *wcg.Response, req *wcg.Request) {
		if req.URL().Path == "/favicon.ico" {
			res.WriteHeader(404)
			res.End()
		}
	})

	routes.Before(middleware.StaticFile("/static", filepath.Join(dir, "app/static")))
	before, after := middleware.SessionSupport(SessionConfig)

	routes.Before(before)
	routes.Before(func(res *wcg.Response, req *wcg.Request) {
		res.SetLocal("title", AppConfig.SiteTitle)
		res.SetLocal("copyright", AppConfig.Copyright)
	})

	routes.Post("/*", middleware.CSRFSupport())
	routes.Put("/*", middleware.CSRFSupport())
	routes.Delete("/*", middleware.CSRFSupport())

	configureOAuth(routes)
	routes.Get("/", TopHandler)
	configureBlogs(routes)
	configurePosts(routes)

	routes.After(after)
	routes.After(middleware.AccessLog(os.Stderr, ""))

	app.Run()
}
示例#4
0
文件: app.go 项目: speedland/apps
type App struct {
	Key         string
	Title       string
	Start       func(*wcg.Response, *wcg.Request)
	Warmup      func(*wcg.Response, *wcg.Request)
	Api         *ApiHelper
	Cron        *CronHelper
	Page        *PageHelper
	pages       []*Page
	navigations []*Page
	routes      *wcg.Router
	DefaultOgp  map[string]string
}

var GAEServer = gae.NewServer()
var apps = make(map[string]*App)

func NewApp(key string, title string) *App {
	app := &App{}
	app.Key = key
	app.Title = title
	app.routes = GAEServer.Routes()
	app.pages = make([]*Page, 0)
	app.navigations = make([]*Page, 0)
	app.Api = &ApiHelper{app: app}
	app.Page = &PageHelper{app: app}
	app.Cron = NewCronHelper(app)
	app.DefaultOgp = make(map[string]string)
	apps[key] = app
	return app