Repository navigation
Expand file tree
/
Copy pathtypes.go
More file actions
96 lines (71 loc) · 2.2 KB
/
Copy pathtypes.go
File metadata and controls
96 lines (71 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package idempotency
import "time"
// RecordStatus represents the status of an idempotency record
type RecordStatus string
const (
// StatusPending indicates a request is currently being processed
StatusPending RecordStatus = "pending"
// StatusCompleted indicates a request has been successfully processed
StatusCompleted RecordStatus = "completed"
// StatusFailed indicates a request processing failed
StatusFailed RecordStatus = "failed"
)
// Record represents a stored idempotency record
type Record struct {
// Key is the idempotency key
Key string
// RequestHash is a hash of the request content for validation
RequestHash string
// Status is the current status of the request
Status RecordStatus
// Response contains the cached response if status is completed
Response *CachedResponse
// CreatedAt is when the record was created
CreatedAt time.Time
// ExpiresAt is when the record should expire
ExpiresAt time.Time
}
// CachedResponse represents a cached HTTP response
type CachedResponse struct {
// StatusCode is the HTTP status code
StatusCode int
// Headers are the response headers
Headers map[string][]string
// Body is the response body
Body []byte
// ContentType is the content type of the response
ContentType string
}
// Request represents an incoming HTTP request for idempotency checking
type Request struct {
// Method is the HTTP method (GET, POST, etc.)
Method string
// Path is the request path
Path string
// Headers are the request headers
Headers map[string][]string
// Body is the request body
Body []byte
// IdempotencyKey is the extracted or generated idempotency key
IdempotencyKey string
}
// Response represents an HTTP response to be cached
type Response struct {
// StatusCode is the HTTP status code
StatusCode int
// Headers are the response headers
Headers map[string][]string
// Body is the response body
Body []byte
// ContentType is the content type of the response
ContentType string
}
// ToCachedResponse converts a Response to a CachedResponse
func (r *Response) ToCachedResponse() *CachedResponse {
return &CachedResponse{
StatusCode: r.StatusCode,
Headers: r.Headers,
Body: r.Body,
ContentType: r.ContentType,
}
}