Documentation
¶
Overview ¶
Package user provides user domain models and management.
Index ¶
- Constants
- func RegisterUserServiceServer(s interface{}, srv UserServiceServer)
- type AuthenticateUserRequest
- type AuthenticateUserResponse
- type CacheService
- type CreateUserRequest
- type CreateUserResponse
- type Event
- type EventBus
- type EventHandler
- type GetUserRequest
- type GetUserResponse
- type Group
- type ListFilter
- type ListUsersRequest
- type ListUsersResponse
- type MetricsCollector
- type Permission
- type Session
- type UnimplementedUserServiceServer
- func (UnimplementedUserServiceServer) AuthenticateUser(context.Context, *AuthenticateUserRequest) (*AuthenticateUserResponse, error)
- func (UnimplementedUserServiceServer) CreateUser(context.Context, *CreateUserRequest) (*CreateUserResponse, error)
- func (UnimplementedUserServiceServer) GetUser(context.Context, *GetUserRequest) (*GetUserResponse, error)
- func (UnimplementedUserServiceServer) ListUsers(context.Context, *ListUsersRequest) (*ListUsersResponse, error)
- func (UnimplementedUserServiceServer) UpdateUser(context.Context, *UpdateUserRequest) (*UpdateUserResponse, error)
- type UpdateUserRequest
- type UpdateUserResponse
- type User
- type UserProto
- type UserRepository
- type UserService
- func (s *UserService) AuthenticateUser(ctx context.Context, req *AuthenticateUserRequest) (*AuthenticateUserResponse, error)
- func (s *UserService) CreateUser(ctx context.Context, req *CreateUserRequest) (*CreateUserResponse, error)
- func (s *UserService) GetUser(ctx context.Context, req *GetUserRequest) (*GetUserResponse, error)
- func (s *UserService) ListUsers(ctx context.Context, req *ListUsersRequest) (*ListUsersResponse, error)
- func (s *UserService) Start(port int) error
- func (s *UserService) UpdateUser(ctx context.Context, req *UpdateUserRequest) (*UpdateUserResponse, error)
- type UserServiceServer
Constants ¶
const ( RoleAdmin = "Admin" RoleAgent = "Agent" RoleCustomer = "Customer" RoleGuest = "Guest" )
User roles.
const ( ActionCreate = "create" ActionRead = "read" ActionUpdate = "update" ActionDelete = "delete" ActionList = "list" ActionManage = "manage" )
Permission actions.
const ( ResourceTicket = "ticket" ResourceUser = "user" ResourceQueue = "queue" ResourceReport = "report" ResourceSystem = "system" ResourceOrganization = "organization" )
Permission resources.
Variables ¶
This section is empty.
Functions ¶
func RegisterUserServiceServer ¶
func RegisterUserServiceServer(s interface{}, srv UserServiceServer)
RegisterUserServiceServer registers the service with gRPC server.
Types ¶
type AuthenticateUserRequest ¶
type CacheService ¶
type CacheService interface {
Get(ctx context.Context, key string) ([]byte, error)
Set(ctx context.Context, key string, value []byte, ttl time.Duration) error
Delete(ctx context.Context, key string) error
Invalidate(ctx context.Context, pattern string) error
}
CacheService defines the interface for caching.
type CreateUserRequest ¶
type CreateUserResponse ¶
type CreateUserResponse struct {
User *UserProto `json:"user"`
}
type Event ¶
type Event struct {
ID string `json:"id"`
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Data map[string]interface{} `json:"data"`
Source string `json:"source"`
Version string `json:"version"`
}
Event represents a domain event.
type EventBus ¶
type EventBus interface {
Publish(ctx context.Context, event Event) error
Subscribe(ctx context.Context, topic string, handler EventHandler) error
}
EventBus defines the interface for event publishing.
type EventHandler ¶
EventHandler processes events.
type GetUserRequest ¶
type GetUserRequest struct {
Id string `json:"id"`
}
type GetUserResponse ¶
type GetUserResponse struct {
User *UserProto `json:"user"`
}
type Group ¶
type Group struct {
ID string `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
Permissions []Permission `json:"permissions,omitempty"`
Metadata map[string]interface{} `json:"metadata" db:"metadata"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
Group represents a user group.
type ListFilter ¶
type ListFilter struct {
Role string `json:"role,omitempty"`
Department string `json:"department,omitempty"`
IsActive *bool `json:"is_active,omitempty"`
GroupID string `json:"group_id,omitempty"`
CreatedFrom time.Time `json:"created_from,omitempty"`
CreatedTo time.Time `json:"created_to,omitempty"`
SortBy string `json:"sort_by,omitempty"`
SortOrder string `json:"sort_order,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
ListFilter represents user list filtering options.
type ListUsersRequest ¶
type ListUsersResponse ¶
type MetricsCollector ¶
type MetricsCollector interface {
IncrementCounter(name string, labels map[string]string)
RecordDuration(name string, duration time.Duration, labels map[string]string)
SetGauge(name string, value float64, labels map[string]string)
}
MetricsCollector defines the interface for metrics collection.
type Permission ¶
type Permission struct {
ID string `json:"id" db:"id"`
Name string `json:"name" db:"name"`
Resource string `json:"resource" db:"resource"`
Action string `json:"action" db:"action"`
Description string `json:"description" db:"description"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
Permission represents a system permission.
type Session ¶
type Session struct {
ID string `json:"id" db:"id"`
UserID string `json:"user_id" db:"user_id"`
Token string `json:"token" db:"token"`
IPAddress string `json:"ip_address" db:"ip_address"`
UserAgent string `json:"user_agent" db:"user_agent"`
ExpiresAt time.Time `json:"expires_at" db:"expires_at"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
LastUsedAt time.Time `json:"last_used_at" db:"last_used_at"`
Metadata map[string]interface{} `json:"metadata" db:"metadata"`
}
Session represents a user session.
type UnimplementedUserServiceServer ¶
type UnimplementedUserServiceServer struct{}
UnimplementedUserServiceServer can be embedded to have forward compatible implementations.
func (UnimplementedUserServiceServer) AuthenticateUser ¶
func (UnimplementedUserServiceServer) AuthenticateUser(context.Context, *AuthenticateUserRequest) (*AuthenticateUserResponse, error)
func (UnimplementedUserServiceServer) CreateUser ¶
func (UnimplementedUserServiceServer) CreateUser(context.Context, *CreateUserRequest) (*CreateUserResponse, error)
func (UnimplementedUserServiceServer) GetUser ¶
func (UnimplementedUserServiceServer) GetUser(context.Context, *GetUserRequest) (*GetUserResponse, error)
func (UnimplementedUserServiceServer) ListUsers ¶
func (UnimplementedUserServiceServer) ListUsers(context.Context, *ListUsersRequest) (*ListUsersResponse, error)
func (UnimplementedUserServiceServer) UpdateUser ¶
func (UnimplementedUserServiceServer) UpdateUser(context.Context, *UpdateUserRequest) (*UpdateUserResponse, error)
type UpdateUserRequest ¶
type UpdateUserResponse ¶
type UpdateUserResponse struct {
User *UserProto `json:"user"`
}
type User ¶
type User struct {
ID string `json:"id" db:"id"`
Email string `json:"email" db:"email"`
FirstName string `json:"first_name" db:"first_name"`
LastName string `json:"last_name" db:"last_name"`
PasswordHash string `json:"-" db:"password_hash"`
Role string `json:"role" db:"role"`
Department string `json:"department,omitempty" db:"department"`
Phone string `json:"phone,omitempty" db:"phone"`
Mobile string `json:"mobile,omitempty" db:"mobile"`
IsActive bool `json:"is_active" db:"is_active"`
EmailVerified bool `json:"email_verified" db:"email_verified"`
TwoFactorAuth bool `json:"two_factor_auth" db:"two_factor_auth"`
Preferences map[string]interface{} `json:"preferences" db:"preferences"`
LastLoginAt *time.Time `json:"last_login_at,omitempty" db:"last_login_at"`
LastActivityAt *time.Time `json:"last_activity_at,omitempty" db:"last_activity_at"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
DeletedAt *time.Time `json:"deleted_at,omitempty" db:"deleted_at"`
// Relationships
Groups []Group `json:"groups,omitempty"`
Permissions []Permission `json:"permissions,omitempty"`
Sessions []Session `json:"sessions,omitempty"`
}
User represents a system user.
type UserProto ¶
type UserProto struct {
Id string `json:"id"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Role string `json:"role"`
Department string `json:"department"`
Phone string `json:"phone"`
Mobile string `json:"mobile"`
IsActive bool `json:"is_active"`
EmailVerified bool `json:"email_verified"`
TwoFactorAuth bool `json:"two_factor_auth"`
LastLoginAt int64 `json:"last_login_at"`
LastActivityAt int64 `json:"last_activity_at"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
UserProto represents a user in protobuf format.
type UserRepository ¶
type UserRepository interface {
Create(ctx context.Context, user *User) error
GetByID(ctx context.Context, id string) (*User, error)
GetByEmail(ctx context.Context, email string) (*User, error)
Update(ctx context.Context, user *User) error
Delete(ctx context.Context, id string) error
List(ctx context.Context, filter *ListFilter) ([]*User, error)
Search(ctx context.Context, query string) ([]*User, error)
UpdateLastLogin(ctx context.Context, id string, timestamp time.Time) error
GetByRole(ctx context.Context, role string) ([]*User, error)
}
UserRepository defines the interface for user data access.
type UserService ¶
type UserService struct {
UnimplementedUserServiceServer
// contains filtered or unexported fields
}
UserService handles all user-related operations as a microservice.
func NewUserService ¶
func NewUserService(repo UserRepository, cache CacheService, events EventBus, metrics MetricsCollector) *UserService
NewUserService creates a new user service instance.
func (*UserService) AuthenticateUser ¶
func (s *UserService) AuthenticateUser(ctx context.Context, req *AuthenticateUserRequest) (*AuthenticateUserResponse, error)
AuthenticateUser authenticates a user with email and password.
func (*UserService) CreateUser ¶
func (s *UserService) CreateUser(ctx context.Context, req *CreateUserRequest) (*CreateUserResponse, error)
CreateUser creates a new user.
func (*UserService) GetUser ¶
func (s *UserService) GetUser(ctx context.Context, req *GetUserRequest) (*GetUserResponse, error)
GetUser retrieves a user by ID.
func (*UserService) ListUsers ¶
func (s *UserService) ListUsers(ctx context.Context, req *ListUsersRequest) (*ListUsersResponse, error)
ListUsers lists users with filtering.
func (*UserService) Start ¶
func (s *UserService) Start(port int) error
Start starts the gRPC server.
func (*UserService) UpdateUser ¶
func (s *UserService) UpdateUser(ctx context.Context, req *UpdateUserRequest) (*UpdateUserResponse, error)
UpdateUser updates an existing user.
type UserServiceServer ¶
type UserServiceServer interface {
CreateUser(context.Context, *CreateUserRequest) (*CreateUserResponse, error)
GetUser(context.Context, *GetUserRequest) (*GetUserResponse, error)
UpdateUser(context.Context, *UpdateUserRequest) (*UpdateUserResponse, error)
AuthenticateUser(context.Context, *AuthenticateUserRequest) (*AuthenticateUserResponse, error)
ListUsers(context.Context, *ListUsersRequest) (*ListUsersResponse, error)
}
gRPC Server interface.