代码拉取完成,页面将自动刷新
package test_tool
import (
"fmt"
"gitee.com/kelvins-io/kelvins/util/middleware"
"github.com/bojand/ghz/printer"
"github.com/bojand/ghz/runner"
"google.golang.org/grpc"
"io"
"os"
)
type ReportFormat string
const (
ReportHTML ReportFormat = "html"
ReportCSV ReportFormat = "csv"
ReportSummary ReportFormat = "summary"
ReportJSON ReportFormat = "json"
ReportPretty ReportFormat = "pretty"
ReportInfluxSummary ReportFormat = "influx-summary"
ReportInfluxDetails ReportFormat = "influx-details"
)
type GhzTestOption struct {
Call string
Host string
Token string
ReportFormat ReportFormat
Out io.Writer
Options []runner.Option
}
func ExecuteRPCGhzTest(opt *GhzTestOption) error {
if opt == nil {
return fmt.Errorf("ghz test opt nil")
}
if opt.ReportFormat == "" {
opt.ReportFormat = ReportHTML
}
if opt.Out == nil {
opt.Out = os.Stdout
}
var optsCall []grpc.CallOption
var optsGhz []runner.Option
if opt.Token != "" {
optsCall = append(optsCall, grpc.PerRPCCredentials(middleware.RPCPerCredentials(opt.Token)))
}
optsGhz = append(optsGhz, runner.WithDefaultCallOptions(optsCall))
optsGhz = append(optsGhz, opt.Options...)
report, err := runner.Run(
opt.Call,
opt.Host,
optsGhz...,
)
if err != nil {
return err
}
reportPrinter := printer.ReportPrinter{
Out: opt.Out,
Report: report,
}
return reportPrinter.Print(string(opt.ReportFormat))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。