Exemplo n.º 1
0
Arquivo: init.go Projeto: huntaub/list
func StartApp() {
	revel.INFO.Printf("Beginning Initialization Process...")

	// Load Database Connections
	revel.INFO.Printf("Connecting to Database...")
	session, err := mgo.Dial("mongodb://*****:*****@oceanic.mongohq.com:10000/list")
	if err != nil {
		panic(err)
	}

	collection = session.DB("list").C("classes")
	users = session.DB("list").C("users")
	rand.Seed(time.Now().UnixNano())

	// Start Parsing Lou's List
	revel.INFO.Printf("Launching Parser...")
	jobs.Now(Parser{})
	jobs.Every(1*time.Hour, Parser{})

	// Regex to Recognize Classes
	revel.INFO.Printf("Compiling Regular Expressions...")
	classRegex = regexp.MustCompile(`([A-z]{1,4})\s?(\d{4})\s?(?::{((?:,?\s?\d{1,3})+)})?`)
	sectionRegex = regexp.MustCompile(`\d{1,3}`)

	/*	revel.INFO.Printf("Adding Template Functions...")
		CreateTemplateFunctions()*/

	// Interceptions
	revel.INFO.Printf("Starting Interceptors...")
	revel.InterceptMethod(App.Init, revel.BEFORE)

	revel.INFO.Printf("Initialization Complete")
}
Exemplo n.º 2
0
func init() {
	// Set up the database.
	revel.OnAppStart(InitDB)

	// Start running the probes.
	revel.OnAppStart(func() {
		jobs.Every(10*time.Second, ProbeJob{})
	})

	// Before a request, make sure the right API token is set.
	revel.InterceptMethod((*GorpController).CheckToken, revel.BEFORE)

	// Before a request, we want to start a transaction.
	revel.InterceptMethod((*GorpController).Begin, revel.BEFORE)

	//	revel.InterceptMethod(Application.AddUser, revel.BEFORE)
	//	revel.InterceptMethod(Hotels.checkUser, revel.BEFORE)

	// When a request is done, we want to commit the transaction.
	revel.InterceptMethod((*GorpController).Commit, revel.AFTER)
	revel.InterceptMethod((*GorpController).Rollback, revel.FINALLY)
}
Exemplo n.º 3
0
func init() {
	// Filters is the default set of global filters.
	revel.Filters = []revel.Filter{
		revel.PanicFilter,             // Recover from panics and display an error page instead.
		revel.RouterFilter,            // Use the routing table to select the right Action
		revel.FilterConfiguringFilter, // A hook for adding or removing per-Action filters.
		revel.ParamsFilter,            // Parse parameters into Controller.Params.
		revel.SessionFilter,           // Restore and write the session cookie.
		revel.FlashFilter,             // Restore and write the flash cookie.
		revel.ValidationFilter,        // Restore kept validation errors and save new ones from cookie.
		revel.I18nFilter,              // Resolve the requested language
		HeaderFilter,                  // Add some security based headers
		revel.InterceptorFilter,       // Run interceptors around the action.
		revel.CompressFilter,          // Compress the result.
		revel.ActionInvoker,           // Invoke the action.
	}

	revel.TemplateFuncs["delim"] = func(num int) string {
		var buffer bytes.Buffer
		runes := []rune(strconv.Itoa(num))
		for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
			runes[i], runes[j] = runes[j], runes[i]
		}
		revStr := string(runes)
		for i := 0; i < len(revStr); i++ {
			if i%3 == 0 && i != 0 {
				buffer.WriteString(",")
			}
			buffer.WriteString(string(revStr[i]))
		}
		runes1 := []rune(buffer.String())
		for i, j := 0, len(runes1)-1; i < j; i, j = i+1, j-1 {
			runes1[i], runes1[j] = runes1[j], runes1[i]
		}
		return string(runes1)

	}
	revel.TemplateFuncs["delim64"] = func(num int64) string {
		var buffer bytes.Buffer
		runes := []rune(strconv.FormatInt(num, 10))
		for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
			runes[i], runes[j] = runes[j], runes[i]
		}
		revStr := string(runes)
		for i := 0; i < len(revStr); i++ {
			if i%3 == 0 && i != 0 {
				buffer.WriteString(",")
			}
			buffer.WriteString(string(revStr[i]))
		}
		runes1 := []rune(buffer.String())
		for i, j := 0, len(runes1)-1; i < j; i, j = i+1, j-1 {
			runes1[i], runes1[j] = runes1[j], runes1[i]
		}
		return string(runes1)

	}

	revel.TemplateFuncs["neq"] = func(a, b interface{}) bool {
		return a != b
	}

	revel.TemplateFuncs["formatDate"] = func(timestamp int64) string {
		return time.Unix(timestamp, 0).String()
	}

	revel.TemplateFuncs["encode"] = func(message string) string {
		return url.QueryEscape(message)
	}

	revel.OnAppStart(func() {
		jobs.Every(10*time.Minute, background.ProcessSpeed{})
	})

	// register startup functions with OnAppStart
	// ( order dependent )
	// revel.OnAppStart(InitDB())
	// revel.OnAppStart(FillCache())
}