-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathservice.go
61 lines (54 loc) · 1.04 KB
/
service.go
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
52
53
54
55
56
57
58
59
60
61
package main
import (
"github.com/axgle/service"
"fmt"
"os"
)
func main() {
var displayName = "Go Service Test2"
var desc = "This is a test Go service. It is designed to run well."
var ws, err = service.NewService("GoServiceTest2", displayName, desc)
if(err != nil) {
fmt.Printf("%s unable to start: %s", displayName, err)
return
}
if len(os.Args) > 1 {
var err error
verb := os.Args[1]
switch verb {
case "install":
err = ws.Install()
if err != nil {
fmt.Printf("Failed to install: %s\n", err)
return
}
fmt.Printf("Service \"%s\" installed.\n", displayName)
case "remove":
err = ws.Remove()
if err != nil {
fmt.Printf("Failed to remove: %s\n", err)
return
}
fmt.Printf("Service \"%s\" removed.\n", displayName)
}
return
}
err = ws.Run(func() error {
// start
go doWork()
ws.LogInfo("I'm Running!")
return nil
}, func() error {
// stop
stopWork()
ws.LogInfo("I'm Stopping!")
return nil
})
if err != nil {
ws.LogError(err.Error())
}
}
func doWork() {
}
func stopWork() {
}