feat: initial AWS Server Go SDK
test / go (push) Successful in 1m7s

This commit is contained in:
shiran
2026-08-22 22:14:08 +08:00
commit 3d4c2dbb20
16 changed files with 1272 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
package awsserversdk
import (
"encoding/json"
"fmt"
"net/http"
)
type APIError struct {
StatusCode int
Code int
Message string
Data json.RawMessage
Body string
}
func (e *APIError) Error() string {
return fmt.Sprintf("aws server API: HTTP %d code %d: %s", e.StatusCode, e.Code, e.Message)
}
func IsUnauthorized(err error) bool {
value, ok := err.(*APIError)
return ok && (value.StatusCode == http.StatusUnauthorized || value.StatusCode == http.StatusForbidden)
}
func IsConflict(err error) bool {
value, ok := err.(*APIError)
return ok && value.StatusCode == http.StatusConflict
}
func IsBudgetExceeded(err error) bool {
value, ok := err.(*APIError)
if !ok || value.StatusCode != http.StatusConflict {
return false
}
var data map[string]any
return json.Unmarshal(value.Data, &data) == nil && data["shortfall"] != nil
}
type TaskError struct{ Task Task }
func (e *TaskError) Error() string {
if e.Task.ErrorMessage != "" {
return e.Task.ErrorMessage
}
return "operation task failed: " + e.Task.Status
}