mirror of
https://github.com/sstent/go-garth.git
synced 2026-01-26 00:52:40 +00:00
feat(refactor): Implement 1A.1 Package Structure Refactoring
This commit implements the package structure refactoring as outlined in phase1.md (Task 1A.1). Key changes include: - Reorganized packages into `pkg/garmin` for public API and `internal/` for internal implementations. - Updated all import paths to reflect the new structure. - Consolidated types and client logic into their respective new packages. - Updated `cmd/garth/main.go` to use the new public API. - Fixed various compilation and test issues encountered during the refactoring process. - Converted `internal/api/client/auth_test.go` to a functional test. This establishes a solid foundation for future enhancements and improves maintainability.
This commit is contained in:
84
internal/errors/errors.go
Normal file
84
internal/errors/errors.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package errors
|
||||
|
||||
import "fmt"
|
||||
|
||||
// GarthError represents the base error type for all custom errors in Garth
|
||||
type GarthError struct {
|
||||
Message string
|
||||
Cause error
|
||||
}
|
||||
|
||||
func (e *GarthError) Error() string {
|
||||
if e.Cause != nil {
|
||||
return fmt.Sprintf("garth error: %s: %v", e.Message, e.Cause)
|
||||
}
|
||||
return fmt.Sprintf("garth error: %s", e.Message)
|
||||
}
|
||||
|
||||
// GarthHTTPError represents HTTP-related errors in API calls
|
||||
type GarthHTTPError struct {
|
||||
GarthError
|
||||
StatusCode int
|
||||
Response string
|
||||
}
|
||||
|
||||
func (e *GarthHTTPError) Error() string {
|
||||
if e.Cause != nil {
|
||||
return fmt.Sprintf("HTTP error (%d): %s: %v", e.StatusCode, e.Response, e.Cause)
|
||||
}
|
||||
return fmt.Sprintf("HTTP error (%d): %s", e.StatusCode, e.Response)
|
||||
}
|
||||
|
||||
// AuthenticationError represents authentication failures
|
||||
type AuthenticationError struct {
|
||||
GarthError
|
||||
}
|
||||
|
||||
func (e *AuthenticationError) Error() string {
|
||||
if e.Cause != nil {
|
||||
return fmt.Sprintf("authentication error: %s: %v", e.Message, e.Cause)
|
||||
}
|
||||
return fmt.Sprintf("authentication error: %s", e.Message)
|
||||
}
|
||||
|
||||
// OAuthError represents OAuth token-related errors
|
||||
type OAuthError struct {
|
||||
GarthError
|
||||
}
|
||||
|
||||
func (e *OAuthError) Error() string {
|
||||
if e.Cause != nil {
|
||||
return fmt.Sprintf("OAuth error: %s: %v", e.Message, e.Cause)
|
||||
}
|
||||
return fmt.Sprintf("OAuth error: %s", e.Message)
|
||||
}
|
||||
|
||||
// APIError represents errors from API calls
|
||||
type APIError struct {
|
||||
GarthHTTPError
|
||||
}
|
||||
|
||||
// IOError represents file I/O errors
|
||||
type IOError struct {
|
||||
GarthError
|
||||
}
|
||||
|
||||
func (e *IOError) Error() string {
|
||||
if e.Cause != nil {
|
||||
return fmt.Sprintf("I/O error: %s: %v", e.Message, e.Cause)
|
||||
}
|
||||
return fmt.Sprintf("I/O error: %s", e.Message)
|
||||
}
|
||||
|
||||
// ValidationError represents input validation failures
|
||||
type ValidationError struct {
|
||||
GarthError
|
||||
Field string
|
||||
}
|
||||
|
||||
func (e *ValidationError) Error() string {
|
||||
if e.Field != "" {
|
||||
return fmt.Sprintf("validation error for %s: %s", e.Field, e.Message)
|
||||
}
|
||||
return fmt.Sprintf("validation error: %s", e.Message)
|
||||
}
|
||||
Reference in New Issue
Block a user