First step in reducing the number of places we have to check the service type manually. Create a way to get a handle to a service specific handler and implement exports for those handlers --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #4254 #### Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [x] 💚 E2E
34 lines
981 B
Go
34 lines
981 B
Go
package m365
|
|
|
|
import (
|
|
"github.com/alcionai/clues"
|
|
|
|
"github.com/alcionai/corso/src/internal/m365/service/groups"
|
|
"github.com/alcionai/corso/src/internal/m365/service/onedrive"
|
|
"github.com/alcionai/corso/src/internal/m365/service/sharepoint"
|
|
"github.com/alcionai/corso/src/internal/operations/inject"
|
|
"github.com/alcionai/corso/src/pkg/control"
|
|
"github.com/alcionai/corso/src/pkg/path"
|
|
)
|
|
|
|
// NewServiceHandler returns an instance of a struct capable of running various
|
|
// operations for a given service.
|
|
func (ctrl *Controller) NewServiceHandler(
|
|
opts control.Options,
|
|
service path.ServiceType,
|
|
) (inject.ServiceHandler, error) {
|
|
switch service {
|
|
case path.OneDriveService:
|
|
return onedrive.NewOneDriveHandler(opts), nil
|
|
|
|
case path.SharePointService:
|
|
return sharepoint.NewSharePointHandler(opts), nil
|
|
|
|
case path.GroupsService:
|
|
return groups.NewGroupsHandler(opts), nil
|
|
}
|
|
|
|
return nil, clues.New("unrecognized service").
|
|
With("service_type", service.String())
|
|
}
|