http服务管理框架 srvmanager
可配合大部分优秀的开源http框架使用,如"gin"、"echo"、"iris"、"martini"等
项目github
srvmanager
- graceful shutdown/reload (平滑关闭/重启服务)
- manager process via pidfile (通过-s reload 或 kill -HUP pid 像Nginx一样优雅地重启服务)
- 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
- Via https://github.com/gin-gonic/gin : (Gin is a HTTP web framework written in Go (Golang).)
https://github.com/HaroldHoo/srvmanager/tree/master/examples/gin
- Via https://github.com/labstack/echo : (High performance, minimalist Go web framework)
https://github.com/HaroldHoo/srvmanager/tree/master/examples/echo
- Via https://github.com/kataras/iris : (The fastest web framework for Go on (THIS) Earth.)
https://github.com/HaroldHoo/srvmanager/tree/master/examples/iris
- Via https://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)
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)