コード例 #1
0
ファイル: negroni.go プロジェクト: socceroos/negroni
// RunWithOptions is a convenience function that runs the negroni stack as a
// provided HTTP server, with the following caveats:
// 1. the Handler field of the provided serverConfig should be nil,
//    because the Handler used will be the n Negroni object.
func (n *Negroni) RunTLSWithOptions(addr string, certFile string, keyFile string, serverConfig *http.Server) {
	l := log.New(os.Stdout, "[negroni] ", 0)
	if serverConfig.Addr == "" {
		l.Fatal("Address not specified.")
	}
	if serverConfig.Handler != nil {
		l.Fatal("Handler not supported.")
	}
	// Don't need this since ListenAndServeTLS expects Handler argument
	//serverConfig.Handler = n
	if serverConfig.ErrorLog == nil {
		serverConfig.ErrorLog = l
	}
	l.Printf("listening on %s with configuration %v\n", serverConfig.Addr, serverConfig)
	l.Fatal(serverConfig.ListenAndServeTLS(addr, certFile, keyFile, n))
}
コード例 #2
0
ファイル: main.go プロジェクト: nutmegdevelopment/nutcracker
func main() {

	err := database.Connect()
	if err != nil {
		log.Fatal(err)
	}

	addr := os.Getenv("LISTEN")
	if addr == "" {
		addr = "0.0.0.0:8443"
	}

	if os.Getenv("DEBUG") == "true" {
		log.SetLevel(log.DebugLevel)
	}

	var cert tls.Certificate

	if certName == "" {
		log.Info("Generating self-signed certificate")
		cert, err = GenCert()
	} else {
		log.Info("Using certificate from vault")
		cert, err = GetNutcrackerCert()
	}
	if err != nil {
		log.Fatal(err)
	}

	sock, err := Socket(addr, cert)
	if err != nil {
		log.Fatal(err)
	}

	r := mux.NewRouter()
	addRoutes(r)

	server := new(http.Server)
	server.ErrorLog = new(stdLog.Logger)
	server.ErrorLog.SetOutput(ioutil.Discard)
	server.Addr = addr
	server.Handler = context.ClearHandler(r)
	log.Infof("HTTPS server listening on: %s", addr)
	server.Serve(sock)
}