-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (41 loc) · 766 Bytes
/
main.go
File metadata and controls
51 lines (41 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"log"
"os"
"github.com/kardianos/service"
)
type program struct{}
func (p *program) Start(s service.Service) error {
go p.run()
return nil
}
func (p *program) run() {
// 服务逻辑代码...
}
func (p *program) Stop(s service.Service) error {
return nil
}
func main() {
svcConfig := &service.Config{
Name: "quant1x-x",
DisplayName: "Quant1X-Lab X",
Description: "Quant1X的实验工程",
}
prg := &program{}
s, err := service.New(prg, svcConfig)
if err != nil {
log.Fatal(err)
}
if len(os.Args) > 1 {
// 支持命令行操作:install/uninstall/start/stop
err = service.Control(s, os.Args[1])
if err != nil {
log.Fatal(err)
}
return
}
err = s.Run()
if err != nil {
log.Fatal(err)
}
}