Skip to content

Commit

Permalink
Option-ize NanoMDM service
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepeterson committed Jun 19, 2021
1 parent c03b3b8 commit d16aa2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/nanomdm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
18 changes: 15 additions & 3 deletions service/nanomdm/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d16aa2a

Please sign in to comment.