You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1 KiB

  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "os"
  6. "github.com/gorilla/handlers"
  7. mgo "gopkg.in/mgo.v2"
  8. )
  9. var cellCollection *mgo.Collection
  10. func main() {
  11. savelog()
  12. //connect with mongodb
  13. readMongodbConfig("./mongodbConfig.json")
  14. session, err := getSession()
  15. check(err)
  16. cellCollection = getCollection(session, "cells")
  17. if len(os.Args) > 1 {
  18. if os.Args[1] == "-dataset" {
  19. log.Println("starting to read dataset")
  20. readDataset("cell_towers.csv")
  21. //readDataset("dataModel_head.csv")
  22. log.Println("finished reading dataset")
  23. }
  24. }
  25. //http server start
  26. readServerConfig("./serverConfig.json")
  27. log.Println("server running")
  28. log.Print("port: ")
  29. log.Println(serverConfig.ServerPort)
  30. router := NewRouter()
  31. headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin"})
  32. originsOk := handlers.AllowedOrigins([]string{"*"})
  33. methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
  34. log.Fatal(http.ListenAndServe(":"+serverConfig.ServerPort, handlers.CORS(originsOk, headersOk, methodsOk)(router)))
  35. }