Example #1
0
func Init(appName, port string) {
	AppName = appName
	basePath = foundation.BasePath
	internalPath = filepath.Join(basePath, "internal")
	ViewsPath = filepath.Join(internalPath, "views")

	paths := [][]string{
		{"    BasePath", foundation.BasePath},
		{"   ViewsPath", ViewsPath},
	}
	foundation.DebugPrintf("[%s] Running %s in %s mode\n", AppName, AppName, foundation.Mode())
	foundation.DebugPrintf("[%s] Listening and serving HTTP on %s\n", AppName, port)
	for _, v := range paths {
		foundation.DebugPrintf("[%s] %s = %s\n", AppName, v[0], v[1])
	}
}
Example #2
0
	}

	// Sync database scheme (create or migrate tables)
	orm := database.NewGorm()
	scheme.Sync(orm)
}

/////////////////////////////////////////////////
////////// Middlewares (for Request))
/////////////////////////////////////////////////

var DebugMiddleware = func() foundation.Middleware {
	mw := foundation.Middleware{
		Func: func(ctx foundation.Context) {
			req := ctx.Request()
			foundation.DebugPrintf("Request ClientIP: %s\n", req.ClientIP())
			foundation.DebugPrintf("Request User-Agent: %s\n", req.UserAgent())
			ctx.Operation().Next()
		},
	}
	return mw
}

var CookieSessionMiddleware = func() foundation.Middleware {
	opt := foundation.SessionOptions{
		Secure:   false,
		HttpOnly: false,
	}
	name, secret := config.GetApp().Name, config.GetApp().Secret
	return foundation.CookieSessionMiddleware(opt, name, []byte(secret))
}