Skip to main content

How to use the Keploy Go SDK

Get the SDK

Add the Keploy Go SDK to your project:

go get -u github.com/keploy/go-sdk

Or clone the Go SDK repo to your preferred location:

git clone git@github.com:keploy/go-sdk.git

SDK Modes

The Keploy SDKs modes can operated by setting KEPLOY_MODE environment variable. There are 3 Keploy SDK modes:

  1. Off : In the off mode the Keploy SDK will turn off all the functionality provided by the Keploy platform.
export KEPLOY_MODE="off"
  1. Record mode :
    • Record requests, response and all external calls and sends to Keploy server.
    • After keploy server removes duplicates, it then runs the request on the API again to identify noisy fields.
    • Sends the noisy fields to the keploy server to be saved along with the testcase.
export KEPLOY_MODE="record"
  1. Test mode :
    • Fetches testcases for the app from keploy server.
    • Calls the API with same request payload in testcase.
    • Mocks external calls based on data stored in the testcase.
    • Validates the responses and uploads results to the keploy server
export KEPLOY_MODE="test"

Where is the Go SDK technical reference?

The Keploy Go SDK API reference is published on pkg.go.dev

Usage

import(
"github.com/keploy/go-sdk/keploy"
"github.com/keploy/go-sdk/integrations/<package_name>"
)

Create your app instance

k := keploy.New(keploy.Config{
App: keploy.AppConfig{
Name: "<app_name>",
Port: "<app_port>",
},
Server: keploy.ServerConfig{
URL: "<keploy_host>",
LicenseKey: "<license_key>", //optional for managed services
},
})

For example:

port := "8080"
k := keploy.New(keploy.Config{
App: keploy.AppConfig{
Name: "my-app",
Port: port,
},
Server: keploy.ServerConfig{
URL: "http://localhost:8081/api",
},
})

Now wrap the routers, https clients and external dependencies like DBs. See the list of supported frameworks.