123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package main
- import (
- _ "eta/eta_pub/routers"
- "os"
- "github.com/beego/beego/v2/server/web"
- "github.com/kardianos/service"
- )
- var logger = service.ConsoleLogger
- type program struct{}
- func (p *program) Start(s service.Service) error {
- go p.run()
- return nil
- }
- func (p *program) run() {
- web.Run()
- // 运行逻辑
- }
- func (p *program) Stop(s service.Service) error {
- return nil
- }
- func main() {
- svcConfig := &service.Config{
- Name: "Trim", //服务显示名称
- DisplayName: "Trim Service", //服务名称
- Description: "微服务", //服务描述
- }
- prg := &program{}
- s, err := service.New(prg, svcConfig)
- if err != nil {
- logger.Error(err)
- }
- if len(os.Args) > 1 {
- switch os.Args[1] {
- case "install":
- s.Install()
- logger.Info("服务安装成功!")
- s.Start()
- logger.Info("服务启动成功!")
- break
- case "start":
- s.Start()
- logger.Info("服务启动成功!")
- break
- case "stop":
- s.Stop()
- logger.Info("服务关闭成功!")
- break
- case "restart":
- s.Stop()
- logger.Info("服务关闭成功!")
- s.Start()
- logger.Info("服务启动成功!")
- break
- case "remove":
- s.Stop()
- logger.Info("服务关闭成功!")
- s.Uninstall()
- logger.Info("服务卸载成功!")
- break
- }
- return
- }
- err = s.Run()
- if err != nil {
- logger.Error(err)
- }
- if web.BConfig.RunMode == "dev" {
- web.BConfig.WebConfig.DirectoryIndex = true
- web.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
- }
- web.Run()
- }
|