capture/capture.go

43 lines
891 B
Go
Raw Normal View History

2017-11-21 22:36:40 +01:00
package main
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-08-04 01:53:54 +02:00
type CaptureMetadata struct {
2018-09-16 16:18:39 +02:00
ID int `json:"id"`
Path string `json:"path"`
Method string `json:"method"`
Status int `json:"status"`
2018-07-21 19:50:53 +02:00
}
type Captures []Capture
func (items *Captures) Add(capture Capture) {
*items = append(*items, capture)
2018-08-04 01:53:54 +02:00
}
func (items *Captures) RemoveLastAfterReaching(maxItems int) {
if len(*items) > maxItems {
2018-07-21 19:50:53 +02:00
*items = (*items)[1:]
}
2017-11-21 22:36:40 +01:00
}
2018-08-04 01:53:54 +02:00
func (items *Captures) MetadataOnly() []CaptureMetadata {
refs := make([]CaptureMetadata, len(*items))
2018-07-21 19:50:53 +02:00
for i, item := range *items {
2018-08-04 01:53:54 +02:00
refs[i] = CaptureMetadata{
2018-09-16 16:18:39 +02:00
ID: item.ID,
Path: item.Path,
Method: item.Method,
Status: item.Status,
2018-07-21 19:50:53 +02:00
}
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
}