mirror of
https://github.com/labstack/echo.git
synced 2025-01-26 03:20:08 +02:00
e7c89c424f
Signed-off-by: Vishal Rana <vr@labstack.com>
44 lines
782 B
Go
44 lines
782 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"os"
|
|
"os/signal"
|
|
|
|
"time"
|
|
|
|
"net/http"
|
|
|
|
"github.com/labstack/echo"
|
|
"github.com/labstack/gommon/log"
|
|
)
|
|
|
|
func main() {
|
|
// Setup
|
|
e := echo.New()
|
|
e.Logger.SetLevel(log.INFO)
|
|
e.GET("/", func(c echo.Context) error {
|
|
time.Sleep(5 * time.Second)
|
|
return c.JSON(http.StatusOK, "OK")
|
|
})
|
|
|
|
// Start server
|
|
go func() {
|
|
if err := e.Start(":1323"); err != nil {
|
|
e.Logger.Info("shutting down the server")
|
|
}
|
|
}()
|
|
|
|
// Wait for interrupt signal to gracefully shutdown the server with
|
|
// a timeout of 10 seconds.
|
|
quit := make(chan os.Signal)
|
|
signal.Notify(quit, os.Interrupt)
|
|
<-quit
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
if err := e.Shutdown(ctx); err != nil {
|
|
e.Logger.Fatal(err)
|
|
}
|
|
}
|