mirror of
https://github.com/openziti/zrok.git
synced 2025-01-21 21:38:50 +01:00
wiring up the go-swagger client
This commit is contained in:
parent
a0664a4562
commit
ab8ddd66f6
38
cmd/zrok/api.go
Normal file
38
cmd/zrok/api.go
Normal 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)
|
||||
},
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user