本文整理汇总了Golang中github.com/tylerb/graceful.ListenAndServe函数的典型用法代码示例。如果您正苦于以下问题:Golang ListenAndServe函数的具体用法?Golang ListenAndServe怎么用?Golang ListenAndServe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ListenAndServe函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Run
func (b *Broker) Run() {
b.running = true
b.RegisterMiddleware()
b.RegisterURL()
go b.HandleFailTask()
graceful.ListenAndServe(b.web.Server(b.addr), 5*time.Second)
}
开发者ID:xxoxx,项目名称:kingtask,代码行数:7,代码来源:broker.go
示例2: main
func main() {
// inti config and component
componentInit()
// Echo instance
e := echo.New()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
// e.Use(handler.CrossDomain)
// Routes
e.Get("/hello", handler.Hello)
e.Get("/api/v1/seckill", handler.Tickets)
e.Get("/api/v1/reset", handler.Reset)
// go cache.StartUpdateEventStatus()
// go kafka.StartKafkaProducer()
// Start server
port := viper.GetString("port")
log.Println("server port: ", port)
graceful.ListenAndServe(e.Server(port), 1*time.Second)
}
开发者ID:Dataman-Cloud,项目名称:seckilling,代码行数:26,代码来源:main.go
示例3: main
func main() {
port := "8080"
e := echo.New()
e.SetDebug(true)
e.Use(mw.Logger())
e.Use(mw.Recover())
e.StripTrailingSlash()
assetHandler := http.FileServer(assetFS())
e.Get("/clicks", buttonsStateHandler)
e.Post("/click/:button", buttonClicker)
e.WebSocket("/ws", socketHandler)
e.Get("/*", func(c *echo.Context) error {
assetHandler.ServeHTTP(c.Response().Writer(), c.Request())
return nil
})
// Start the "message hub"
go hub.Run()
// Detect clicks on buttons
btns = newButtons()
defer btns.Close()
btns.Run()
// Control the leds based on clicks
newLeds(btns, hub)
// Start server
log.Println("Starting server on port " + port)
graceful.ListenAndServe(e.Server(":"+port), 2*time.Second)
}
开发者ID:fgrehm,项目名称:pucrs-iot-experiment,代码行数:35,代码来源:main.go
示例4: main
func main() {
cfg := readConfig()
jwtKey := []byte(cfg.JwtKey)
mongoSession := createMongoSession()
defer mongoSession.Close()
db := mongoSession.DB(cfg.Database)
userCollection := db.C(collections.UserCollectionName)
e := echo.New()
e.Get("/ping", func(c echo.Context) error {
return c.String(http.StatusOK, "pong")
})
restService := rest.NewService(db)
restGroup := e.Group("/collection")
restGroup.Get("/:collection", restService.Get)
restGroup.Post("/:collection", restService.Post)
restGroup.Put("/:collection", restService.Put)
restGroup.Delete("/:collection", restService.Delete)
userService := user.NewService(userCollection, jwtKey)
userGroup := e.Group("/user")
userGroup.Post("/signup", userService.Signup)
userGroup.Post("/confirm", userService.ConfirmSignup)
userGroup.Post("/signin", userService.Signin)
userGroup.Post("/forgot-password", userService.ForgotPassword)
userGroup.Post("/reset-password", userService.ResetPassword)
sessionService := session.NewService(userCollection, jwtKey)
sessionMiddleware := middleware.CreateSessionMiddleware(userCollection, jwtKey)
sessionGroup := e.Group("/session", sessionMiddleware)
sessionGroup.Post("/signout", sessionService.Signout)
sessionGroup.Post("/change-password", sessionService.ChangePassword)
sessionGroup.Post("/change-email", sessionService.ChangeEmail)
sessionGroup.Post("/set-profile", sessionService.SetProfile)
adminService := admin.NewService(userCollection, jwtKey)
adminSessionMiddleware := middleware.CreateAdminSessionMiddleware(userCollection, jwtKey)
adminGroup := e.Group("/admin", adminSessionMiddleware)
adminGroup.Get("/get-users", adminService.GetUsers)
adminGroup.Post("/create-user", adminService.CreateUser)
adminGroup.Post("/change-user-password", adminService.ChangeUserPassword)
adminGroup.Post("/change-user-email", adminService.ChangeUserEmail)
adminGroup.Post("/set-user-roles", adminService.SetUserRoles)
adminGroup.Post("/set-user-profile", adminService.SetUserProfile)
adminGroup.Delete("/remove-users", adminService.RemoveUsers)
adminGroup.Post("/signout-users", adminService.SignoutUsers)
adminGroup.Post("/suspend-users", adminService.SuspendUsers)
adminGroup.Post("/unsuspend-users", adminService.UnsuspendUsers)
adminGroup.Delete("/remove-unconfirmed-users", adminService.RemoveUnconfirmedUsers)
adminGroup.Post("/remove-expired-reset-keys", adminService.RemoveExpiredResetKeys)
fmt.Println("Listening at http://localhost:5025")
std := standard.New(":5025")
std.SetHandler(e)
graceful.ListenAndServe(std.Server, 5*time.Second)
}
开发者ID:getdiskette,项目名称:diskette,代码行数:60,代码来源:main.go
示例5: main
func main() {
// ---------------------------
// Setting Active Environment
// ---------------------------
if len(os.Args) > 1 {
err := environment.Set(os.Args[1])
if err != nil {
log.Fatal(err)
}
} else {
log.Fatal("Running requires an environment argument")
}
// ---------
// Database
// ---------
db.Open()
defer db.Close()
// -----
// Echo
// -----
e := request.BuildEcho()
// ----
// Run
// ----
port := environment.GetEnvVar(environment.PORT)
log.Println("Server started on :" + port)
graceful.ListenAndServe(e.Server(":"+port), 5*time.Second) // Graceful shutdown
}
开发者ID:carrot,项目名称:burrow,代码行数:35,代码来源:api.go
示例6: Run
func (s *ApiServer) Run() error {
s.RegisterMiddleware()
s.RegisterURL()
std := standard.New(s.webAddr)
std.SetHandler(s)
graceful.ListenAndServe(std.Server, 5*time.Second)
return nil
}
开发者ID:flike,项目名称:kingshard,代码行数:8,代码来源:server.go
示例7: main
func main() {
// Setup
e := echo.New()
e.Get("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "Sue sews rose on slow jor crows nose")
})
graceful.ListenAndServe(e.Server(":1323"), 5*time.Second)
}
开发者ID:xyproto,项目名称:echo,代码行数:9,代码来源:server.go
示例8: main
func main() {
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Post("/auth/register", controllers.AuthRegister)
graceful.ListenAndServe(e.Server(":9000"), 10*time.Second)
}
开发者ID:lukashes,项目名称:go-echo-auth,代码行数:9,代码来源:server.go
示例9: main
func main() {
// Setup
e := echo.New()
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Sue sews rose on slow joe crows nose")
})
std := standard.New(":1323")
std.SetHandler(e)
graceful.ListenAndServe(std.Server, 5*time.Second)
}
开发者ID:AlekSi,项目名称:echo,代码行数:10,代码来源:server.go
示例10: main
func main() {
// Setup
e := echo.New()
e.Get("/", func(c *echo.Context) error {
c.String(http.StatusOK, "Sue sews rose on slow jor crows nose")
return nil
})
// Use github.com/tylerb/graceful
graceful.ListenAndServe(e.Server(":1323"), 5*time.Second)
}
开发者ID:codeblanche,项目名称:echo,代码行数:11,代码来源:server.go
示例11: main
// main runs the jumphash program.
// There are two optional arguments, addr and seconds.
func main() {
var addr = flag.String("address", "127.0.0.1:8080", "tcp address to listen on")
var seconds = flag.Int("sleep", 5, "time in seconds to sleep each POST request")
flag.Parse()
e := echo.New()
e.Use(middleware.Logger())
e.Use(server.Shutdown())
e.Use(server.Sleep(*seconds))
e.Post("/", server.Hash)
log.Printf("listening on %s", *addr)
graceful.ListenAndServe(e.Server(*addr), 0)
}
开发者ID:binarydud,项目名称:jumphash,代码行数:14,代码来源:main.go
示例12: main
func main() {
// Echo instance
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Routes
e.Get("/", hello)
// Start server
port := "8080"
std := standard.New(":" + port)
std.SetHandler(e)
log.Printf("Starting app on port %+v\n", port)
graceful.ListenAndServe(std.Server, 1*time.Second)
}
开发者ID:amsokol,项目名称:openshift-golang-template,代码行数:19,代码来源:main.go
示例13: SetupTest
func (suite *ApiTestSuite) SetupTest() {
// Loading .env file. We're not failing here in the
// event that the .env file can't be loaded. The
// project might be running through a CI system
// and the environment variables. Will fail later
// rather than early
environment.SetWithRelativeDirectory("../", environment.TESTING)
// Starting database
db.Open()
// Getting our Echo instance
e := BuildEcho()
// Running the server
port := environment.GetEnvVar(environment.PORT)
suite.wreckerClient = wrecker.New("http://localhost:" + port)
log.Println("Server started on :" + port)
go graceful.ListenAndServe(e.Server(":"+port), 5*time.Second) // Graceful shutdown
}
开发者ID:gitter-badger,项目名称:burrow,代码行数:20,代码来源:topics_test.go
示例14: main
func main() {
e := echo.New()
// Enable colored log
e.ColoredLog(true)
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Use(mw.Gzip())
// https://github.com/thoas/stats
s := stats.New()
e.Use(s.Handler)
// Route
e.Get("/stats", func(c *echo.Context) error {
return c.JSON(http.StatusOK, s.Data())
})
// Serve index file
e.Index("public/index.html")
// Serve favicon
e.Favicon("public/favicon.ico")
// Serve static files
e.Static("/scripts", "public/scripts")
//-----------
// Templates
//-----------
e.SetRenderer(controllers.CreateRenderer())
e.Get("/page1", controllers.Page1Handler)
e.Get("/page2", controllers.Page2Handler)
// Start server
log.Println("Server is starting for port 8080...")
graceful.ListenAndServe(e.Server(":8080"), 2*time.Second)
log.Println("Server stoped")
}
开发者ID:amsokol,项目名称:sti-labs-golang1,代码行数:40,代码来源:main.go
示例15: main
//.........这里部分代码省略.........
name := req.FormValue("name")
ttags := req.FormValue("tags")
tags := strings.Split(ttags, " ")
path := x.UniqueString(10)
// Read files
file := req.MultipartForm.File["file"]
src, err := file[0].Open()
if err != nil {
return err
}
defer src.Close()
// Destination file
dst, err := os.Create("webms/" + path + ".webm")
if err != nil {
return err
}
defer dst.Close()
if _, err = io.Copy(dst, src); err != nil {
return err
}
if err = api.Get("WebmCont", rootid).SetSource(rootid).AddChild("Webm").Set("path", path).
Set("tags", tags).Set("name", name).Execute(ctx); err != nil {
return err
}
return c.String(http.StatusOK, "eyo uploaded file")
})
e.Get("/webm", func(c *echo.Context) error {
result, err := api.NewQuery("WebmCont", rootid).Collect("Webm").Run(ctx)
if err != nil {
return err
}
by, err := result.ToJson()
if err != nil {
return err
}
return c.String(200, string(by))
})
e.Get("/webm/filter/:filter", func(c *echo.Context) error {
tags := strings.Split(c.Param("filter"), "+")
result, err := api.NewQuery("WebmCont", rootid).Collect("Webm").Run(ctx)
if err != nil {
return err
}
by, err := filter(result, tags...)
if err != nil {
return err
}
return c.String(200, string(by))
})
e.Get("/webm/:id", func(c *echo.Context) error {
result, err := api.NewQuery("Webm", c.Param("id")).Run(ctx)
if err != nil {
return err
}
by, err := result.ToJson()
if err != nil {
return err
}
return c.String(200, string(by))
})
e.Get("/webm/:id/tag/:tag", func(c *echo.Context) error {
result, err := api.NewQuery("Webm", c.Param("id")).Run(ctx)
if err != nil {
return err
}
var tags []interface{}
tagb, ok := result.Columns["tags"].Value.([]interface{})
if ok {
tags = tagb
}
cont := contains(tags, c.Param("tag"))
var atags []string
var resp string
if cont {
resp = "removed"
atags = convertButLeave(tags, c.Param("tag"))
} else {
resp = "added"
atags = convert(tags)
atags = append(atags, c.Param("tag"))
}
err = api.Get("Webm", c.Param("id")).SetSource(rootid).Set("tags", atags).Execute(ctx)
if err != nil {
return err
}
return c.String(200, resp)
})
graceful.ListenAndServe(e.Server(":8080"), 5*time.Second)
}
开发者ID:Kemonozume,项目名称:webmgallery,代码行数:101,代码来源:main.go
示例16: Run
func (s *Server) Run() {
s.registerGlobalMiddlewares()
controller.RegisterURLs(s.web)
fmt.Printf("runing on %s\n", s.httpAddr)
graceful.ListenAndServe(s.web.Server(s.httpAddr), 5*time.Second)
}
开发者ID:holys,项目名称:rice,代码行数:6,代码来源:server.go
示例17: main
func main() {
var port string
if port = os.Getenv("VCAP_APP_PORT"); len(port) == 0 {
port = DEFAULT_PORT
}
var host string
if host = os.Getenv("VCAP_APP_HOST"); len(host) == 0 {
host = DEFAULT_HOST
}
// prepare folder for DB with sample data
dir := "./.fakedata-db"
os.RemoveAll(dir)
defer os.RemoveAll(dir)
var tiedot *db.DB
var err error
// init sample data
if tiedot, err = db.OpenDB(dir); err != nil {
log.Panic(err)
}
defer tiedot.Close()
// init sample data
if err = fakedata.AddData(tiedot); err != nil {
log.Panic(err)
}
// init persistence stores
rest.SetProductStore(data.GetProductStore(tiedot))
// Echo instance
e := echo.New()
// Static test web pages
e.Static("/", "website")
e.Index("website/index.html")
// Customization
e.SetDebug(true)
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
// Routes
routes(e)
s := e.Server(host + ":" + port)
// 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
// Start server
log.Printf("Starting app on %+v:%+v\n", host, port)
graceful.ListenAndServe(s, 5*time.Second)
}
开发者ID:amsokol,项目名称:kendo-ui-echo-samples,代码行数:61,代码来源:app.go
示例18: main
func main() {
routes := NewRoutes()
graceful.ListenAndServe(routes.Server(":60000"), 5*time.Second)
}
开发者ID:Rompei,项目名称:zepher-bansaku,代码行数:4,代码来源:main.go
示例19: gracefulRun
func gracefulRun(std *standard.Server) {
log.Fatal(graceful.ListenAndServe(std.Server, 5*time.Second))
}
开发者ID:studygolang,项目名称:studygolang,代码行数:3,代码来源:graceful_windows.go
示例20: main
func main() {
e := echo.New()
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c *echo.Context) error {
start := time.Now()
entry := log.WithFields(log.Fields{
"uuid": uuid4(),
"path": c.Request().RequestURI,
"method": c.Request().Method,
"ip": c.Request().RemoteAddr,
})
if reqID := c.Request().Header.Get("X-Request-Id"); reqID != "" {
entry = entry.WithField("request_id", reqID)
}
entry.Info("started handling request")
if err := next(c); err != nil {
c.Error(err)
}
latency := time.Since(start)
entry.WithFields(log.Fields{
"status": c.Response().Status(),
"text_status": http.StatusText(c.Response().Status()),
"took": latency,
fmt.Sprintf("measure#%s.latency", "web"): latency.Nanoseconds(),
}).Info("completed handling request")
return nil
}
})
e.Use(mw.Recover())
startTime := time.Now()
if time.Since(startTime).Minutes() >= 3 {
// finish game
}
e.Static("/", "public")
e.WebSocket("/ws", func(c *echo.Context) (err error) {
ws := c.Socket()
if err = websocket.Message.Send(ws, "Please Login"); err != nil {
return err
}
msg := ""
for {
// if err = websocket.Message.Send(ws, "Hello, Client!"); err != nil {
// return err
// }
if err = websocket.Message.Receive(ws, &msg); err != nil {
if err == io.EOF {
return nil
}
}
if strings.Contains(msg, "login") {
// split get tokenString
// checkToken(tokenString)
// if valid {
// login
// } else {
// return
// }
} else if strings.Contains(msg, "join_game") {
} else if strings.Contains(msg, "leave_game") {
}
log.Info(msg)
}
ws.Close()
return nil
})
log.Info("Starting websocket server at localhost:4000")
graceful.ListenAndServe(e.Server(":4000"), 3*time.Minute)
}
开发者ID:pyros2097,项目名称:spike,代码行数:78,代码来源:server.go
注:本文中的github.com/tylerb/graceful.ListenAndServe函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论