more scaffolding

This commit is contained in:
Michael Quigley 2022-07-19 16:15:54 -04:00
parent e6edeebf44
commit 50d37132a1
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 33 additions and 0 deletions

View File

@ -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 <configPath>",
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)

5
proxy/config.go Normal file
View File

@ -0,0 +1,5 @@
package proxy
type Config struct {
Address string
}

16
proxy/proxy.go Normal file
View File

@ -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")
}