engine

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2023 License: MIT

README

benchttp/engine

Github Worklow Status Code coverage Go Report Card
Go package Reference Latest version

About

Benchttp engine is a Go library providing a way to perform benchmarks and tests on HTTP endpoints.

Installation

Prerequisites

Go1.17 environment or higher is required.

Install.

go get github.com/benchttp/engine

Usage

Basic usage

package main

import (
    "context"
    "fmt"

    "github.com/benchttp/engine/benchttp"
)

func main() {
    report, _ := benchttp.
        DefaultRunner(). // Default runner with safe configuration
        WithNewRequest("GET", "http://localhost:3000", nil). // Attach request
        Run(context.Background()) // Run benchmark, retrieve report

    fmt.Println(report.Metrics.ResponseTimes.Mean)
}

Usage with JSON config via configio

package main

import (
    "context"
    "fmt"

    "github.com/benchttp/engine/benchttp"
    "github.com/benchttp/engine/configio"
)

func main() {
    // JSON configuration obtained via e.g. a file or HTTP call
    jsonConfig := []byte(`
{
  "request": {
    "url": "http://localhost:3000"
  }
}`)

    // Instantiate a base Runner (here the default with a safe configuration)
    runner := benchttp.DefaultRunner()

    // Parse the json configuration into the Runner
    _ = configio.UnmarshalJSONRunner(jsonConfig, &runner)

    // Run benchmark, retrieve report
    report, _ := runner.Run(context.Background())

    fmt.Println(report.Metrics.ResponseTimes.Mean)
}

📄 Please refer to our Wiki for exhaustive Runner and Report structures (and more!)

Development

Prerequisites

  1. Go 1.17 or higher is required
  2. Golangci-lint for linting files

Main commands

Command Description
./script/lint Runs lint on the codebase
./script/test Runs tests suites from all packages
./script/doc Serves Go doc for this module at localhost:9995

Directories

Path Synopsis
Package benchttptest proovides utilities for benchttp testing.
Package benchttptest proovides utilities for benchttp testing.
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL