Integration for Go (v1.0.0)
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
Integrate
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
},
})
<details><summary> Example </summary>
port := "6789"
k := keploy.New(keploy.Config{
App: keploy.AppConfig{
Name: "my-app",
Port: port,
},
Server: keploy.ServerConfig{
URL: "http://localhost:6789/api",
},
})
</details>
Now wrap the routers, https clients and external dependencies like DBs.
Wrapping Dependencies
Supported Routers
Chi
Integration
r := chi.NewRouter()
r.Use(kchi.ChiMiddlewareV5(k))
Example
import(
"github.com/keploy/go-sdk/integrations/kchi"
"github.com/keploy/go-sdk/keploy"
"github.com/go-chi/chi"
)
func main(){
r := chi.NewRouter()
port := "8080"
k := keploy.New(keploy.Config{
App: keploy.AppConfig{
Name: "my_app",
Port: port,
},
Server: keploy.ServerConfig{
URL: "http://localhost:6789/api",
},
})
r.Use(kchi.ChiMiddlewareV5(k))
http.ListenAndServe(":" + port, r)
}
Gin
Integration
r:=gin.New()
kgin.GinV1(k, r)
Example
import(
"github.com/keploy/go-sdk/integrations/kgin/v1"
"github.com/keploy/go-sdk/keploy"
)
func main(){
r:=gin.New()
port := "8080"
k := keploy.New(keploy.Config{
App: keploy.AppConfig{
Name: "my_app",
Port: port,
},
Server: keploy.ServerConfig{
URL: "http://localhost:6789/api",
},
})
kgin.GinV1(k, r)
r.Run(":" + port)
}
Echo
Integration
import(
"github.com/keploy/go-sdk/integrations/kecho/v4"
"github.com/keploy/go-sdk/keploy"
"github.com/labstack/echo/v4"
)
func main(){
e := echo.New()
port := "8080"
k := keploy.New(keploy.Config{
App: keploy.AppConfig{
Name: "my-app",
Port: port,
},
Server: keploy.ServerConfig{
URL: "http://localhost:6789/api",
},
})
e.Use(kecho.EchoMiddlewareV4(k))
e.Start(":" + port)
}
WebGo
WebGo V4 Integration
router := webgo.NewRouter(cfg, getRoutes())
router.Use(kwebgo.WebgoMiddlewareV4(k))
router.Start()
WebGo V6 Integration
router := webgo.NewRouter(cfg, getRoutes())
router.Use(kwebgo.WebgoMiddlewareV6(k))
router.Start()
Example
import(
"github.com/keploy/go-sdk/integrations/kwebgo/v4"
"github.com/keploy/go-sdk/keploy"
"github.com/bnkamalesh/webgo/v4"
)
func main(){
port := "8080"
k := keploy.New(keploy.Config{
App: keploy.AppConfig{
Name: "my-app",
Port: port,
},
Server: keploy.ServerConfig{
URL: "http://localhost:6789/api",
},
})
router := webgo.NewRouter(&webgo.Config{
Host: "",
Port: port,
ReadTimeout: 15 * time.Second,
WriteTimeout: 60 * time.Second,
}, []*webgo.Route{})
router.Use(kwebgo.WebgoMiddlewareV4(k))
router.Start()
}
Gorilla/Mux
Integration
r := mux.NewRouter()
r.Use(kmux.MuxMiddleware(k))
Example
import(
"github.com/keploy/go-sdk/integrations/kmux"
"github.com/keploy/go-sdk/keploy"
"github.com/gorilla/mux"
"net/http"
)
func main(){
r := mux.NewRouter()
port := "8080"
k := keploy.New(keploy.Config{
App: keploy.AppConfig{
Name: "my-app",
Port: port,
},
Server: keploy.ServerConfig{
URL: "http://localhost:6789/api",
},
})
r.Use(kmux.MuxMiddleware(k))
http.ListenAndServe(":"+port, r)
}