From d30bfb7fa1c32984eaba8ad1cf744328812e02b9 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Fri, 12 Mar 2021 02:11:11 +0700 Subject: trunks: a module for testing HTTP services Trunks is a library and HTTP service that provide web user interface to test HTTP service, similar to Postman, and for load testing. For the load testing we use vegeta [1] as the backend. [1] https://github.com/tsenart/vegeta --- errors.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 errors.go (limited to 'errors.go') diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..989561a --- /dev/null +++ b/errors.go @@ -0,0 +1,46 @@ +// Copyright 2021, Shulhan . All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package trunks + +import ( + "fmt" + "net/http" + + liberrors "github.com/shuLhan/share/lib/errors" + libhttp "github.com/shuLhan/share/lib/http" +) + +func errInternal(err error) error { + res := &libhttp.EndpointResponse{ + E: liberrors.E{ + Code: http.StatusInternalServerError, + Message: err.Error(), + Name: "ERR_INTERNAL", + }, + } + return res +} + +func errInvalidTarget(id string) error { + res := &libhttp.EndpointResponse{ + E: liberrors.E{ + Code: http.StatusBadRequest, + Message: fmt.Sprintf("invalid or emtpy Target.ID: %q", id), + Name: "ERR_INVALID_TARGET", + }, + } + return res +} + +func errInvalidHttpTarget(id string) error { + res := &libhttp.EndpointResponse{ + E: liberrors.E{ + Code: http.StatusBadRequest, + Message: fmt.Sprintf("invalid or emtpy HttpTarget.ID: %q", id), + Name: "ERR_INVALID_HTTP_TARGET", + }, + } + return res +} -- cgit v1.3