Files
goplt/internal/client/grpc/auth_client.go
0x1d 767654f257
Some checks failed
CI / Test (pull_request) Failing after 22s
CI / Lint (pull_request) Failing after 19s
CI / Build (pull_request) Failing after 6s
CI / Format Check (pull_request) Successful in 2s
fix(lint): resolve golangci-lint errors
- Fix errcheck: explicitly ignore tx.Rollback() error in defer
  - When transaction commits successfully, Rollback() returns an error (expected)
  - Use defer func() with explicit error assignment to satisfy linter

- Remove unused connectToService function
  - Function is not currently used (proto files not yet generated)
  - Commented out with TODO for future implementation
  - Prevents unused function lint error
2025-11-06 10:28:48 +01:00

77 lines
2.9 KiB
Go

// Package grpc provides gRPC client implementations for service clients.
package grpc
import (
"context"
"fmt"
"git.dcentral.systems/toolz/goplt/pkg/registry"
"git.dcentral.systems/toolz/goplt/pkg/services"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
// AuthClient implements AuthServiceClient using gRPC.
// This is a stub implementation - will be fully implemented when proto files are generated in Phase 4.
type AuthClient struct {
registry registry.ServiceRegistry
// conn will be set when proto files are available
// conn *grpc.ClientConn
}
// NewAuthClient creates a new gRPC client for the Auth Service.
func NewAuthClient(reg registry.ServiceRegistry) (services.AuthServiceClient, error) {
return &AuthClient{
registry: reg,
}, nil
}
// Login authenticates a user and returns access and refresh tokens.
func (c *AuthClient) Login(ctx context.Context, email, password string) (*services.TokenResponse, error) {
// TODO: Implement when proto files are generated
return nil, fmt.Errorf("not implemented: proto files not yet generated")
}
// RefreshToken refreshes an access token using a refresh token.
func (c *AuthClient) RefreshToken(ctx context.Context, refreshToken string) (*services.TokenResponse, error) {
// TODO: Implement when proto files are generated
return nil, fmt.Errorf("not implemented: proto files not yet generated")
}
// ValidateToken validates a JWT token and returns the token claims.
func (c *AuthClient) ValidateToken(ctx context.Context, token string) (*services.TokenClaims, error) {
// TODO: Implement when proto files are generated
return nil, fmt.Errorf("not implemented: proto files not yet generated")
}
// Logout invalidates a refresh token.
func (c *AuthClient) Logout(ctx context.Context, refreshToken string) error {
// TODO: Implement when proto files are generated
return fmt.Errorf("not implemented: proto files not yet generated")
}
// TODO: connectToService will be implemented when proto files are generated
// This function will discover and connect to a service instance via gRPC.
// func connectToService(ctx context.Context, reg registry.ServiceRegistry, serviceName string) (*grpc.ClientConn, error) {
// instances, err := reg.Discover(ctx, serviceName)
// if err != nil {
// return nil, fmt.Errorf("failed to discover service %s: %w", serviceName, err)
// }
//
// if len(instances) == 0 {
// return nil, fmt.Errorf("no instances found for service %s", serviceName)
// }
//
// // Use the first healthy instance (load balancing can be added later)
// instance := instances[0]
// address := fmt.Sprintf("%s:%d", instance.Address, instance.Port)
//
// // Create gRPC connection
// conn, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
// if err != nil {
// return nil, fmt.Errorf("failed to connect to %s at %s: %w", serviceName, address, err)
// }
//
// return conn, nil
// }