Skip to content

Commit ad0f34d

Browse files
committed
feat: add history for requests
1 parent 14361f2 commit ad0f34d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

webreq.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type Request struct {
3232
StatusCode int
3333
}
3434

35+
var DatabaseHistory []Request
36+
3537
func Builder(method string) *Request {
3638
r := Request{}
3739

@@ -71,8 +73,25 @@ func (r *Request) SetStatusCode(statusCode int) *Request {
7173
return r
7274
}
7375

76+
// list history of requests, can pass limit
77+
func GetHistory(limit int) []Request {
78+
79+
if limit == 0 {
80+
return DatabaseHistory
81+
}
82+
83+
if limit > len(DatabaseHistory) {
84+
for i := 0; i < len(DatabaseHistory); i++ {
85+
return DatabaseHistory
86+
}
87+
}
88+
return DatabaseHistory[:limit]
89+
}
90+
7491
func (r *Request) Execute() ([]byte, error) {
7592

93+
DatabaseHistory = append(DatabaseHistory, *r)
94+
7695
client := &http.Client{}
7796
ctx := context.Background()
7897
ctx, cancel := context.WithTimeout(ctx, time.Duration(r.TimeOut)*time.Second)

0 commit comments

Comments
 (0)