当前位置: 首页>>代码示例>>Golang>>正文


Golang http2.ConfigureServer函数代码示例

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


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


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