capture/capture.go
2018-07-21 20:48:51 -03:00

44 lines
907 B
Go

package main
import "strconv"
type Capture struct {
Path string `json:"path"`
Method string `json:"method"`
Status int `json:"status"`
Request string `json:"request"`
Response string `json:"response"`
}
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:]
}
}
func (items *Captures) GetRefs(itemBaseUrl string) []CaptureRef {
refs := make([]CaptureRef, len(*items))
for i, item := range *items {
refs[i] = CaptureRef{
ID: i,
Path: item.Path,
Method: item.Method,
Status: item.Status,
ItemUrl: itemBaseUrl + strconv.Itoa(i),
}
}
return refs
}