本文整理汇总了Golang中github.com/bradfitz/http2.ConfigureServer函数的典型用法代码示例。如果您正苦于以下问题:Golang ConfigureServer函数的具体用法?Golang ConfigureServer怎么用?Golang ConfigureServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigureServer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: startTLS
func startTLS() {
srv := &http.Server{Addr: *tlsListeningAddr}
http2.ConfigureServer(srv, nil)
log.Printf("TLS HTTP2 server listening on %q", *tlsListeningAddr)
log.Fatal(srv.ListenAndServeTLS(*tlsCertFile, *tlsKeyFile))
}
开发者ID:kidaa,项目名称:kythe,代码行数:7,代码来源:http_server.go
示例2: main
func main() {
flag.Parse()
ln, err := net.Listen("tcp", ":"+PORT)
if err != nil {
glog.Fatalf("Listen(%s) error: %s", PORT, err)
}
cert, err := getCertificate(nil)
if err != nil {
glog.Fatalf("getCertificate error: %s", err)
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{*cert},
// GetCertificate: getCertificate,
}
s := &http.Server{
Handler: http.HandlerFunc(handler),
TLSConfig: tlsConfig,
}
http2.ConfigureServer(s, &http2.Server{})
glog.Infof("ListenAndServe on %s\n", ln.Addr().String())
s.Serve(tls.NewListener(ln, tlsConfig))
}
开发者ID:snowink,项目名称:goproxy,代码行数:27,代码来源:vps.go
示例3: main
func main() {
flag.Parse()
addr := fmt.Sprintf("%s:%s", os.Getenv("HOST"), os.Getenv("PORT"))
ln, err := net.Listen("tcp", addr)
if err != nil {
glog.Fatalf("Listen(%s) error: %s", addr, err)
}
cert, err := getCertificate(nil)
if err != nil {
glog.Fatalf("getCertificate error: %s", err)
}
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{*cert},
// GetCertificate: getCertificate,
}
s := &http.Server{
Handler: http.HandlerFunc(handler),
TLSConfig: tlsConfig,
}
// http2.VerboseLogs = true
http2.ConfigureServer(s, &http2.Server{})
glog.Infof("ListenAndServe on %s\n", ln.Addr().String())
s.Serve(tls.NewListener(ln, tlsConfig))
}
开发者ID:nonovc,项目名称:goproxy,代码行数:29,代码来源:vps.go
示例4: ListenAndServeSecure
func ListenAndServeSecure(addr string, certFile string, keyFile string, numOfServers int, handler http.Handler) error {
port, err := parsePort(addr)
if err != nil {
return err
}
if handler == nil {
handler = http.DefaultServeMux
}
go func() {
httpServer := &http.Server{Addr: addr, Handler: altProtoMiddleware(handler, port)}
http2.ConfigureServer(httpServer, nil)
err := httpServer.ListenAndServeTLS(certFile, keyFile)
if err != nil {
panic(err)
}
}()
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
return err
}
server := &QuicSpdyServer{Addr: addr, Handler: handler, numOfServers: numOfServers, Certificate: cert, isSecure: true}
return server.ListenAndServe()
}
开发者ID:horiga,项目名称:gospdyquic,代码行数:26,代码来源:spdyquic.go
示例5: Start
func (this *Server) Start() error {
logger.Debug("serverConfig is %#v", this.config)
this.router.matcher.sort()
conf := this.config
server := &http.Server{Handler: http.HandlerFunc(this.serverHttpHandler), MaxHeaderBytes: conf.MaxHeaderBytes, TLSConfig: conf.TLSConfig}
if conf.ReadTimeout > 0 {
server.ReadTimeout = conf.ReadTimeout
}
if conf.WriteTimeout > 0 {
server.WriteTimeout = conf.WriteTimeout
}
http2.ConfigureServer(server, &http2.Server{})
var err error
this.listener, err = net.Listen("tcp", conf.serverAddr)
if err != nil {
return errors.New(logger.Error("listen [%s] fail:%s", conf.serverAddr, err))
}
logger.Info("start HttpServer :%s", conf.serverAddr)
keepAliveListrener := tcpKeepAliveListener{this.listener.(*net.TCPListener)}
if conf.TLSConfig != nil {
conf.TLSConfig.NextProtos = append(conf.TLSConfig.NextProtos, "http/1.1")
go server.Serve(tls.NewListener(keepAliveListrener, conf.TLSConfig))
} else {
go server.Serve(keepAliveListrener)
}
return nil
}
开发者ID:nymbian,项目名称:web,代码行数:27,代码来源:server.go
示例6: main
func main() {
var srv http.Server
flag.BoolVar(&http2.VerboseLogs, "verbose", false, "Verbose HTTP/2 debugging.")
flag.Parse()
srv.Addr = *addr
registerHandlers()
if *prod {
*httpAddr = "http2.golang.org"
log.Fatal(serveProd())
}
url := "https://" + *addr + "/"
log.Printf("Listening on " + url)
http2.ConfigureServer(&srv, &http2.Server{})
if *httpAddr != "" {
go func() { log.Fatal(http.ListenAndServe(*httpAddr, nil)) }()
}
go func() {
log.Fatal(srv.ListenAndServeTLS("server.crt", "server.key"))
}()
if *openFirefox && runtime.GOOS == "darwin" {
time.Sleep(250 * time.Millisecond)
exec.Command("open", "-b", "org.mozilla.nightly", "https://localhost:4430/").Run()
}
select {}
}
开发者ID:johndmulhausen,项目名称:kubernetes,代码行数:30,代码来源:h2demo.go
示例7: listenHttp
func listenHttp() {
log.Printf("Listening on port :%s\n", *httpport)
port := fmt.Sprintf(":%s", *httpport)
if secure {
log.Println("Serving via TLS")
server := &http.Server{Addr: port, Handler: nil}
if os.Getenv("DISABLE_HTTP2") == "" {
http2.ConfigureServer(server, nil)
log.Println("HTTP/2 support is enabled.")
} else {
log.Println("HTTP/2 support is disabled.")
}
if err := server.ListenAndServeTLS(CertFilePath, KeyFilePath); err != nil {
log.Fatalf("Error starting server: %s\n", err.Error())
}
} else {
if err := http.ListenAndServe(port, nil); err != nil {
log.Fatalf("Error starting server: %s\n", err.Error())
}
}
}
开发者ID:danrjohnson,项目名称:media-proxy,代码行数:25,代码来源:main.go
示例8: newGracefulServer
// Create a new graceful server configuration
func newGracefulServer(mux *http.ServeMux, http2support bool, addr string, shutdownTimeout time.Duration) *graceful.Server {
// Server configuration
s := &http.Server{
Addr: addr,
Handler: mux,
// The timeout values is also the maximum time it can take
// for a complete page of Server-Sent Events (SSE).
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
if http2support {
// Enable HTTP/2 support
http2.ConfigureServer(s, nil)
}
gracefulServer := &graceful.Server{
Server: s,
Timeout: shutdownTimeout,
}
// Handle ctrl-c
gracefulServer.ShutdownInitiated = runShutdown
return gracefulServer
}
开发者ID:sneakyweasel,项目名称:algernon,代码行数:26,代码来源:serve.go
示例9: Server
// Server returns the internal *http.Server.
func (e *Echo) Server(addr string) *http.Server {
s := &http.Server{Addr: addr}
s.Handler = e
if e.http2 {
http2.ConfigureServer(s, nil)
}
return s
}
开发者ID:transtone,项目名称:echo,代码行数:9,代码来源:echo.go
示例10: Server
// Server returns the internal *http.Server.
func (e *Echo) Server(addr string) *http.Server {
s := &http.Server{Addr: addr, Handler: e}
// TODO: Remove in Go 1.6+
if e.http2 {
http2.ConfigureServer(s, nil)
}
return s
}
开发者ID:scofieldpeng,项目名称:echo,代码行数:9,代码来源:echo.go
示例11: newServer
func newServer(addr string, h http.Handler, HTTP2 bool) *http.Server {
srv := &http.Server{
Addr: addr,
Handler: h,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
if HTTP2 {
http2.ConfigureServer(srv, &http2.Server{})
}
return srv
}
开发者ID:bubble-bot,项目名称:weavebox,代码行数:12,代码来源:server.go
示例12: run
func (e *Echo) run(s *http.Server, files ...string) {
s.Handler = e
if e.http2 {
http2.ConfigureServer(s, nil)
}
if len(files) == 0 {
log.Fatal(s.ListenAndServe())
} else if len(files) == 2 {
log.Fatal(s.ListenAndServeTLS(files[0], files[1]))
} else {
log.Fatal("echo => invalid TLS configuration")
}
}
开发者ID:alkhatib,项目名称:echo,代码行数:13,代码来源:echo.go
示例13: Serve
// Serve starts the server. It blocks until the server quits.
func (s *Server) Serve() error {
server := &http.Server{
Addr: s.address,
Handler: s,
}
if s.HTTP2 {
// TODO: This call may not be necessary after HTTP/2 is merged into std lib
http2.ConfigureServer(server, nil)
}
for _, vh := range s.vhosts {
// Execute startup functions now
for _, start := range vh.config.Startup {
err := start()
if err != nil {
return err
}
}
// Execute shutdown commands on exit
if len(vh.config.Shutdown) > 0 {
go func(vh virtualHost) {
// Wait for signal
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill)
<-interrupt
// Run callbacks
exitCode := 0
for _, shutdownFunc := range vh.config.Shutdown {
err := shutdownFunc()
if err != nil {
exitCode = 1
log.Println(err)
}
}
os.Exit(exitCode) // BUG: Other shutdown goroutines might be running; use sync.WaitGroup
}(vh)
}
}
if s.tls {
var tlsConfigs []TLSConfig
for _, vh := range s.vhosts {
tlsConfigs = append(tlsConfigs, vh.config.TLS)
}
return ListenAndServeTLSWithSNI(server, tlsConfigs)
}
return server.ListenAndServe()
}
开发者ID:hacdias,项目名称:caddy,代码行数:52,代码来源:server.go
示例14: Serve
func (s *Server) Serve() error {
server := &http.Server{
Addr: s.address,
Handler: s,
}
if s.HTTP2 {
http2.ConfigureServer(server, nil)
}
for _, vh := range s.vhosts {
for _, start := range vh.config.Startup {
err := start()
if err != nil {
return err
}
}
// Execute shutdown commands on exit
if len(vh.config.Shutdown) > 0 {
go func(vh virtualHost) {
// Wait for signal
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill)
<-interrupt
// Run callbacks
exitCode := 0
for _, shutdownFunc := range vh.config.Shutdown {
err := shutdownFunc()
if err != nil {
exitCode = 1
log.Println(err)
}
}
os.Exit(exitCode)
}(vh)
}
}
if s.tls {
var tlsConfigs []TLSConfig
for _, vh := range s.vhosts {
tlsConfigs = append(tlsConfigs, vh.config.TLS)
}
return ListenAndServeTLSWithSNI(server, tlsConfigs)
}
return server.ListenAndServe()
}
开发者ID:sanata-,项目名称:snail,代码行数:51,代码来源:server.go
示例15: run
func (e *Echo) run(s *http.Server, files ...string) {
s.Handler = e
// TODO: Remove in Go 1.6+
if e.http2 {
http2.ConfigureServer(s, nil)
}
if len(files) == 0 {
e.logger.Fatal(s.ListenAndServe())
} else if len(files) == 2 {
e.logger.Fatal(s.ListenAndServeTLS(files[0], files[1]))
} else {
e.logger.Fatal("invalid TLS configuration")
}
}
开发者ID:scofieldpeng,项目名称:echo,代码行数:14,代码来源:echo.go
示例16: main
func main() {
r := httprouter.New()
r.GET("/", index)
r.ServeFiles("/webapp/*filepath", http.Dir("webapp"))
r.GET("/api/fs/*filepath", fsRead)
r.PUT("/api/fs/*filepath", fsWrite)
r.DELETE("/api/fs/*filepath", fsDelete)
r.POST("/api/fs/*filepath", fsSpecial)
s := &http.Server{}
s.Addr = ":8080"
s.Handler = r
http2.ConfigureServer(s, nil)
log.Fatalln(s.ListenAndServeTLS("cert.pem", "key.pem"))
}
开发者ID:mastercactapus,项目名称:goinone,代码行数:16,代码来源:main.go
示例17: ListenAndServe
func ListenAndServe(addr string, numOfServers int, handler http.Handler) error {
port, err := parsePort(addr)
if err != nil {
return err
}
if handler == nil {
handler = http.DefaultServeMux
}
httpServer := &http.Server{Addr: addr, Handler: altProtoMiddleware(handler, port)}
http2.ConfigureServer(httpServer, nil)
go httpServer.ListenAndServe()
server := &QuicSpdyServer{Addr: addr, Handler: handler, numOfServers: numOfServers, isSecure: false}
return server.ListenAndServe()
}
开发者ID:horiga,项目名称:gospdyquic,代码行数:16,代码来源:spdyquic.go
示例18: Serve
// Serve starts the server. It blocks until the server quits.
func (s *Server) Serve() error {
server := &http.Server{
Addr: s.address,
Handler: s,
}
if s.HTTP2 {
// TODO: This call may not be necessary after HTTP/2 is merged into std lib
http2.ConfigureServer(server, nil)
}
for _, vh := range s.vhosts {
// Execute startup functions now
for _, start := range vh.config.Startup {
err := start()
if err != nil {
return err
}
}
// Execute shutdown commands on exit
if len(vh.config.Shutdown) > 0 {
go func() {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill) // TODO: syscall.SIGQUIT? (Ctrl+\, Unix-only)
<-interrupt
for _, shutdownFunc := range vh.config.Shutdown {
err := shutdownFunc()
if err != nil {
log.Fatal(err)
}
}
os.Exit(0)
}()
}
}
if s.tls {
var tlsConfigs []TLSConfig
for _, vh := range s.vhosts {
tlsConfigs = append(tlsConfigs, vh.config.TLS)
}
return ListenAndServeTLSWithSNI(server, tlsConfigs)
}
return server.ListenAndServe()
}
开发者ID:ricardoshimoda,项目名称:caddy,代码行数:47,代码来源:server.go
示例19: main
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello world")
})
var srv http.Server
log.Printf("Listening on https://localhost:4430/")
srv.Addr = "localhost:4430"
http2.ConfigureServer(&srv, &http2.Server{})
closeFirefox()
go func() {
log.Fatal(srv.ListenAndServeTLS("server.crt", "server.key"))
}()
time.Sleep(500 * time.Millisecond)
exec.Command("open", "-b", "org.mozilla.nightly", "https://localhost:4430/").Run()
select {}
}
开发者ID:jmhodges,项目名称:http2,代码行数:18,代码来源:h2server.go
示例20: standUpServer
func standUpServer() error {
srv := &http.Server{Addr: hostport}
reg, router, cxt := cookoo.Cookoo()
buildRegistry(reg, router, cxt)
// Our main datasource is the Medium, which manages channels.
m := pubsub.NewMedium()
cxt.AddDatasource(pubsub.MediumDS, m)
cxt.Put("routes", reg.Routes())
http2.ConfigureServer(srv, &http2.Server{})
srv.Handler = web.NewCookooHandler(reg, router, cxt)
srv.ListenAndServeTLS("../server/server.crt", "../server/server.key")
return nil
}
开发者ID:technosophos,项目名称:drift,代码行数:19,代码来源:client_test.go
注:本文中的github.com/bradfitz/http2.ConfigureServer函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论