From d671ec4c78f0fbc74093b8014c09934d32c9b54d Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 30 Aug 2022 09:07:21 -0400 Subject: [PATCH] zrok test endpoint; first skeleton --- cmd/zrok/endpoint_ui/embed.go | 6 + cmd/zrok/endpoint_ui/index.html | 53 +++++++ cmd/zrok/endpoint_ui/ziggy.svg | 259 ++++++++++++++++++++++++++++++++ cmd/zrok/test.go | 44 ++++++ 4 files changed, 362 insertions(+) create mode 100644 cmd/zrok/endpoint_ui/embed.go create mode 100644 cmd/zrok/endpoint_ui/index.html create mode 100755 cmd/zrok/endpoint_ui/ziggy.svg create mode 100644 cmd/zrok/test.go diff --git a/cmd/zrok/endpoint_ui/embed.go b/cmd/zrok/endpoint_ui/embed.go new file mode 100644 index 00000000..10b848f0 --- /dev/null +++ b/cmd/zrok/endpoint_ui/embed.go @@ -0,0 +1,6 @@ +package endpoint_ui + +import "embed" + +//go:embed index.html ziggy.svg +var FS embed.FS diff --git a/cmd/zrok/endpoint_ui/index.html b/cmd/zrok/endpoint_ui/index.html new file mode 100644 index 00000000..c86c0ce1 --- /dev/null +++ b/cmd/zrok/endpoint_ui/index.html @@ -0,0 +1,53 @@ + + + + + + + + + + + zrok + + + +
+ +
+

This is an HTTP server running at address:

+
+
+ + diff --git a/cmd/zrok/endpoint_ui/ziggy.svg b/cmd/zrok/endpoint_ui/ziggy.svg new file mode 100755 index 00000000..73647067 --- /dev/null +++ b/cmd/zrok/endpoint_ui/ziggy.svg @@ -0,0 +1,259 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cmd/zrok/test.go b/cmd/zrok/test.go new file mode 100644 index 00000000..75e6e3bf --- /dev/null +++ b/cmd/zrok/test.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "github.com/openziti-test-kitchen/zrok/cmd/zrok/endpoint_ui" + "github.com/spf13/cobra" + "net/http" +) + +func init() { + testCmd.AddCommand(newTestEndpointCommand().cmd) + rootCmd.AddCommand(testCmd) +} + +var testCmd = &cobra.Command{ + Use: "test", + Short: "Utilities used for testing zrok", +} + +type testEndpointCommand struct { + address string + port uint16 + cmd *cobra.Command +} + +func newTestEndpointCommand() *testEndpointCommand { + cmd := &cobra.Command{ + Use: "endpoint", + Short: "Start a simple HTTP endpoint", + Args: cobra.ExactArgs(0), + } + command := &testEndpointCommand{cmd: cmd} + cmd.Flags().StringVarP(&command.address, "address", "a", "0.0.0.0", "The address for the HTTP listener") + cmd.Flags().Uint16VarP(&command.port, "port", "p", 9090, "The port for the HTTP listener") + cmd.Run = command.run + return command +} + +func (cmd *testEndpointCommand) run(_ *cobra.Command, _ []string) { + fs := http.FileServer(http.FS(endpoint_ui.FS)) + if err := http.ListenAndServe(fmt.Sprintf("%v:%d", cmd.address, cmd.port), fs); err != nil { + panic(err) + } +}