Example #1
0
func BuildApp() appkit.App {
	app := app.NewApp()

	// Set up memory backend.
	backend := memory.New()
	app.RegisterBackend(backend)

	// Set up resources.
	app.RegisterResource(resources.NewResource(&Project{}, &resources.UserResource{}, true))
	app.RegisterResource(resources.NewResource(&Todo{}, &resources.UserResource{}, true))

	return app
}
Example #2
0
func NewFileServiceWithFs(registry kit.Registry, dataPath string) *FileService {
	if dataPath == "" {
		panic("Empty data path")
	}

	service := NewFileService(registry)

	res := resources.NewResource(&FileIntId{}, FilesResource{}, true)
	service.SetResource(res)

	fs, err := fs.New(dataPath)
	if err != nil {
		panic(fmt.Sprintf("Could not initialize filesystem backend: %v", err))
	}
	service.AddBackend(fs)

	return service
}
Example #3
0
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
}