- This is the gateway sdk generated from the open Api specs.
- Report any issue you may encounter while using this Sdk.
Since the SDK is still experimental, we adopt a versioning scheme that reflects both its developmental status and the specific Gateway version used to generate it. For example, a tag like v0.0.1-gateway.5.7.2
indicates that:
- v0.0.1 – The SDK is in an early, experimental stage and may undergo breaking changes.
- -gateway.5.7.2 – The SDK was generated from Gateway version 5.7.2.
This versioning strategy ensures clear traceability, allowing users to easily identify which Gateway version the SDK is compatible with.
go get github.com/TykTechnologies/[email protected]
In these samples Tyk Gateway is running on localhost port 8080.
The BaseUrl is: http://localhost:8080
.
package main
import (
"context"
"fmt"
"io"
"log"
"net/http"
"github.com/TykTechnologies/gateway-sdk/pkg/apim"
)
var (
BaseUrl = "http://tyk-gateway.localhost:8080"
xTykAuthorization = "x-tyk-authorization"
)
func main() {
apiConfig := apim.Configuration{
DefaultHeader: map[string]string{
xTykAuthorization: "<YOUR GATEWAY AUTHORIZATION KEY HERE>",
},
Debug: false,
Servers: apim.ServerConfigurations{
{
URL: BaseUrl,
},
},
HTTPClient: nil,
}
client := apim.NewAPIClient(&apiConfig)
ctx := context.Background()
apis, resp, err := client.APIsAPI.ListApis(ctx).Execute()
if err != nil || resp.StatusCode != 200 {
body, err := ReadResponseBody(resp)
if err != nil {
log.Println(resp.Status)
return
}
log.Println(body)
return
}
for _, item := range apis {
fmt.Printf("%+v\n", item.GetApiId())
}
}
func ReadResponseBody(resp *http.Response) (string, error) {
defer resp.Body.Close()
// Read the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("failed to read response body: %w", err)
}
// Convert the body to a string and return
return string(body), nil
}
For documentation please look here.