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


Golang gracehttp.Serve函數代碼示例

本文整理匯總了Golang中github.com/facebookgo/grace/gracehttp.Serve函數的典型用法代碼示例。如果您正苦於以下問題:Golang Serve函數的具體用法?Golang Serve怎麽用?Golang Serve使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: Run

func (g *gorai) Run() {
	if isConsole() {
		consoleHandler()
		return
	}

	cer, err := tls.LoadX509KeyPair(g.config.Framework.WebServerSSL.CtrFile, g.config.Framework.WebServerSSL.KeyFile)
	if err != nil {
		panic(err)
	}

	config := &tls.Config{Certificates: []tls.Certificate{cer}}

	server := &http.Server{
		Addr:         g.config.Framework.WebServer.Host + ":" + g.config.Framework.WebServer.Port,
		Handler:      webReWriteHandler(),
		ReadTimeout:  g.config.Framework.WebServer.ReadTimeout * time.Second,
		WriteTimeout: g.config.Framework.WebServer.WriteTimeout * time.Second,
	}
	serverSSL := &http.Server{
		Addr:         g.config.Framework.WebServerSSL.Host + ":" + g.config.Framework.WebServerSSL.Port,
		Handler:      webHandler(),
		ReadTimeout:  g.config.Framework.WebServerSSL.ReadTimeout * time.Second,
		WriteTimeout: g.config.Framework.WebServerSSL.WriteTimeout * time.Second,
		TLSConfig:    config,
	}

	gracehttp.Serve(server, serverSSL)
}
開發者ID:go51,項目名稱:gorai,代碼行數:29,代碼來源:gorai.go

示例2: Run

/*
Run ...
*/
func (srv *Server) Run() {
	conf := config.GetConfig()
	port := int(conf.Port)
	logger.Info.Println("Server up and running on port: " + strconv.Itoa(port))
	err := gracehttp.Serve(&http.Server{Addr: ":" + strconv.Itoa(port), Handler: srv})
	utils.PanicOnError(err)
}
開發者ID:leoliuzcl,項目名稱:skizze,代碼行數:10,代碼來源:server.go

示例3: main

func main() {
	var err error
	sentry, err = raven.NewClient(*sentryDSN, nil)
	if err != nil {
		log.Println("No sentry:", err)
	}

	restrict.ReadCryptoKey(*crypto)

	models.Init(
		*dbUser,
		*dbPass,
		*dbService,
		*dbPort,
		*dbName,
	)

	go tunnel.NewRPCServer(messages, *rpcAddr, *rpcPort)
	go messageLoop()

	r := setupRouting()

	pool = setupZombies()

	log.Println(gracehttp.Serve(
		&http.Server{
			Addr:    *httpAddr + ":" + *httpPort,
			Handler: r,
		},
	))
}
開發者ID:BigRoom,項目名稱:vision,代碼行數:31,代碼來源:main.go

示例4: ServeApi

func ServeApi() {
	ApiServers := make([]*http.Server, len(utils.Cfg.ServerSettings.Ports))
	for i, port := range utils.Cfg.ServerSettings.Ports {
		ApiServers[i] = newApiServer(port)
	}
	gracehttp.Serve(ApiServers...)
}
開發者ID:creasty,項目名稱:delta-test-stats-app,代碼行數:7,代碼來源:api_server.go

示例5: main

func main() {
	wg := &sync.WaitGroup{}

	notificationBackend := backend.GetBackend(applicationConfig.BackendName)
	err := notificationBackend.Initialize(applicationConfig.BackendOpenString)
	if err != nil {
		logger.WithField("error", err).Panic("cannot initialize backend")
	}

	notificationBackend.Start(wg)
	defer func() {
		notificationBackend.Shutdown()
		wg.Wait()
	}()

	notificationBackend.BlockUntilReady()
	receiverApp := webreceiver.NewApp(notificationBackend, applicationConfig.Receiver)

	receiverServer := &http.Server{
		Addr:    fmt.Sprintf("%s:%d", applicationConfig.Receiver.ListenHost, applicationConfig.Receiver.ListenPort),
		Handler: receiverApp,
	}

	gracehttp.Serve(receiverServer)
}
開發者ID:shuhaowu,項目名稱:towncrier,代碼行數:25,代碼來源:main.go

示例6: main

func main() {
	//runtime.GOMAXPROCS(runtime.NumCPU())
	e := echo.New()

	e.Use(mw.Logger())
	e.Use(mw.Recover())
	e.Use(mw.Gzip())

	e.Get("/", welcome)
	e.Get("/ping", ping)

	//// Start server
	//e.Run(":1323")

	// Get the http.Server
	s := e.Server(":8000")

	// HTTP2 is currently enabled by default in echo.New(). To override TLS handshake errors
	// you will need to override the TLSConfig for the server so it does not attempt to validate
	// the connection using TLS as required by HTTP2
	s.TLSConfig = nil

	// Serve it like a boss
	log.Fatal(gracehttp.Serve(s))
}
開發者ID:itang,項目名稱:gomonkey,代碼行數:25,代碼來源:server.go

