• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang http2.ConfigureServer函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/net/http2.ConfigureServer函数的典型用法代码示例。如果您正苦于以下问题:Golang ConfigureServer函数的具体用法?Golang ConfigureServer怎么用?Golang ConfigureServer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ConfigureServer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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:Clarifai,项目名称:kubernetes,代码行数:30,代码来源:h2demo.go


示例2: Serve

func (e *endpoint) Serve() error {
	// TODO: Currently only support single server per endpoint
	if len(e.OriginServers) > 1 {
		return errors.New("Currently only 1 origin server per endpoint is supported.")
	}

	// Create http2 server
	var srv http.Server

	// Set Port
	srv.Addr = e.Address

	// Mux setup
	router := http.NewServeMux()

	// Set mux
	srv.Handler = router

	// Set handlers
	setHandlers(router, e)

	err := http2.ConfigureServer(&srv, &http2.Server{})
	if err != nil {
		return err
	}

	log.Printf("Listening on %s", srv.Addr)
	srv.ListenAndServeTLS(e.Certs.CertFile, e.Certs.KeyFile)

	return nil
}
开发者ID:gophergala2016,项目名称:zoom_and_enhance,代码行数:31,代码来源:endpoint.go


示例3: Run

// Run starts an http server using the provided config struct.
//
// This method configures the process to listen for termination signals (SIGINT
// and SIGTERM) to trigger a graceful shutdown by way of the graceful package
// (https://github.com/tylerb/graceful).
func Run(conf Config) {
	srv := setup(conf)

	http2.ConfigureServer(srv.Server, nil)

	if conf.OnStarting != nil {
		conf.OnStarting()
	}

	var err error
	if conf.TLSCert != "" {
		err = srv.ListenAndServeTLS(conf.TLSCert, conf.TLSKey)
	} else {
		err = srv.ListenAndServe()
	}

	if err != nil {
		log.Error(errors.Wrap(err, "failed to start server"))
		os.Exit(1)
	}

	if conf.OnStopped != nil {
		conf.OnStopped()
	}
	os.Exit(0)
}
开发者ID:stellar,项目名称:bridge-server,代码行数:31,代码来源:main.go


示例4: listenAndServeProtoHTTP

func listenAndServeProtoHTTP(listener net.Listener, tlsConfig *tls.Config) error {
	srv := http.Server{
		TLSConfig: tlsConfig,
		Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			reqBody, err := ioutil.ReadAll(r.Body)
			if err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			if err := r.Body.Close(); err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			args := EchoRequest{}
			if err := proto.Unmarshal(reqBody, &args); err != nil {
				http.Error(w, err.Error(), http.StatusBadRequest)
				return
			}
			reply := EchoResponse{Msg: args.Msg}
			respBody, err := proto.Marshal(&reply)
			if err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			w.Header().Set(contentType, xProtobuf)
			w.Write(respBody)
		}),
	}

	http2.ConfigureServer(&srv, nil)

	return srv.Serve(listener)
}
开发者ID:iamqizhao,项目名称:rpc-bench,代码行数:33,代码来源:rpc_test.go


示例5: main

func main() {
	var srv http.Server
	flag.BoolVar(&http2.VerboseLogs, "verbose", false, "Verbose HTTP/2 debugging.")
	flag.Parse()
	srv.Addr = *httpsAddr
	srv.ConnState = idleTimeoutHook()

	registerHandlers()

	if *prod {
		*hostHTTP = "http2.golang.org"
		*hostHTTPS = "http2.golang.org"
		log.Fatal(serveProd())
	}

	url := "https://" + httpsHost() + "/"
	log.Printf("Listening on " + url)
	http2.ConfigureServer(&srv, &http2.Server{})

	if *httpAddr != "" {
		go func() {
			log.Printf("Listening on http://" + httpHost() + "/ (for unencrypted HTTP/1)")
			log.Fatal(http.ListenAndServe(*httpAddr, nil))
		}()
	}

	go func() {
		log.Fatal(srv.ListenAndServeTLS("server.crt", "server.key"))
	}()
	select {}
}
开发者ID:Requilence,项目名称:integram,代码行数:31,代码来源:h2demo.go


示例6: 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:yenchih,项目名称:kythe,代码行数:7,代码来源:http_server.go


示例7: newH2Server

