59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"go_dreamfactory/modules/web"
|
|
"go_dreamfactory/services"
|
|
"go_dreamfactory/sys/cache"
|
|
"go_dreamfactory/sys/db"
|
|
|
|
"github.com/liwei1dao/lego"
|
|
"github.com/liwei1dao/lego/base/rpcx"
|
|
"github.com/liwei1dao/lego/core"
|
|
"github.com/liwei1dao/lego/sys/log"
|
|
)
|
|
|
|
var (
|
|
conf = flag.String("conf", "./conf/web_1.yaml", "获取需要启动的服务配置文件") //启动服务的Id
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
s := NewService(
|
|
rpcx.SetConfPath(*conf),
|
|
rpcx.SetVersion("1.0.0.0"),
|
|
)
|
|
s.OnInstallComp( //装备组件
|
|
services.NewGateRouteComp(),
|
|
)
|
|
lego.Run(s, //运行模块
|
|
web.NewModule(),
|
|
)
|
|
|
|
}
|
|
|
|
func NewService(ops ...rpcx.Option) core.IService {
|
|
s := new(Service)
|
|
s.Configure(ops...)
|
|
return s
|
|
}
|
|
|
|
type Service struct {
|
|
services.ServiceBase
|
|
}
|
|
|
|
func (this *Service) InitSys() {
|
|
this.ServiceBase.InitSys()
|
|
if err := cache.OnInit(this.GetSettings().Sys["cache"]); err != nil {
|
|
panic(fmt.Sprintf("init sys.cache err: %s", err.Error()))
|
|
} else {
|
|
log.Infof("init sys.cache success!")
|
|
}
|
|
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
|
|
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
|
|
} else {
|
|
log.Infof("init sys.db success!")
|
|
}
|
|
}
|