wiring up the go-swagger client

This commit is contained in:
Michael Quigley 2022-07-22 12:24:45 -04:00
parent a0664a4562
commit ab8ddd66f6
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 40 additions and 2 deletions

38
cmd/zrok/api.go Normal file
View File

@ -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 <endpoint>",
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)
},
}

View File

@ -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