Documentation
¶
Overview ¶
Package fs provides a filesystem-based implementation of the UsersService. It stores user data as JSON files on the local filesystem, making it ideal for development, testing, and single-instance deployments.
Storage Layout ¶
Users are stored in the following directory structure:
{storageDir}/
{userId}/
user.json # User profile data
Thread Safety ¶
The service includes optional in-memory caching via BaseUsersService. File operations are atomic via the goutils/storage package.
Usage ¶
userService := fs.NewUsersService("/path/to/users")
resp, err := userService.CreateUser(ctx, &v1.CreateUserRequest{
User: &v1.User{Name: "John Doe", Email: "john@example.com"},
})
Index ¶
- type UsersService
- func (s *UsersService) CreateUser(ctx context.Context, req *v1.CreateUserRequest) (*v1.CreateUserResponse, error)
- func (s *UsersService) DeleteFromStorage(ctx context.Context, id string) error
- func (s *UsersService) ListAllUsers(ctx context.Context) ([]*v1.User, error)
- func (s *UsersService) LoadUser(ctx context.Context, id string) (*v1.User, error)
- func (s *UsersService) SaveUser(ctx context.Context, id string, user *v1.User) error
- func (s *UsersService) UpdateUser(ctx context.Context, req *v1.UpdateUserRequest) (*v1.UpdateUserResponse, error)
- func (s *UsersService) UserExists(ctx context.Context, id string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type UsersService ¶
type UsersService struct {
services.BaseUsersService
// contains filtered or unexported fields
}
UsersService implements services.UsersService using filesystem storage. It embeds BaseUsersService to inherit caching and shared operations.
func NewUsersService ¶
func NewUsersService(storageDir string) *UsersService
NewUsersService creates a new filesystem-backed UsersService
func (*UsersService) CreateUser ¶
func (s *UsersService) CreateUser(ctx context.Context, req *v1.CreateUserRequest) (*v1.CreateUserResponse, error)
CreateUser creates a new user profile
func (*UsersService) DeleteFromStorage ¶
func (s *UsersService) DeleteFromStorage(ctx context.Context, id string) error
DeleteFromStorage implements UserStorageProvider
func (*UsersService) ListAllUsers ¶
ListAllUsers implements UserStorageProvider
func (*UsersService) UpdateUser ¶
func (s *UsersService) UpdateUser(ctx context.Context, req *v1.UpdateUserRequest) (*v1.UpdateUserResponse, error)
UpdateUser updates an existing user profile
func (*UsersService) UserExists ¶
func (s *UsersService) UserExists(ctx context.Context, id string) bool
UserExists implements UserStorageProvider