mirror of
https://github.com/openziti/zrok.git
synced 2025-04-01 18:16:13 +02:00
cmd scaffolding for controller; lint removal
This commit is contained in:
parent
5598f40426
commit
6b4fcb8dc1
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/michaelquigley/pfxlog"
|
"github.com/michaelquigley/pfxlog"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/controller"
|
||||||
"github.com/openziti-test-kitchen/zrok/http"
|
"github.com/openziti-test-kitchen/zrok/http"
|
||||||
"github.com/openziti-test-kitchen/zrok/proxy"
|
"github.com/openziti-test-kitchen/zrok/proxy"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -14,6 +15,7 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
pfxlog.GlobalInit(logrus.InfoLevel, pfxlog.DefaultOptions().SetTrimPrefix("github.com/openziti-test-kitchen/"))
|
pfxlog.GlobalInit(logrus.InfoLevel, pfxlog.DefaultOptions().SetTrimPrefix("github.com/openziti-test-kitchen/"))
|
||||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging")
|
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging")
|
||||||
|
rootCmd.AddCommand(controllerCmd)
|
||||||
rootCmd.AddCommand(httpCmd)
|
rootCmd.AddCommand(httpCmd)
|
||||||
rootCmd.AddCommand(proxyCmd)
|
rootCmd.AddCommand(proxyCmd)
|
||||||
}
|
}
|
||||||
@ -29,6 +31,27 @@ var rootCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
var verbose bool
|
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{
|
var proxyCmd = &cobra.Command{
|
||||||
Use: "proxy <configPath>",
|
Use: "proxy <configPath>",
|
||||||
Short: "Start a zrok proxy",
|
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() {
|
func main() {
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
5
controller/config.go
Normal file
5
controller/config.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
ApiEndpoint string
|
||||||
|
}
|
5
controller/controller.go
Normal file
5
controller/controller.go
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
func Run(cfg *Config) error {
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user