示例7: do

func do() error {
	server, err := createServer()
	if err != nil {
		return err
	}
	glog.V(2).Infof("start server")
	return gracehttp.Serve(server)
}
開發者ID:bborbe,項目名稱:portfolio,代碼行數:8,代碼來源:portfolio_server.go

示例8: do

func do(writer io.Writer, address string, documentRoot string, dbPath string) error {
	dbPath, err := io_util.NormalizePath(dbPath)
	if err != nil {
		return err
	}
	gracehttp.Serve(createServer(address, documentRoot, dbPath))
	return nil
}
開發者ID:zhanglong2005,項目名稱:stats,代碼行數:8,代碼來源:stats_server.go

示例9: main

func main() {
	flag.Parse()
	gracehttp.Serve(
		&http.Server{Addr: *address0, Handler: newHandler("Zero  ")},
		&http.Server{Addr: *address1, Handler: newHandler("First ")},
		&http.Server{Addr: *address2, Handler: newHandler("Second")},
	)
}
開發者ID:raceli,項目名稱:grace,代碼行數:8,代碼來源:demo.go

示例10: main

func main() {
	e := echo.New()
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Six sick bricks tick")
	})
	std := standard.New(":1323")
	std.SetHandler(e)
	gracehttp.Serve(std.Server)
}
開發者ID:AlekSi,項目名稱:echo,代碼行數:9,代碼來源:server.go

示例11: mainImpl

func mainImpl() error {
	port := flag.Int("port", 8010, "port number")
	notLocal := flag.Bool("all", false, "listen on all IPs, not just localhost")
	cwd, _ := os.Getwd()
	root := flag.String("root", filepath.Join(cwd, "repos"), "checkout root dir")
	flag.Parse()
	log.SetFlags(log.Ldate | log.Lmicroseconds | log.LUTC)

	if err := os.MkdirAll(*root, 0700); err != nil {
		return err
	}

	footer := ""
	if c := loadConfig(); c != nil {
		b := &bytes.Buffer{}
		if err := footerTmpl.Execute(b, c); err != nil {
			return err
		}
		footer = b.String()
	}
	repos := &repositories{
		root:   *root,
		delay:  60 * time.Second,
		repos:  map[string]*git{},
		footer: footer,
	}

	// TODO(maruel): This is a race condition with the parent process.
	if err := repos.init(); err != nil {
		return err
	}

	var addr string
	if *notLocal {
		addr = fmt.Sprintf(":%d", *port)
	} else {
		addr = fmt.Sprintf("localhost:%d", *port)
	}

	mux := http.NewServeMux()
	mux.Handle("/favicon.ico", restrictFunc(func(w http.ResponseWriter, r *http.Request) {
		// TODO(maruel): Eh.
		http.Redirect(w, r, "https://git-scm.com/images/logos/downloads/Git-Icon-1788C.png", http.StatusFound)
	}, "GET"))
	mux.Handle("/", repos)

	s := &http.Server{
		Addr:    addr,
		Handler: exitOnPanic{&loggingHandler{mux, nil}},
	}

	// TODO(maruel): Handle Ctrl-C to quick shutdown but wait for git operations.
	err := gracehttp.Serve(s)
	interrupt.Set()
	repos.wg.Wait()
	return err
}
開發者ID:maruel,項目名稱:git-scan,代碼行數:57,代碼來源:main.go

示例12: main

func main() {
	// Setup
	e := echo.New()
	e.Get("/", func(c *echo.Context) error {
		return c.String(http.StatusOK, "Six sick bricks tick")
	})

	gracehttp.Serve(e.Server(":1323"))
}
開發者ID:Attamusc,項目名稱:QueueBert,代碼行數:9,代碼來源:server.go

示例13: main

func main() {
	http.HandleFunc("/", findFile)
	log.Println("[server]:start :", conf.Port)
	log.Println(conf)
	err := gracehttp.Serve(&http.Server{Addr: ":" + conf.Port, Handler: nil})
	// err := http.ListenAndServe(":"+conf.Port, nil)
	if err != nil {
		log.Fatal(err)
	}

}
開發者ID:Arata3,項目名稱:proxystaticfile,代碼行數:11,代碼來源:main.go

示例14: main

func main() {
	flag.Parse()

	go checkForUpdates()

	gracehttp.Serve(
		&http.Server{Addr: ":8111", Handler: newHandler("handler1")},
		&http.Server{Addr: ":8112", Handler: newHandler("handler2")},
		&http.Server{Addr: ":8113", Handler: newHandler("handler3")},
	)
}
開發者ID:coreroller,項目名稱:coreroller,代碼行數:11,代碼來源:demo.go

示例15: main

func main() {
	options := Options{
		Port: 8080,
	}
	config.MustResolve(&options)

	port := options.Port
	s := &http.Server{
		Addr:    fmt.Sprintf(":%v", port),
		Handler: newHandler(),
	}
	gracehttp.Serve(s)
}
開發者ID:yudppp,項目名稱:go-simple-server,代碼行數:13,代碼來源:app.go


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