Пример #1
0
func main() {

	flag.Parse()

	log.Println("Accessing DB...")
	session, err := mgo.Dial(dbhost)
	if err != nil {
		log.Fatal(err.Error())
	}
	defer session.Close()
	session.SetMode(mgo.Monotonic, true)
	db := session.DB(dbname)
	log.Printf("DB (%s %s) opend.", dbhost, dbname)

	log.Println("Initializing handlers...")
	api.Init(db)
	goweb.ConfigureDefaultFormatters()
	http.Handle("/api/", http.StripPrefix("/api", goweb.DefaultHttpHandler))
	log.Println("Registered a handler for RESTful API.")

	http.Handle("/", http.FileServer(http.Dir("static")))
	log.Println("Registered a handler for static files.")

	log.Printf("Starting Diary Server at %s", addr)
	http.ListenAndServe(addr, nil)
}
Пример #2
0
func main() {

	if toris.ShowModules {
		log.Println("Installed modules", toris.Context.ModuleList())
		os.Exit(0)
	}

	c := toris.Context.ConfigFile

	serverPort, _ := c.GetInt("server", "port")

	// Add default result formatter (JSON)
	goweb.ConfigureDefaultFormatters()

	// start the modules
	for name, _ := range toris.Context.ModuleList() {
		log.Println("Starting module " + name)
		err := toris.Context.Start(name)
		if err != nil {
			log.Println("[ERROR]", "An exception was raised", err)
		} else {
			log.Println("OK")
		}
	}

	serverUrl := fmt.Sprintf(":%d", serverPort)
	log.Println("Starting server on: " + serverUrl)
	log.Fatal(goweb.ListenAndServe(serverUrl))

}