From 6b4fcb8dc1bd561e026f9cb407caeb395b13ec03 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Thu, 21 Jul 2022 16:43:42 -0400 Subject: [PATCH] cmd scaffolding for controller; lint removal --- cmd/zrok/curl.go | 41 ---------------------------------------- cmd/zrok/main.go | 33 ++++++++++++++++++++++---------- controller/config.go | 5 +++++ controller/controller.go | 5 +++++ 4 files changed, 33 insertions(+), 51 deletions(-) delete mode 100644 cmd/zrok/curl.go create mode 100644 controller/config.go create mode 100644 controller/controller.go diff --git a/cmd/zrok/curl.go b/cmd/zrok/curl.go deleted file mode 100644 index fca53eb1..00000000 --- a/cmd/zrok/curl.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "github.com/openziti-test-kitchen/zrok/util" - "github.com/openziti/sdk-golang/ziti" - "github.com/openziti/sdk-golang/ziti/config" - "github.com/spf13/cobra" - "io" - "net/http" - "os" -) - -func init() { - rootCmd.AddCommand(curlCmd) -} - -var curlCmd = &cobra.Command{ - Use: "curl ", - Short: "curl a zrok service", - Run: curl, -} - -func curl(_ *cobra.Command, args []string) { - zCfg, err := config.NewFromFile(args[0]) - if err != nil { - panic(err) - } - zCtx := ziti.NewContextWithConfig(zCfg) - zDialContext := util.ZitiDialContext{Context: zCtx} - zTransport := http.DefaultTransport.(*http.Transport).Clone() - zTransport.DialContext = zDialContext.Dial - client := &http.Client{Transport: zTransport} - resp, err := client.Get("http://zrok/") - if err != nil { - panic(err) - } - _, err = io.Copy(os.Stdout, resp.Body) - if err != nil { - panic(err) - } -} diff --git a/cmd/zrok/main.go b/cmd/zrok/main.go index ef7b5e69..81fd175a 100644 --- a/cmd/zrok/main.go +++ b/cmd/zrok/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/michaelquigley/pfxlog" + "github.com/openziti-test-kitchen/zrok/controller" "github.com/openziti-test-kitchen/zrok/http" "github.com/openziti-test-kitchen/zrok/proxy" "github.com/sirupsen/logrus" @@ -14,6 +15,7 @@ import ( 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.AddCommand(controllerCmd) rootCmd.AddCommand(httpCmd) rootCmd.AddCommand(proxyCmd) } @@ -29,6 +31,27 @@ var rootCmd = &cobra.Command{ } var verbose bool +var controllerCmd = &cobra.Command{ + Use: "controller ", + Short: "Start a zrok controller", + Aliases: []string{"ctrl"}, + Run: func(_ *cobra.Command, args []string) { + if err := controller.Run(&controller.Config{ApiEndpoint: "0.0.0.0:18888"}); err != nil { + panic(err) + } + }, +} + +var httpCmd = &cobra.Command{ + Use: "http ", + Short: "Start an http terminator", + Run: func(_ *cobra.Command, args []string) { + if err := http.Run(&http.Config{IdentityPath: args[0]}); err != nil { + panic(err) + } + }, +} + var proxyCmd = &cobra.Command{ Use: "proxy ", Short: "Start a zrok proxy", @@ -39,16 +62,6 @@ var proxyCmd = &cobra.Command{ }, } -var httpCmd = &cobra.Command{ - Use: "http ", - Short: "Start an http endpoint", - Run: func(_ *cobra.Command, args []string) { - if err := http.Run(&http.Config{IdentityPath: args[0]}); err != nil { - panic(err) - } - }, -} - func main() { if err := rootCmd.Execute(); err != nil { panic(err) diff --git a/controller/config.go b/controller/config.go new file mode 100644 index 00000000..6f609532 --- /dev/null +++ b/controller/config.go @@ -0,0 +1,5 @@ +package controller + +type Config struct { + ApiEndpoint string +} diff --git a/controller/controller.go b/controller/controller.go new file mode 100644 index 00000000..b32c1b10 --- /dev/null +++ b/controller/controller.go @@ -0,0 +1,5 @@ +package controller + +func Run(cfg *Config) error { + return nil +}