阶段十:完成 Go Cmd Tools 注释基线清零
This commit is contained in:
1 parent
393c45a1e3
commit
ea1f2ec430
25 files changed
+694
-4281
No files matched your search
@@ -9,35 +9,44 @@ import (
|
||||
"golang.org/x/sys/windows/svc"
|
||||
)
|
||||
|
||||
// windowsServiceHandler 保存windowsServiceHandler,供当前处理流程使用
|
||||
type windowsServiceHandler struct {
|
||||
run func(context.Context) error
|
||||
}
|
||||
|
||||
// runPlatformService 负责运行PlatformService相关处理。
|
||||
func runPlatformService(name string, run func(context.Context) error) error {
|
||||
if err := svc.Run(name, windowsServiceHandler{run: run}); err != nil {
|
||||
if // err 保存err,供当前处理流程使用
|
||||
err := svc.Run(name, windowsServiceHandler{run: run}); err != nil {
|
||||
return fmt.Errorf("Windows Service %q: %w", name, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Execute 负责Execute相关处理。
|
||||
func (h windowsServiceHandler) Execute(_ []string, requests <-chan svc.ChangeRequest, status chan<- svc.Status) (bool, uint32) {
|
||||
// accepted 保存accepted,供当前处理流程使用
|
||||
const accepted = svc.AcceptStop | svc.AcceptShutdown
|
||||
status <- svc.Status{State: svc.StartPending}
|
||||
|
||||
// ctx、cancel 保存ctx、cancel,供当前处理流程使用
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
// done 保存done,供当前处理流程使用
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- h.run(ctx) }()
|
||||
status <- svc.Status{State: svc.Running, Accepts: accepted}
|
||||
|
||||
for {
|
||||
select {
|
||||
case request := <-requests:
|
||||
case // request 保存请求,供当前处理流程使用
|
||||
request := <-requests:
|
||||
switch request.Cmd {
|
||||
case svc.Stop, svc.Shutdown:
|
||||
status <- svc.Status{State: svc.StopPending, Accepts: accepted}
|
||||
cancel()
|
||||
}
|
||||
case err := <-done:
|
||||
case // err 保存err,供当前处理流程使用
|
||||
err := <-done:
|
||||
cancel()
|
||||
if err != nil {
|
||||
return true, 1
|
||||
|
||||
Reference in new issue
Block a user