proxy -> http listen (#32)

This commit is contained in:
Michael Quigley 2022-08-18 17:48:49 -04:00
parent bb55008451
commit 6fa4fc2973
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 40 additions and 27 deletions

40
cmd/zrok/httplisten.go Normal file
View File

@ -0,0 +1,40 @@
package main
import (
"github.com/openziti-test-kitchen/zrok/endpoints/listen"
"github.com/spf13/cobra"
)
func init() {
httpCmd.AddCommand(newHttpListenCommand().cmd)
}
type httpListenCommand struct {
endpoint string
cmd *cobra.Command
}
func newHttpListenCommand() *httpListenCommand {
cmd := &cobra.Command{
Use: "listen <zitiIdentity>",
Short: "Create an HTTP listener",
Args: cobra.ExactArgs(1),
}
command := &httpListenCommand{cmd: cmd}
cmd.Flags().StringVarP(&command.endpoint, "endpoint", "e", "0.0.0.0:10111", "Address for HTTP listening endpoint")
cmd.Run = command.run
return command
}
func (self *httpListenCommand) run(_ *cobra.Command, args []string) {
httpListener, err := listen.NewHTTP(&listen.Config{
IdentityPath: args[0],
Address: self.endpoint,
})
if err != nil {
panic(err)
}
if err := httpListener.Run(); err != nil {
panic(err)
}
}

View File

@ -1,27 +0,0 @@
package main
import (
"github.com/openziti-test-kitchen/zrok/endpoints/listen"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(proxyCmd)
}
var proxyCmd = &cobra.Command{
Use: "proxy <configPath>",
Short: "Start a zrok proxy",
Run: func(_ *cobra.Command, args []string) {
httpListener, err := listen.NewHTTP(&listen.Config{
IdentityPath: args[0],
Address: "0.0.0.0:10111",
})
if err != nil {
panic(err)
}
if err := httpListener.Run(); err != nil {
panic(err)
}
},
}