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.

45 lines
1022 B

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "os"
  7. "github.com/fatih/color"
  8. "github.com/gorilla/handlers"
  9. )
  10. const keysDir = "keys"
  11. const keysize = 2048
  12. const hashize = 1536
  13. func main() {
  14. color.Blue("Starting darkID clientApp")
  15. readConfig("config.json")
  16. fmt.Println(config)
  17. //create models directory
  18. _ = os.Mkdir(keysDir, os.ModePerm)
  19. //run thw webserver
  20. go GUI()
  21. //run API
  22. log.Println("api server running")
  23. log.Print("port: ")
  24. log.Println(config.Port)
  25. router := NewRouter()
  26. headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin"})
  27. originsOk := handlers.AllowedOrigins([]string{"*"})
  28. methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
  29. log.Fatal(http.ListenAndServe(":"+config.Port, handlers.CORS(originsOk, headersOk, methodsOk)(router)))
  30. }
  31. func GUI() {
  32. //here, run webserver
  33. log.Println("webserver in port " + "8080")
  34. http.Handle("/", http.FileServer(http.Dir("./GUI")))
  35. http.ListenAndServe(":"+"8080", nil)
  36. }