func (s *Server) newH2Server(tlsConfig *tls.Config, laddr string) (*http.Server, func(error)) {
	var mu sync.Mutex
	var h2sleep time.Duration = 1
	h2Server := &http.Server{
		Addr:      laddr,
		Handler:   http.HandlerFunc(s.serveH2),
		TLSConfig: tlsConfig,
		ConnState: func(c net.Conn, s http.ConnState) {
			if s == http.StateNew {
				mu.Lock()
				h2sleep = 1
				mu.Unlock()
			}
		},
	}
	http2.ConfigureServer(h2Server, &http2.Server{
		MaxReadFrameSize: s.H2BufSize,
	})

	afterServeError := func(err error) {
		Log.Error("h2 server failed", zap.Error(err))
		mu.Lock()
		if h2sleep < s.H2RetryMaxSecond {
			h2sleep++
		}
		sec := h2sleep
		mu.Unlock()
		time.Sleep(time.Second * sec)
	}
	return h2Server, afterServeError
}
开发者ID:empirefox,项目名称:wsh2s,代码行数:31,代码来源:h2.go


示例8: main

func main() {
	var httpServer http.Server
	var httpsServer http.Server
	http2.VerboseLogs = true
	http2.ConfigureServer(&httpsServer, nil)

	http.HandleFunc("/auth", authHandler)
	http.HandleFunc("/", handler)
	http.HandleFunc("/js", jsHandler)

	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		log.Println("start http listening :18888")
		httpServer.Addr = ":18888"
		log.Println(httpServer.ListenAndServe())
		wg.Done()
	}()
	go func() {
		log.Println("start https listening :18889")
		httpsServer.Addr = ":18889"
		log.Println(httpsServer.ListenAndServeTLS("server.crt", "server.key"))
		wg.Done()
	}()
	wg.Wait()
}
开发者ID:VViles,项目名称:curl_as_dsl,代码行数:26,代码来源:server.go


示例9: main

func main() {
	router := lib.NewRouter()
	srvTLS := &http.Server{Addr: ":4000", Handler: router}

	log.Println("Listening...")
	http2.ConfigureServer(srvTLS, &http2.Server{})
	srvTLS.ListenAndServeTLS("openssl/server.crt", "openssl/server.key")
}
开发者ID:droff,项目名称:polaris,代码行数:8,代码来源:main.go


示例10: 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:jameswei,项目名称:kingtask,代码行数:9,代码来源:echo.go


示例11: 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:nikelmwann,项目名称:dokku-api-server,代码行数:9,代码来源:echo.go


示例12: NewServer

func NewServer(port string, handler http.Handler) ListenAndServer {
	addr := fmt.Sprintf(":%s", port)
	server := &http.Server{
		Addr:    addr,
		Handler: handler,
	}
	http2.ConfigureServer(server, nil)
	return server
}
开发者ID:kasey,项目名称:camus,代码行数:9,代码来源:server.go


示例13: startWebServer

func startWebServer() {
	key := "/" + *accessKey + "/"
	mux := http.NewServeMux()
	mux.HandleFunc(key+"upload", upload)
	mux.Handle(key, http.StripPrefix(key, http.FileServer(assetFS())))
	mux.Handle(key+"f/", http.StripPrefix(key+"f/", http.FileServer(http.Dir(*rootDir))))

	if *h1Port != "" {
		log.Println("http://localhost" + *h1Port + key)
		s := &http.Server{
			Addr:    *h1Port,
			Handler: mux,
		}

		http2.ConfigureServer(s, nil)

		go func() {
			err := s.ListenAndServe()
			if err != nil {
				log.Fatal("HTTP server error:", err)
			}
		}()
	}

	if *h2Port != "" {
		log.Println("https://localhost" + *h2Port + key)

		s := &http.Server{
			Addr:      *h2Port,
			Handler:   mux,
			TLSConfig: CreateTLS(),
		}

		http2.ConfigureServer(s, nil)

		go func() {
			err := s.ListenAndServeTLS("", "")
			if err != nil {
				log.Fatal("HTTPS/2 server error:", err)
			}
		}()
	}
}
开发者ID:JonahBraun,项目名称:sweetdrop,代码行数:43,代码来源:main.go


示例14: main

func main() {
	var srv http.Server

	srv.Addr = ":8000"
	http2.ConfigureServer(&srv, nil)

	http.HandleFunc("/", HelloWorld)
	http.HandleFunc("/favicon.ico", Error404)
	log.Fatal(srv.ListenAndServeTLS("localhost.crt", "localhost.key"))
}
开发者ID:bdenning,项目名称:http2-golang-docker-demo,代码行数:10,代码来源:webservice.go


示例15: main

