Beispiel #1
0
func loadAllConfig(t *testing.T) {
	// Load app config
	Config, err := configuration.LoadConfig()
	if err != nil {
		t.Errorf("loadDatabase does not pass. Configuration does not load, looking for %v, got %v", nil, err)
	}

	// Set config in packages
	accounts.SetConfig(&Config)
	payments.SetConfig(&Config)
	appauth.SetConfig(&Config)
	push.SetConfig(&Config)
}
Beispiel #2
0
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
}
Beispiel #3
0
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
}