capture/capture.go

45 lines
947 B
Go
Raw Normal View History

2017-11-21 22:36:40 +01:00
package main
2018-07-21 19:50:53 +02:00
import "strconv"
2017-11-21 22:36:40 +01:00
type Capture struct {
2018-07-27 00:49:12 +02:00
ID int `json:"id"`
2018-07-21 19:50:53 +02:00
Path string `json:"path"`
2017-11-21 22:36:40 +01:00
Method string `json:"method"`
Status int `json:"status"`
Request string `json:"request"`
Response string `json:"response"`
}
2018-07-21 19:50:53 +02:00
type CaptureRef struct {
ID int `json:"id"`
Path string `json:"path"`
Method string `json:"method"`
Status int `json:"status"`
ItemUrl string `json:"itemUrl"`
}
type Captures []Capture
func (items *Captures) Add(capture Capture) {
*items = append(*items, capture)
size := len(*items)
if size > args.maxCaptures {
*items = (*items)[1:]
}
2017-11-21 22:36:40 +01:00
}
2018-07-22 20:14:27 +02:00
func (items *Captures) ToReferences(itemBaseUrl string) []CaptureRef {
2018-07-21 19:50:53 +02:00
refs := make([]CaptureRef, len(*items))
for i, item := range *items {
refs[i] = CaptureRef{
2018-07-27 00:49:12 +02:00
ID: item.ID,
2018-07-21 19:50:53 +02:00
Path: item.Path,
Method: item.Method,
Status: item.Status,
ItemUrl: itemBaseUrl + strconv.Itoa(i),
}
2017-11-21 22:36:40 +01:00
}
2018-07-21 19:50:53 +02:00
return refs
2017-11-21 22:36:40 +01:00
}