// NewControl creates a new instance of Control with the given config. func NewControl(conf Config, ks *keyStore.KeyStore) (*Control, error) { err := conf.Validate() if err != nil { return nil, err } a, err := access.NewAccess(conf.Access, "caretakerctl", ks) if err != nil { return nil, errors.New("Could not create caretakerctl interface.").CausedBy(err) } return &Control{ config: conf, access: a, }, nil }
// NewService creates a new service instance from the given Config. func NewService(conf Config, name string, syncGroup *usync.Group, sec *keyStore.KeyStore) (*Service, error) { err := conf.Validate() if err != nil { return nil, errors.New("Config of service '%v' is not valid.", name).CausedBy(err) } acc, err := access.NewAccess(conf.Access, name, sec) if err != nil { return nil, errors.New("Could not create access for service '%v'.", name).CausedBy(err) } log, err := logger.NewLogger(conf.Logger, name, syncGroup) if err != nil { return nil, errors.New("Could not create logger for service '%v'.", name).CausedBy(err) } result := &Service{ config: conf, logger: log, name: name, syncGroup: syncGroup, access: acc, } runtime.SetFinalizer(result, finalize) return result, nil }