1 Star 2 Fork 3

kristas/booting-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
iris_starter.go 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
kristas 提交于 2021-03-22 18:48 . feat: port now can be assign by cmd
package iris_container
import (
"fmt"
"gitee.com/kristas/booting-go/framework"
. "gitee.com/kristas/booting-go/framework/bean/bean_factory"
"gitee.com/kristas/booting-go/framework/common/tool/browser"
"github.com/kataras/iris/v12"
"github.com/sirupsen/logrus"
"strings"
)
func init() {
framework.Application().Use(new(IrisStarter))
}
type IrisStarter struct {
Log *logrus.Logger `bean:"log"`
IrisConfig iris.Configuration `value:"iris"`
Logging framework.Logging `value:"logging"`
IrisApp *iris.Application `bean:"iris_app"`
}
func (r *IrisStarter) Bean() string {
return "web_container"
}
func (r *IrisStarter) AfterPropertiesSet() {
RegisterIrisApp(r.Logging.Level)
}
func (r *IrisStarter) ListenAndServe(port int) {
if framework.OpenBrowser {
browser.Open(fmt.Sprintf("http://localhost:%d", port))
}
r.Log.Fatal(
r.IrisApp.Listen(
fmt.Sprintf(":%d", port),
iris.WithConfiguration(r.IrisConfig),
),
)
}
func RegisterIrisApp(loggingLevel string) {
app := iris.New()
app.Logger().SetLevel(irisLevelAdapter(loggingLevel))
RegisterWithName("iris_app", app)
}
func irisLevelAdapter(level string) string {
switch strings.ToLower(level) {
case "panic":
return "fatal"
case "trace":
return "debug"
default:
return level
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kristas/booting-go.git
git@gitee.com:kristas/booting-go.git
kristas
booting-go
booting-go
v1.1.2

搜索帮助