當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Server.ErrorLog方法代碼示例

本文整理匯總了Golang中net/http.Server.ErrorLog方法的典型用法代碼示例。如果您正苦於以下問題:Golang Server.ErrorLog方法的具體用法?Golang Server.ErrorLog怎麽用?Golang Server.ErrorLog使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/http.Server的用法示例。


在下文中一共展示了Server.ErrorLog方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RunTLSWithOptions

// 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))
}
開發者ID:socceroos,項目名稱:negroni,代碼行數:20,代碼來源:negroni.go

示例2: main

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)
}
開發者ID:nutmegdevelopment,項目名稱:nutcracker,代碼行數:45,代碼來源:main.go


注:本文中的net/http.Server.ErrorLog方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。