API Reference
Package: github.com/cyberspacesec/request-mock-skills/pkg/mock
Generate Functions
go
func GenerateOne(spec *RequestSpec) (*har.Har, error)
func Generate(specs []*RequestSpec) (*har.Har, error)
func MustGenerate(specs []*RequestSpec) *har.Har
func GenerateAndExport(spec *RequestSpec, format string) (*Result, error)
func GenerateOneAndExport(spec *RequestSpec, format string) (*Result, error)
func GenerateNAndExport(spec *RequestSpec, n int, format string, opts ...GenerateOption) (*Result, error)
func GenerateNAndExportToFile(spec *RequestSpec, n int, format string, output string, opts ...GenerateOption) errorGenerator
go
func NewGenerator(seed int64) *Generator
func (g *Generator) Seed() int64
func (g *Generator) GenerateSpecs(base *RequestSpec, n int, transforms ...Transform) []*RequestSpec
func (g *Generator) GenerateSpecsBatch(counts []int, transforms ...Transform) []*RequestSpecTemplates
go
func GetTemplate(name string) *RequestSpec
func ListTemplates() []stringBuilt-in Templates (20)
Basic (6): getjson, postjson, postform, login, upload, bearer
HTTP Method (5): delete, put, patch, head, options
Recon (4): banner, redirect, error, portscan
Extended (5): graphql, sse, websocket, grpcweb, chunked
Transforms
go
type Transform func(spec *RequestSpec, index int, r *rand.Rand)
var DefaultTransforms []Transform
func LookupTransform(name string) Transform
func NamedTransforms() map[string]TransformBuilt-in Transforms (16)
| Function | Name string | Description |
|---|---|---|
RandomServerIP | server_ip | Random IPv4 address |
RandomUserAgent | user_agent | Random UA from pool |
RandomPath | path | Random suffix segment |
RandomQueryNoise | query_noise | Add random noise params |
RandomStatus | status | Random HTTP status |
RandomTimings | timings | Random timing values |
IndexSuffix | index | Append /_idx=<i> query param |
RandomPort | port | Replace port with random from pool |
RandomHost | host | Random subdomain prefix |
RandomResponseCookie | resp_cookie | Random response cookie |
RandomHeader | header | Random request header |
RandomBodyNoise | body_noise | Inject noise into JSON body |
SequentialStatus | seq_status | Sequential status codes |
RandomPriority | priority | Random Chrome priority |
RandomResourceType | resource_type | Random Chrome resource type |
RandomConnection | connection | Random connection ID |
Export
go
func Export(h *har.Har, format string) (string, error)
func ExportToFile(h *har.Har, format string, output string) error
func ExportBytes(h *har.Har, format string, opts ...ExportOption) ([]byte, error)
func ExportWithOpts(h *har.Har, format string, opts ...ExportOption) (string, error)
func MustExport(h *har.Har, format string) string
func ExportString(h *har.Har, format string) (string, error)
type ExportOption func(*exportOptions)
func WithExportIndent(indent int) ExportOptionFormat Constants
go
const FormatCurl = "curl"
const FormatWget = "wget"
const FormatPython = "python"
const FormatPostman = "postman"
const FormatXML = "xml"
const FormatYAML = "yaml"
const FormatHAR = "har"
const FormatJSON = "json"
const FormatJSONLines = "jsonl"
const FormatCSV = "csv"
const FormatMarkdown = "markdown"
const FormatHTML = "html"
const FormatText = "text"Channel Streaming
go
func GenerateStream(ctx context.Context, specs []*RequestSpec, opts ...StreamOptions) (<-chan StreamItem, error)
func GenerateStreamFromSpecs(ctx context.Context, specs []*RequestSpec, opts ...StreamOptions) <-chan StreamItem
func CollectStream(ctx context.Context, stream <-chan StreamItem) ([]*StreamItem, error)
type StreamItem struct {
Index int
Data string
Error error
Done bool
}
type StreamOptions struct {
Format string
Indent int
Mode DeliveryMode
}
type DeliveryMode int
const DeliveryEntry DeliveryMode = iota
const DeliveryExport DeliveryMode = iotaEngine
go
func NewEngine(cfg *Config) *Engine
func (e *Engine) Run() (*har.Har, error)
func (e *Engine) RunExport() (*Result, error)
func (e *Engine) RunStream(ctx context.Context) (<-chan StreamItem, error)Request Chain
go
func NewChain(g *Generator) *Chain
func (c *Chain) AddStep(name string, spec *RequestSpec) *Chain
func (c *Chain) Execute() (*har.Har, error)Config
go
func LoadConfig(path string) (*Config, error)
func ParseConfig(data []byte) (*Config, error)
func (c *Config) Run() (*har.Har, error)
type Config struct {
Seed int64 `yaml:"seed,omitempty"`
Count int `yaml:"count,omitempty"`
Specs []*RequestSpec `yaml:"specs,omitempty"`
Templates []TemplateRef `yaml:"templates,omitempty"`
Transforms []string `yaml:"transforms,omitempty"`
Export *ExportConfig `yaml:"export,omitempty"`
}Split
go
func Split(h *har.Har, mode SplitMode, opts ...SplitOption) (map[string]*har.Har, error)
type SplitMode string
const SplitByPage SplitMode = "page"
const SplitByDomain SplitMode = "domain"
const SplitByStatus SplitMode = "status"
const SplitByMethod SplitMode = "method"
const SplitBySize SplitMode = "size"
const SplitByTime SplitMode = "time"
type SplitOption func(*splitOptions)
func WithSplitSize(size int) SplitOption
func WithSplitInterval(interval string) SplitOptionResult
go
type Result struct {
OK bool `json:"ok"`
Count int `json:"count,omitempty"`
Seed int64 `json:"seed,omitempty"`
Format string `json:"format,omitempty"`
Data interface{} `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}
func NewOKResult(data interface{}) *Result
func NewErrorResult(err error) *Result
func (r *Result) MarshalJSONString() (string, error)GenerateOption
go
type GenerateOption func(*generateOptions)
func WithCreator(name, version string) GenerateOption
func WithBrowser(name, version string) GenerateOption
func WithHTTPVersion(version string) GenerateOption
func WithIndent(indent int) GenerateOption
func WithPages(pages []PageSpec) GenerateOption