Esempio n. 1
0
File: httpApi.go Progetto: BVNK/bank
func RunHttpServer() (err error) {
	bLog(0, "HTTP server called", trace())

	// Load app config
	Config, err := configuration.LoadConfig()
	if err != nil {
		return errors.New("server.runServer: " + err.Error())
	}

	// Set config in packages
	accounts.SetConfig(&Config)
	transactions.SetConfig(&Config)
	appauth.SetConfig(&Config)
	push.SetConfig(&Config)

	router := NewRouter()

	err = http.ListenAndServeTLS(":"+Config.HttpPort, configuration.ImportPath+"certs/"+Config.FQDN+".pem", configuration.ImportPath+"certs/"+Config.FQDN+".key", router)
	//err = http.ListenAndServeTLS(":8443", "certs/thebankoftoday.com.crt", "certs/thebankoftoday.com.key", router)
	fmt.Println(err)
	bLog(4, err.Error(), trace())
	return
}
Esempio n. 2
0
File: server.go Progetto: BVNK/bank
func runServer(mode string) (message string, err error) {

	// Load app config
	Config, err := configuration.LoadConfig()
	if err != nil {
		return "", errors.New("server.runServer: " + err.Error())
	}

	// Set config in packages
	accounts.SetConfig(&Config)
	transactions.SetConfig(&Config)
	appauth.SetConfig(&Config)
	push.SetConfig(&Config)

	switch mode {
	case "tls":
		cert, err := tls.LoadX509KeyPair(configuration.ImportPath+"certs/server.pem", configuration.ImportPath+"certs/server.key")
		if err != nil {
			return "", err
		}

		// Load config and generate seed
		config := tls.Config{Certificates: []tls.Certificate{cert}, ClientAuth: tls.RequireAnyClientCert}
		config.Rand = rand.Reader

		// Listen for incoming connections.
		l, err := tls.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT, &config)
		if err != nil {
			return "", err
		}

		// Close the listener when the application closes.
		defer l.Close()
		bLog(0, "Listening on secure "+CONN_HOST+":"+CONN_PORT, trace())
		for {
			// Listen for an incoming connection.
			conn, err := l.Accept()
			if err != nil {
				return "", err
			}
			// Handle connections in a new goroutine.
			go handleTCPRequest(conn)
		}
	case "no-tls":
		// Listen for incoming connections.
		l, err := net.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT)
		if err != nil {
			return "", err
		}

		// Close the listener when the application closes.
		defer l.Close()
		bLog(0, "Listening on unsecure "+CONN_HOST+":"+CONN_PORT, trace())
		for {
			// Listen for an incoming connection.
			conn, err := l.Accept()
			if err != nil {
				return "", err
			}
			// Handle connections in a new goroutine.
			go handleTCPRequest(conn)
		}
	}

	return
}