summaryrefslogtreecommitdiff
path: root/internal/clients
diff options
context:
space:
mode:
authorPaul Buetow <git@mx.buetow.org>2020-12-26 11:44:31 +0000
committerPaul Buetow <git@mx.buetow.org>2020-12-26 11:44:31 +0000
commit60fa324cd5296b088c24d8db1d334a25ca955788 (patch)
tree88c14b39b66f5273cebf96307c86293b178cce40 /internal/clients
parentab676c2b484225ed22765b23d8f0545088ecd610 (diff)
initial spartan mode support
Diffstat (limited to 'internal/clients')
-rw-r--r--internal/clients/args.go1
-rw-r--r--internal/clients/baseclient.go2
-rw-r--r--internal/clients/catclient.go3
-rw-r--r--internal/clients/grepclient.go3
-rw-r--r--internal/clients/maprclient.go3
-rw-r--r--internal/clients/stats.go4
-rw-r--r--internal/clients/tailclient.go3
7 files changed, 12 insertions, 7 deletions
diff --git a/internal/clients/args.go b/internal/clients/args.go
index 34fcfa2..cd0f174 100644
--- a/internal/clients/args.go
+++ b/internal/clients/args.go
@@ -22,4 +22,5 @@ type Args struct {
SSHAuthMethods []gossh.AuthMethod
SSHHostKeyCallback gossh.HostKeyCallback
PrivateKeyPathFile string
+ Spartan bool
}
diff --git a/internal/clients/baseclient.go b/internal/clients/baseclient.go
index 69055a3..1e40ff2 100644
--- a/internal/clients/baseclient.go
+++ b/internal/clients/baseclient.go
@@ -70,7 +70,7 @@ func (c *baseClient) Start(ctx context.Context, statsCh <-chan string) (status i
// Periodically check for unknown hosts, and ask the user whether to trust them or not.
go c.hostKeyCallback.PromptAddHosts(ctx)
// Print client stats every time something on statsCh is recieved.
- go c.stats.Start(ctx, c.throttleCh, statsCh)
+ go c.stats.Start(ctx, c.throttleCh, statsCh, c.Args.Spartan)
// Keep count of active connections
active := make(chan struct{}, len(c.connections))
diff --git a/internal/clients/catclient.go b/internal/clients/catclient.go
index d8e9196..50a8d18 100644
--- a/internal/clients/catclient.go
+++ b/internal/clients/catclient.go
@@ -42,8 +42,9 @@ func (c CatClient) makeHandler(server string) handlers.Handler {
}
func (c CatClient) makeCommands() (commands []string) {
+ options := fmt.Sprintf("spartan=%v", c.Args.Spartan)
for _, file := range strings.Split(c.What, ",") {
- commands = append(commands, fmt.Sprintf("%s %s %s", c.Mode.String(), file, c.Regex.Serialize()))
+ commands = append(commands, fmt.Sprintf("%s:%s %s %s", c.Mode.String(), options, file, c.Regex.Serialize()))
}
return
}
diff --git a/internal/clients/grepclient.go b/internal/clients/grepclient.go
index e6fc94a..5fa0ae0 100644
--- a/internal/clients/grepclient.go
+++ b/internal/clients/grepclient.go
@@ -41,8 +41,9 @@ func (c GrepClient) makeHandler(server string) handlers.Handler {
}
func (c GrepClient) makeCommands() (commands []string) {
+ options := fmt.Sprintf("spartan=%v", c.Args.Spartan)
for _, file := range strings.Split(c.What, ",") {
- commands = append(commands, fmt.Sprintf("%s %s %s", c.Mode.String(), file, c.Regex.Serialize()))
+ commands = append(commands, fmt.Sprintf("%s:%s %s %s", c.Mode.String(), options, file, c.Regex.Serialize()))
}
return
diff --git a/internal/clients/maprclient.go b/internal/clients/maprclient.go
index 6aadd6b..d201d40 100644
--- a/internal/clients/maprclient.go
+++ b/internal/clients/maprclient.go
@@ -112,6 +112,7 @@ func (c MaprClient) makeHandler(server string) handlers.Handler {
func (c MaprClient) makeCommands() (commands []string) {
commands = append(commands, fmt.Sprintf("map %s", c.query.RawQuery))
+ options := fmt.Sprintf("spartan=%v", c.Args.Spartan)
modeStr := "cat"
if c.Mode == omode.TailClient {
@@ -123,7 +124,7 @@ func (c MaprClient) makeCommands() (commands []string) {
commands = append(commands, fmt.Sprintf("timeout %d %s %s %s", c.Timeout, modeStr, file, c.Regex.Serialize()))
continue
}
- commands = append(commands, fmt.Sprintf("%s %s %s", modeStr, file, c.Regex.Serialize()))
+ commands = append(commands, fmt.Sprintf("%s:%s %s %s", modeStr, options, file, c.Regex.Serialize()))
}
return
diff --git a/internal/clients/stats.go b/internal/clients/stats.go
index 2ec6f22..3ea59b7 100644
--- a/internal/clients/stats.go
+++ b/internal/clients/stats.go
@@ -34,7 +34,7 @@ func newTailStats(connectionsTotal int) *stats {
// Start starts printing client connection stats every time a signal is recieved or
// connection count has changed.
-func (s *stats) Start(ctx context.Context, throttleCh <-chan struct{}, statsCh <-chan string) {
+func (s *stats) Start(ctx context.Context, throttleCh <-chan struct{}, statsCh <-chan string, spartan bool) {
var connectedLast int
for {
@@ -55,7 +55,7 @@ func (s *stats) Start(ctx context.Context, throttleCh <-chan struct{}, statsCh <
newConnections := connected - connectedLast
- if connected == connectedLast && !force {
+ if (connected == connectedLast || spartan) && !force {
continue
}
diff --git a/internal/clients/tailclient.go b/internal/clients/tailclient.go
index ff2f46e..853bdf1 100644
--- a/internal/clients/tailclient.go
+++ b/internal/clients/tailclient.go
@@ -38,8 +38,9 @@ func (c TailClient) makeHandler(server string) handlers.Handler {
}
func (c TailClient) makeCommands() (commands []string) {
+ options := fmt.Sprintf("spartan=%v", c.Args.Spartan)
for _, file := range strings.Split(c.What, ",") {
- commands = append(commands, fmt.Sprintf("%s %s %s", c.Mode.String(), file, c.Regex.Serialize()))
+ commands = append(commands, fmt.Sprintf("%s:%s %s %s", c.Mode.String(), options, file, c.Regex.Serialize()))
}
logger.Debug(commands)