From ab8ddd66f699fa692b1d65dbd7f37e0153eb6bb8 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 22 Jul 2022 12:24:45 -0400 Subject: [PATCH] wiring up the go-swagger client --- cmd/zrok/api.go | 38 +++++++++++++++++++++++++++++++++ rest_zrok_client/zrok_client.go | 4 ++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 cmd/zrok/api.go diff --git a/cmd/zrok/api.go b/cmd/zrok/api.go new file mode 100644 index 00000000..95518d7c --- /dev/null +++ b/cmd/zrok/api.go @@ -0,0 +1,38 @@ +package main + +import ( + "github.com/go-openapi/runtime" + httptransport "github.com/go-openapi/runtime/client" + "github.com/go-openapi/strfmt" + "github.com/openziti-test-kitchen/zrok/rest_zrok_client" + "github.com/openziti-test-kitchen/zrok/rest_zrok_client/metadata" + "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "time" +) + +func init() { + apiCmd.AddCommand(apiVersionCmd) + rootCmd.AddCommand(apiCmd) +} + +var apiCmd = &cobra.Command{ + Use: "api", + Short: "Exercise API calls", +} + +var apiVersionCmd = &cobra.Command{ + Use: "version ", + Short: "Get API version", + Run: func(_ *cobra.Command, args []string) { + transport := httptransport.New(args[0], "", nil) + transport.Producers["application/zrok.v1+json"] = runtime.JSONProducer() + transport.Consumers["application/zrok.v1+json"] = runtime.JSONConsumer() + zrok := rest_zrok_client.New(transport, strfmt.Default) + resp, err := zrok.Metadata.Get(metadata.NewGetParamsWithTimeout(30 * time.Second)) + if err != nil { + panic(err) + } + logrus.Infof("found api version [%v]", resp.Payload.Version) + }, +} diff --git a/rest_zrok_client/zrok_client.go b/rest_zrok_client/zrok_client.go index 935b7493..e1aa3ebe 100644 --- a/rest_zrok_client/zrok_client.go +++ b/rest_zrok_client/zrok_client.go @@ -67,10 +67,10 @@ func DefaultTransportConfig() *TransportConfig { BasePath: DefaultBasePath, Schemes: DefaultSchemes, } -} - // TransportConfig contains the transport related info, // found in the meta section of the spec file. +} + type TransportConfig struct { Host string BasePath string