Sybren A. Stüvel 98a5d48611 Manager: make the 'platform' of a variable its own type
This prevents too many `string` types; those are now just used for the
variable name & value, whereas the platform is a `VariablePlatform` type.
2022-03-25 16:19:59 +01:00

46 lines
979 B
Go

package config
import "github.com/rs/zerolog/log"
// SPDX-License-Identifier: GPL-3.0-or-later
// Service provides access to Flamenco Manager configuration.
type Service struct {
config Conf
}
func NewService() *Service {
return &Service{
config: DefaultConfig(),
}
}
func (s *Service) Load() error {
config, err := getConf()
if err != nil {
return err
}
s.config = config
return nil
}
func (s *Service) ExpandVariables(valueToExpand string, audience VariableAudience, platform VariablePlatform) string {
return s.config.ExpandVariables(valueToExpand, audience, platform)
}
func (s *Service) Get() *Conf {
return &s.config
}
// Save writes the in-memory configuration to the config file.
func (s *Service) Save() error {
err := s.config.Write(configFilename)
if err != nil {
return err
}
// Do the logging here, as our caller doesn't know `configFilename``.
log.Info().Str("filename", configFilename).Msg("configuration file written")
return nil
}