func main() {
	var srv http.Server
	srv.Addr = ":12345"
	authenticator := auth.NewDigestAuthenticator("063.jp", secret)
	http.HandleFunc("/", authenticator.Wrap(func(res http.ResponseWriter, req *auth.AuthenticatedRequest) {
		http.FileServer(http.Dir("/var/www/html/SS/")).ServeHTTP(res, &req.Request)
	}))
	http2.ConfigureServer(&srv, &http2.Server{})
	srv.ListenAndServeTLS("../key/server.crt", "../key/server.key")
}
开发者ID:Goryudyuma,项目名称:go-work,代码行数:10,代码来源:http2.go


示例16: startClusterListener

// startClusterListener starts cluster request listeners during postunseal. It
// is assumed that the state lock is held while this is run.
func (c *Core) startClusterListener() error {
	if c.clusterListenerShutdownCh != nil {
		c.logger.Printf("[ERR] core/startClusterListener: attempt to set up cluster listeners when already set up")
		return fmt.Errorf("cluster listeners already setup")
	}

	if c.clusterListenerSetupFunc == nil {
		c.logger.Printf("[ERR] core/startClusterListener: cluster listener setup function has not been set")
		return fmt.Errorf("cluster listener setup function has not been set")
	}

	if c.clusterAddr == "" {
		c.logger.Printf("[TRACE] core/startClusterListener: clustering disabled, starting listeners")
		return nil
	}

	c.logger.Printf("[TRACE] core/startClusterListener: starting listeners")

	lns, handler, err := c.clusterListenerSetupFunc()
	if err != nil {
		return err
	}

	tlsConfig, err := c.ClusterTLSConfig()
	if err != nil {
		c.logger.Printf("[ERR] core/startClusterListener: failed to get tls configuration: %v", err)
		return err
	}

	tlsLns := make([]net.Listener, 0, len(lns))
	for _, ln := range lns {
		tlsLn := tls.NewListener(ln, tlsConfig)
		tlsLns = append(tlsLns, tlsLn)
		server := &http.Server{
			Handler: handler,
		}
		http2.ConfigureServer(server, nil)
		c.logger.Printf("[TRACE] core/startClusterListener: serving cluster requests on %s", tlsLn.Addr())
		go server.Serve(tlsLn)
	}

	c.clusterListenerShutdownCh = make(chan struct{})
	c.clusterListenerShutdownSuccessCh = make(chan struct{})

	go func() {
		<-c.clusterListenerShutdownCh
		c.logger.Printf("[TRACE] core/startClusterListener: shutting down listeners")
		for _, tlsLn := range tlsLns {
			tlsLn.Close()
		}
		close(c.clusterListenerShutdownSuccessCh)
	}()

	return nil
}
开发者ID:mhurne,项目名称:vault,代码行数:57,代码来源:cluster.go


示例17: main

func main() {
	var httpServer http.Server
	http2.VerboseLogs = true
	httpServer.Addr = ":8080"
	http2.ConfigureServer(&httpServer, nil)
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Welcome to test HTTP2 page %q\n", html.EscapeString(r.URL.Path))
		ShowRequestInfoHandler(w, r)
	})
	log.Fatal(httpServer.ListenAndServeTLS("localhost.cert", "localhost.key"))
}
开发者ID:Chubik,项目名称:http2test,代码行数:11,代码来源:http2server.go


示例18: main

func main() {
	var srv http.Server
	//http2.VerboseLogs = true
	srv.Addr = ":8443"
	http2.ConfigureServer(&srv, nil)
	http.HandleFunc("/", get)
	err := srv.ListenAndServeTLS("cert.pem", "key.pem")
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:jomoespe,项目名称:docker-nano-container,代码行数:11,代码来源:rest-server.go


示例19: main

func main() {
	var srv core.Server

	srv.Addr = ":8080"
	http2.ConfigureServer(&srv.Server, nil)

	http.HandleFunc("/", handlers.NewDirList().Reply)

	srv.Init()
	srv.Run()
	srv.Quit()
}
开发者ID:http2d,项目名称:server,代码行数:12,代码来源:dirlist01.go


示例20: ListenAndServeTLS

func (s *Http2Server) ListenAndServeTLS(config *tls.Config) error {
	srv := http.Server{
		Addr:      s.Base.Node.Addr,
		Handler:   s.Handler,
		TLSConfig: config,
	}
	if srv.Handler == nil {
		srv.Handler = http.HandlerFunc(s.HandleRequest)
	}
	http2.ConfigureServer(&srv, nil)
	return srv.ListenAndServeTLS("", "")
}
开发者ID:guest6379,项目名称:gost,代码行数:12,代码来源:http.go



注:本文中的golang.org/x/net/http2.ConfigureServer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang http2.ErrCode函数代码示例发布时间:2022-05-28
下一篇:
Golang charset.NewReader函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap