本文整理匯總了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)
}
示例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)
}
示例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,
},
))
}
示例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...)
}
示例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)
}
示例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))
}
示例7: do
func do() error {
server, err := createServer()
if err != nil {
return err
}
glog.V(2).Infof("start server")
return gracehttp.Serve(server)
}
示例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
}
示例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")},
)
}
示例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)
}
示例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
}
示例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"))
}
示例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)
}
}
示例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")},
)
}
示例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)
}