1. 程式人生 > 其它 >http服務管理框架 srvmanager

http服務管理框架 srvmanager

https://studygolang.com/p/srvmanager
可配合大部分優秀的開源http框架使用,如"gin"、"echo"、"iris"、"martini"等

專案github

https://github.com/HaroldHoo/srvmanager

srvmanager

  1. graceful shutdown/reload (平滑關閉/重啟服務)
  2. manager process via pidfile (通過-s reload 或 kill -HUP pid 像Nginx一樣優雅地重啟服務)
  3. log something easier (記錄日誌更便捷)

Usage

./main/bin/server -h

Usage of ./main/bin/server:
  -accesslog string
        log file (default "/var/log/server_access.log")
  -errorlog string
        log file (default "/var/log/server_error.log")
  -pid string
        pid file (default "/var/run/server.pid")
  -d    Start as deamon. (default true)
  -p string
        Listen port (default "8080")
  -s string
        (When used with the -pid option, the pid will be from specified pidfile.)
        Send a signal to the process.  The argument signal can be one of: start stop reload restart,
        The following table shows the corresponding system signals:
        stop    SIGTERM
        reload    SIGHUP
        restart    SIGHUP
         (default "start")

Examples

  1. Viahttps://github.com/gin-gonic/gin: (Gin is a HTTP web framework written in Go (Golang).)

    https://github.com/HaroldHoo/srvmanager/tree/master/examples/gin

  2. Viahttps://github.com/labstack/echo: (High performance, minimalist Go web framework)

    https://github.com/HaroldHoo/srvmanager/tree/master/examples/echo

  3. Viahttps://github.com/kataras/iris: (The fastest web framework for Go on (THIS) Earth.)

    https://github.com/HaroldHoo/srvmanager/tree/master/examples/iris

  4. Viahttps://github.com/go-martini/martini: (Classy web framework for Go)

    https://github.com/HaroldHoo/srvmanager/tree/master/examples/martini

package main

import (
    "github.com/HaroldHoo/srvmanager"
    "github.com/gin-gonic/gin"
    "log"
    "net/http"
    "time"
)

func main() {
    m := srvmanager.New()

    gin.DefaultWriter = m.GetAccessLogWriter()
    gin.DefaultErrorWriter = m.GetErrorLogWriter()

    router := gin.Default()
    router.GET("/", func(c *gin.Context) {
        time.Sleep(2 * time.Second)
        srvmanager.Log(*m.ErrorLogFile).Infof("%s ---- \n", time.Now().Format("2006-01-02 15:04:05"))
        log.Printf("%s\n", "log test ----")
        c.String(http.StatusOK, "Welcome !")
    })

    srv := &http.Server{
        Handler:        router,
        ReadTimeout:    5 * time.Second,
        WriteTimeout:   5 * time.Second,
        MaxHeaderBytes: 1 << 20,
    }

    m.Run(srv)
}

HaroldHoo/srvmanager

184

golang http server manager, graceful shutdown/reload—Read More

Latest commit to themasterbranch on 4-10-2018 Download as zip
授權協議:
開發語言:
go檢視原始碼»