From 05474abb07f73aace79bcf339be8e5619dd4564b Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 21 Mar 2021 04:30:07 +0700 Subject: all: implement API and interface for attack functionality When the user click "Attack" it will call the API to run the load testing. If there is load testing currently, it will return with an error. On success, the result of load testing will be stored on directory defined in Environment.ResultsDir with file named ..xs..bin This file contains the vegeta.Results. --- errors.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'errors.go') diff --git a/errors.go b/errors.go index 989561a..faf009c 100644 --- a/errors.go +++ b/errors.go @@ -12,6 +12,29 @@ import ( libhttp "github.com/shuLhan/share/lib/http" ) +func errAttackConflict(ltr *loadTestingResult) error { + res := &libhttp.EndpointResponse{ + E: liberrors.E{ + Code: http.StatusConflict, + Message: "another attack is already running", + Name: "ERR_ATTACK_CONFLICT", + }, + Data: ltr, + } + return res +} + +func errAttackNotAllowed() error { + res := &libhttp.EndpointResponse{ + E: liberrors.E{ + Code: http.StatusNotAcceptable, + Message: "attack is not allowed", + Name: "ERR_ATTACK_NOT_ALLOWED", + }, + } + return res +} + func errInternal(err error) error { res := &libhttp.EndpointResponse{ E: liberrors.E{ -- cgit v1.3-5-g9baa