-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* prepare for command and control * allow setting QoS and ttd for publish
- Loading branch information
Showing
6 changed files
with
158 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea/ | ||
hot-* | ||
hot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 Red Hat Inc | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
|
||
package main | ||
|
||
import ( | ||
"bufio" | ||
"os" | ||
"time" | ||
) | ||
|
||
type CommandReader interface { | ||
ReadCommand(timeout time.Duration) *string | ||
} | ||
|
||
// noop command reader | ||
|
||
type NoopCommandReader struct { | ||
} | ||
|
||
func (_ *NoopCommandReader) ReadCommand(timeout time.Duration) *string { | ||
return nil | ||
} | ||
|
||
var _ CommandReader = &NoopCommandReader{} | ||
|
||
// stdin command reader | ||
|
||
type StdinCommandReader struct { | ||
} | ||
|
||
func (_ *StdinCommandReader) ReadCommand(timeout time.Duration) *string { | ||
|
||
s := make(chan string) | ||
e := make(chan error) | ||
|
||
go func() { | ||
reader := bufio.NewReader(os.Stdin) | ||
line, err := reader.ReadString('\n') | ||
if err != nil { | ||
e <- err | ||
} else { | ||
s <- line | ||
} | ||
close(s) | ||
close(e) | ||
}() | ||
|
||
select { | ||
case line := <-s: | ||
return &line | ||
case _ = <-e: | ||
return nil | ||
case <-time.After(timeout): | ||
return nil | ||
} | ||
|
||
} | ||
|
||
var _ CommandReader = &StdinCommandReader{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters