Exemple #1
0
func main() {
	tracelog.StartFile(tracelog.LevelTrace, "logs", 1)
	tracelog.Started("main", "Initializing Postgres")
	var confName string = os.Getenv("BOOKS_CONF")
	if len(confName) == 0 {
		confName = "default"
	}
	s := []string{"conf/db/", confName, ".json"}
	jsonconf, err := config.NewConfig("json", strings.Join(s, ""))
	if err != nil {
		tracelog.Errorf(err, "main", "config.NewConfig", "Failed to find config", strings.Join(s, ""))
	}
	var User string = jsonconf.String("User")
	var Pass string = jsonconf.String("Pass")
	var DBName string = jsonconf.String("DBName")
	var buffer bytes.Buffer
	buffer.WriteString("user="******" password="******" dbname=")
	buffer.WriteString(DBName)
	s2 := []string{"user="******" password="******" dbname=", DBName, " sslmode=disable"}
	orm.RegisterDriver("postgres", orm.DR_Postgres)
	orm.RegisterDataBase("default", "postgres", strings.Join(s2, ""))
	beego.SetStaticPath("/images", "static/images")
	beego.SetStaticPath("/css", "static/css")
	beego.SetStaticPath("/js", "static/js")
	beego.SetStaticPath("/fonts", "static/fonts")
	beego.SetStaticPath("/partials", "static/partials")
	beego.EnableAdmin = true
	orm.RunCommand()
	beego.Run()
}
// Prepare is called prior to the baseController method.
func (baseController *BaseController) Prepare() {

	UserID := baseController.GetSession("UserID")
	if UserID == nil {
		UserID = "Unknown"
	}
	baseController.UserID = UserID.(string)

	if err := baseController.Service.Prepare(); err != nil {
		log.Errorf(err, baseController.UserID, "BaseController.Prepare", baseController.Ctx.Request.URL.Path)
		baseController.ServeError(err)
		return
	}

	log.Trace(baseController.UserID, "BaseController.Prepare", "UserID[%s] Path[%s]", baseController.UserID, baseController.Ctx.Request.URL.Path)
}
Exemple #3
0
// Prepare is called prior to the baseController method.
func (baseController *BaseController) Prepare() {
	baseController.UserID = baseController.GetString("userID")
	if baseController.UserID == "" {
		baseController.UserID = baseController.GetString(":userID")
	}

	if baseController.UserID == "" {
		baseController.UserID = "Unknow"
	}

	if err := baseController.Service.Prepare(); err != nil {
		log.Errorf(err, baseController.UserID, "BaseController.Prepare", baseController.Ctx.Request.URL.Path)
		baseController.ServeError(err)
		return
	}
	log.Trace(baseController.UserID, "BaseController.Prepare", "UserID[%s] Path[%s]", baseController.UserID, baseController.Ctx.Request.URL.Path)
}
Exemple #4
0
// Prepare is called prior to the baseController method
func (baseController *BaseController) Prepare() {
	baseController.UserId = baseController.GetString("userId")
	if baseController.UserId == "" {
		baseController.UserId = baseController.GetString(":userId")
	}
	if baseController.UserId == "" {
		baseController.UserId = "Unknown"
	}

	err := baseController.Service.Prepare()
	if err != nil {
		tracelog.Errorf(err, baseController.UserId, "BaseController.Prepare", baseController.Ctx.Request.URL.Path)
		baseController.ServeError(err)
		return
	}

	tracelog.Trace(baseController.UserId, "BaseController.Prepare", "UserId[%s] Path[%s]", baseController.UserId, baseController.Ctx.Request.URL.Path)
}