Beispiel #1
0
func (application *HelperController) Init(filename *string) {
	config, err := toml.LoadFile(*filename)
	if err != nil {
		glog.Fatalf("TOML load failed: %s\n", err)
	}
	application.Config = config
}
Beispiel #2
0
func (application *Application) Init(filename *string) {

	config, err := toml.LoadFile(*filename)
	if err != nil {
		glog.Fatalf("TOML load failed: %s\n", err)
	}

	//hash := sha256.New()
	//io.WriteString(hash, config.Get("cookie.mac_secret").(string))
	//application.Store = sessions.NewCookieStore(hash.Sum(nil))
	// application.Store.Options = &sessions.Options{
	// 	Path:     "/",
	// 	HttpOnly: true,
	// 	Secure:   config.Get("cookie.secure").(bool),
	// }
	//dbConfig := config.Get("database").(*toml.TomlTree)
	// application.DbMap = models.GetDbMap(
	// 	dbConfig.Get("user").(string),
	// 	dbConfig.Get("password").(string),
	// 	dbConfig.Get("hostname").(string),
	// 	dbConfig.Get("port").(string),
	// 	dbConfig.Get("database").(string))

	application.GormDB = models.GetDB("gohan")

	// application.CsrfProtection = &CsrfProtection{
	// 	Key:    config.Get("csrf.key").(string),
	// 	Cookie: config.Get("csrf.cookie").(string),
	// 	Header: config.Get("csrf.header").(string),
	// 	Secure: config.Get("cookie.secure").(bool),
	// }

	application.Config = config
	//Helpers register
	raymond.RegisterHelper("time", func(input, format string) raymond.SafeString {
		fmt.Println(input)
		t, err := time.Parse("2006-01-02 15:04:05.00000000 +0000 UTC", input)
		if err != nil {
			t, err = time.Parse("2006-01-02 15:04:05.000000000 +0000 UTC", input)
			if err != nil {
				panic(err)
			}
		}
		return raymond.SafeString(t.Format("January 2006"))
	})
}