diff --git a/cmd/nanomdm/main.go b/cmd/nanomdm/main.go index 0de6547..36925dc 100644 --- a/cmd/nanomdm/main.go +++ b/cmd/nanomdm/main.go @@ -89,7 +89,7 @@ func main() { } // create 'core' MDM service - nano := nanomdm.New(mdmStorage, logger.With("service", "nanomdm")) + nano := nanomdm.New(mdmStorage, nanomdm.WithLogger(logger.With("service", "nanomdm"))) mux := http.NewServeMux() diff --git a/service/nanomdm/service.go b/service/nanomdm/service.go index 6dbe7d9..ce32447 100644 --- a/service/nanomdm/service.go +++ b/service/nanomdm/service.go @@ -43,13 +43,25 @@ func normalize(e *mdm.Enrollment) *mdm.EnrollID { return eid } +type Option func(*Service) + +func WithLogger(logger log.Logger) Option { + return func(s *Service) { + s.logger = logger + } +} + // New returns a new NanoMDM main service. -func New(store storage.ServiceStore, logger log.Logger) *Service { - return &Service{ +func New(store storage.ServiceStore, opts ...Option) *Service { + nanomdm := &Service{ store: store, - logger: logger, + logger: log.NopLogger, normalizer: normalize, } + for _, opt := range opts { + opt(nanomdm) + } + return nanomdm } func (s *Service) updateEnrollID(r *mdm.Request, e *mdm.Enrollment) error {