2
0

style(service): improve comments and fix linter warnings
Some checks failed
CI / build-and-test (push) Failing after 24s
Release / build (amd64, darwin) (push) Failing after 38s
Release / build (amd64, linux) (push) Failing after 40s
Release / build (amd64, windows) (push) Failing after 32s
Release / build (arm64, darwin) (push) Failing after 31s
Release / build (arm64, linux) (push) Failing after 39s
Release / release (push) Has been skipped

- Add package documentation comments
- Use blank identifiers for unused parameters
- Add periods to comment sentences for consistency
- Fix naked return statement
This commit is contained in:
2026-01-25 11:44:38 -05:00
parent 26b4e7497f
commit bf71b55cb7
2 changed files with 14 additions and 11 deletions

View File

@@ -3,23 +3,25 @@
//go:build !windows
// Package service provides Windows service integration for the runner.
// On non-Windows platforms, these functions are no-ops.
package service
import (
"context"
)
// IsWindowsService returns false on non-Windows platforms
// IsWindowsService returns false on non-Windows platforms.
func IsWindowsService() bool {
return false
}
// RunAsService is a no-op on non-Windows platforms
func RunAsService(serviceName string, run func(ctx context.Context)) error {
// RunAsService is a no-op on non-Windows platforms.
func RunAsService(_ string, _ func(ctx context.Context)) error {
return nil
}
// GetServiceName returns empty on non-Windows platforms
// GetServiceName returns empty on non-Windows platforms.
func GetServiceName() string {
return ""
}

View File

@@ -3,6 +3,7 @@
//go:build windows
// Package service provides Windows service integration for the runner.
package service
import (
@@ -15,14 +16,14 @@ import (
"golang.org/x/sys/windows/svc"
)
// runnerService implements svc.Handler for Windows service management
// runnerService implements svc.Handler for Windows service management.
type runnerService struct {
ctx context.Context
cancel context.CancelFunc
}
// Execute is called by the Windows Service Control Manager
func (s *runnerService) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
// Execute is called by the Windows Service Control Manager.
func (s *runnerService) Execute(_ []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
changes <- svc.Status{State: svc.StartPending}
@@ -53,10 +54,10 @@ loop:
}
changes <- svc.Status{State: svc.StopPending}
return
return false, 0
}
// IsWindowsService returns true if the process is running as a Windows service
// IsWindowsService returns true if the process is running as a Windows service.
func IsWindowsService() bool {
// Check if we're running interactively
isInteractive, err := svc.IsWindowsService()
@@ -67,7 +68,7 @@ func IsWindowsService() bool {
return isInteractive
}
// RunAsService runs the application as a Windows service
// RunAsService runs the application as a Windows service.
func RunAsService(serviceName string, run func(ctx context.Context)) error {
ctx, cancel := context.WithCancel(context.Background())
@@ -84,7 +85,7 @@ func RunAsService(serviceName string, run func(ctx context.Context)) error {
return nil
}
// GetServiceName returns the service name from environment or default
// GetServiceName returns the service name from environment or default.
func GetServiceName() string {
if name := os.Getenv("GITEA_RUNNER_SERVICE_NAME"); name != "" {
return name