Example #1
0
func main() {
	parsePage()
	props.ParseProperties()

	fs := http.FileServer(http.Dir("static"))
	http.Handle("/static/", http.StripPrefix("/static/", fs))

	router := mux.NewRouter()
	router.HandleFunc("/", handleIndex())
	router.HandleFunc("/incident", handleIncident)
	router.HandleFunc("/incident/{id}", handleIncident)
	router.HandleFunc("/create-incident", handleCreateIncident)

	http.Handle("/", router)

	port := ":3001"
	if len(os.Args) >= 2 {
		port = ":" + os.Args[1]
	}
	if len(os.Args) >= 3 {
		props.SetProp("db.url", os.Args[2])
	}
	log.Println("Database URL:", props.GetProp("db.url"))
	log.Println("Listening on", port)
	log.Fatal(http.ListenAndServe(port, nil))
}
Example #2
0
// Connect - Connect to mongo database
func (m *MongoConnection) Connect() *mgo.Session {
	var err error
	if m.Session == nil {
		m.Session, err = mgo.Dial(props.GetProp("db.url"))
		if err != nil {
			panic(err)
		}
		m.Session.SetMode(mgo.Monotonic, true)
	}

	return m.Session.Copy()
}