Implement JSON-RPC client foundation
Add core JSON-RPC 2.0 protocol implementation for Kanboard API: - JSONRPCRequest/Response/Error structs with proper JSON tags - Generic call() method for sending requests and parsing responses - Thread-safe request ID generation using atomic.Int64 - Automatic /jsonrpc.php path appending to baseURL - Support for subdirectory installations - HTTP Basic Auth support (API token and username/password) - Error handling for unauthorized/forbidden responses Includes comprehensive tests with httptest mock server. Closes: kanboard-api-2g1
This commit is contained in:
parent
347fb75f11
commit
a486a73ce1
6 changed files with 611 additions and 1 deletions
28
errors.go
Normal file
28
errors.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package kanboard
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrConnectionFailed indicates a connection to the Kanboard server failed.
|
||||
ErrConnectionFailed = errors.New("connection to Kanboard server failed")
|
||||
|
||||
// ErrUnauthorized indicates authentication failed.
|
||||
ErrUnauthorized = errors.New("authentication failed: invalid credentials")
|
||||
|
||||
// ErrForbidden indicates insufficient permissions.
|
||||
ErrForbidden = errors.New("access forbidden: insufficient permissions")
|
||||
)
|
||||
|
||||
// APIError represents an error returned by the Kanboard API.
|
||||
type APIError struct {
|
||||
Code int
|
||||
Message string
|
||||
}
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e *APIError) Error() string {
|
||||
return fmt.Sprintf("Kanboard API error (code %d): %s", e.Code, e.Message)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue