mirror of
https://github.com/openziti/zrok.git
synced 2025-03-31 01:26:12 +02:00
more shared scaffolding between 'zrok' and 'zrokloop' (#40)
This commit is contained in:
parent
175f8e8167
commit
779eb8fb24
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
@ -13,11 +14,7 @@ func init() {
|
||||
pfxlog.GlobalInit(logrus.InfoLevel, pfxlog.DefaultOptions().SetTrimPrefix("github.com/openziti-test-kitchen/"))
|
||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
|
||||
rootCmd.PersistentFlags().BoolVarP(&panicInstead, "panic", "p", false, "Panic instead of showing pretty errors")
|
||||
apiEndpointDefault := os.Getenv("ZROK_API_ENDPOINT")
|
||||
if apiEndpointDefault == "" {
|
||||
apiEndpointDefault = "https://api.zrok.io"
|
||||
}
|
||||
rootCmd.PersistentFlags().StringVarP(&apiEndpoint, "endpoint", "e", apiEndpointDefault, "zrok API endpoint address")
|
||||
zrokdir.AddZrokApiEndpointFlag(&apiEndpoint, rootCmd.PersistentFlags())
|
||||
rootCmd.AddCommand(httpCmd)
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/pfxlog"
|
||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
@ -8,6 +10,12 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func init() {
|
||||
pfxlog.GlobalInit(logrus.InfoLevel, pfxlog.DefaultOptions().SetTrimPrefix("github.com/openziti-test-kitchen/"))
|
||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
|
||||
zrokdir.AddZrokApiEndpointFlag(&apiEndpoint, rootCmd.PersistentFlags())
|
||||
}
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: strings.TrimSuffix(filepath.Base(os.Args[0]), filepath.Ext(os.Args[0])),
|
||||
Short: "zrok loopback harness",
|
||||
|
@ -6,9 +6,19 @@ import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/openziti-test-kitchen/zrok/rest_client_zrok"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/pflag"
|
||||
"net/url"
|
||||
"os"
|
||||
)
|
||||
|
||||
func AddZrokApiEndpointFlag(v *string, flags *pflag.FlagSet) {
|
||||
defaultEndpoint := os.Getenv("ZROK_API_ENDPOINT")
|
||||
if defaultEndpoint == "" {
|
||||
defaultEndpoint = "https://api.zrok.io"
|
||||
}
|
||||
flags.StringVarP(v, "endpoint", "e", defaultEndpoint, "zrok API endpoint address")
|
||||
}
|
||||
|
||||
func ZrokClient(endpoint string) (*rest_client_zrok.Zrok, error) {
|
||||
apiUrl, err := url.Parse(endpoint)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user