目前一些 Web 框架 比如 Gin fiber 等 都支持 HTTP 服务,可以使用静态资源
func main() {
app := fiber.New()
app.Static("/", "./home.html")
.....
}
将打包编译的二进制文件 与 html 静态资源文件放置在一起 "/usr/local/bin/", 想通过创建 systemd 服务来管理进程
[Unit]
Description=GoWeb Server
After=network.target ntp.service
[Service]
PrivateTmp=true
Type=simple
ExecStart=/usr/local/bin/goweb
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s SIGINT $MAINPID
User=root
Group=root
[Install]
WantedBy=multi-user.target
程序启动后发现调用的 "app.Static("/", "./home.html")" 相对路径找不到资源, 发现 systemd 启动的环境变量可能不对? 而手动启动 /usr/local/bin/goweb 能找到资源
[root@VM-16-10-~]# systemctl start goweb
查看状态
[root@VM-16-10-~]# systemctl status goweb
ctrls.service - GoWeb Server
Loaded: loaded (/etc/systemd/system/go-web.service, enabled)
Active: active (running)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.