Ejemplo n.º 1
0
func (config *ServerConfig) serve(addr string, handler http.Handler) {
	maxConns := DefaultMaxIncomingConnections
	if config.MaxIncomingConnections != nil {
		maxConns = *config.MaxIncomingConnections
	}

	err := base.ListenAndServeHTTP(addr, maxConns, config.SSLCert, config.SSLKey, handler, config.ServerReadTimeout, config.ServerWriteTimeout)
	if err != nil {
		base.LogFatal("Failed to start HTTP server on %s: %v", addr, err)
	}
}
Ejemplo n.º 2
0
func RunServer(config *ServerConfig) {

	//This variable used for pretty JSON reponses
	PrettyPrint = config.Pretty

	//New Server Context
	sc := NewServerContext(config)

	//Open Database and add to server context
	if _, err := sc.AddDatabaseFromConfig(config.Database); err != nil {
		base.LogFatal("Error opening database: %v", err)
	}

	defer sc.CloseDatabase()

	base.Logf("Starting server on %s ...", *config.Interface)
	config.serve(*config.Interface, CreatePublicHandler(sc))

}