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.

38 lines
819 B

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. mgo "gopkg.in/mgo.v2"
  7. "github.com/fatih/color"
  8. )
  9. var userCollection *mgo.Collection
  10. var itemCollection *mgo.Collection
  11. func main() {
  12. fmt.Println("starting")
  13. //mongodb start
  14. readMongodbConfig("./mongodbConfig.json")
  15. session, err := getSession()
  16. check(err)
  17. userCollection = getCollection(session, "users")
  18. itemCollection = getCollection(session, "items")
  19. color.Green("mongodb connected")
  20. //read items dataset
  21. itemsDataset := readDataset("./itemSamples.data", "\n", ",")
  22. items := getItemsFromDataset(itemsDataset)
  23. datasetToMongodbIfNotExist(itemCollection, items)
  24. //http server start
  25. readServerConfig("./serverConfig.json")
  26. color.Green("server running")
  27. router := NewRouter()
  28. log.Fatal(http.ListenAndServe(":"+serverConfig.ServerPort, router))
  29. }