Skip to content

v2.0.0

Latest
Compare
Choose a tag to compare
@LittleJono LittleJono released this 02 Dec 00:24
· 2 commits to main since this release
2e2c4b3

Authsignal Go SDK v2.0.0

Installation

go get github.com/authsignal/authsignalgo/v2

Client Initialization

// Initialize with default API URL (https://api.authsignal.com/v1)
client := client.NewAuthsignalClient("your-secret-key", "")

// Or with an API URL for a different region
client := client.NewAuthsignalClient("your-secret-key", "https://au.api.authsignal.com/v1")

API Methods

We have altered the interface for all of the SDK's methods. Please see our docs for examples.

Error Handling

The SDK includes a custom error type AuthsignalAPIError that implements the standard Go error interface:

type AuthsignalAPIError struct {
    ErrorCode        string // Specific error code
    ErrorDescription string // Human-readable error description
    StatusCode       int    // HTTP status code
}

// Implements the error interface
func (e *AuthsignalAPIError) Error() string {
    return fmt.Sprintf("AuthsignalException: %d - %s", e.StatusCode, e.ErrorDescription)
}

Example Error Handling

response, err := client.GetUser(client.GetUserRequest{
    UserId: "user-id",
})
if err != nil {
    // Type assert to check if it's an API error
    if apiErr, ok := err.(*client.AuthsignalAPIError); ok {
        switch apiErr.StatusCode {
        case 401:
            // Handle unauthorized
            fmt.Printf("Authentication failed: %s\n", apiErr.ErrorDescription)
        case 404:
            // Handle not found
            fmt.Printf("User not found: %s\n", apiErr.ErrorDescription)
        default:
            // Handle other API errors
            fmt.Printf("API Error (%d): %s\n", apiErr.StatusCode, apiErr.ErrorDescription)
        }
        return err
    }
    // Handle non-API errors (network issues, etc.)
    return fmt.Errorf("unexpected error: %w", err)
}