cmd scaffolding for controller; lint removal

This commit is contained in:
Michael Quigley 2022-07-21 16:43:42 -04:00
parent 5598f40426
commit 6b4fcb8dc1
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 33 additions and 51 deletions

View File

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

View File

@ -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 <configPath>",
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 <identity>",
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 <configPath>",
Short: "Start a zrok proxy",
@ -39,16 +62,6 @@ var proxyCmd = &cobra.Command{
},
}
var httpCmd = &cobra.Command{
Use: "http <identity>",
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)

5
controller/config.go Normal file
View File

@ -0,0 +1,5 @@
package controller
type Config struct {
ApiEndpoint string
}

5
controller/controller.go Normal file
View File

@ -0,0 +1,5 @@
package controller
func Run(cfg *Config) error {
return nil
}