19 Star 123 Fork 0

kelvins-io/kelvins

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ghz.go 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
雨化田 提交于 2021-08-14 07:44 . auth interface&ghz test tool
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))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kelvins-io/kelvins.git
git@gitee.com:kelvins-io/kelvins.git
kelvins-io
kelvins
kelvins
v1.5.9

搜索帮助