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.
 
 
 
 
 

58 lines
1.3 KiB

package main
import (
"fmt"
"log"
"net/http"
mgo "gopkg.in/mgo.v2"
"github.com/fatih/color"
"github.com/gorilla/handlers"
ownrsa "./ownrsa"
)
var userCollection *mgo.Collection
var serverRSA ownrsa.RSA
func main() {
color.Blue("Starting serverIDsigner")
//read configuration file
readConfig("config.json")
initializeToken()
//initialize RSA
serverRSA = ownrsa.GenerateKeyPair()
color.Blue("Public Key:")
fmt.Println(serverRSA.PubK)
color.Green("Private Key:")
fmt.Println(serverRSA.PrivK)
//mongodb
session, err := getSession()
check(err)
userCollection = getCollection(session, "users")
//run thw webserver
go webserver()
//run API
log.Println("api server running")
log.Print("port: ")
log.Println(config.Port)
router := NewRouter()
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin"})
originsOk := handlers.AllowedOrigins([]string{"*"})
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
log.Fatal(http.ListenAndServe(":"+config.Port, handlers.CORS(originsOk, headersOk, methodsOk)(router)))
}
func webserver() {
log.Println("webserver in port " + config.WebServerPort)
http.Handle("/", http.FileServer(http.Dir("./webapp")))
http.ListenAndServe(":"+config.WebServerPort, nil)
}