1 Star 0 Fork 0

kzangv/gsf-fof

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
web.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
kzangv 提交于 2023-04-27 13:30 . fixed
package gsf
import (
"fmt"
"gitee.com/kzangv/gsf-fof/logger"
"github.com/urfave/cli/v2"
"net/http"
)
const (
CliWebIP = "web-ip"
CliWebPort = "web-port"
)
type WebService struct {
BasicService
Cfg struct {
IP string `yaml:"ip"` // 监听端口
Port int `yaml:"listen"` // 监听端口
RunMode string `yaml:"runmode"` // 服务运行模式
}
Handler http.Handler
}
func (c *WebService) CliFlags() []cli.Flag {
return []cli.Flag{
// web
&cli.StringFlag{
Name: CliWebIP,
Usage: "web service ip",
Action: func(_ *cli.Context, s string) error { c.Cfg.IP = s; return nil },
},
&cli.IntFlag{
Name: CliWebPort,
Usage: "web service port",
Action: func(_ *cli.Context, s int) error { c.Cfg.Port = s; return nil },
},
}
}
func (c *WebService) Init(cfg *AppConfig, ctx *cli.Context) (logger.Interface, error) {
return c.BasicService.Init(c.Cfg.RunMode, cfg, ctx)
}
func (c *WebService) Run(log logger.Interface, cfg *AppConfig) error {
if c.RunBefore != nil {
if err := c.RunBefore(); err != nil {
return err
}
}
if c.Cfg.IP == "" {
log.WarnForce("Listening Server [[[ Run-Mode: %s ]]] http://127.0.0.1:%d\n", cfg.EnvDesc(), c.Cfg.Port)
} else {
log.WarnForce("Listening Server [[[ Run-Mode: %s ]]] http://%s:%d\n", cfg.EnvDesc(), c.Cfg.IP, c.Cfg.Port)
}
srv := &http.Server{
Addr: fmt.Sprintf("%s:%d", c.Cfg.IP, c.Cfg.Port),
Handler: c.Handler,
}
srv.SetKeepAlivesEnabled(true)
return srv.ListenAndServe()
}
func (c *WebService) Close() {}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kzangv/gsf-fof.git
git@gitee.com:kzangv/gsf-fof.git
kzangv
gsf-fof
gsf-fof
v0.4.3

搜索帮助

0d507c66 1850385 C8b1a773 1850385