From 50d37132a1b8531883cfab4375236d98c5611e2f Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 19 Jul 2022 16:15:54 -0400 Subject: [PATCH] more scaffolding --- cmd/zrok/main.go | 12 ++++++++++++ proxy/config.go | 5 +++++ proxy/proxy.go | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 proxy/config.go create mode 100644 proxy/proxy.go diff --git a/cmd/zrok/main.go b/cmd/zrok/main.go index 16c18a65..86fa6556 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/proxy" "github.com/sirupsen/logrus" "github.com/spf13/cobra" "os" @@ -12,6 +13,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(proxyCmd) } var rootCmd = &cobra.Command{ @@ -25,6 +27,16 @@ var rootCmd = &cobra.Command{ } var verbose bool +var proxyCmd = &cobra.Command{ + Use: "proxy ", + Short: "Start a zrok proxy", + Run: func(_ *cobra.Command, args []string) { + if err := proxy.Run(&proxy.Config{Address: "0.0.0.0:10081"}); err != nil { + panic(err) + } + }, +} + func main() { if err := rootCmd.Execute(); err != nil { panic(err) diff --git a/proxy/config.go b/proxy/config.go new file mode 100644 index 00000000..96cce8ec --- /dev/null +++ b/proxy/config.go @@ -0,0 +1,5 @@ +package proxy + +type Config struct { + Address string +} diff --git a/proxy/proxy.go b/proxy/proxy.go new file mode 100644 index 00000000..a8c66ae8 --- /dev/null +++ b/proxy/proxy.go @@ -0,0 +1,16 @@ +package proxy + +import ( + "fmt" + "net/http" +) + +func Run(cfg *Config) error { + return http.ListenAndServe(cfg.Address, &handler{}) +} + +type handler struct{} + +func (self *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "zrok") +}