mirror of
https://github.com/openziti/zrok.git
synced 2025-06-23 03:01:54 +02:00
'zrok http -s' for 'service mode' (no tui chrome)
This commit is contained in:
parent
e32bca31b2
commit
2983d16a06
115
cmd/zrok/http.go
115
cmd/zrok/http.go
@ -28,6 +28,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type httpCommand struct {
|
type httpCommand struct {
|
||||||
|
service bool
|
||||||
basicAuth []string
|
basicAuth []string
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
}
|
}
|
||||||
@ -39,17 +40,20 @@ func newHttpCommand() *httpCommand {
|
|||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
}
|
}
|
||||||
command := &httpCommand{cmd: cmd}
|
command := &httpCommand{cmd: cmd}
|
||||||
|
cmd.Flags().BoolVarP(&command.service, "service", "s", false, "Disable TUI 'chrome' for service operation")
|
||||||
cmd.Flags().StringArrayVar(&command.basicAuth, "basic-auth", []string{}, "Basic authentication users (<username:password>,...")
|
cmd.Flags().StringArrayVar(&command.basicAuth, "basic-auth", []string{}, "Basic authentication users (<username:password>,...")
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *httpCommand) run(_ *cobra.Command, args []string) {
|
func (self *httpCommand) run(_ *cobra.Command, args []string) {
|
||||||
if err := ui.Init(); err != nil {
|
if !self.service {
|
||||||
panic(err)
|
if err := ui.Init(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer ui.Close()
|
||||||
|
tb.SetInputMode(tb.InputEsc)
|
||||||
}
|
}
|
||||||
defer ui.Close()
|
|
||||||
tb.SetInputMode(tb.InputEsc)
|
|
||||||
|
|
||||||
idCfg, err := zrokdir.IdentityConfigFile()
|
idCfg, err := zrokdir.IdentityConfigFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -113,63 +117,70 @@ func (self *httpCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ui.Clear()
|
if !self.service {
|
||||||
w, h := ui.TerminalDimensions()
|
ui.Clear()
|
||||||
|
w, h := ui.TerminalDimensions()
|
||||||
|
|
||||||
p := widgets.NewParagraph()
|
p := widgets.NewParagraph()
|
||||||
p.Border = true
|
p.Border = true
|
||||||
p.Title = " access your zrok service "
|
p.Title = " access your zrok service "
|
||||||
p.Text = fmt.Sprintf("%v%v", strings.Repeat(" ", (((w-12)-len(resp.Payload.ProxyEndpoint))/2)-1), resp.Payload.ProxyEndpoint)
|
p.Text = fmt.Sprintf("%v%v", strings.Repeat(" ", (((w-12)-len(resp.Payload.ProxyEndpoint))/2)-1), resp.Payload.ProxyEndpoint)
|
||||||
p.TextStyle = ui.Style{Fg: ui.ColorWhite}
|
p.TextStyle = ui.Style{Fg: ui.ColorWhite}
|
||||||
p.PaddingTop = 1
|
p.PaddingTop = 1
|
||||||
p.SetRect(5, 5, w-10, 10)
|
p.SetRect(5, 5, w-10, 10)
|
||||||
|
|
||||||
lastRequests := float64(0)
|
lastRequests := float64(0)
|
||||||
var requestData []float64
|
var requestData []float64
|
||||||
spk := widgets.NewSparkline()
|
spk := widgets.NewSparkline()
|
||||||
spk.Title = " requests "
|
spk.Title = " requests "
|
||||||
spk.Data = requestData
|
spk.Data = requestData
|
||||||
spk.LineColor = ui.ColorCyan
|
spk.LineColor = ui.ColorCyan
|
||||||
|
|
||||||
slg := widgets.NewSparklineGroup(spk)
|
slg := widgets.NewSparklineGroup(spk)
|
||||||
slg.SetRect(5, 11, w-10, h-5)
|
slg.SetRect(5, 11, w-10, h-5)
|
||||||
|
|
||||||
ui.Render(p, slg)
|
ui.Render(p, slg)
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Second).C
|
ticker := time.NewTicker(time.Second).C
|
||||||
uiEvents := ui.PollEvents()
|
uiEvents := ui.PollEvents()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case e := <-uiEvents:
|
case e := <-uiEvents:
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
case ui.ResizeEvent:
|
case ui.ResizeEvent:
|
||||||
ui.Clear()
|
ui.Clear()
|
||||||
w, h = ui.TerminalDimensions()
|
w, h = ui.TerminalDimensions()
|
||||||
p.SetRect(5, 5, w-10, 10)
|
p.SetRect(5, 5, w-10, 10)
|
||||||
slg.SetRect(5, 11, w-10, h-5)
|
slg.SetRect(5, 11, w-10, h-5)
|
||||||
ui.Render(p, slg)
|
ui.Render(p, slg)
|
||||||
|
|
||||||
case ui.KeyboardEvent:
|
case ui.KeyboardEvent:
|
||||||
switch e.ID {
|
switch e.ID {
|
||||||
case "q", "<C-c>":
|
case "q", "<C-c>":
|
||||||
ui.Close()
|
ui.Close()
|
||||||
cleanupHttp(id, cfg, zrok, auth)
|
cleanupHttp(id, cfg, zrok, auth)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
case <-ticker:
|
case <-ticker:
|
||||||
currentRequests := float64(httpProxy.Requests())
|
currentRequests := float64(httpProxy.Requests())
|
||||||
deltaRequests := currentRequests - lastRequests
|
deltaRequests := currentRequests - lastRequests
|
||||||
requestData = append(requestData, deltaRequests)
|
requestData = append(requestData, deltaRequests)
|
||||||
lastRequests = currentRequests
|
lastRequests = currentRequests
|
||||||
requestData = append(requestData, deltaRequests)
|
requestData = append(requestData, deltaRequests)
|
||||||
for len(requestData) > w-17 {
|
for len(requestData) > w-17 {
|
||||||
requestData = requestData[1:]
|
requestData = requestData[1:]
|
||||||
|
}
|
||||||
|
spk.Title = fmt.Sprintf(" requests (%d) ", int(currentRequests))
|
||||||
|
spk.Data = requestData
|
||||||
|
ui.Render(p, slg)
|
||||||
}
|
}
|
||||||
spk.Title = fmt.Sprintf(" requests (%d) ", int(currentRequests))
|
}
|
||||||
spk.Data = requestData
|
} else {
|
||||||
ui.Render(p, slg)
|
for {
|
||||||
|
logrus.Infof("access your zrok service: %v", resp.Payload.ProxyEndpoint)
|
||||||
|
time.Sleep(30 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user