modulepackage
0.0.0-20200827020641-f720214eb6e8
Repository: https://github.com/devopsmi/daemon.git
Documentation: pkg.go.dev
# README
STEP 1:
git clone https://github.com/devopsmi/daemon
cd $GOPATH/github.com/devopsmi/daemon
go mod init
go mod tidy
go mod download
go mod vendor
STEP 2
package main
import (
"context"
"net/http"
"os"
"os/signal"
"time"
_ "github.com/devopsmi/daemon" //仅导入,包的init方法被自动调用,嵌入daemon功能
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/labstack/gommon/log"
)
func main() {
// Setup
e := echo.New()
e.Use(middleware.CORS())
e.Use(middleware.Recover())
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(":8080"); 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)
}
}
# Packages
No description provided by the author