mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-27 12:52:27 +02:00
refactor: replace direct newService calls with ServiceCommand pattern
- Replace all direct newService() calls with ServiceCommand initialization - Update command constructors to use ServiceCommand instead of ServiceManager - Simplify LogCommand and UpgradeCommand structs by removing serviceManager field - Remove unused global svcConfig variable from prog.go - Improve consistency and centralize service creation logic This change establishes a consistent pattern for service operations across the codebase, making it easier to maintain and extend service-related functionality.
This commit is contained in:
committed by
Cuong Manh Le
parent
33dd720d80
commit
a61cb1f5bf
@@ -35,7 +35,7 @@ func (sc *ServiceCommand) initializeServiceManager() (service.Service, *prog, er
|
||||
func (sc *ServiceCommand) initializeServiceManagerWithServiceConfig(svcConfig *service.Config) (service.Service, *prog, error) {
|
||||
p := &prog{}
|
||||
|
||||
s, err := newService(p, svcConfig)
|
||||
s, err := sc.newService(p, svcConfig)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("failed to create service: %w", err)
|
||||
}
|
||||
@@ -44,6 +44,15 @@ func (sc *ServiceCommand) initializeServiceManagerWithServiceConfig(svcConfig *s
|
||||
return s, p, nil
|
||||
}
|
||||
|
||||
// newService creates a new service instance using the provided program and configuration.
|
||||
func (sc *ServiceCommand) newService(p *prog, svcConfig *service.Config) (service.Service, error) {
|
||||
s, err := newService(p, svcConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create service: %w", err)
|
||||
}
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// NewServiceCommand creates a new service command handler
|
||||
func NewServiceCommand() *ServiceCommand {
|
||||
return &ServiceCommand{}
|
||||
|
||||
Reference in New Issue
Block a user