代码拉取完成,页面将自动刷新
package main
import (
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/plugins/cors"
"github.com/common-nighthawk/go-figure"
"github.com/kqbi/service"
_ "github.com/tsingeye/FreeEhome/routers"
"github.com/tsingeye/FreeEhome/service/udp"
"github.com/tsingeye/FreeEhome/tools"
"github.com/tsingeye/FreeEhome/tools/logs"
"github.com/tsingeye/FreeEhome/tools/sqlDB"
"os"
"time"
)
type program struct {
exit chan bool
}
func (p *program) Start(s service.Service) error {
appPath := tools.GetAbsPath()
os.Chdir(appPath)
beego.SetStaticPath("/", appPath+"www")
go p.run()
return nil
}
func (p *program) run() {
figure.NewFigure("FreeEhome", "", true).Print()
logs.BeeLogger.Info("FreeEHome Service Start!!!")
fmt.Printf("%s FreeEHome Service Start!!!\n", time.Now().Format("2006-01-02 15:04:05"))
//初始化数据库
sqlDB.InitDB()
//开启UDP服务
go udp.ListenUDPServer()
//实现服务端允许跨域
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowAllOrigins: true,
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
ExposeHeaders: []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
AllowCredentials: true,
}))
beego.Run()
return
}
func (p *program) Stop(s service.Service) error {
logs.BeeLogger.Info("FreeEHome Service Stop!!!")
fmt.Printf("%s FreeEHome Service Stop!!!\n", time.Now().Format("2006-01-02 15:04:05"))
close(p.exit)
if service.Interactive() {
os.Exit(0)
}
return nil
}
func main() {
svcConfig := &service.Config{
Name: "FreeEHome", //服务显示名称
DisplayName: "FreeEHome", //服务名称
Description: "FreeEHome", //服务描述
}
prg := &program{
exit: make(chan bool),
}
s, err := service.New(prg, svcConfig)
if err != nil {
logs.PanicLogger.Fatalln("service.New() error: ", err)
}
if len(os.Args) > 1 {
//install, uninstall, start, stop 的另一种实现方式
err = service.Control(s, os.Args[1])
if err != nil {
logs.PanicLogger.Fatalln(err)
}
return
}
err = s.Run()
if err != nil {
logs.PanicLogger.Fatalln(err)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。