func NewService(reg kit.Registry, b db.Backend) *Service { var model kit.Model if b.HasStringIds() { model = &TaskStrId{} } else { model = &TaskIntId{} } s := &Service{} runner := NewRunner(reg, b, model) s.Runner = *runner return s }
func NewService(registry kit.Registry, backend db.Backend, profileModel kit.UserProfile) *Service { h := Service{ registry: registry, } h.AuthAdaptors = make(map[string]kit.AuthAdaptor) // Register auth adaptors. h.AddAuthAdaptor(&password.AuthAdaptorPassword{}) h.AddAuthAdaptor(oauth.NewAdaptor()) // Build resources. var userModel kit.Model if backend.HasStringIds() { userModel = &UserStrId{} } else { userModel = &UserIntId{} } users := resources.NewResource(userModel, UserResourceHooks{}, true) h.Users = users if profileModel != nil { profiles := resources.NewResource(profileModel, nil, false) h.Profiles = profiles } var sessionModel kit.Model if backend.HasStringIds() { sessionModel = &Session{} } else { sessionModel = &IntUserSession{} } sessions := resources.NewResource(sessionModel, SessionResourceHooks{}, true) h.Sessions = sessions h.Tokens = resources.NewResource(&Token{}, nil, false) roles := resources.NewResource(&Role{}, RoleResourceHooks{}, true) h.Roles = roles permissions := resources.NewResource(&Permission{}, PermissionResourceHooks{}, true) h.Permissions = permissions // Ensure proper backend setup. h.SetBackend(backend) return &h }