Ejemplo n.º 1
0
// Executes the function provided against the database. Will connect to the database as per the
// application configuration and execute the function providing the desired collection
func execute(fn executeFunc, col string) {
	session, err := mgo.Dial(gouter.Configuration().Database.Host)
	if err != nil {
		panic(err)
	}
	defer session.Close()
	collection := session.DB(gouter.Configuration().Database.Database).C(col)
	// Call the provided function with the loaded collection
	fn(collection)
}
Ejemplo n.º 2
0
// Displays the start blurb for the router
func start(port string) {
	log.Printf("\n  ________               __                \n /  _____/  ____  __ ___/  |_  ___________ \n/   \\  ___ /  _ \\|  |  \\   __\\/ __ \\_  __ \\ \n\\    \\_\\  (  <_> )  |  /|  | \\  ___/|  | \\/\n \\______  /\\____/|____/ |__|  \\___  >__|\n        \\/                        \\/")
	log.Printf("Starting Gouter v0.5. A simple HTTP router for RESTful API calls.")
	log.Printf("Please call http://localhost:%v%v to configure Gouter.", port, gouter.Configuration().Application.AdminUrl)
	http.HandleFunc("/", lib.HandleRequest)
	controllers.Load()
	log.Printf("Listening for HTTP requests on Port '%v'", port)
}
Ejemplo n.º 3
0
// Loads the route handers for configuration for the go router
func Load() {
	log.Printf("Administration: Loading the configuration handlers.")
	// Handle the Controller actions
	http.HandleFunc(gouter.Configuration().Application.AdminUrl, index)
	// Standard handling of the css, js and fonts paths
	http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("./tmpl/css"))))
	http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("./tmpl/js"))))
	http.Handle("/fonts/", http.StripPrefix("/fonts/", http.FileServer(http.Dir("./tmpl/fonts"))))
	http.Handle("/favicon.ico", http.StripPrefix("/fonts/", http.FileServer(http.Dir("./tmpl/images"))))
}
Ejemplo n.º 4
0
// Loads the parameters that got provided on the command line. If not provided will use the defaults instead
func loadParameters() string {
	wordPtr := flag.String("port", gouter.Configuration().Application.Port, "Port Number for the Gouter to run at")
	flag.Parse()
	return *wordPtr
}