2022-04-26 20:50:09 +03:00
|
|
|
// Package agh contains common entities and interfaces of AdGuard Home.
|
|
|
|
package agh
|
|
|
|
|
2024-11-13 15:44:21 +03:00
|
|
|
import (
|
|
|
|
"github.com/AdguardTeam/golibs/service"
|
|
|
|
)
|
2022-10-10 14:05:24 +03:00
|
|
|
|
|
|
|
// ServiceWithConfig is an extension of the [Service] interface for services
|
|
|
|
// that can return their configuration.
|
|
|
|
//
|
|
|
|
// TODO(a.garipov): Consider removing this generic interface if we figure out
|
|
|
|
// how to make it testable in a better way.
|
|
|
|
type ServiceWithConfig[ConfigType any] interface {
|
2024-11-13 15:44:21 +03:00
|
|
|
service.Interface
|
2022-10-10 14:05:24 +03:00
|
|
|
|
2024-12-11 17:41:00 +03:00
|
|
|
// Config returns a deep clone of the configuration of the service.
|
2022-10-10 14:05:24 +03:00
|
|
|
Config() (c ConfigType)
|
|
|
|
}
|
|
|
|
|
|
|
|
// type check
|
|
|
|
var _ ServiceWithConfig[struct{}] = (*EmptyServiceWithConfig[struct{}])(nil)
|
|
|
|
|
|
|
|
// EmptyServiceWithConfig is a ServiceWithConfig that does nothing. Its Config
|
|
|
|
// method returns Conf.
|
|
|
|
//
|
|
|
|
// TODO(a.garipov): Remove if unnecessary.
|
|
|
|
type EmptyServiceWithConfig[ConfigType any] struct {
|
2024-11-13 15:44:21 +03:00
|
|
|
service.Empty
|
2022-10-10 14:05:24 +03:00
|
|
|
|
|
|
|
Conf ConfigType
|
|
|
|
}
|
|
|
|
|
|
|
|
// Config implements the [ServiceWithConfig] interface for
|
|
|
|
// *EmptyServiceWithConfig.
|
|
|
|
func (s *EmptyServiceWithConfig[ConfigType]) Config() (conf ConfigType) {
|
|
|
|
return s.Conf
|
|
|
|
}
|